ularn.c 18 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028
  1. /* =============================================================================
  2. * PROGRAM: ularn
  3. * FILENAME: ularn.c
  4. *
  5. * DESCRIPTION:
  6. * This is the main module for ularn.
  7. * It contains the setup and main processing loop.
  8. *
  9. * =============================================================================
  10. * EXPORTED VARIABLES
  11. *
  12. * None.
  13. *
  14. * =============================================================================
  15. * EXPORTED FUNCTIONS
  16. *
  17. * None.
  18. *
  19. * =============================================================================
  20. */
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include "patchlevel.h"
  25. #include "ularn_game.h"
  26. #include "ularn_win.h"
  27. #include "ularn_ask.h"
  28. #include "getopt.h"
  29. #include "savegame.h"
  30. #include "scores.h"
  31. #include "header.h"
  32. #include "dungeon_obj.h"
  33. #include "dungeon.h"
  34. #include "player.h"
  35. #include "monster.h"
  36. #include "action.h"
  37. #include "object.h"
  38. #include "potion.h"
  39. #include "scroll.h"
  40. #include "spell.h"
  41. #include "show.h"
  42. #include "help.h"
  43. #include "diag.h"
  44. #include "itm.h"
  45. #ifdef WINDOWS
  46. #include <windows.h>
  47. #endif
  48. /* =============================================================================
  49. * Local variables
  50. */
  51. #define BUFSZ 256 /* for getlin buffers */
  52. #define MAX_CMDLINE_PARAM 255
  53. static char copyright[] =
  54. "\nVLarn by Jeffrey H. Johnson\n"
  55. " Ularn created by Phil Cordier -- based on Larn by Noah Morgan\n"
  56. " Updated by Josh Brandt and David Richerby\n"
  57. " Rewrite and Windows32/X11/Amiga graphics conversion by Julian Olds";
  58. static char cmdhelp[] = "\
  59. Cmd line format: vlarn [-sicnh] [-o <optsfile>] [-d #] [-r]\n\
  60. -s show the scoreboard\n\
  61. -i show the scoreboard with inventories\n\
  62. -c create new scoreboard (wizard only)\n\
  63. -n suppress welcome message when starting game\n\
  64. -h display this help message\n\
  65. -o <optsfile> specify options file to be used instead of \"~/vlarn.opt\"\n\
  66. -d # specify level of difficulty (example: vlarn -d 5)\n\
  67. -r restore checkpoint (vlarn.ckp) file\n";
  68. static char *optstring = "sicnhro:d:";
  69. static short viewflag;
  70. /* =============================================================================
  71. * Local functions
  72. */
  73. #ifdef WINDOWS
  74. /*
  75. * Windows programs don't use standard command line arguments, so provide
  76. * a function to convert the windows command line to argc, argv.
  77. */
  78. /* =============================================================================
  79. * FUNCTION: _get_cmd_arg
  80. *
  81. * DESCRIPTION:
  82. * Function to help process the windows command line into argc, argv
  83. * format.
  84. *
  85. * PARAMETERS:
  86. *
  87. * pCmdLine : The command line.
  88. *
  89. * RETURN VALUE:
  90. *
  91. * The next word on the command line.
  92. */
  93. static char* _get_cmd_arg(char* pCmdLine)
  94. {
  95. static char* pArgs = NULL;
  96. char *pRetArg;
  97. if ((pCmdLine == NULL) && (pArgs == NULL)) return NULL;
  98. if (pArgs == NULL) pArgs = pCmdLine;
  99. /* skip whitespace */
  100. for (pRetArg = pArgs; (*pRetArg != 0) && isspace(*pRetArg); pRetArg++);
  101. {
  102. if (*pRetArg == 0) {
  103. /* Hit end of string, so return */
  104. pArgs = NULL;
  105. return NULL;
  106. }
  107. }
  108. /* check for quote */
  109. if ( *pRetArg == '"' ) {
  110. pRetArg++;
  111. pArgs = strchr(pRetArg, '"');
  112. }else
  113. /* skip to whitespace */
  114. for (pArgs = pRetArg; (*pArgs != 0) && !isspace(*pArgs); pArgs++);
  115. if ((pArgs != NULL) && (*pArgs != 0) ) {
  116. char* p;
  117. p = pArgs;
  118. pArgs++;
  119. *p = 0;
  120. }else
  121. pArgs = NULL;
  122. return pRetArg;
  123. }
  124. #endif
  125. /* =============================================================================
  126. * FUNCTION: ULarnSetup
  127. *
  128. * DESCRIPTION:
  129. * Perform once off initialisation and parse the command parameters.
  130. *
  131. * PARAMETERS:
  132. *
  133. * argc : The command line argumant count
  134. *
  135. * argv : The command line arguments.
  136. *
  137. * RETURN VALUE:
  138. *
  139. * None.
  140. */
  141. void ULarnSetup(int argc, char *argv[])
  142. {
  143. int i;
  144. int hard;
  145. int restore_ckp;
  146. int set_optfile;
  147. int reset_scores;
  148. int show_scores;
  149. char buf[BUFSIZ];
  150. char *home;
  151. /* clear the loginname and logname */
  152. loginname[0] = 0;
  153. logname[0] = 0;
  154. set_display(DISPLAY_TEXT);
  155. ClearText();
  156. nap(100);
  157. #ifdef UNIX
  158. home = getenv("HOME");
  159. #else
  160. #ifdef AMIGA_WIN
  161. home = "";
  162. #else
  163. home = ".";
  164. #endif
  165. #endif
  166. /* set the save directory to the home directory by default */
  167. strcpy(savedir, home);
  168. /* initialize dungeon storage */
  169. init_cells();
  170. /* set the initial clock and initialise the random number generator*/
  171. newgame();
  172. hard = -1;
  173. restore_ckp = 0;
  174. set_optfile = 0;
  175. reset_scores = 0;
  176. show_scores = 0;
  177. /*
  178. * now process the command line arguments
  179. */
  180. opterr = 0;
  181. while ((i = ugetopt(argc, argv, optstring)) != -1) {
  182. switch (i) {
  183. case 's':
  184. show_scores = 1;
  185. break;
  186. case 'i':
  187. show_scores = 2;
  188. break;
  189. case 'c':
  190. reset_scores = 1;
  191. break;
  192. case 'n':
  193. nowelcome = 1;
  194. break;
  195. case 'd':
  196. /* specify hardness */
  197. hard = atoi(optarg);
  198. if (hard > 100) hard = 100;
  199. if (hard < 0) {
  200. Printf("Difficulty level must be > 0\n");
  201. Print(cmdhelp);
  202. get_prompt_input("\n\nPress space to exit", " ", 0);
  203. endgame();
  204. }
  205. break;
  206. case 'h':
  207. case '?':
  208. /* print out command line arguments */
  209. Printf("%s", copyright);
  210. Printf("\n\n Version %s.%s (%s)", LARN_VERSION, LARN_PATCHLEVEL, LARN_DATE);
  211. Printf("\n\n%s", cmdhelp);
  212. get_prompt_input("\n\nPress space to exit", " ", 0);
  213. endgame();
  214. break;
  215. case 'o':
  216. /* specify a Ularn.opt filename */
  217. strcpy(optsfile, optarg);
  218. set_optfile = 1;
  219. break;
  220. case 'r':
  221. /* restore checkpointed game */
  222. restore_ckp = 1;
  223. break;
  224. default:
  225. if (!opterr)
  226. Printf("Unknown option <%s>\n",
  227. argv[optind - 1]);
  228. Printf("%s\n", copyright);
  229. Printf("Version %s.%s (%s)\n", LARN_VERSION, LARN_PATCHLEVEL, LARN_DATE);
  230. Printf("%s", cmdhelp);
  231. get_prompt_input("\n\nPress space to exit", " ", 0);
  232. endgame();
  233. break;
  234. } /* end switch */
  235. } /* end while */
  236. /* Options filename was not specified on the command line, so set default */
  237. if (!set_optfile) {
  238. sprintf(buf, "%s/%s", home, optsfile);
  239. strcpy(optsfile, buf);
  240. }
  241. /* read the options file if there is one */
  242. read_options();
  243. /*
  244. * Process scorefile initialisation
  245. */
  246. /* the Ularn scoreboard filename */
  247. sprintf(scorefile, "%s/%s", libdir, SCORENAME);
  248. if (reset_scores) {
  249. /* anyone with password can create scoreboard */
  250. Print("Preparing to initialize the scoreboard.\n");
  251. if (getpassword() != 0) {
  252. if (makeboard() == -1) {
  253. Print("Scoreboard creation failed!!\n");
  254. endgame();
  255. }
  256. showscores();
  257. Print("\nScoreboard initialized.\n");
  258. }
  259. endgame();
  260. }
  261. if (show_scores == 1) {
  262. showscores();
  263. endgame();
  264. }else if (show_scores == 2) {
  265. showallscores();
  266. endgame();
  267. }
  268. /* now make scoreboard if it is not there (don't clear) */
  269. if (access(scorefile, 0) == -1) {
  270. /* score file not there */
  271. if (makeboard() == -1) {
  272. Printf("I can't create the scoreboard.\n");
  273. Printf("Check permissions on %s\n", libdir);
  274. endgame();
  275. }
  276. }
  277. /*
  278. * Get the user name and id.
  279. * For OS without usernames, use the logname, if it is specified.
  280. */
  281. strcpy(loginname, logname);
  282. GetUser(loginname, &userid);
  283. if (logname[0] == 0)
  284. /* no logname specified, so use loginname */
  285. strcpy(logname, loginname);
  286. /*
  287. * Set the file names
  288. */
  289. /* the Ularn on-line help file */
  290. sprintf(helpfile, "%s/%s", libdir, HELPNAME);
  291. /* the pre-made cave level data file */
  292. sprintf(larnlevels, "%s/%s", libdir, LEVELSNAME);
  293. /* the fortune data file name */
  294. sprintf(fortfile, "%s/%s", libdir, FORTSNAME);
  295. /* save file name in home directory */
  296. sprintf(savefilename, "%s/vlarn_%s.sav", savedir, loginname);
  297. /* the checkpoint file */
  298. sprintf(ckpfile, "%s/vlarn_%s.ckp", home, loginname);
  299. if (restore_ckp) {
  300. if (access(ckpfile, 0) == -1) {
  301. Printf("Cannot find checkpoint file %s\n", ckpfile);
  302. endgame();
  303. }
  304. Printf("Restoring...");
  305. restorflag = 1;
  306. hitflag = 1;
  307. restoregame(ckpfile);
  308. }
  309. /* restore game if need to, and haven't restored ckpfile */
  310. if (!restorflag && (access(savefilename, 0) == 0)) {
  311. restorflag = 1;
  312. hitflag = 1;
  313. Print("Restoring...");
  314. restoregame(savefilename);
  315. }
  316. /* create new game */
  317. if (restorflag == 0) {
  318. /* make the character that will play */
  319. /* XXX trn */
  320. wizard = 0;
  321. makeplayer();
  322. /* make the dungeon */
  323. newcavelevel(0);
  324. if (nowelcome == 0)
  325. /* welcome the player to the game */
  326. welcome();
  327. }
  328. /* set up the desired difficulty */
  329. sethard(hard);
  330. set_display(DISPLAY_MAP);
  331. showplayer();
  332. yrepcount = 0;
  333. hit2flag = 0;
  334. }
  335. /* =============================================================================
  336. * FUNCTION: parse
  337. *
  338. * DESCRIPTION:
  339. * Execute a command entered by the player.
  340. *
  341. * PARAMETERS:
  342. *
  343. * Action : The action command requested.
  344. *
  345. * RETURN VALUE:
  346. *
  347. * None.
  348. */
  349. void parse(ActionType Action)
  350. {
  351. int i, j;
  352. int flag;
  353. switch (Action) {
  354. case ACTION_DIAG:
  355. if (wizard)
  356. diag();
  357. yrepcount = 0;
  358. return;
  359. case ACTION_MOVE_WEST:
  360. moveplayer(4);
  361. return;
  362. case ACTION_RUN_WEST:
  363. run(4);
  364. return;
  365. case ACTION_MOVE_EAST:
  366. moveplayer(2);
  367. return;
  368. case ACTION_RUN_EAST:
  369. run(2);
  370. return;
  371. case ACTION_MOVE_SOUTH:
  372. moveplayer(1);
  373. return;
  374. case ACTION_RUN_SOUTH:
  375. run(1);
  376. return;
  377. case ACTION_MOVE_NORTH:
  378. moveplayer(3);
  379. return;
  380. case ACTION_RUN_NORTH:
  381. run(3);
  382. return;
  383. case ACTION_MOVE_NORTHEAST:
  384. moveplayer(5);
  385. return;
  386. case ACTION_RUN_NORTHEAST:
  387. run(5);
  388. return;
  389. case ACTION_MOVE_NORTHWEST:
  390. moveplayer(6);
  391. return;
  392. case ACTION_RUN_NORTHWEST:
  393. run(6);
  394. return;
  395. case ACTION_MOVE_SOUTHEAST:
  396. moveplayer(7);
  397. return;
  398. case ACTION_RUN_SOUTHEAST:
  399. run(7);
  400. return;
  401. case ACTION_MOVE_SOUTHWEST:
  402. moveplayer(8);
  403. return;
  404. case ACTION_RUN_SOUTHWEST:
  405. run(8);
  406. return;
  407. case ACTION_WAIT:
  408. if (yrepcount) viewflag = 1;
  409. return;
  410. case ACTION_NONE:
  411. yrepcount = 0;
  412. nomove = 1;
  413. return;
  414. case ACTION_WIELD:
  415. yrepcount = 0;
  416. wield();
  417. return;
  418. case ACTION_WEAR:
  419. yrepcount = 0;
  420. wear();
  421. return;
  422. case ACTION_READ:
  423. yrepcount = 0;
  424. if (c[BLINDCOUNT])
  425. Print("\nYou can't read anything when you're blind!");
  426. else if (c[TIMESTOP] == 0)
  427. readscr();
  428. return;
  429. case ACTION_QUAFF:
  430. yrepcount = 0;
  431. if (c[TIMESTOP] == 0)
  432. quaff();
  433. return;
  434. case ACTION_DROP:
  435. yrepcount = 0;
  436. if (c[TIMESTOP] == 0)
  437. dropobj();
  438. return;
  439. case ACTION_CAST_SPELL:
  440. yrepcount = 0;
  441. cast();
  442. return;
  443. case ACTION_OPEN_DOOR:
  444. yrepcount = 0;
  445. opendoor();
  446. return;
  447. case ACTION_CLOSE_DOOR:
  448. yrepcount = 0;
  449. closedoor();
  450. return;
  451. case ACTION_OPEN_CHEST:
  452. yrepcount = 0;
  453. openchest();
  454. return;
  455. case ACTION_INVENTORY:
  456. yrepcount = 0;
  457. nomove = 1;
  458. showstr();
  459. return;
  460. case ACTION_EAT_COOKIE:
  461. yrepcount = 0;
  462. if (c[TIMESTOP] == 0)
  463. eatcookie();
  464. return;
  465. case ACTION_LIST_SPELLS:
  466. yrepcount = 0;
  467. seemagic(0);
  468. nomove = 1;
  469. return;
  470. case ACTION_HELP:
  471. yrepcount = 0;
  472. help();
  473. nomove = 1;
  474. return;
  475. case ACTION_SAVE:
  476. ClearText();
  477. Print("Saving . . .");
  478. if (savegame(savefilename) == -1)
  479. Print("\nSave game failed.\n");
  480. wizard = 1; /* so not show scores */
  481. died(DIED_SUSPENDED, 0);
  482. return;
  483. case ACTION_TELEPORT:
  484. yrepcount = 0;
  485. if (wizard) {
  486. int t;
  487. Print("\nWhich level do you wish to teleport to? ");
  488. t = (int)get_num_input(20);
  489. if (t > VBOTTOM || t < 0) {
  490. Print(" sorry!");
  491. return;
  492. }
  493. playerx = (char)rnd(MAXX - 2);
  494. playery = (char)rnd(MAXY - 2);
  495. newcavelevel(t);
  496. positionplayer();
  497. draws(0, MAXX, 0, MAXY);
  498. UpdateStatusAndEffects();
  499. return;
  500. }
  501. if (c[LEVEL] >= INNATE_TELEPORT_LEVEL) {
  502. oteleport(1);
  503. return;
  504. }
  505. Print("\nYou don't know how to teleport yet.");
  506. return;
  507. case ACTION_IDENTIFY_TRAPS:
  508. flag = 0;
  509. yrepcount = 0;
  510. Printc('\n');
  511. for (j = playery - 1; j < playery + 2; j++) {
  512. if (j < 0) j = 0;
  513. if (j >= MAXY) break;
  514. for (i = playerx - 1; i < playerx + 2; i++) {
  515. if (i < 0) i = 0;
  516. if (i >= MAXX) break;
  517. switch (item[i][j]) {
  518. case OTRAPDOOR:
  519. case ODARTRAP:
  520. case OTRAPARROW:
  521. case OTELEPORTER:
  522. case OELEVATORUP:
  523. case OELEVATORDOWN:
  524. Print("\nIt's ");
  525. Print(objectname[(int)item[i][j]]);
  526. flag++;
  527. }
  528. }
  529. }
  530. if (flag == 0)
  531. Print("\nNo traps are visible.");
  532. return;
  533. case ACTION_BECOME_CREATOR:
  534. yrepcount = 0;
  535. nomove = 1;
  536. if (!wizard)
  537. if (getpassword() == 0)
  538. return;
  539. raiseexperience(370 * 1000000);
  540. recalc();
  541. UpdateStatus();
  542. drawscreen();
  543. return;
  544. case ACTION_CREATE_ITEM:
  545. yrepcount = 0;
  546. if (wizard)
  547. do_create();
  548. return;
  549. case ACTION_TOGGLE_WIZARD:
  550. yrepcount = 0;
  551. nomove = 1;
  552. if (wizard) {
  553. Print("\nYou are no longer a wizard.");
  554. wizard = 0;
  555. return;
  556. }
  557. if (getpassword()) {
  558. Print("\nYou are now a wizard.");
  559. wizard = 1;
  560. }else
  561. Print("Sorry.\n");
  562. return;
  563. case ACTION_DEBUG_MODE:
  564. yrepcount = 0;
  565. nomove = 1;
  566. if (!wizard) {
  567. if (getpassword() == 0)
  568. return;
  569. wizard = 1;
  570. }
  571. for (i = 0; i < 6; i++)
  572. c[i] = 70;
  573. iven[0] = ONOTHING;
  574. iven[1] = ONOTHING;
  575. take(OPROTRING, 50);
  576. take(OLANCE, 25);
  577. for (i = 0; i < IVENSIZE; i++) {
  578. if (iven[i] == OLANCE && ivenarg[i] == 25) {
  579. c[WIELD] = i;
  580. break;
  581. }
  582. }
  583. c[LANCEDEATH] = 1;
  584. c[WEAR] = c[SHIELD] = -1;
  585. raiseexperience(370 * 1000000);
  586. c[AWARENESS] += 25000;
  587. /* learn all spells, scrolls and potions */
  588. for (i = 0; i < SPELL_COUNT; i++) spelknow[i] = 1;
  589. for (i = 0; i < MAXSCROLL; i++) potionknown[i] = 1;
  590. for (i = 0; i < MAXPOTION; i++) potionknown[i] = 1;
  591. for (i = 0; i < MAXSCROLL; i++) {
  592. if (strlen(scrollname[i]) > 2) {
  593. item[i][0] = OSCROLL;
  594. iarg[i][0] = (short)i;
  595. }
  596. }
  597. for (i = 0; i < MAXPOTION; i++) {
  598. /* no null items */
  599. if (strlen(potionname[i]) > 2) {
  600. item[(MAXX - 1) - i][0] = OPOTION;
  601. iarg[(MAXX - 1) - i][0] = (short)(i);
  602. }
  603. }
  604. j = OALTAR;
  605. for (i = 1; i < MAXY; i++) {
  606. item[0][i] = (char)j;
  607. iarg[0][i] = (short)0;
  608. j++;
  609. }
  610. for (i = 1; i < MAXX; i++) {
  611. item[i][MAXY - 1] = (char)j;
  612. iarg[i][MAXY - 1] = (short)0;
  613. j++;
  614. }
  615. for (i = 1; i < MAXY - 1; i++) {
  616. item[MAXX - 1][i] = (char)j;
  617. iarg[MAXX - 1][i] = 0;
  618. j++;
  619. }
  620. for (i = 0; i < MAXY; i++)
  621. for (j = 0; j < MAXX; j++)
  622. know[j][i] = item[j][i];
  623. c[GOLD] += 250000;
  624. recalc();
  625. UpdateStatus();
  626. drawscreen();
  627. return;
  628. case ACTION_REMOVE_ARMOUR:
  629. yrepcount = 0;
  630. if (c[SHIELD] != -1) {
  631. c[SHIELD] = -1;
  632. Print("\nYour shield is off.");
  633. recalc();
  634. UpdateStatus();
  635. }else {
  636. if (c[WEAR] != -1) {
  637. c[WEAR] = -1;
  638. Print("\nYour armor is off.");
  639. recalc();
  640. UpdateStatus();
  641. }else
  642. Print("\nYou aren't wearing anything.");
  643. }
  644. return;
  645. case ACTION_PACK_WEIGHT:
  646. Printf("\nThe stuff you are carrying presently weighs %d pound%s.",
  647. (long)packweight(),
  648. plural(packweight()));
  649. nomove = 1;
  650. yrepcount = 0;
  651. return;
  652. case ACTION_VERSION:
  653. yrepcount = 0;
  654. Printf("\nVLarn %s.%s (%s) - Difficulty level %d",
  655. LARN_VERSION,
  656. LARN_PATCHLEVEL,
  657. LARN_DATE,
  658. (long)c[HARDGAME]);
  659. if (wizard) Print(" (WIZARD)");
  660. nomove = 1;
  661. if (cheat) Print(" (Cheater)");
  662. Print(copyright);
  663. return;
  664. case ACTION_QUIT:
  665. yrepcount = 0;
  666. quit();
  667. nomove = 1;
  668. return;
  669. case ACTION_REDRAW_SCREEN:
  670. yrepcount = 0;
  671. drawscreen();
  672. nomove = 1;
  673. return;
  674. case ACTION_SHOW_TAX:
  675. if (outstanding_taxes > 0)
  676. Printf("\nYou presently owe %d gp in taxes.", (long)outstanding_taxes);
  677. else
  678. Print("\nYou do not owe any taxes.");
  679. return;
  680. default:
  681. Print("HELP! unknown command\n");
  682. break;
  683. }
  684. }
  685. #ifdef WINDOWS
  686. /* windows uses WinMain instead of main */
  687. /* =============================================================================
  688. * FUNCTION: WinMain
  689. *
  690. * DESCRIPTION:
  691. * Windows main entry point.
  692. *
  693. * PARAMETERS:
  694. *
  695. * hinstance : This isntance of the application
  696. *
  697. * hprevinstance : The previous instance of the application (if any)
  698. *
  699. * lpcmdline : The command line
  700. *
  701. * ncmdshow : The initial state for the application window
  702. *
  703. * RETURN VALUE:
  704. *
  705. * Exit status of the application.
  706. * 0 => normal exit.
  707. */
  708. int WINAPI WinMain(
  709. HINSTANCE hinstance,
  710. HINSTANCE hprevinstance,
  711. LPSTR lpcmdline,
  712. int ncmdshow)
  713. #else
  714. /* =============================================================================
  715. * FUNCTION: main
  716. *
  717. * DESCRIPTION:
  718. * Main entry point.
  719. *
  720. * PARAMETERS:
  721. *
  722. * argc : Command line argument count
  723. *
  724. * argv : Command line argument strings
  725. *
  726. * RETURN VALUE:
  727. *
  728. * Exit status of the application.
  729. * 0 => normal exit.
  730. */
  731. int main(int argc, char *argv[])
  732. #endif
  733. {
  734. ActionType Action;
  735. #ifdef WINDOWS
  736. int argc;
  737. char* argv[MAX_CMDLINE_PARAM];
  738. TCHAR *p;
  739. TCHAR wbuf[BUFSZ];
  740. char buf[BUFSZ];
  741. size_t len;
  742. #endif
  743. #ifdef AMIGA_WIN
  744. int StartedFromWB = 0;
  745. char *fake_argv[1] = { "ularn" };
  746. #endif
  747. #ifdef UNIX_X11
  748. init_app(getenv("DISPLAY"));
  749. #else
  750. #ifdef WINDOWS
  751. /*
  752. * get command line parameters
  753. */
  754. p = _get_cmd_arg(GetCommandLine());
  755. p = _get_cmd_arg(NULL); /* skip first paramter - command name */
  756. for (argc = 1; p && argc < MAX_CMDLINE_PARAM; argc++ ) {
  757. len = strlen(p);
  758. if ( len > 0 )
  759. argv[argc] = strdup(p);
  760. else
  761. argv[argc] = "";
  762. p = _get_cmd_arg(NULL);
  763. }
  764. GetModuleFileName(NULL, wbuf, BUFSZ);
  765. argv[0] = strdup(strncpy(wbuf, buf, BUFSZ));
  766. //
  767. // Setup the display interface
  768. //
  769. if (!init_app(hinstance))
  770. return 0;
  771. #else
  772. #ifdef AMIGA_WIN
  773. /* The Amiga sets argc to 0 if the program was started from Workbench
  774. * In this case the arg list points to a WBStartup structure instead
  775. * of and array of arguments.
  776. */
  777. if (argc == 0)
  778. StartedFromWB = 1;
  779. if (!init_app()) {
  780. close_app();
  781. return 0;
  782. }
  783. #else
  784. init_app();
  785. #endif
  786. #endif
  787. #endif
  788. #ifdef AMIGA_WIN
  789. if (!StartedFromWB)
  790. ULarnSetup(argc, argv);
  791. else
  792. /* fake parameters */
  793. ULarnSetup(1, fake_argv);
  794. #else
  795. ULarnSetup(argc, argv);
  796. #endif
  797. /* Everything should be common from here on */
  798. do{
  799. if (dropflag == 0) {
  800. lookforobject(); /* see if there is an object here*/
  801. }else {
  802. dropflag = 0; /* don't show it just dropped an item */
  803. }
  804. if (hitflag == 0) {
  805. if (c[HASTEMONST]) movemonst();
  806. movemonst();
  807. }
  808. if (viewflag == 0)
  809. showcell(playerx, playery);
  810. else{
  811. viewflag = 0; /* show stuff around player */
  812. }
  813. hitflag = 0;
  814. hit3flag = 0;
  815. nomove = 1;
  816. /* get commands and make moves */
  817. while (nomove) {
  818. nomove = 0;
  819. Action = get_normal_input();
  820. parse(Action); /* may reset nomove=1 */
  821. }
  822. /* regenerate hp and spells */
  823. regen();
  824. if (c[TIMESTOP] == 0) {
  825. rmst--;
  826. if (rmst <= 0) {
  827. rmst = (char)(120 - (level << 2));
  828. fillmonst(makemonst(level));
  829. }
  830. }
  831. } while (Action != ACTION_QUIT);
  832. /*
  833. * tidyup and exit
  834. */
  835. endgame();
  836. /* not actually reachable */
  837. return 0;
  838. }