counter.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978
  1. /* $Id$
  2. * MegaZeux
  3. *
  4. * Copyright (C) 1996 Greg Janson
  5. * Copyright (C) 1998 Matthew D. Williams - dbwilli@scsn.net
  6. * Copyright (C) 1999 Charles Goetzman
  7. * Copyright (C) 2002 B.D.A - Koji_takeo@worldmailer.com
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. */
  23. // Code for setting and retrieving counters and keys.
  24. #include <time.h>
  25. #include <dos.h>
  26. #include <io.h>
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include "counter.h"
  30. #include "egacode.h"
  31. #include "admath.h"
  32. #include "blink.h"
  33. #include "const.h"
  34. #include "cursor.h"
  35. #include "data.h"
  36. #include "egacode.h"
  37. #include "game.h"
  38. #include "game2.h"
  39. #include "graphics.h"
  40. #include "idarray.h"
  41. #include "idput.h"
  42. #include "mouse.h"
  43. #include "palette.h"
  44. #include "runrobot.h"
  45. #include "sfx.h"
  46. #include "string.h"
  47. #include "struct.h"
  48. #include "conio.h"
  49. // I took away the mzxakversion stuff. So you no longer
  50. // have to set "mzxakversion" to 1. -Koji
  51. //Temp vars for new funcitons
  52. int dir,dirx,diry,loc;
  53. // Date and Time data
  54. struct time t;
  55. struct date d;
  56. //File stuff
  57. FILE *inputfile;
  58. FILE *outputfile;
  59. long offset;
  60. char fileio;
  61. void set_built_in_messages(int param);
  62. int player_restart_x=0,player_restart_y=0,gridxsize=1,gridysize=1;
  63. int myscrolledx=0,myscrolledy=0;
  64. //int MZXAKWENDEVERSION = 0;
  65. //Some added variables to speed up pixel editing -Koji
  66. unsigned char pixel_x = 0, pixel_y = 0;
  67. //if (inputfile != NULL)
  68. // fclose(inputfile);
  69. //if (outputfile != NULL)
  70. // fclose(outputfile);
  71. char was_zapped=0;
  72. extern char mid_prefix;
  73. void prefix_xy(int&fx,int&fy,int&mx,int&my,int&lx,int&ly,int robotx,
  74. int roboty);
  75. //Get a counter. Include robot id if a robot is running.
  76. int get_counter(char far *name,unsigned char id) {
  77. int t1;
  78. //a few counters convert to var's for speed.
  79. if(!str_cmp(name,"CHAR_X")) return pixel_x;
  80. if(!str_cmp(name,"CHAR_Y")) return pixel_y;
  81. if(!str_cmp(name,"PLAYERDIST")) return abs((robots[id].xpos-player_x)
  82. +(robots[id].ypos-player_y));
  83. //REAL distance -Koji
  84. // Can only handle real distances up to 129.
  85. // Can't seem to help that.
  86. if(!str_cmp(name,"R_PLAYERDIST"))
  87. {
  88. long d;
  89. d= (long)((robots[id].xpos-player_x)
  90. *(robots[id].xpos-player_x));
  91. d+=(long)((robots[id].ypos-player_y)
  92. *(robots[id].ypos-player_y));
  93. if (d < 16384)
  94. return sqrt(d);
  95. else return 129;
  96. }
  97. //Reads a single byte of a char -Koji
  98. if(!str_cmp(name,"CHAR_BYTE"))
  99. return *(curr_set + (get_counter("CHAR") * 14) + (get_counter("BYTE") % 14));
  100. //Reads a single pixel - Koji
  101. // I was really tired the night I was trying to make this.
  102. // and Exophase practically gave me the source
  103. // I would've made one myself the next day, but it's already done.
  104. if(!str_cmp(name,"PIXEL"))
  105. {
  106. int pixel_mask;
  107. char sub_x, sub_y, current_byte;
  108. unsigned char current_char;
  109. sub_x = pixel_x % 8;
  110. sub_y = pixel_y % 14;
  111. current_char = ((pixel_y / 14) * 32) + (pixel_x / 8);
  112. current_byte = *(curr_set+(current_char*14)+sub_y);
  113. pixel_mask = (128 >> sub_x);
  114. return (current_byte & pixel_mask) >> (7 - sub_x);
  115. }
  116. //Read binary positions of "INT" ("bit_place" = 0-15) - Koji
  117. if(!str_cmp(name,"INT2BIN"))
  118. {
  119. unsigned int integer;
  120. int bin_mask, place;
  121. place = ((get_counter("BIT_PLACE") % 16) * -1) + 15;
  122. integer = get_counter("INT") + 32768;
  123. bin_mask = (32768 >> place);
  124. return (integer & bin_mask) >> (15 - place);
  125. }
  126. //Open inputfile! -Koji
  127. if(!str_cmp(name,"FREAD_OPEN"))
  128. {
  129. fileio = 1;
  130. return 0;
  131. }
  132. //opens outputfile as normal. -Koji
  133. if(!str_cmp(name,"FWRITE_OPEN"))
  134. {
  135. fileio = 2;
  136. return 0;
  137. }
  138. //Opens outputfile as APPEND. -Koji
  139. if(!str_cmp(name,"FWRITE_APPEND"))
  140. {
  141. fileio = 3;
  142. return 0;
  143. }
  144. //Reads from inputfile. -Koji
  145. if(!str_cmp(name,"FREAD"))
  146. {
  147. if(inputfile == NULL) return -1;
  148. return fgetc(inputfile);
  149. }
  150. //Ok, ok. I did steal the "pos" within "page" idea from Akwende.
  151. //It is a great idea to be able to read more than 32767 bytes.
  152. // -Koji
  153. if(!str_cmp(name,"FREAD_POS"))
  154. {
  155. if(inputfile == NULL) return -1;
  156. return (ftell(inputfile) % 32767);
  157. }
  158. if(!str_cmp(name,"FREAD_PAGE"))
  159. {
  160. if(inputfile == NULL) return -1;
  161. return (ftell(inputfile) / 32767);
  162. }
  163. if(!str_cmp(name,"FWRITE_POS"))
  164. {
  165. if(outputfile == NULL) return -1;
  166. return (ftell(outputfile) % 32767);
  167. }
  168. if(!str_cmp(name,"FWRITE_PAGE"))
  169. {
  170. if(outputfile == NULL) return -1;
  171. return (ftell(outputfile) / 32767);
  172. }
  173. if(!str_cmp(name,"FREAD_LENGTH"))
  174. {
  175. if(inputfile == NULL) return -1;
  176. return filelength(fileno(inputfile));
  177. }
  178. if(!str_cmp(name,"FWRITE_LENGTH"))
  179. {
  180. if(outputfile == NULL) return -1;
  181. return filelength(fileno(outputfile));
  182. }
  183. // }if(MZXAKWENDEVERSION == 1)
  184. // {
  185. if(!str_cmp(name,"OVERLAY_MODE"))
  186. return overlay_mode;
  187. // if(!str_cmp(name,"SMZX_MODE"))
  188. // return smzx_mode;
  189. if(!str_cmp(name,"DATE_DAY"))
  190. {
  191. getdate(&d);
  192. return d.da_day;
  193. }
  194. if(!str_cmp(name,"DATE_YEAR"))
  195. {
  196. getdate(&d);
  197. return d.da_year;
  198. }
  199. if(!str_cmp(name,"DATE_MONTH"))
  200. {
  201. getdate(&d);
  202. return d.da_mon;
  203. }
  204. if(!str_cmp(name,"TIME_SECONDS"))
  205. {
  206. gettime(&t);
  207. return t.ti_sec;
  208. }
  209. if(!str_cmp(name,"TIME_MINUTES"))
  210. {
  211. gettime(&t);
  212. return t.ti_min;
  213. }
  214. if(!str_cmp(name,"TIME_HOURS"))
  215. {
  216. gettime(&t);
  217. return t.ti_hour;
  218. }
  219. // }
  220. if(!str_cmp(name,"LOOPCOUNT"))
  221. return robots[id].loop_count;
  222. if(!str_cmp(name,"LOCAL"))
  223. return robots[id].blank;
  224. if(!str_cmp(name,"MZX_SPEED"))
  225. return overall_speed;
  226. //First, check for robot specific counters
  227. if(!str_cmp(name,"BULLETTYPE"))
  228. return robots[id].bullet_type;
  229. if(!str_cmp(name,"HORIZPLD"))
  230. return abs(robots[id].xpos-player_x);
  231. if(!str_cmp(name,"VERTPLD"))
  232. return abs(robots[id].ypos-player_y);
  233. if(!str_cmp(name,"THISX"))
  234. {
  235. if(mid_prefix<2) return robots[id].xpos;
  236. else if(mid_prefix==2) return robots[id].xpos-player_x;
  237. else return robots[id].xpos-get_counter("XPOS");
  238. }
  239. if(!str_cmp(name,"THISY"))
  240. {
  241. if(mid_prefix<2) return robots[id].ypos;
  242. else if(mid_prefix==2) return robots[id].ypos-player_y;
  243. else return robots[id].ypos-get_counter("YPOS");
  244. }
  245. //Next, check for global, non-standard counters
  246. if(!str_cmp(name,"INPUT")) return num_input;
  247. if(!str_cmp(name,"INPUTSIZE")) return input_size;
  248. if(!str_cmp(name,"KEY")) return last_key;
  249. if(!str_cmp(name,"SCORE")) return (unsigned int)score;
  250. if(!str_cmp(name,"TIMERESET")) return time_limit;
  251. if(!str_cmp(name,"PLAYERFACEDIR")) return player_last_dir>>4;
  252. if(!str_cmp(name,"PLAYERLASTDIR")) return player_last_dir&15;
  253. // Mouse info Spid
  254. if(!str_cmp(name,"MOUSEX")) return saved_mouse_x;
  255. if(!str_cmp(name,"MOUSEY")) return saved_mouse_y;
  256. if(!str_cmp(name,"BUTTONS")) return saved_mouse_buttons;
  257. // scroll_x and scroll_y never work, always return 0. Spid
  258. if(!str_cmp(name,"SCROLLEDX"))
  259. {
  260. calculate_xytop(myscrolledx,myscrolledy);
  261. return myscrolledx;
  262. }
  263. if(!str_cmp(name,"SCROLLEDY"))
  264. {
  265. calculate_xytop(myscrolledx,myscrolledy);
  266. return myscrolledy;
  267. }
  268. // Player position Spid
  269. if(!str_cmp(name,"PLAYERX")) return player_x;
  270. if(!str_cmp(name,"PLAYERY")) return player_y;
  271. if(!str_cmp(name,"MBOARDX"))
  272. {
  273. calculate_xytop(myscrolledx,myscrolledy);
  274. return (mousex + myscrolledx - viewport_x);
  275. }
  276. if(!str_cmp(name,"MBOARDY"))
  277. {
  278. calculate_xytop(myscrolledx,myscrolledy);
  279. return (mousey + myscrolledy - viewport_y);
  280. }
  281. // Functions added :by Akwende
  282. // Adds Time Counters, and access to internal Robot ID
  283. // if(MZXAKWENDEVERSION == 1)
  284. // {
  285. // if(!str_cmp(name,"ROBOT_ID"))
  286. // return id;
  287. if(!str_cmp(name,"OVERLAY_CHAR"))
  288. {
  289. if (overlay_mode == 0) return 0;
  290. loc = get_counter("OVERLAY_X",id);
  291. if(loc > board_xsiz)
  292. return 0;
  293. loc += (get_counter("OVERLAY_Y",id) * board_xsiz);
  294. if(loc > (board_xsiz * board_ysiz))
  295. return 0;
  296. return overlay[loc];
  297. }
  298. if(!str_cmp(name,"OVERLAY_COLOR"))
  299. {
  300. if (overlay_mode == 0) return 0;
  301. loc = get_counter("OVERLAY_X",id);
  302. if(loc > board_xsiz)
  303. return 0;
  304. loc += (get_counter("OVERLAY_Y",id) * board_xsiz);
  305. if(loc > (board_xsiz * board_ysiz))
  306. return 0;
  307. return overlay_color[loc];
  308. }
  309. if(!str_cmp(name,"BOARD_CHAR"))
  310. {
  311. loc = get_counter("BOARD_X",id);
  312. if(loc > board_xsiz)
  313. return 0;
  314. loc += (get_counter("BOARD_Y",id) * board_xsiz);
  315. if(loc > (board_xsiz * board_ysiz))
  316. return 0;
  317. return get_id_char(loc);
  318. }
  319. if(!str_cmp(name,"BOARD_COLOR"))
  320. {
  321. loc = get_counter("BOARD_X",id);
  322. if(loc > board_xsiz)
  323. return 0;
  324. loc += (get_counter("BOARD_Y",id) * board_xsiz);
  325. if(loc > (board_xsiz * board_ysiz))
  326. return 0;
  327. return level_color[loc];
  328. }
  329. if(!str_cmp(name,"RED_VALUE"))
  330. {
  331. return get_Color_Aspect(get_counter("CURRENT_COLOR",id),0);
  332. }
  333. if(!str_cmp(name,"GREEN_VALUE"))
  334. {
  335. return get_Color_Aspect(get_counter("CURRENT_COLOR",id),1);
  336. }
  337. if(!str_cmp(name,"BLUE_VALUE"))
  338. {
  339. return get_Color_Aspect(get_counter("CURRENT_COLOR",id),2);
  340. }
  341. if(!str_cmp(name,"BULLET_TYPE"))
  342. {
  343. return robots[id].bullet_type;
  344. }
  345. //My_target messed with the can_lavawalk local
  346. //I'll just make it into a new local with that name -Koji
  347. if(!str_cmp(name,"LAVA_WALK"))
  348. {
  349. return robots[id].can_lavawalk;
  350. }
  351. if(!str_cmp(name,"THIS_CHAR"))
  352. return robots[id].robot_char;
  353. if(!str_cmp(name,"THIS_COLOR"))
  354. return level_color[robots[id].ypos * board_xsiz + robots[id].xpos];
  355. /*
  356. if(!str_cmp(name,"GET_TARGET_ID"))
  357. {
  358. loc = get_counter("BOARD_X",id);
  359. if(mid_prefix==1)
  360. {
  361. loc+= robots[id].xpos;
  362. loc += ((get_counter("BOARD_Y",id)+ robots[id].ypos) * board_xsiz);
  363. }
  364. else
  365. {
  366. if(mid_prefix==2)
  367. {
  368. loc+= player_x;
  369. loc += ((get_counter("BOARD_Y",id)+ player_y) * board_xsiz);
  370. }
  371. else
  372. {
  373. int temp = get_counter("YPOS");
  374. loc+= temp;
  375. loc+= ((get_counter("BOARD_Y",id)+ temp) * board_xsiz);
  376. }
  377. }
  378. if ((level_id[loc] == 123) || (level_id[loc] ==124))
  379. return level_param[loc];
  380. else
  381. return 0;
  382. }
  383. if(!str_cmp(name,"TARGET_X"))
  384. {
  385. return robots[robots[id].can_lavawalk].xpos;
  386. }
  387. if(!str_cmp(name,"TARGET_Y"))
  388. return robots[robots[id].can_lavawalk].ypos;
  389. if(!str_cmp(name,"TARGET_XDIR"))
  390. {
  391. dir = robots[robots[id].can_lavawalk].xpos - robots[id].xpos;
  392. if (dir == 0) return 0;
  393. return dir/abs(dir);
  394. }
  395. if(!str_cmp(name,"TARGET_YDIR"))
  396. {
  397. dir = robots[robots[id].can_lavawalk].ypos - robots[id].ypos;
  398. if (dir == 0) return 0;
  399. return dir/abs(dir);
  400. }
  401. if(!str_cmp(name,"TARGET_DIST"))
  402. {
  403. diry = robots[robots[id].can_lavawalk].ypos;
  404. diry -= robots[id].ypos;
  405. dirx = robots[robots[id].can_lavawalk].xpos;
  406. dirx = robots[id].xpos;
  407. return abs(dirx) + abs(diry);
  408. }*/
  409. // }
  410. //Now search counter structs
  411. for(t1=0;t1<NUM_COUNTERS;t1++)
  412. if(!str_cmp(name,counters[t1].counter_name)) break;
  413. if(t1<NUM_COUNTERS) return counters[t1].counter_value;
  414. return 0;//Not found
  415. }
  416. //Sets the value of a counter. Include robot id if a robot is running.
  417. void set_counter(char far *name,int value,unsigned char id) {
  418. int t1;
  419. //File protocal -Koji
  420. if(fileio > 0)
  421. { //This can be good thing or a bad thing...
  422. //I'd say it'd be wise to seclude a new game
  423. //inside a it's own folder to fight against
  424. //a posible viral threat. -Koji
  425. if(fileio == 1)
  426. {
  427. //read
  428. if(inputfile != NULL)
  429. fclose(inputfile);
  430. inputfile = fopen(name,"rb");
  431. }
  432. if(fileio == 2)
  433. {
  434. //write
  435. if(outputfile != NULL)
  436. fclose(outputfile);
  437. outputfile = fopen(name,"wb");
  438. }
  439. if(fileio == 3)
  440. {
  441. //Append
  442. if(outputfile != NULL)
  443. fclose(outputfile);
  444. outputfile = fopen(name,"ab");
  445. }
  446. fileio = 0;
  447. return;
  448. }
  449. //Ok, ok. I did steal the "pos" within "page" idea from Akwende.
  450. //It is a great idea to be able to read more than 32767 bytes.
  451. // The pages are limited to 256, so The max size of a file is
  452. // about 8MB
  453. // -Koji
  454. if(!str_cmp(name,"FREAD_POS"))
  455. {
  456. if(inputfile == NULL)
  457. return;
  458. offset = 32767 * get_counter("FREAD_PAGE") + value;
  459. fseek(inputfile,offset,0);
  460. }
  461. if(!str_cmp(name,"FREAD_PAGE"))
  462. {
  463. value %= 256;
  464. if(inputfile == NULL)
  465. return;
  466. offset = 32767 * value + get_counter("FREAD_POS");
  467. fseek(inputfile,offset,0);
  468. }
  469. if(!str_cmp(name,"FWRITE_POS"))
  470. {
  471. if(outputfile == NULL)
  472. return;
  473. offset = 32767 * get_counter("FWRITE_PAGE") + value;
  474. fseek(outputfile,offset,0);
  475. }
  476. if(!str_cmp(name,"FWRITE_PAGE"))
  477. {
  478. value %= 256;
  479. if(outputfile == NULL)
  480. return;
  481. offset = 32767 * value + get_counter("FWRITE_POS");
  482. fseek(outputfile,offset,0);
  483. }
  484. //Writes to the outputfile. -Koji
  485. if(!str_cmp(name,"FWRITE"))
  486. {
  487. if(outputfile == NULL)
  488. return;
  489. fputc(value % 256,outputfile);
  490. return;
  491. }
  492. if(!str_cmp(name,"CHAR_X")) {
  493. pixel_x = value;
  494. return;
  495. }
  496. if(!str_cmp(name,"CHAR_Y")) {
  497. pixel_y = value;
  498. return;
  499. }
  500. //Writes to a single byte of a char -koji
  501. if(!str_cmp(name,"CHAR_BYTE")) {
  502. *(curr_set + (get_counter("CHAR") * 14) + (get_counter("BYTE") % 14)) = value;
  503. return;
  504. }
  505. //Writes to a pixel -Koji
  506. if(!str_cmp(name,"PIXEL"))
  507. {
  508. char sub_x, sub_y, current_byte;
  509. unsigned char current_char;
  510. pixel_x = abs(pixel_x % 256);
  511. pixel_y = abs(pixel_y % 112);
  512. sub_x = pixel_x % 8;
  513. sub_y = pixel_y % 14;
  514. current_char = ((pixel_y / 14) * 32) + (pixel_x / 8);
  515. current_byte = ec_read_byte(current_char, sub_y);
  516. if(value == 0)
  517. {
  518. //clear
  519. current_byte &= ~(128 >> sub_x);
  520. *(curr_set + (current_char * 14) + (sub_y % 14)) = (current_byte % 256);
  521. }
  522. else if(value == 1)
  523. {
  524. //set
  525. current_byte |= (128 >> sub_x);
  526. *(curr_set + (current_char * 14) + (pixel_y % 14)) = (current_byte % 256);
  527. }
  528. else
  529. {
  530. //toggle
  531. current_byte ^= (128 >> sub_x);
  532. *(curr_set + (current_char * 14) + (pixel_y % 14)) = (current_byte % 256);
  533. }
  534. return;
  535. }
  536. //Writes a single bit to a given bit place of "INT" -Koji
  537. //(bit place = 0-15)
  538. if(!str_cmp(name,"INT2BIN"))
  539. {
  540. unsigned int integer;
  541. int place;
  542. place = ((get_counter("BIT_PLACE") % 16) * (-1)) + 15;
  543. integer = get_counter("INT") + 32768;
  544. if(value % 3 == 0)
  545. {
  546. //clear
  547. integer &= ~(32768 >> place);
  548. set_counter("INT", integer - 32768);
  549. }
  550. else if(value % 3 == 1)
  551. {
  552. //set
  553. integer |= (32768 >> place);
  554. set_counter("INT", integer - 32768);
  555. }
  556. else
  557. {
  558. //toggle
  559. integer ^= (32768 >> place);
  560. set_counter("INT", integer - 32768);
  561. }
  562. }
  563. //First, check for robot specific counters
  564. /* if(!str_cmp(name,"MZXAKVERSION"))
  565. {
  566. MZXAKWENDEVERSION = value % 2;
  567. return;
  568. }
  569. */
  570. //Functions added by Akwende
  571. //ABS Value Function
  572. // if(MZXAKWENDEVERSION == 1)
  573. // {
  574. if(!str_cmp(name,"ABS_VALUE"))
  575. {
  576. if (value < 0 ) value = value * -1;
  577. set_counter("VALUE",value,id);
  578. return;
  579. }
  580. if(!str_cmp(name,"SQRT_VALUE"))
  581. {
  582. set_counter("VALUE",sqrt(value),id);
  583. return;
  584. }
  585. //Akwende tried to make another overlay... Tried! -koji
  586. /* if(!str_cmp(name,"OVERLAY_MODE_4"))
  587. {
  588. overlay_mode = 4;
  589. }
  590. */
  591. /* if(!str_cmp(name,"SMZX_MODE"))
  592. {
  593. smzx_mode = (char)value % 3;
  594. if(smzx_mode==1)
  595. {
  596. smzx_14p_mode();
  597. cursor_off();
  598. blink_off();
  599. ec_update_set();
  600. //init_palette();
  601. smzx_update_palette(0);
  602. }
  603. else
  604. {
  605. if(smzx_mode==1)
  606. {
  607. ega_14p_mode();
  608. cursor_off();
  609. blink_off();
  610. ec_update_set();
  611. update_palette(0);
  612. }
  613. else
  614. {
  615. ega_14p_mode();
  616. cursor_off();
  617. blink_off();
  618. ec_update_set();
  619. update_palette(0);
  620. }
  621. }
  622. }*/
  623. if(!str_cmp(name,"RED_VALUE"))
  624. {
  625. value = value % 64;
  626. set_Color_Aspect(get_counter("CURRENT_COLOR",id),0,value);
  627. return;
  628. }
  629. if(!str_cmp(name,"GREEN_VALUE"))
  630. {
  631. value = value % 64;
  632. set_Color_Aspect(get_counter("CURRENT_COLOR",id),1,value);
  633. return;
  634. }
  635. if(!str_cmp(name,"BLUE_VALUE"))
  636. {
  637. value = value % 64;
  638. set_Color_Aspect(get_counter("CURRENT_COLOR",id),2,value);
  639. return;
  640. }
  641. /* //Silly Akwende we already have a variable that does
  642. //This. It's called "bulltettype" -Koji
  643. if(!str_cmp(name,"BULLET_TYPE"))
  644. {
  645. robots[id].bullet_type=value;
  646. return;
  647. }
  648. */ //New Lava_walk local counter. -Koji
  649. if(!str_cmp(name,"LAVA_WALK"))
  650. {
  651. robots[id].can_lavawalk=value;
  652. return;
  653. }
  654. // }
  655. if(!str_cmp(name,"LOOPCOUNT")) {
  656. robots[id].loop_count=value;
  657. return;
  658. }
  659. if(!str_cmp(name,"LOCAL")) {
  660. robots[id].blank=value;
  661. return;
  662. }
  663. //I'm suprised Akwende didn't do this...
  664. //MZX_SPEED can now be changed by robots.
  665. //Meaning the game speed can now be set
  666. //by robots. -Koji
  667. if(!str_cmp(name,"MZX_SPEED")){
  668. overall_speed=value;
  669. return;
  670. }
  671. //Took out the Number contraints. -Koji
  672. if(!str_cmp(name,"BULLETTYPE")) {
  673. robots[id].bullet_type=value;
  674. return;
  675. }
  676. //Next, check for global, non-standard counters
  677. // SHOULD allow instant scrolling of screen, once scroll_x can be referenced
  678. // As of yet, doesn't work. Spid
  679. if(!str_cmp(name,"SCROLLEDX")) {
  680. scroll_x= value;
  681. return;
  682. }
  683. if(!str_cmp(name,"SCROLLEDY")) {
  684. scroll_y= value;
  685. return;
  686. }
  687. /* // These Grids will be used for mouse buttons, once that is in. Spid
  688. if(!str_cmp(name,"GRIDXSIZE")) {
  689. gridxsize=value;
  690. return;
  691. }
  692. if(!str_cmp(name,"GRIDYSIZE")) {
  693. gridysize=value;
  694. return;
  695. }
  696. */ // Shows or hides the hardware cursor Spid
  697. if(!str_cmp(name,"CURSORSTATE")) {
  698. if (value==1) m_show();
  699. if (value==0) m_hide();
  700. } //Don't return! We need to set the counter, as well.
  701. // CURSORSTATE is referenced in GAME.CPP
  702. // This should PROBABLY be a variable, instead of a counter,
  703. // but I DID have a reason for using a counter, if I ever
  704. // remember it. Spid
  705. if(!str_cmp(name,"BIMESG"))
  706. {
  707. set_built_in_messages(abs(value % 2));
  708. }
  709. //Don't return! Spid
  710. if(!str_cmp(name,"MOUSEX")) {
  711. if(value>79) value=79;
  712. if(value<0) value=0;
  713. saved_mouse_y = value;
  714. m_move(value,mousey);
  715. return;
  716. }
  717. if(!str_cmp(name,"MOUSEY")) {
  718. if(value>24) value=24;
  719. if(value<0) value=0;
  720. saved_mouse_x = value;
  721. m_move(mousex,value);
  722. return;
  723. }
  724. if(!str_cmp(name,"INPUT")) {
  725. num_input=value;
  726. return;
  727. }
  728. if(!str_cmp(name,"INPUTSIZE")) {
  729. if(value>255) value=255;
  730. input_size=(unsigned char)value;
  731. return;
  732. }
  733. if(!str_cmp(name,"KEY")) {
  734. if(value>255) value=255;
  735. last_key=(unsigned char)value;
  736. return;
  737. }
  738. if(!str_cmp(name,"SCORE")) {
  739. score=value;
  740. return;
  741. }
  742. if(!str_cmp(name,"TIMERESET")) {
  743. time_limit=value;
  744. return;
  745. }
  746. if(!str_cmp(name,"PLAYERFACEDIR")) {
  747. if(value<0) value=0;
  748. if(value>3) value=3;
  749. player_last_dir=(player_last_dir&15)+(value<<4);
  750. return;
  751. }
  752. if(!str_cmp(name,"PLAYERLASTDIR")) {
  753. if(value<0) value=0;
  754. if(value>4) value=4;
  755. player_last_dir=(player_last_dir&240)+value;
  756. return;
  757. }
  758. //Check for overflow on HEALTH and LIVES
  759. if(!str_cmp(name,"HEALTH")) {
  760. if(value<0) value=0;
  761. if(value>health_limit)
  762. value=health_limit;
  763. }
  764. if(!str_cmp(name,"LIVES")) {
  765. if(value<0) value=0;
  766. if(value>lives_limit)
  767. value=lives_limit;
  768. }
  769. //Invinco
  770. if(!str_cmp(name,"INVINCO")) {
  771. if(!get_counter("INVINCO",0))
  772. saved_pl_color=*player_color;
  773. else if(value==0) {
  774. clear_sfx_queue();
  775. play_sfx(18);
  776. *player_color=saved_pl_color;
  777. }
  778. }
  779. //Now search counter structs
  780. for(t1=0;t1<NUM_COUNTERS;t1++)
  781. if(!str_cmp(name,counters[t1].counter_name)) break;
  782. if(t1<NUM_COUNTERS) {
  783. if(t1<RESERVED_COUNTERS)//Reserved counters can't go below 0
  784. if(value<0) value=0;
  785. counters[t1].counter_value=value;
  786. return;
  787. }
  788. //Not found- search for an empty space AFTER the reserved spaces
  789. for(t1=RESERVED_COUNTERS;t1<NUM_COUNTERS;t1++)
  790. if(!counters[t1].counter_value) break;
  791. if(t1<NUM_COUNTERS)
  792. {//Space found
  793. str_cpy(counters[t1].counter_name,name);
  794. counters[t1].counter_value=value;
  795. }
  796. return;
  797. }
  798. //Take a key. Returns non-0 if none of proper color exist.
  799. char take_key(char color)
  800. {
  801. int t1;
  802. color&=15;
  803. for(t1=0;t1<NUM_KEYS;t1++)
  804. if(keys[t1]==color) break;
  805. if(t1<NUM_KEYS) {
  806. keys[t1]=NO_KEY;
  807. return 0;
  808. }
  809. return 1;
  810. }
  811. //Give a key. Returns non-0 if no room.
  812. char give_key(char color) {
  813. int t1;
  814. color&=15;
  815. for(t1=0;t1<NUM_KEYS;t1++)
  816. if(keys[t1]==NO_KEY) break;
  817. if(t1<NUM_KEYS) {
  818. keys[t1]=color;
  819. return 0;
  820. }
  821. return 1;
  822. }
  823. //Increase or decrease a counter.
  824. void inc_counter(char far *name,int value,unsigned char id) {
  825. long t;
  826. if(!str_cmp(name,"CHAR_X")) {
  827. pixel_x = (pixel_x + value) % 256;
  828. return;
  829. }
  830. if(!str_cmp(name,"CHAR_Y")) {
  831. pixel_y = (pixel_y + value) % 256;
  832. return;
  833. }
  834. if(!str_cmp(name,"SCORE")) {//Special score inc. code
  835. if((score+value)<score) score=4294967295ul;
  836. else score+=value;
  837. return;
  838. }
  839. if(!str_cmp(name,"WRAP"))
  840. {
  841. int current,max;
  842. current = get_counter("WRAP",id) + value;
  843. max = get_counter("WRAPVAL",id);
  844. if (current > max) current = 0;
  845. set_counter("WRAP",current,id);
  846. }
  847. t=((long)get_counter(name,id))+value;
  848. if(t>32767L) t=-32767L;
  849. if(t<-32768L) t=32768L;
  850. set_counter(name,(int)t,id);
  851. }
  852. void dec_counter(char far *name,int value,unsigned char id) {
  853. long t;
  854. if(!str_cmp(name,"CHAR_X")) {
  855. pixel_x = (pixel_x - value + 256) % 256;
  856. return;
  857. }
  858. if(!str_cmp(name,"CHAR_Y")) {
  859. pixel_y = (pixel_y - value + 256) % 256;
  860. return;
  861. }
  862. if((!str_cmp(name,"HEALTH"))&&(value>0)) {//Prevent hurts if invinco
  863. if(get_counter("INVINCO",0)>0) return;
  864. send_robot_def(0,13);
  865. if(restart_if_zapped) {
  866. //Restart since we were hurt
  867. if((player_restart_x!=player_x)||(player_restart_y!=player_y)) {
  868. id_remove_top(player_x,player_y);
  869. player_x=player_restart_x;
  870. player_y=player_restart_y;
  871. id_place(player_x,player_y,127,0,0);
  872. was_zapped=1;
  873. }
  874. }
  875. }
  876. if(!str_cmp(name,"SCORE")) {//Special score dec. code
  877. if((score-value)>score) score=0;
  878. else score-=value;
  879. return;
  880. }
  881. if(!str_cmp(name,"WRAP"))
  882. {
  883. int current,max;
  884. current = get_counter("WRAP",id);
  885. current -= value;
  886. max = get_counter("WRAPVAL",id);
  887. if (current < 0) current = max;
  888. set_counter("WRAP",current,id);
  889. }
  890. t=((long)get_counter(name,id))-value;
  891. if(t>32767L) t=-32767L;
  892. if(t<-32768L) t=32768L;
  893. set_counter(name,(int)t,id);
  894. }