Wolf3D-Mac/EnMove.c

1 line
10 KiB
C
Raw Permalink Normal View History

/* enmove.c*/ #include "wolfdef.h" dirtype opposite[9] = {west,southwest,south,southeast,east,northeast,north,northwest,nodir}; dirtype diagonal[9][9] = { /* east */ {nodir,nodir,northeast,nodir,nodir,nodir,southeast,nodir,nodir}, {nodir,nodir,nodir,nodir,nodir,nodir,nodir,nodir,nodir}, /* north */ {northeast,nodir,nodir,nodir,northwest,nodir,nodir,nodir,nodir}, {nodir,nodir,nodir,nodir,nodir,nodir,nodir,nodir,nodir}, /* west */ {nodir,nodir,northwest,nodir,nodir,nodir,southwest,nodir,nodir}, {nodir,nodir,nodir,nodir,nodir,nodir,nodir,nodir,nodir}, /* south */ {southeast,nodir,nodir,nodir,southwest,nodir,nodir,nodir,nodir}, {nodir,nodir,nodir,nodir,nodir,nodir,nodir,nodir,nodir}, {nodir,nodir,nodir,nodir,nodir,nodir,nodir,nodir,nodir} }; /********************************** Changes actor to a new state, setting ticcount to the max for that state **********************************/ void NewState(actor_t *ActorPtr,stateindex_t state) { state_t *StatePtr; StatePtr = &states[state]; /* Get the state record pointer */ ActorPtr->state = state; /* Set the actor's state */ ActorPtr->ticcount = StatePtr->tictime; /* Set the initial tick value */ ActorPtr->pic = StatePtr->shapenum; /* Set the current shape number */ } /********************************** Attempts to move actor in its current (ActorPtr->dir) direction. If blocked by either a wall or an actor returns FALSE If move is either clear or blocked only by a door, returns TRUE and sets ActorPtr->tilex = new destination ActorPtr->tiley ActorPtr->areanumber = the floor tile number (0-(MAXAREAS-1)) of destination ActorPtr->distance = TILEGLOBAL, or doornumber if a door is blocking the way If a door is in the way, an OpenDoor call is made to start it opening. The actor code should wait until doorobjlist[ActorPtr->distance].action = dr_open, meaning the door has been fully opened **********************************/ /********************************** Check if I can move in a diagonal direction **********************************/ Boolean CheckDiag(Word x,Word y) { /* anything blocking stops diagonal move*/ if (tilemap[y][x]&(TI_BLOCKMOVE|TI_ACTOR)) { return FALSE; /* It's blocked */ } return TRUE; /* It's open! */ } /********************************** Check if I can move in a sideways direction also do the code for an actor to open a door return 0 if blocked, 1 if open, 2 if I need to open a door **********************************/ Word CheckSide(Word x,Word y,actor_t *ActorPtr) { Word temp; temp=tilemap[y][x]; /* Get the tile */ if (temp & TI_DOOR) { /* Door? */ if (!(temp&TI_BLOCKMOVE)) { /* Not blocked? */ return 1; /* door is open*/ } if (ActorPtr->class == CL_DOG) { return 0; /* dogs can't open doors */ } return 2; /* I have to open the door */ } if (temp&(TI_BLOCKMOVE|TI_ACTOR)) { /* Normally blocked? */ return 0; /* Can't go this way */ } return 1; /* I can go! */ } /********************************** Try to move the actor around **********************************/ Boolean TryWalk (actor_t *ActorPtr) { Word x,y; Word Temp; Word *TileMapPtr; Word tile; x = ActorPtr->goalx; /* Where is my goal x,y? */ y = ActorPtr->goaly; switch (ActorPtr->dir) { /* Go in my direction */ case north: /* Go n,s,e,w */ --y; goto DoSide; case east: ++x; goto DoSide; case south: ++y; goto DoSide; case west: --x; DoSide: Temp = CheckSide(x,y,ActorPtr); /* See if I can move this way */ if (!Temp) { /* Not this way? */ return FALSE; /* Exit */ } if (Temp==2) { /* Door? */ OpenDoor(&doors[tilemap[y][x]&TI_NUMMASK]); /* Open the door */ ActorPtr->flags |= (FL_WAITDOOR|FL_NOTMOVING); /* Force the actor to pause */ return TRUE; /* I'm ok! */ } break; /* Continue */ case northeast: if (!CheckDiag(x+1,y)) { return FALSE; } y--; goto FixEast; case southeast: if (!CheckDiag(x+1,y)) { return FALSE; } y++; FixEast: if (!CheckDiag(x,y)) { return FALSE; } x++; if (!CheckDiag(x,y)) { return FALSE;