bandit

oldschool thievery roguelike
git clone git://moonbender.net/bandit
Log | Files | Refs | README

bandit_actor.c (1713B)


      1 #include "common.h"
      2 
      3 extern u32 ltiles[MAXLEVELWIDTH * MAXLEVELHEIGHT];
      4 
      5 Actor actors[MAXACTORS];
      6 /* 
      7 unsigned int ActorX[MAXACTORS] = {3, 12, 12, 0, 0};
      8 unsigned int ActorY[MAXACTORS] = {3, 12, 8, 0, 0};
      9 */
     10 u32 icons[MAXACTORS] = {'@', 'G', 'T', '?', '?'};
     11 
     12 u8 bandit_actor_place(u32 in, u32 x, u32 y) {
     13 	if (x > MAXLEVELWIDTH || y > MAXLEVELHEIGHT)
     14 		return 1;
     15 
     16 	if (ltiles[tile_index(x, y)] == TILE_FLOOR || ltiles[tile_index(x, y)] == TILE_DOOR_OPEN ) {
     17 		actors[in].x = x;
     18 		actors[in].y = y;
     19         return 0;
     20 	}
     21 
     22     return 1;
     23 }
     24 
     25 u8 los(u32 viewer, u32 target) {
     26     u32 i;
     27 
     28 	for ( i = 0; 
     29 		  i < (MAXLEVELWIDTH * MAXLEVELHEIGHT); 
     30 		  i++ ) {
     31 		u32 x = i % MAXLEVELWIDTH;
     32 		u32 y = i / MAXLEVELWIDTH;
     33 
     34 		/* skip tiles that don't block LOS */
     35 		if (ltiles[i] != TILE_WALL && ltiles[i] != TILE_DOOR_OPEN) { continue; }
     36         
     37 		if ((x > actors[target].x) && (x > actors[viewer].x)) { continue; }
     38  		if((x < actors[target].x) && (x < actors[viewer].x))  { continue; }
     39 
     40 		if((y < actors[target].y) && (y < actors[viewer].y)) { continue; }
     41 		if((y > actors[target].y) && (y > actors[viewer].y)) { continue; }
     42 
     43 		return 0;
     44 	}
     45 	return 1;
     46 }
     47 
     48 u8 bandit_actor_think(void)
     49 {
     50     /* glorg this sucks rewrite 
     51 	u32 destx = ActorX[1];
     52 	u32 desty = ActorY[1];
     53 
     54 	if (!CheckLOS(1, 0))
     55 	{
     56 		return;
     57 	}
     58 
     59 	if (ActorY[1] > ActorY[0])
     60 	{
     61 		desty -= 1;
     62 	}
     63 	else if (ActorY[1] < ActorY[0])
     64 	{
     65 		desty += 1;
     66 	}
     67 	else
     68 	{
     69 		if (ActorX[1] > ActorX[0])
     70 		{
     71 			destx -= 1;
     72 		}
     73 		else if (ActorX[1] < ActorX[0])
     74 		{
     75 			destx += 1;
     76 		}
     77 	}
     78 
     79 	if (destx == ActorX[0] && desty == ActorY[0])
     80 	{
     81 		//if player is in destination tile, attack
     82 		AddMessage("You're DEAD\n");
     83 		return;
     84 	}
     85 
     86 	actor_place(1, destx, desty);
     87     */
     88     return 0;
     89 }