1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
|
#include <stdio.h>
#include <string.h>
#include "handwave.h"
#include "spelllist.h"
#include <libintl.h>
#define _(String) gettext (String)
struct maingame {
int ignorestuff;
};
static void PrintMsg(msg, gameval, rock)
char *msg;
game *gameval;
struct maingame *rock;
{
if (msg) {
printf("*: ");
fputs(msg, stdout);
}
}
static void PrintMsg2(person1, msg1, msgelse, gameval, rock)
int person1;
char *msg1, *msgelse;
game *gameval;
struct maingame *rock;
{
if (msg1) {
printf(_("%d: "), person1);
fputs(msg1, stdout);
}
if (msgelse) {
printf(_("~%d: "), person1);
fputs(msgelse, stdout);
}
}
static void PrintMsg3(person1, person2, msg1, msg2, msgelse, gameval, rock)
int person1, person2;
char *msg1, *msg2, *msgelse;
game *gameval;
struct maingame *rock;
{
if (msg1) {
printf(_("%d: "), person1);
fputs(msg1, stdout);
}
if (msg2) {
printf(_("%d: "), person2);
fputs(msg2, stdout);
}
if (msgelse) {
printf(_("~%d/~%d: "), person1, person2);
fputs(msgelse, stdout);
}
}
static void Queries(numqueries, qlist, gameval, rock)
int numqueries;
struct query qlist[];
game *gameval;
struct maingame *rock;
{
int ix, jx, attnum, spellnum;
int res;
char inbuf[256];
char outbuf[512];
static int targetlist[256];
static char *targetnamelist[256];
int numtargs, targnum;
int *hlist;
char *ques, *handage;
for (ix=0; ix<numqueries; ix++) {
switch (qlist[ix].qtype) {
case Qu_NoQuery:
/*printf(_("ERROR: got NoQuery\n"));*/
break;
case Qu_SetOffDelay:
printf(
_("%d: Do you want to release the %s from the Delayed Effect?\n (0:no, 1:yes): "),
qlist[ix].player,
_(spelllist[(int)qlist[ix].rock].name));
while (1) {
fgets(inbuf, 256, stdin);
res = atol(inbuf);
if (res!=0 && res!=1) {
printf(_(" [Please enter 0 or 1]: "));
}
else
break;
}
qlist[ix].answer = res;
break;
case Qu_LeftHand:
case Qu_RightHand:
if (qlist[ix].qtype==Qu_LeftHand)
ques = _("What spell do you want to cast with your left hand?");
else
ques = _("What spell do you want to cast with your right hand?");
hlist = (int *)qlist[ix].rock;
printf(_("%d: %s\n ("), qlist[ix].player, ques);
for (jx=0; jx<hlist[0]; jx++) {
spellnum = hlist[jx+1];
printf(_("%d: %s%s%s"), jx, _(spelllist[spellnum & (~QuVal_Hand_Both)].name),
((spellnum & QuVal_Hand_Both) ? _(" [both hands]") : ""),
(jx+1==hlist[0]) ? "): " : ", ");
}
while (1) {
fgets(inbuf, 256, stdin);
res = atol(inbuf);
if (res<0 || res>=hlist[0]) {
printf(_(" [Please enter a number from 0 to %d]: "), hlist[0]-1);
}
else
break;
}
qlist[ix].answer = res;
break;
case Qu_ElementalType:
printf(
_("%d: Which type of elemental do you want to summon?\n (0:fire, 1:ice): "),
qlist[ix].player);
while (1) {
fgets(inbuf, 256, stdin);
res = atol(inbuf);
if (res!=0 && res!=1) {
printf(_(" [Please enter 0 or 1]: "));
}
else
break;
}
qlist[ix].answer = res;
break;
case Qu_ParalysisHand:
printf(
_("%d: Which of %s's hands do you want to paralyze?\n (0:left, 1:right): "),
qlist[ix].player,
NameOfBeing(gameval, QuVal_Target_Wizard,
qlist[ix].rock));
while (1) {
fgets(inbuf, 256, stdin);
res = atol(inbuf);
if (res!=0 && res!=1) {
printf(_(" [Please enter 0 or 1]: "));
}
else
break;
}
qlist[ix].answer = res;
break;
case Qu_CharmHand:
printf(
_("%d: Which of %s's hands do you want to charm?\n (0:left, 1:right): "),
qlist[ix].player,
NameOfBeing(gameval, QuVal_Target_Wizard,
qlist[ix].rock));
while (1) {
fgets(inbuf, 256, stdin);
res = atol(inbuf);
if (res!=0 && res!=1) {
printf(_(" [Please enter 0 or 1]: "));
}
else
break;
}
qlist[ix].answer = res;
break;
case Qu_CharmGesture:
jx = (int)(qlist[ix].rock);
if (jx >= 128) {
spellnum = jx - 128;
jx = 1;
}
else {
spellnum = jx;
jx = 0;
}
printf(
_("%d: What gesture do you want %s's %s hand to make?\n (enter a letter): "),
qlist[ix].player,
NameOfBeing(gameval, QuVal_Target_Wizard,
spellnum), (jx?"right":"left"));
while (1) {
fgets(inbuf, 256, stdin);
if (inbuf[0]=='\0' || inbuf[0]=='\n') {
printf(_(" [Please enter a letter]: "));
}
else {
res = cheap_translate(inbuf[0]);
break;
}
}
qlist[ix].answer = res;
break;
case Qu_MonsterTarget:
jx = (int)(qlist[ix].rock);
attnum = jx / 256;
spellnum = jx % 256;
switch (attnum) {
case 1:
sprintf(outbuf, _("Whom do you want %s to attack?"),
NameOfBeing(gameval,
QuVal_Target_Creature, spellnum));
break;
case 2:
sprintf(outbuf, _("Whom do you want %s's first attack to be at?"),
NameOfBeing(gameval,
QuVal_Target_Creature, spellnum));
break;
case 3:
sprintf(outbuf, _("Whom do you want %s's second attack to be at?"),
NameOfBeing(gameval,
QuVal_Target_Creature, spellnum));
break;
default:
sprintf(outbuf, _("ERROR: Query about %d (%d)"), spellnum, attnum);
break;
}
printf(_("%d: %s\n"), qlist[ix].player, outbuf);
targnum = 0;
targetlist[targnum] = 0;
targetnamelist[targnum] = _("nobody");
targnum++;
numtargs = NumberOfTargets(gameval, QuVal_Target_Wizard);
for (jx=0; jx<numtargs; jx++) {
targetlist[targnum] = jx | QuVal_Target_Wizard;
targetnamelist[targnum] = NameOfTarget(gameval,
QuVal_Target_Wizard, jx);
targnum++;
}
numtargs = NumberOfTargets(gameval, QuVal_Target_Creature);
for (jx=0; jx<numtargs; jx++) {
targetlist[targnum] = jx | QuVal_Target_Creature;
targetnamelist[targnum] = NameOfTarget(gameval,
QuVal_Target_Creature, jx);
targnum++;
}
numtargs = targnum;
if (numtargs==0)
printf(_("ERROR: No targets available!\n"));
else {
printf(" [");
for (jx=0; jx<numtargs; jx++) {
printf(_("%d: %s%s"), jx, targetnamelist[jx],
((jx<numtargs-1)?"), ":""));
}
printf("]: ");
while (1) {
fgets(inbuf, 256, stdin);
res = atol(inbuf);
if (res<0 || res>=numtargs) {
printf(_(" [Please enter a number from 0 to %d]: "),
numtargs-1);
}
else
break;
}
qlist[ix].answer = targetlist[res];
}
break;
case Qu_WhichToDelay:
case Qu_WhichToPerm:
if (qlist[ix].qtype == Qu_WhichToDelay)
printf(_("%d: Which spell do you want to delay?\n"),
qlist[ix].player);
else
printf(_("%d: Which spell do you want to make permanent?\n"),
qlist[ix].player);
hlist = (int *)qlist[ix].rock;
printf(" [");
for (jx=0; hlist[jx]!=(-1); jx++) {
printf(_("%s%d: %s"), ((jx)?", ":""), jx, _(spelllist[hlist[jx]].name));
}
numtargs = jx;
printf("]: ");
while (1) {
fgets(inbuf, 256, stdin);
res = atol(inbuf);
if (res<0 || res>=numtargs) {
printf(_(" [Please enter a number from 0 to %d]: "), numtargs-1);
}
else
break;
}
qlist[ix].answer = res;
break;
case Qu_TargetBeing:
case Qu_TargetBeingNone:
case Qu_TargetWizard:
case Qu_TargetWizardNone:
case Qu_TargetRaiseDead:
jx = (int)(qlist[ix].rock);
spellnum = jx & (~QuVal_Hand_MASK);
if (jx & QuVal_Hand_Left)
handage = _("with your left hand");
else if (jx & QuVal_Hand_Right)
handage = _("with your right hand");
else if (jx & QuVal_Hand_Both)
handage = _("with both hands");
else
handage = _("from the Delayed Effect");
if (spellnum==SP__STAB)
sprintf(outbuf, _("Who do you want to stab at (%s)?"), handage);
else
sprintf(outbuf, _("Who do you want to cast %s at (%s)?"),
_(spelllist[spellnum].name), handage);
printf(_("%d: %s\n"), qlist[ix].player, outbuf);
targnum = 0;
if (qlist[ix].qtype==Qu_TargetBeingNone ||
qlist[ix].qtype==Qu_TargetWizardNone) {
targetlist[targnum] = 0;
targetnamelist[targnum] = _("nobody");
targnum++;
}
numtargs = NumberOfTargets(gameval, QuVal_Target_Wizard);
for (jx=0; jx<numtargs; jx++) {
targetlist[targnum] = jx | QuVal_Target_Wizard;
targetnamelist[targnum] = NameOfTarget(gameval,
QuVal_Target_Wizard, jx);
targnum++;
}
if (qlist[ix].qtype==Qu_TargetBeing ||
qlist[ix].qtype==Qu_TargetBeingNone ||
qlist[ix].qtype==Qu_TargetRaiseDead) {
numtargs = NumberOfTargets(gameval, QuVal_Target_Creature);
for (jx=0; jx<numtargs; jx++) {
targetlist[targnum] = jx | QuVal_Target_Creature;
targetnamelist[targnum] = NameOfTarget(gameval,
QuVal_Target_Creature, jx);
targnum++;
}
}
if (qlist[ix].qtype==Qu_TargetRaiseDead) {
numtargs = NumberOfTargets(gameval, QuVal_Target_Corpse);
for (jx=0; jx<numtargs; jx++) {
targetlist[targnum] = jx | QuVal_Target_Corpse;
targetnamelist[targnum] = NameOfTarget(gameval,
QuVal_Target_Corpse, jx);
targnum++;
}
}
numtargs = targnum;
if (numtargs==0)
printf(_("ERROR: No targets available!\n"));
else {
printf(" [");
for (jx=0; jx<numtargs; jx++) {
/* Check with original sources please. Maybe we stumbled here??? */
printf("%d: %s%s", jx, targetnamelist[jx], (jx<numtargs-1)?",":"");
}
printf("]: ");
while (1) {
fgets(inbuf, 256, stdin);
res = atol(inbuf);
if (res<0 || res>=numtargs) {
printf(_(" [Please enter a number from 0 to %d]: "),
numtargs-1);
}
else
break;
}
qlist[ix].answer = targetlist[res];
}
break;
default:
printf(_("ERROR: Unknown query type %d!\n"), qlist[ix].qtype);
break;
}
}
}
int cheap_translate(ch)
char ch;
{
switch (ch) {
case 'p':
case 'P':
return Gesture_PALM;
case 'f':
case 'F':
return Gesture_FINGERS;
case 'd':
case 'D':
return Gesture_DIGIT;
case 's':
case 'S':
return Gesture_SNAP;
case 'c':
case 'C':
return Gesture_CLAPHALF;
case 'w':
case 'W':
return Gesture_WAVE;
case 'k':
case 'K':
return Gesture_KNIFE;
case ' ':
case 'n':
case 'N':
default:
return Gesture_NOTHING;
}
}
void show_beings(gameval)
game *gameval;
{
int ix, max, hp;
printf("\n");
max = NumberOfBeings(gameval, QuVal_Target_Wizard);
for (ix=0; ix<max; ix++) {
hp = HitPointsOfBeing(gameval, QuVal_Target_Wizard, ix);
if (hp>=0)
printf(_("%s (%d); "), NameOfBeing(gameval, QuVal_Target_Wizard, ix), hp);
}
max = NumberOfBeings(gameval, QuVal_Target_Creature);
for (ix=0; ix<max; ix++) {
hp = HitPointsOfBeing(gameval, QuVal_Target_Creature, ix);
if (hp>=0)
printf("%s (%d); ", NameOfBeing(gameval, QuVal_Target_Creature, ix), hp);
}
printf("\n");
}
main(argc, argv)
int argc;
char *argv[];
{
struct interface procs;
struct maingame ignorerock;
game *gameval;
static char *namelist[MAXPLAYERS] = {"Arnold", "Barbara", "Crash"};
static int genderlist[MAXPLAYERS] = {Gender_MALE, Gender_FEMALE, Gender_NEUTER};
static int movelist[MAXPLAYERS*2];
static char inbuf[256];
int numplayers, whowon;
int ix, val;
procs.proc_PrintMsg = PrintMsg;
procs.proc_PrintMsg2 = PrintMsg2;
procs.proc_PrintMsg3 = PrintMsg3;
procs.proc_Queries = Queries;
numplayers = 2;
if (argc==2 && !strcmp(argv[1], "-3")) {
numplayers = 3;
}
else if (argc>=2) {
numplayers = 0;
for (ix=1; ix<argc; ix++) {
char *tmp;
namelist[numplayers] = argv[ix];
tmp = index(namelist[numplayers], ':');
if (!tmp)
genderlist[numplayers] = Gender_MALE;
else {
switch (*(tmp+1)) {
case 'f':
case 'F':
genderlist[numplayers] = Gender_FEMALE;
break;
case 'n':
case 'N':
genderlist[numplayers] = Gender_NEUTER;
break;
case 'x':
case 'X':
genderlist[numplayers] = Gender_NONE;
break;
case 'm':
case 'M':
default:
genderlist[numplayers] = Gender_MALE;
break;
}
*tmp = '\0';
}
numplayers++;
}
}
if (numplayers < 2) {
printf(_("You have listed only %d players!\n"), numplayers);
exit(12);
}
if (numplayers > MAXPLAYERS) {
printf(_("There is a maximum of %d players!\n"), MAXPLAYERS);
exit(12);
}
gameval = BeginGame(numplayers, namelist, genderlist, &procs, &ignorerock);
do {
show_beings(gameval);
val = 0;
switch (TurnType(gameval)) {
case Turn_HASTE:
printf(_("(hasted) "));
break;
case Turn_TIMESTOP:
printf(_("(timestopped) "));
break;
case Turn_NORMAL:
default:
break;
}
for (ix=0; ix<MAXPLAYERS; ix++)
if (TurnPlayerActive(gameval, ix)) {
val++;
printf(_("%d"), ix);
}
printf(_(": Enter moves: "));
bzero(inbuf, numplayers*2);
fgets(inbuf, 256, stdin);
for (ix=0; ix<numplayers*2; ix++) {
movelist[ix] = cheap_translate(inbuf[ix]);
}
whowon = RunTurn(gameval, movelist);
} while (whowon < 0);
if (whowon==MAXPLAYERS)
printf(_("+++ the game is a draw +++\n"));
else
printf(_("+++ %s has won +++\n"), namelist[whowon]);
FreeGame(gameval);
}
|