home *** CD-ROM | disk | FTP | other *** search
- void Plant_a_forest(void);
- void PlantTree(int x, int y);
- void inc_manual_view(int x, int y);
- void view_manual(void);
- void init_manual_track(void);
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
-
- #include "dtypes.h"
- #include "tiles.h"
- #include "host.h"
- #include "newload.h"
- #include "callasm.h"
-
- #define TANKSTART TANK1D8A
- #define BWALL 1
- #define BTANK 2
-
- extern BOOL update_scr;
-
- int empty;
-
- int top1, left1;
-
- int rx1, rx2, ry1, ry2, top, left;
-
- /*<f>----------------------------------------
- * FUNCTION: <s> void follow_tank(p_TANK t)
- * PURPOSE : track the motion of a tank T
- * :
- * CREATION: 01/06/1989 12:18:58
- */
- void follow_tank(p_TANK t)
- {
- monitor_tank(t);
- } /* void follow_tank(p_TANK t) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> void v_startup_playfield(int t)
- * PURPOSE : Set up graphics table and go to CGA mode
- * :
- * CREATION: 01/06/1989 12:11:27
- */
- void v_startup_playfield(int t)
- {
- gotocga();
- inittables();
-
- setphyXY(0,0);
- setwindXY(WINDX,WINDY);
-
- initmap(t);
-
- gotoxy(1,21); printf("TANK # NAME ");
- gotoxy(1,22); printf("DAMAGE HITS ");
-
- gotoxy(1,24); printf("Press 0-9, SPACE to view, ESC to END");
-
- capturescr();
-
- } /* void v_startup_playfield(int t) */
-
- /*-------------------------------------
- * Function : void monitor_tank(p_TANK t)
- * Purpose : Monitor the actions of tank pointed to by T
- * Date : 12/18/1988 14:48:45
- */
- void monitor_tank(p_TANK t)
- {
- check_tank_position(t);
- setlogXY(left,top);
- regenscr();
- refreshscr();
- } /* void monitor_tank(p_TANK t) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> void RectMap(int x1, int y1, int x2, int y2, int b)
- * PURPOSE : Fill map from (x1,y1) to (x2,y2) with tile B
- * :
- * CREATION: 12/13/1988 08:14:15
- */
- void RectMap(int x1, int y1, int x2, int y2, int b)
- {
- int x,y;
-
- for (y=y1; y<=y2; y++)
- for (x=x1; x<=x2; x++)
- setmapXY(x,y,b);
-
- } /* void RectMap(int x1, int y1, int x2, int y2, int b) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> void vMapLine(int x, int y1, int y2, int b)
- * PURPOSE : Draw a vertical line from (x,y1) to (x,y2) with tile B
- * :
- * CREATION: 12/13/1988 08:22:43
- */
- void vMapLine(int x, int y1, int y2, int b)
- {
- int y;
- for (y=y1; y<=y2; y++)
- setmapXY(x,y,b);
- } /* void vMapLine(int x, int y1, int y2, int b) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> void hMapLine(int y, int x1, int x2, int b)
- * PURPOSE : Draw a horizontal line from (x1,y) to (x2,y) with tile B
- * :
- * CREATION: 12/13/1988 12:11:02
- */
- void hMapLine(int y, int x1, int x2, int b)
- {
- int x;
- for (x=x1; x<=x2; x++)
- setmapXY(x,y,b);
- } /* void hMapLine(int y, int x1, int x2, int b) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> void RandRectMap(int x1, int y1, int x2, int y2, int B)
- * PURPOSE : Create a fuzzy rectangle within (x1,y1) - (x2,y2) with tile B
- * :
- * CREATION: 12/13/1988 14:07:55
- */
- void RandRectMap(int x1, int y1, int x2, int y2, int b)
- {
- int xr, yr,a, x,y;
-
- xr=abs(x2-x1);
- yr=abs(y2-y1);
-
- for (a=0; a<(xr*yr) >> 1; a++) {
- x=x1+(rand() % xr);
- y=y1+(rand() % yr);
- setmapXY(x,y,b);
- }
- } /* void RandRectMap(int x1, int y1, int x2, int y2, int b) */
-
- /*-------------------------------------
- * Function : void initmap(int t)
- * Purpose : Initilize map to playfield data
- * Date : 12/18/1988 14:36:31
- */
- void initmap(int t)
- {
- RectMap(MINPX,MINPY,MAXPX,MAXPY,TGREEN);
- RandRectMap(MINPX,MINPY,MAXPX,MAXPY,GRASS);
-
- hMapLine(MINPY,MINPX,MAXPX,TRED);
- hMapLine(MAXPY,MINPX,MAXPX,TRED);
- vMapLine(MINPX,MINPY,MAXPY,TRED);
- vMapLine(MAXPX,MINPY,MAXPY,TRED);
-
- if (t!=TGRASS) {
- RandRectMap(10,4,44,31,SWAMP);
- RandRectMap(80,27,110,70,SWAMP);
- }
-
- if (t==TWOODS)
- Plant_a_forest();
-
- if (t==TVILLAGE) {
-
- hMapLine(40,10,35,BRICK);
- vMapLine(22,40,49,BRICK);
- hMapLine(55,20,45,BRICK);
- vMapLine(30,46,55,BRICK);
-
- RectMap(16,10,27,19,BRICK);
- RectMap(32,21,38,25,BRICK);
- vMapLine(90,55,65,BRICK);
- hMapLine(55,90,105,BRICK);
- }
-
- } /* void initmap(int t) */
-
- /*-------------------------------------
- * Function : void PlantTree(int x, int y)
- * Purpose : Plant a large tree with (x,y) at top-left
- * Date : 02/09/1989 19:30:38
- */
- void PlantTree(int x, int y)
- {
- setmapXY(x ,y ,TREE11);
- setmapXY(x+1,y ,TREE12);
- setmapXY(x+2,y ,TREE13);
- setmapXY(x ,y+1,TREE21);
- setmapXY(x+1,y+1,TREE22);
- setmapXY(x+2,y+1,TREE23);
- setmapXY(x ,y+2,TREE31);
- setmapXY(x+1,y+2,TREE32);
- setmapXY(x+2,y+2,TREE33);
- } /* void PlantTree(int x, int y) */
-
- /*-------------------------------------
- * Function : void Plant_a_forest(void)
- * Purpose : Make a scatter of trees
- * Date : 02/09/1989 19:35:05
- */
- void Plant_a_forest(void)
- {
- int a;
-
- for (a=0; a<40+(rand() % 40); a++)
- PlantTree(1+(rand() % (MAXPX-5)), 1+(rand() % (MAXPY-5)));
- } /* void Plant_a_forest(void) */
-
-
- /*-------------------------------------
- * Function : void init_tank_image(p_TANK t, int tm)
- * Purpose : Initilize tank image data to known value
- * Date : 12/18/1988 14:37:55
- */
- void init_tank_image(p_TANK t, int tm)
- {
- int a;
-
- t->cpoint = 1+rand()%8;
- t->cgpoint= 1+rand()%8;
-
- t->px =rand() % MAXPX;
- t->py =rand() % MAXPY;
-
- set_move_range(t);
-
- if (tm==0) {
- init_view(&t->pic[0],TANK1D1A, TANK1D1B, TANK1D1C, TANK1D1D);
- init_view(&t->pic[2],TANK1D3A, TANK1D3B, TANK1D3C, TANK1D3D);
- init_view(&t->pic[1],TANK1D2A, TANK1D2B, TANK1D2C, TANK1D2D);
- init_view(&t->pic[3],TANK1D4A, TANK1D4B, TANK1D4C, TANK1D4D);
- init_view(&t->pic[5],TANK1D6A, TANK1D6B, TANK1D6C, TANK1D6D);
- init_view(&t->pic[4],TANK1D5A, TANK1D5B, TANK1D5C, TANK1D5D);
- init_view(&t->pic[6],TANK1D7A, TANK1D7B, TANK1D7C, TANK1D7D);
- init_view(&t->pic[7],TANK1D8A, TANK1D8B, TANK1D8C, TANK1D8D);
- } else if (tm==1) {
- init_view(&t->pic[0],TANK21A, TANK21B, TANK21C, TANK21D);
- init_view(&t->pic[2],TANK23A, TANK23B, TANK23C, TANK23D);
- init_view(&t->pic[4],TANK25A, TANK25B, TANK25C, TANK25D);
- init_view(&t->pic[6],TANK27A, TANK27B, TANK27C, TANK27D);
- init_view(&t->pic[1],TANK22A, TANK22B, TANK22C, TANK22D);
- init_view(&t->pic[3],TANK24A, TANK24B, TANK24C, TANK24D);
- init_view(&t->pic[5],TANK26A, TANK26B, TANK26C, TANK26D);
- init_view(&t->pic[7],TANK28A, TANK28B, TANK28C, TANK28D);
- } else {
- init_view(&t->pic[0],TANK31A, TANK31B, TANK31C, TANK31D);
- init_view(&t->pic[2],TANK33A, TANK33B, TANK33C, TANK33D);
- init_view(&t->pic[4],TANK35A, TANK35B, TANK35C, TANK35D);
- init_view(&t->pic[6],TANK37A, TANK37B, TANK37C, TANK37D);
- init_view(&t->pic[1],TANK32A, TANK32B, TANK32C, TANK32D);
- init_view(&t->pic[3],TANK34A, TANK34B, TANK34C, TANK34D);
- init_view(&t->pic[5],TANK36A, TANK36B, TANK36C, TANK36D);
- init_view(&t->pic[7],TANK38A, TANK38B, TANK38C, TANK38D);
- }
-
- save_under_tank(t);
-
- } /* void init_tank_image(p_TANK t, int tm) */
-
- /*-------------------------------------
- * Function : void init_view(p_TANKTILE t, int ta, int tb, int tc, int td)
- * Purpose : Initilize each view of tank during rotation
- * Date : 12/18/1988 14:58:45
- */
- void init_view(p_TANKTILE t, int ta, int tb, int tc, int td)
- {
- t->image[0]=ta;
- t->image[1]=tb;
- t->image[2]=tc;
- t->image[3]=td;
- } /* void init_view(p_TANKTILE t, int ta, int tb, int tc, int td) */
-
- /*-------------------------------------
- * Function : void save_under_tank(p_TANK t)
- * Purpose : Saves image under tank image
- * Date : 12/18/1988 14:42:21
- */
- void save_under_tank(p_TANK t)
- {
- t->save.image[0]=getmapXY(t->px ,t->py );
- t->save.image[1]=getmapXY(t->px+1,t->py );
- t->save.image[2]=getmapXY(t->px ,t->py+1);
- t->save.image[3]=getmapXY(t->px+1,t->py+1);
- } /* void save_under_tank(p_TANK t) */
-
- /*-------------------------------------
- * Function : void restore_under_tank(p_TANK t)
- * Purpose : Restore image under tank tiles
- * Date : 12/18/1988 15:04:20
- */
- void restore_under_tank(p_TANK t)
- {
- setmapXY(t->px, t->py ,t->save.image[0]);
- setmapXY(t->px+1,t->py ,t->save.image[1]);
- setmapXY(t->px, t->py+1,t->save.image[2]);
- setmapXY(t->px+1,t->py+1,t->save.image[3]);
- } /* void restore_under_tank(p_TANK t) */
-
- /*-------------------------------------
- * Function : void display_tank(p_TANK t)
- * Purpose : Draws tank onto map file
- * Date : 12/18/1988 15:01:41
- */
- void display_tank(p_TANK t)
- {
- save_under_tank(t);
- if (!t->boom) {
- setmapXY(t->px, t->py ,t->pic[t->cgpoint-1].image[0]);
- setmapXY(t->px+1,t->py ,t->pic[t->cgpoint-1].image[1]);
- setmapXY(t->px, t->py+1,t->pic[t->cgpoint-1].image[2]);
- setmapXY(t->px+1,t->py+1,t->pic[t->cgpoint-1].image[3]);
- } else {
- if (t->jiggle) {
- setmapXY(t->px ,t->py ,BOOM1);
- setmapXY(t->px+1,t->py ,BOOM2);
- setmapXY(t->px ,t->py+1,BOOM3);
- setmapXY(t->px+1,t->py+1,BOOM4);
- } else {
- setmapXY(t->px ,t->py ,BOOMA1);
- setmapXY(t->px+1,t->py ,BOOMA2);
- setmapXY(t->px ,t->py+1,BOOMA3);
- setmapXY(t->px+1,t->py+1,BOOMA4);
- }
-
- t->jiggle=~t->jiggle;
- update_scr=TRUE;
-
- t->bwait--;
- if (t->bwait<1) t->boom=FALSE;
- }
-
- } /* void display_tank(p_TANK t) */
-
- /*-------------------------------------
- * Function : BOOL clear(int x, int y)
- * Purpose : Is it clear at (x,y)
- * Date : 12/19/1988 23:18:13
- */
- BOOL clear(int x, int y)
- {
- int a;
- int t;
-
- a=getmapXY(x,y);
- t=0;
-
- if ((a>=BRICK && a< TANKSTART) || a==TRED)
- empty=t=BWALL;
- if (a>=TANKSTART)
- empty=t=BTANK;
-
- return (t>0) ? FALSE : TRUE;
- } /* BOOL clear(int x, int y) */
-
- /*-------------------------------------
- * Function : BOOL check_above(p_TANK t)
- * Purpose : Make sure clear to move above
- * Date : 12/19/1988 23:15:44
- */
- BOOL check_above(p_TANK t)
- {
- return (clear(t->px,t->py-1) && clear(t->px+1,t->py-1)) ? TRUE : FALSE;
-
- } /* BOOL check_above(p_TANK t) */
-
- /*-------------------------------------
- * Function : BOOL check_below(p_TANK t)
- * Purpose : Make sure clear below to move
- * Date : 12/19/1988 23:19:19
- */
- BOOL check_below(p_TANK t)
- {
- return (clear(t->px,t->py+2) && clear(t->px+1, t->py+2)) ? TRUE : FALSE;
-
- } /* BOOL check_below(p_TANK t) */
-
- /*-------------------------------------
- * Function : BOOL check_left(p_TANK t)
- * Purpose : Make sure clear to move left
- * Date : 12/19/1988 23:20:15
- */
- BOOL check_left(p_TANK t)
- {
- return (clear(t->px-1,t->py) && clear(t->px-1, t->py+1)) ? TRUE : FALSE;
-
- } /* BOOL check_left(p_TANK t) */
-
- /*-------------------------------------
- * Function : BOOL check_right(p_TANK t)
- * Purpose : Make sure clear to move right
- * Date : 12/19/1988 23:21:04
- */
- BOOL check_right(p_TANK t)
- {
- return (clear(t->px+2,t->py) && clear(t->px+2,t->py+1)) ? TRUE : FALSE;
- } /* BOOL check_right(p_TANK t) */
-
- /*-------------------------------------
- * Function : void move_up(p_TANK t)
- * Purpose : Move tanks current position up one tile
- * Date : 12/18/1988 15:09:35
- */
- void move_up(p_TANK t)
- {
- if (t->py>MINPY && check_above(t)) t->py--;
- } /* void move_up(p_TANK t) */
-
- /*-------------------------------------
- * Function : void move_down(p_TANK t)
- * Purpose : Move tanks current position down one tile
- * Date : 12/18/1988 15:10:21
- */
- void move_down(p_TANK t)
- {
- if (t->py+1<MAXPY && check_below(t)) t->py++;
-
- } /* void move_down(p_TANK t) */
-
- /*-------------------------------------
- * Function : void move_left(p_TANK t)
- * Purpose : Move tanks current position left one position
- * Date : 12/18/1988 15:11:20
- */
- void move_left(p_TANK t)
- {
- if (t->px>MINPX && check_left(t)) t->px--;
- } /* void move_left(p_TANK t) */
-
- /*-------------------------------------
- * Function : void move_right(p_TANK t)
- * Purpose : Move tanks current position right one tile position
- * Date : 12/18/1988 15:11:57
- */
- void move_right(p_TANK t)
- {
- if (t->px+1<MAXPX && check_right(t)) t->px++;
- } /* void move_right(p_TANK t) */
-
- /*-------------------------------------
- * Function : void move_tank(p_TANK t)
- * Purpose : Move tank T in current direction pointed by t->cpoint
- * Date : 12/18/1988 15:08:06
- */
- void move_tank(p_TANK t)
- {
- int ox, oy;
-
- ox=t->px;
- oy=t->py;
-
- empty = FALSE;
-
- switch(t->cpoint) {
- case 1 : move_up(t);
- break;
- case 2 : move_up(t); move_right(t);
- break;
- case 3 : move_right(t);
- break;
- case 4 : move_down(t); move_right(t);
- break;
- case 5 : move_down(t);
- break;
- case 6 : move_left(t); move_down(t);
- break;
- case 7 : move_left(t);
- break;
- case 8 : move_left(t); move_up(t);
- break;
- }
-
- t->nomove=(ox==t->px && oy==t->py) ? TRUE : FALSE;
-
- t->blockage = empty;
-
- if (!t->nomove) update_scr=TRUE;
-
- } /* void move_tank(p_TANK t) */
-
- /*-------------------------------------
- * Function : void set_move_range(p_TANK t)
- * Purpose : Sets window around tank in which tank may move without regen
- * Date : 12/19/1988 22:59:41
- */
- void set_move_range(p_TANK t)
- {
-
- left=t->px-HALFWINDX;
- top =t->py-HALFWINDY;
-
- if (left<MINPX) left=MINPX;
- if (top <MINPY) top =MINPY;
- if (left>MAXLX) left=MAXLX;
- if (top >MAXLY) top =MAXLY;
-
- rx1=left+5;
- ry1=top+3;
- rx2=left+WINDX-5;
- ry2=top+WINDY-3;
-
- } /* void set_move_range(p_TANK t) */
-
- /*-------------------------------------
- * Function : void check_tank_position(p_TANK t)
- * Purpose : Make sure tank is still within boundries
- * Date : 12/19/1988 23:04:57
- */
- void check_tank_position(p_TANK t)
- {
- if (t->px>rx1 && t->px<rx2 && t->py>ry1 && t->py<ry2)
- return;
-
- if (t->px<=rx1) left--;
- if (t->px>=rx2) left++;
- if (t->py<=ry1) top-- ;
- if (t->py>=ry2) top++ ;
-
- if (left<MINPX) left=MINPX;
- if (top <MINPY) top =MINPY;
- if (left>MAXLX) left=MAXLX;
- if (top >MAXLY) top =MAXLY;
-
- rx1=left+5;
- ry1=top+3;
- rx2=left+WINDX-5;
- ry2=top+WINDY-3;
-
- } /* void check_tank_position(p_TANK t) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> void init_manual_track(void)
- * PURPOSE :
- * : Initilize top, left pointers for manual motion
- * CREATION: 01/19/1989 14:07:43
- */
- void init_manual_track(void)
- {
- top1=top;
- left1=left;
- } /* void init_manual_track(void) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> void view_manual(void)
- * PURPOSE : Look at screen from manual view
- * :
- * CREATION: 01/19/1989 14:09:58
- */
- void view_manual(void)
- {
- setlogXY(left1,top1);
- regenscr();
- refreshscr();
- } /* void view_manual(void) */
-
- /*<f>----------------------------------------
- * FUNCTION: <s> void inc_manual_view(int x, int y)
- * PURPOSE : Move manual view by (x,y)
- * :
- * CREATION: 01/19/1989 14:11:00
- */
- void inc_manual_view(int x, int y)
- {
- top1+=y;
- left1+=x;
-
- if (left1<MINPX) left1=MINPX;
- if (top1 <MINPY) top1 =MINPY;
- if (left1>MAXLX) left1=MAXLX;
- if (top1 >MAXLY) top1 =MAXLY;
-
- } /* void inc_manual_view(int x, int y) */
-