示例#1
0
void npc_next_pos_line_of_sight(dungeon *d, character *c, pair_t next)
{
  pair_t dir;

  dir[dim_y] = character_get_y(d->PC) - c->position[dim_y];
  dir[dim_x] = character_get_x(d->PC) - c->position[dim_x];
  if (dir[dim_y]) {
    dir[dim_y] /= abs(dir[dim_y]);
  }
  if (dir[dim_x]) {
    dir[dim_x] /= abs(dir[dim_x]);
  }

  if (((npc *) c)->characteristics & NPC_PASS_WALL) {
    next[dim_x] += dir[dim_x];
    next[dim_y] += dir[dim_y];
  } else {
    if (mapxy(next[dim_x] + dir[dim_x],
              next[dim_y] + dir[dim_y]) >= ter_floor) {
      next[dim_x] += dir[dim_x];
      next[dim_y] += dir[dim_y];
    } else if (mapxy(next[dim_x] + dir[dim_x], next[dim_y]) >= ter_floor) {
      next[dim_x] += dir[dim_x];
    } else if (mapxy(next[dim_x], next[dim_y] + dir[dim_y]) >= ter_floor) {
      next[dim_y] += dir[dim_y];
    }
  }
}
示例#2
0
void npc_next_pos_line_of_sight(dungeon_t *d, character *c, pair_t next)
{
  pair_t dir;
  pc *the_pc;
  npc *the_npc;

  the_pc = (pc *) d->the_pc;
  the_npc = (npc *) c;

  dir[dim_y] = the_pc->position[dim_y] - the_npc->position[dim_y];
  dir[dim_x] = the_pc->position[dim_x] - the_npc->position[dim_x];
  if (dir[dim_y]) {
    dir[dim_y] /= abs(dir[dim_y]);
  }
  if (dir[dim_x]) {
    dir[dim_x] /= abs(dir[dim_x]);
  }

  if (mapxy(next[dim_x] + dir[dim_x],
            next[dim_y] + dir[dim_y]) >= ter_floor) {
    next[dim_x] += dir[dim_x];
    next[dim_y] += dir[dim_y];
  } else if (mapxy(next[dim_x] + dir[dim_x], next[dim_y]) >= ter_floor) {
    next[dim_x] += dir[dim_x];
  } else if (mapxy(next[dim_x], next[dim_y] + dir[dim_y]) >= ter_floor) {
    next[dim_y] += dir[dim_y];
  }
}
示例#3
0
static int read_rooms(dungeon_t *d, FILE *f)
{
  uint32_t i;
  uint32_t x, y;

  for (i = 0; i < d->num_rooms; i++) {
    fread(&d->rooms[i].position[dim_x], 1, 1, f);
    fread(&d->rooms[i].position[dim_y], 1, 1, f);
    fread(&d->rooms[i].size[dim_x], 1, 1, f);
    fread(&d->rooms[i].size[dim_y], 1, 1, f);

    /* After reading each room, we need to reconstruct them in the dungeon. */
    for (y = d->rooms[i].position[dim_y];
         y < d->rooms[i].position[dim_y] + d->rooms[i].size[dim_y];
         y++) {
      for (x = d->rooms[i].position[dim_x];
           x < d->rooms[i].position[dim_x] + d->rooms[i].size[dim_x];
           x++) {
        mapxy(x, y) = ter_floor_room;
      }
    }
  }

  return 0;
}
示例#4
0
文件: move.cpp 项目: jkuczek15/rlg327
uint32_t in_corner(dungeon_t *d, character *c)
{
  uint32_t num_immutable;

  num_immutable = 0;

  num_immutable += (mapxy(character_get_x(c) - 1,
                          character_get_y(c)    ) == ter_wall_immutable);
  num_immutable += (mapxy(character_get_x(c) + 1,
                          character_get_y(c)    ) == ter_wall_immutable);
  num_immutable += (mapxy(character_get_x(c)    ,
                          character_get_y(c) - 1) == ter_wall_immutable);
  num_immutable += (mapxy(character_get_x(c)    ,
                          character_get_y(c) + 1) == ter_wall_immutable);

  return num_immutable > 1;
}
示例#5
0
void mapall(commondata *pdata)
{
	//-- Changes all Screen Positions to Physical positions

	//-- if Left to Right (i.e (0,0) is bottomLeft)
	mapxy(&(pdata->ballpos),&(pdata->ballposS),pdata);
	mapxy(&(pdata->goaliepos),&(pdata->goalieposS),pdata);
	mapxy(&(pdata->robot1pos),&(pdata->robot1posS),pdata);
	mapxy(&(pdata->robot2pos),&(pdata->robot2posS),pdata);

	if (gParallaxCorrectionEnabled)
	{
		//-- Parallax correction functions, using calculated physical image centre

		pdata->ballposS = parallaxCorrection(&(pdata->ballposS),pdata, (float)BALLHEIGHT);
		pdata->goalieposS = parallaxCorrection(&(pdata->goalieposS), pdata, (float)ROBOTHEIGHT);
		pdata->robot1posS = parallaxCorrection(&(pdata->robot1posS), pdata, (float)ROBOTHEIGHT);
		pdata->robot2posS = parallaxCorrection(&(pdata->robot2posS), pdata, (float)ROBOTHEIGHT);
		
	}
	
	//-- Copy Screen angle to Physical angle
	pdata->ballangleS = pdata->ballangle;
	pdata->goalieangleS = pdata->goalieangle;
	pdata->robot1angleS = pdata->robot1angle;
	pdata->robot2angleS = pdata->robot2angle;

	//-- if Right to Left (i.e (0,0) is topright)
	if(pdata->game_area==RIGHT_AREA)
	{
		//-- swap the coordinates and angle

		rotatemapxy(&(pdata->ballposS));
		rotatemapxy(&(pdata->goalieposS));
		rotatemapxy(&(pdata->robot1posS));
		rotatemapxy(&(pdata->robot2posS));

		turnangle(&(pdata->goalieangleS));
		turnangle(&(pdata->robot1angleS));
		turnangle(&(pdata->robot2angleS));
		turnangle(&(pdata->ballangleS));
	}

	//-- everything is converted
}
示例#6
0
static int empty_dungeon(dungeon_t *d)
{
  uint8_t x, y;

  for (y = 0; y < DUNGEON_Y; y++) {
    for (x = 0; x < DUNGEON_X; x++) {
      mapxy(x, y) = ter_wall;
      hardnessxy(x, y) = rand_range(1, 254);
      if (y == 0 || y == DUNGEON_Y - 1 ||
          x == 0 || x == DUNGEON_X - 1) {
        mapxy(x, y) = ter_wall_immutable;
        hardnessxy(x, y) = 255;
      }
    }
  }

  return 0;
}
示例#7
0
void smartTarget(floatPOINT *Targetpos)
{
    float NEARPOS, NEAR_Y_OFFSET;
    floatPOINT nearpoint;
    floatPOINT homegoalbottom;
    float GOALSIZE = 40;

    homegoalbottom.x = (float)globaldata.homegoalbottom.x;
    homegoalbottom.y = (float)globaldata.homegoalbottom.y;
    mapxy(&homegoalbottom,&nearpoint,&globaldata);
    NEARPOS = nearpoint.x;
    NEAR_Y_OFFSET = (float)fabs(nearpoint.y - Physical_Yby2);

    floatPOINT oppoGoaliepos;
    //---- dumb tracking
    Targetpos->x = Physical_X;
    Targetpos->y = Physical_Yby2;
    //----

    if(gTrackOpponent)
    {
        BOOL oppoGoalieFound = FALSE;

        if(gNumOppoRobots>0 && oppoArea(globaldata.opporobot1posS, NEARPOS, NEAR_Y_OFFSET))
        {
            oppoGoalieFound = TRUE;
            oppoGoaliepos = globaldata.opporobot1posS;
        }
        else if(gNumOppoRobots>1 && oppoArea(globaldata.opporobot2posS, NEARPOS, NEAR_Y_OFFSET))
        {
            oppoGoalieFound = TRUE;
            oppoGoaliepos = globaldata.opporobot2posS;
        }
        else if(gNumOppoRobots>2 && oppoArea(globaldata.opporobot3posS, NEARPOS, NEAR_Y_OFFSET))
        {
            oppoGoalieFound = TRUE;
            oppoGoaliepos = globaldata.opporobot3posS;
        }

        if (oppoGoalieFound)
        {
            float GOALPOSTSHOTRATIO = 0.5; // 0 is goal keeper, 1 is goal post
            if(oppoGoaliepos.y > Physical_Yby2)
            {
                //-- Shoot to left (lower half of goal)
                Targetpos->y = Physical_Yby2 - GOALSIZE*GOALPOSTSHOTRATIO/2;
            }
            else if(oppoGoaliepos.y < Physical_Yby2)
            {
                //-- Shoot to right (lower half of goal)
                Targetpos->y = Physical_Yby2 + GOALSIZE*GOALPOSTSHOTRATIO/2;
            }
        }
    }	//-- if(gTrackOpponent)
    return;
}	//-- smartTarget()
示例#8
0
static int empty_dungeon(dungeon_t *d)
{
  uint8_t x, y;

  smooth_hardness(d);
  for (y = 0; y < DUNGEON_Y; y++) {
    for (x = 0; x < DUNGEON_X; x++) {
      mapxy(x, y) = ter_wall;
      if (y == 0 || y == DUNGEON_Y - 1 ||
          x == 0 || x == DUNGEON_X - 1) {
        mapxy(x, y) = ter_wall_immutable;
        hardnessxy(x, y) = 255;
      }
      charxy(x, y) = NULL;
    }
  }

  return 0;
}
示例#9
0
void avoidGoalAreas(int which, floatPOINT finalPos)
{
	floatPOINT robotPos;
	floatPOINT nearpoint;
	floatPOINT movePos;
	floatPOINT homegoalbottom;
	float NEARPOS;
	int NUM_ROBOTS = 3;
	homegoalbottom.x = (float)globaldata.homegoalbottom.x;
	homegoalbottom.y = (float)globaldata.homegoalbottom.y;
	mapxy(&homegoalbottom, &nearpoint, &globaldata);
	NEARPOS = nearpoint.x;

	switch(which)
	{
	case HGOALIE	:	robotPos = globaldata.goalieposS;
						break;
	case HROBOT1	:	robotPos = globaldata.robot1posS;
						break;
	case HROBOT2	:	robotPos = globaldata.robot2posS;
						break;
	}	//-- end of switch

	//------ Our own goal area

	if( ownArea(which) ) //-- this robot is in our goal area
	{
		//---- back out
		if (finalPos.x < NEARPOS + ROBOTWIDTHby2)
		{
			movePos.y = finalPos.y + (finalPos.y-robotPos.y)*((float)2.0/3);

			movePos.x = NEARPOS + (float)ROBOTWIDTHby2;
		}
		else
			movePos = finalPos;

		position(which, movePos, 90, 0);
	}

	//----- Opponent's goal area -------------------------------------
	if(oppArea(which) && ( oppArea((which+1)%NUM_ROBOTS) ||
		oppArea((which+2)%NUM_ROBOTS) )) // take care when modifying for different number of robots
	// another robot in area
	// this robot in area
	{
		//-- back off
		movePos.y = finalPos.y+ (finalPos.y-robotPos.y)*((float)2.0/3);
		movePos.x = Physical_X - (NEARPOS + 8); // Adjust this value (8) for how far 
												//out the goal area you want to back off
		position(which, movePos, 90, 0);
	}

	return;
}	//---- avoidGoalAreas()
示例#10
0
int read_rooms(dungeon_t *d, FILE *f)
{
  uint32_t i;
  int32_t x, y;
  uint8_t p;

  for (i = 0; i < d->num_rooms; i++) {
    fread(&p, 1, 1, f);
    d->rooms[i].position[dim_y] = p;
    fread(&p, 1, 1, f);
    d->rooms[i].position[dim_x] = p;
    fread(&p, 1, 1, f);
    d->rooms[i].size[dim_y] = p;
    fread(&p, 1, 1, f);
    d->rooms[i].size[dim_x] = p;

    if (d->rooms[i].size[dim_x] < 1             ||
        d->rooms[i].size[dim_y] < 1             ||
        d->rooms[i].size[dim_x] > DUNGEON_X - 1 ||
        d->rooms[i].size[dim_y] > DUNGEON_X - 1) {
      fprintf(stderr, "Invalid room size in restored dungeon.\n");

      exit(-1);
    }

    if (d->rooms[i].position[dim_x] < 1                                       ||
        d->rooms[i].position[dim_y] < 1                                       ||
        d->rooms[i].position[dim_x] > DUNGEON_X - 1                           ||
        d->rooms[i].position[dim_y] > DUNGEON_Y - 1                           ||
        d->rooms[i].position[dim_x] + d->rooms[i].size[dim_x] > DUNGEON_X - 1 ||
        d->rooms[i].position[dim_x] + d->rooms[i].size[dim_x] < 0             ||
        d->rooms[i].position[dim_y] + d->rooms[i].size[dim_y] > DUNGEON_Y - 1 ||
        d->rooms[i].position[dim_y] + d->rooms[i].size[dim_y] < 0)             {
      fprintf(stderr, "Invalid room position in restored dungeon.\n");

      exit(-1);
    }
        

    /* After reading each room, we need to reconstruct them in the dungeon. */
    for (y = d->rooms[i].position[dim_y];
         y < d->rooms[i].position[dim_y] + d->rooms[i].size[dim_y];
         y++) {
      for (x = d->rooms[i].position[dim_x];
           x < d->rooms[i].position[dim_x] + d->rooms[i].size[dim_x];
           x++) {
        mapxy(x, y) = ter_floor_room;
      }
    }
  }

  return 0;
}
示例#11
0
void io_display_all(dungeon_t *d)
{
  uint32_t y, x;

  clear();
  for (y = 0; y < DUNGEON_Y; y++) {
    for (x = 0; x < DUNGEON_X; x++) {
      if (d->charmap[y][x]) {
        attron(COLOR_PAIR(1));
        mvaddch(y + 1, x, character_get_symbol(d->charmap[y][x]));
        attroff(COLOR_PAIR(1));
      } else {
        switch (mapxy(x, y)) {
        case ter_wall:
        case ter_wall_immutable:
          mvaddch(y + 1, x, ' ');
          break;
        case ter_floor:
        case ter_floor_room:
          mvaddch(y + 1, x, '.');
          break;
        case ter_floor_hall:
          mvaddch(y + 1, x, '#');
          break;
        case ter_debug:
          mvaddch(y + 1, x, '*');
          break;
        case ter_stairs_up:
          mvaddch(y + 1, x, '<');
          break;
        case ter_stairs_down:
          mvaddch(y + 1, x, '>');
          break;
        default:
 /* Use zero as an error symbol, since it stands out somewhat, and it's *
  * not otherwise used.                                                 */
          mvaddch(y + 1, x, '0');
        }
      }
    }
  }

  io_print_message_queue(0, 0);

  refresh();
}
示例#12
0
void switchRobotsIfCan()
{
    //-- Switch for faster defence --//
    floatPOINT dPos = getPos(DEFENDER);
    floatPOINT sPos = getPos(STRIKER);

    // Switch if both robots are in the wrong half,
    // And the defender is further away than the striker
    if (globaldata.ballposS.x < Physical_Xby2 &&
            dPos.x > Physical_Xby2 && sPos.x > Physical_Xby2 &&
            dPos.x > sPos.x)
    {
        Debug::i("Switching striker and defender");
        switchRobots(globaldata.dBehaviour, globaldata.sBehaviour);
    }
    //-------------------------------//


    floatPOINT gPos = getPos(GOALIE);
    floatPOINT home, h;
    home.x = (float)globaldata.homegoalbottom.x;
    home.y = (float)globaldata.homegoalbottom.y;
    mapxy(&home, &h, &globaldata);

    //-- Switch if Str/Def is closer to goal than goalie --//
    float dDist = sqrt(pow(h.x-dPos.x, 2) + pow(Physical_Yby2-dPos.y, 2));
    float sDist = sqrt(pow(h.x-sPos.x, 2) + pow(Physical_Yby2-sPos.y, 2));
    float gDist = sqrt(pow(h.x-gPos.x, 2) + pow(Physical_Yby2-gPos.y, 2));

    if (dDist < gDist && dDist < sDist) // Switch defender and goalie
    {
        CString lol = "";
        lol.Format("%f, %f", h.x, gDist);
        Debug::i("Switching goalie and defender");
        Debug::i(lol);
        switchRobots(globaldata.gBehaviour, globaldata.dBehaviour);
    }
    else if (sDist < gDist && sDist < dDist) // Switch striker and goalie
    {
        Debug::i("Switching goalie and striker");
        switchRobots(globaldata.gBehaviour, globaldata.sBehaviour);
    }
    //-----------------------------------------------------//
}
示例#13
0
BOOL ownArea(floatPOINT Pos)
{   //-- To check if Pos is in own penalty area
    float NEARPOS, NEAR_Y_OFFSET;
    floatPOINT nearpoint;
    floatPOINT homegoalbottom;

    homegoalbottom.x = (float)globaldata.homegoalbottom.x;
    homegoalbottom.y = (float)globaldata.homegoalbottom.y;
    mapxy(&homegoalbottom, &nearpoint, &globaldata);
    NEARPOS = nearpoint.x + (float)2.0;
    NEAR_Y_OFFSET = (float)fabs(nearpoint.y - Physical_Yby2) + (float)2.0;

    if(	Pos.x <  NEARPOS
            && Pos.y > Physical_Yby2 - NEAR_Y_OFFSET
            && Pos.y < Physical_Yby2 + NEAR_Y_OFFSET)
    {
        return true;
    }
    else
        return false;
}	//-- ownArea()
示例#14
0
文件: pc.c 项目: influential/dungeon
uint32_t pc_next_pos(dungeon_t *d, pair_t dir)
{
  dir[dim_y] = dir[dim_x] = 0;

  /* Tunnel to the nearest dungeon corner, then move around in hopes *
   * of killing a couple of monsters before we die ourself.          */

  if (in_corner(d, &d->pc)) {
    /*
    dir[dim_x] = (mapxy(d->pc.position[dim_x] - 1,
                        d->pc.position[dim_y]) ==
                  ter_wall_immutable) ? 1 : -1;
    */
    dir[dim_y] = (mapxy(d->pc.position[dim_x],
                        d->pc.position[dim_y] - 1) ==
                  ter_wall_immutable) ? 1 : -1;
  } else {
    dir_nearest_wall(d, &d->pc, dir);
  }

  return 0;
}
示例#15
0
// Test MyShoot Function
void testMyShoot(int which) {
    floatPOINT	oppgoalbottom;
    float		FARPOS;
    floatPOINT	finalPos;
    float		finalAngle;
    float		finalVel;
    floatPOINT	nearpoint;

    oppgoalbottom.x = (float)globaldata.oppgoalbottom.x;
    oppgoalbottom.y = (float)globaldata.oppgoalbottom.y;
    mapxy(&oppgoalbottom, &nearpoint, &globaldata);
    FARPOS = nearpoint.x;

    finalPos.x = FARPOS;
    finalPos.y = Physical_Yby2;

    myShoot(which, &finalPos);
    //position(which, finalPos, 0, 0);

//	avoidBound(which, finalPos);
//	avoidGoalAreas(which, finalPos);
}
示例#16
0
BOOL ownArea(int which)
{	//-- To check if robot is in own penalty area

	floatPOINT robotPos;
	float NEARPOS, NEAR_Y_OFFSET;
	floatPOINT nearpoint;
	floatPOINT homegoalbottom;
	BOOL thisRemoved;

	homegoalbottom.x = (float)globaldata.homegoalbottom.x;
	homegoalbottom.y = (float)globaldata.homegoalbottom.y;
	mapxy(&homegoalbottom, &nearpoint, &globaldata);
	NEARPOS = nearpoint.x + (float)2.0;	//4.0;	//5.5;
	NEAR_Y_OFFSET = (float)fabs(nearpoint.y - Physical_Yby2) + (float)2.0;	//4.0;
	switch(which)
	{
	case HGOALIE	:	robotPos = globaldata.goalieposS;
						thisRemoved = gRemoved.Goalie;
						break;
	case HROBOT1	:	robotPos = globaldata.robot1posS;
						thisRemoved = gRemoved.Robot1;
						break;
	case HROBOT2	:	robotPos = globaldata.robot2posS;
						thisRemoved = gRemoved.Robot2;
						break;
	}	//-- end of switch

	if(	robotPos.x < NEARPOS
		&& robotPos.y > (Physical_Yby2 - NEAR_Y_OFFSET)
		&& robotPos.y < (Physical_Yby2 + NEAR_Y_OFFSET)
		&& !thisRemoved)

		return true;
	else
		return false;

}	//-- ownArea(int which)
示例#17
0
void dijkstra(dungeon_t *d)
{
  /* Currently assumes that monsters only move on floors.  Will *
   * need to be modified for tunneling and pass-wall monsters.  */

  heap_t h;
  uint32_t x, y;
  static path_t p[DUNGEON_Y][DUNGEON_X], *c;
  static uint32_t initialized = 0;

  if (!initialized) {
    initialized = 1;
    dungeon = d;
    for (y = 0; y < DUNGEON_Y; y++) {
      for (x = 0; x < DUNGEON_X; x++) {
        p[y][x].pos[dim_y] = y;
        p[y][x].pos[dim_x] = x;
      }
    }
  }

  for (y = 0; y < DUNGEON_Y; y++) {
    for (x = 0; x < DUNGEON_X; x++) {
      d->pc_distance[y][x] = 255;
    }
  }
  d->pc_distance[d->pc.position[dim_y]][d->pc.position[dim_x]] = 0;

  heap_init(&h, dist_cmp, NULL);

  for (y = 0; y < DUNGEON_Y; y++) {
    for (x = 0; x < DUNGEON_X; x++) {
      if (mapxy(x, y) >= ter_floor) {
        p[y][x].hn = heap_insert(&h, &p[y][x]);
      }
    }
  }

  while ((c = heap_remove_min(&h))) {
    c->hn = NULL;
    if ((p[c->pos[dim_y] - 1][c->pos[dim_x] - 1].hn) &&
        (d->pc_distance[c->pos[dim_y] - 1][c->pos[dim_x] - 1] >
         d->pc_distance[c->pos[dim_y]][c->pos[dim_x]] + 1)) {
      d->pc_distance[c->pos[dim_y] - 1][c->pos[dim_x] - 1] =
        d->pc_distance[c->pos[dim_y]][c->pos[dim_x]] + 1;
      heap_decrease_key_no_replace(&h,
                                   p[c->pos[dim_y] - 1][c->pos[dim_x] - 1].hn);
    }
    if ((p[c->pos[dim_y] - 1][c->pos[dim_x]    ].hn) &&
        (d->pc_distance[c->pos[dim_y] - 1][c->pos[dim_x]    ] >
         d->pc_distance[c->pos[dim_y]][c->pos[dim_x]] + 1)) {
      d->pc_distance[c->pos[dim_y] - 1][c->pos[dim_x]    ] =
        d->pc_distance[c->pos[dim_y]][c->pos[dim_x]] + 1;
      heap_decrease_key_no_replace(&h,
                                   p[c->pos[dim_y] - 1][c->pos[dim_x]    ].hn);
    }
    if ((p[c->pos[dim_y] - 1][c->pos[dim_x] + 1].hn) &&
        (d->pc_distance[c->pos[dim_y] - 1][c->pos[dim_x] + 1] >
         d->pc_distance[c->pos[dim_y]][c->pos[dim_x]] + 1)) {
      d->pc_distance[c->pos[dim_y] - 1][c->pos[dim_x] + 1] =
        d->pc_distance[c->pos[dim_y]][c->pos[dim_x]] + 1;
      heap_decrease_key_no_replace(&h,
                                   p[c->pos[dim_y] - 1][c->pos[dim_x] + 1].hn);
    }
    if ((p[c->pos[dim_y]    ][c->pos[dim_x] - 1].hn) &&
        (d->pc_distance[c->pos[dim_y]    ][c->pos[dim_x] - 1] >
         d->pc_distance[c->pos[dim_y]][c->pos[dim_x]] + 1)) {
      d->pc_distance[c->pos[dim_y]    ][c->pos[dim_x] - 1] =
        d->pc_distance[c->pos[dim_y]][c->pos[dim_x]] + 1;
      heap_decrease_key_no_replace(&h,
                                   p[c->pos[dim_y]    ][c->pos[dim_x] - 1].hn);
    }
    if ((p[c->pos[dim_y]    ][c->pos[dim_x] + 1].hn) &&
        (d->pc_distance[c->pos[dim_y]    ][c->pos[dim_x] + 1] >
         d->pc_distance[c->pos[dim_y]][c->pos[dim_x]] + 1)) {
      d->pc_distance[c->pos[dim_y]    ][c->pos[dim_x] + 1] =
        d->pc_distance[c->pos[dim_y]][c->pos[dim_x]] + 1;
      heap_decrease_key_no_replace(&h,
                                   p[c->pos[dim_y]    ][c->pos[dim_x] + 1].hn);
    }
    if ((p[c->pos[dim_y] + 1][c->pos[dim_x] - 1].hn) &&
        (d->pc_distance[c->pos[dim_y] + 1][c->pos[dim_x] - 1] >
         d->pc_distance[c->pos[dim_y]][c->pos[dim_x]] + 1)) {
      d->pc_distance[c->pos[dim_y] + 1][c->pos[dim_x] - 1] =
        d->pc_distance[c->pos[dim_y]][c->pos[dim_x]] + 1;
      heap_decrease_key_no_replace(&h,
                                   p[c->pos[dim_y] + 1][c->pos[dim_x] - 1].hn);
    }
    if ((p[c->pos[dim_y] + 1][c->pos[dim_x]    ].hn) &&
        (d->pc_distance[c->pos[dim_y] + 1][c->pos[dim_x]    ] >
         d->pc_distance[c->pos[dim_y]][c->pos[dim_x]] + 1)) {
      d->pc_distance[c->pos[dim_y] + 1][c->pos[dim_x]    ] =
        d->pc_distance[c->pos[dim_y]][c->pos[dim_x]] + 1;
      heap_decrease_key_no_replace(&h,
                                   p[c->pos[dim_y] + 1][c->pos[dim_x]    ].hn);
    }
    if ((p[c->pos[dim_y] + 1][c->pos[dim_x] + 1].hn) &&
        (d->pc_distance[c->pos[dim_y] + 1][c->pos[dim_x] + 1] >
         d->pc_distance[c->pos[dim_y]][c->pos[dim_x]] + 1)) {
      d->pc_distance[c->pos[dim_y] + 1][c->pos[dim_x] + 1] =
        d->pc_distance[c->pos[dim_y]][c->pos[dim_x]] + 1;
      heap_decrease_key_no_replace(&h,
                                   p[c->pos[dim_y] + 1][c->pos[dim_x] + 1].hn);
    }
  }
  heap_delete(&h);
}
示例#18
0
void dijkstra_tunnel(dungeon_t *d)
{
  /* Currently assumes that monsters only move on floors.  Will *
   * need to be modified for tunneling and pass-wall monsters.  */

  heap_t h;
  uint32_t x, y;
  static path_t p[DUNGEON_Y][DUNGEON_X], *c;
  static uint32_t initialized = 0;

  if (!initialized) {
    initialized = 1;
    dungeon = d;
    for (y = 0; y < DUNGEON_Y; y++) {
      for (x = 0; x < DUNGEON_X; x++) {
        p[y][x].pos[dim_y] = y;
        p[y][x].pos[dim_x] = x;
      }
    }
  }

  for (y = 0; y < DUNGEON_Y; y++) {
    for (x = 0; x < DUNGEON_X; x++) {
      d->pc_tunnel[y][x] = 255;
    }
  }
  d->pc_tunnel[character_get_y(d->pc)][character_get_x(d->pc)] = 0;

  heap_init(&h, tunnel_cmp, NULL);

  for (y = 0; y < DUNGEON_Y; y++) {
    for (x = 0; x < DUNGEON_X; x++) {
      if (mapxy(x, y) != ter_wall_immutable) {
        p[y][x].hn = heap_insert(&h, &p[y][x]);
      }
    }
  }

  while ((c = heap_remove_min(&h))) {
    c->hn = NULL;
    if ((p[c->pos[dim_y] - 1][c->pos[dim_x] - 1].hn) &&
        (d->pc_tunnel[c->pos[dim_y] - 1][c->pos[dim_x] - 1] >
         d->pc_tunnel[c->pos[dim_y]][c->pos[dim_x]] + 1 +
         (d->hardness[c->pos[dim_y]][c->pos[dim_x]] / 60))) {
      d->pc_tunnel[c->pos[dim_y] - 1][c->pos[dim_x] - 1] =
        (d->pc_tunnel[c->pos[dim_y]][c->pos[dim_x]] + 1 +
         (d->hardness[c->pos[dim_y]][c->pos[dim_x]] / 60));
      heap_decrease_key_no_replace(&h,
                                   p[c->pos[dim_y] - 1][c->pos[dim_x] - 1].hn);
    }
    if ((p[c->pos[dim_y] - 1][c->pos[dim_x]    ].hn) &&
        (d->pc_tunnel[c->pos[dim_y] - 1][c->pos[dim_x]    ] >
         d->pc_tunnel[c->pos[dim_y]][c->pos[dim_x]] + 1 +
         (d->hardness[c->pos[dim_y]][c->pos[dim_x]] / 60))) {
      d->pc_tunnel[c->pos[dim_y] - 1][c->pos[dim_x]    ] =
        (d->pc_tunnel[c->pos[dim_y]][c->pos[dim_x]] + 1 +
         (d->hardness[c->pos[dim_y]][c->pos[dim_x]] / 60));
      heap_decrease_key_no_replace(&h,
                                   p[c->pos[dim_y] - 1][c->pos[dim_x]    ].hn);
    }
    if ((p[c->pos[dim_y] - 1][c->pos[dim_x] + 1].hn) &&
        (d->pc_tunnel[c->pos[dim_y] - 1][c->pos[dim_x] + 1] >
         d->pc_tunnel[c->pos[dim_y]][c->pos[dim_x]] + 1 +
         (d->hardness[c->pos[dim_y]][c->pos[dim_x]] / 60))) {
      d->pc_tunnel[c->pos[dim_y] - 1][c->pos[dim_x] + 1] =
        (d->pc_tunnel[c->pos[dim_y]][c->pos[dim_x]] + 1 +
         (d->hardness[c->pos[dim_y]][c->pos[dim_x]] / 60));
      heap_decrease_key_no_replace(&h,
                                   p[c->pos[dim_y] - 1][c->pos[dim_x] + 1].hn);
    }
    if ((p[c->pos[dim_y]    ][c->pos[dim_x] - 1].hn) &&
        (d->pc_tunnel[c->pos[dim_y]    ][c->pos[dim_x] - 1] >
         d->pc_tunnel[c->pos[dim_y]][c->pos[dim_x]] + 1 +
         (d->hardness[c->pos[dim_y]][c->pos[dim_x]] / 60))) {
      d->pc_tunnel[c->pos[dim_y]    ][c->pos[dim_x] - 1] =
        (d->pc_tunnel[c->pos[dim_y]][c->pos[dim_x]] + 1 +
         (d->hardness[c->pos[dim_y]][c->pos[dim_x]] / 60));
      heap_decrease_key_no_replace(&h,
                                   p[c->pos[dim_y]    ][c->pos[dim_x] - 1].hn);
    }
    if ((p[c->pos[dim_y]    ][c->pos[dim_x] + 1].hn) &&
        (d->pc_tunnel[c->pos[dim_y]    ][c->pos[dim_x] + 1] >
         d->pc_tunnel[c->pos[dim_y]][c->pos[dim_x]] + 1 +
         (d->hardness[c->pos[dim_y]][c->pos[dim_x]] / 60))) {
      d->pc_tunnel[c->pos[dim_y]    ][c->pos[dim_x] + 1] =
        (d->pc_tunnel[c->pos[dim_y]][c->pos[dim_x]] + 1 +
         (d->hardness[c->pos[dim_y]][c->pos[dim_x]] / 60));
      heap_decrease_key_no_replace(&h,
                                   p[c->pos[dim_y]    ][c->pos[dim_x] + 1].hn);
    }
    if ((p[c->pos[dim_y] + 1][c->pos[dim_x] - 1].hn) &&
        (d->pc_tunnel[c->pos[dim_y] + 1][c->pos[dim_x] - 1] >
         d->pc_tunnel[c->pos[dim_y]][c->pos[dim_x]] + 1 +
         (d->hardness[c->pos[dim_y]][c->pos[dim_x]] / 60))) {
      d->pc_tunnel[c->pos[dim_y] + 1][c->pos[dim_x] - 1] =
        (d->pc_tunnel[c->pos[dim_y]][c->pos[dim_x]] + 1 +
         (d->hardness[c->pos[dim_y]][c->pos[dim_x]] / 60));
      heap_decrease_key_no_replace(&h,
                                   p[c->pos[dim_y] + 1][c->pos[dim_x] - 1].hn);
    }
    if ((p[c->pos[dim_y] + 1][c->pos[dim_x]    ].hn) &&
        (d->pc_tunnel[c->pos[dim_y] + 1][c->pos[dim_x]    ] >
         d->pc_tunnel[c->pos[dim_y]][c->pos[dim_x]] + 1 +
         (d->hardness[c->pos[dim_y]][c->pos[dim_x]] / 60))) {
      d->pc_tunnel[c->pos[dim_y] + 1][c->pos[dim_x]    ] =
        (d->pc_tunnel[c->pos[dim_y]][c->pos[dim_x]] + 1 +
         (d->hardness[c->pos[dim_y]][c->pos[dim_x]] / 60));
      heap_decrease_key_no_replace(&h,
                                   p[c->pos[dim_y] + 1][c->pos[dim_x]    ].hn);
    }
    if ((p[c->pos[dim_y] + 1][c->pos[dim_x] + 1].hn) &&
        (d->pc_tunnel[c->pos[dim_y] + 1][c->pos[dim_x] + 1] >
         d->pc_tunnel[c->pos[dim_y]][c->pos[dim_x]] + 1 +
         (d->hardness[c->pos[dim_y]][c->pos[dim_x]] / 60))) {
      d->pc_tunnel[c->pos[dim_y] + 1][c->pos[dim_x] + 1] =
        (d->pc_tunnel[c->pos[dim_y]][c->pos[dim_x]] + 1 +
         (d->hardness[c->pos[dim_y]][c->pos[dim_x]] / 60));
      heap_decrease_key_no_replace(&h,
                                   p[c->pos[dim_y] + 1][c->pos[dim_x] + 1].hn);
    }
  }
  heap_delete(&h);
}
示例#19
0
/* This is the same basic algorithm as in move.c, but *
 * subtle differences make it difficult to reuse.     */
static void dijkstra_corridor(dungeon_t *d, pair_t from, pair_t to)
{
  static corridor_path_t path[DUNGEON_Y][DUNGEON_X], *p;
  static uint32_t initialized = 0;
  heap_t h;
  uint32_t x, y;

  if (!initialized) {
    for (y = 0; y < DUNGEON_Y; y++) {
      for (x = 0; x < DUNGEON_X; x++) {
        path[y][x].pos[dim_y] = y;
        path[y][x].pos[dim_x] = x;
      }
    }
    initialized = 1;
  }
  
  for (y = 0; y < DUNGEON_Y; y++) {
    for (x = 0; x < DUNGEON_X; x++) {
      path[y][x].cost = INT_MAX;
    }
  }

  path[from[dim_y]][from[dim_x]].cost = 0;

  heap_init(&h, corridor_path_cmp, NULL);

  for (y = 0; y < DUNGEON_Y; y++) {
    for (x = 0; x < DUNGEON_X; x++) {
      if (mapxy(x, y) != ter_wall_immutable) {
        path[y][x].hn = heap_insert(&h, &path[y][x]);
      } else {
        path[y][x].hn = NULL;
      }
    }
  }

  while ((p = (corridor_path_t *) heap_remove_min(&h))) {
    p->hn = NULL;

    if ((p->pos[dim_y] == to[dim_y]) && p->pos[dim_x] == to[dim_x]) {
      for (x = to[dim_x], y = to[dim_y];
           (x != from[dim_x]) || (y != from[dim_y]);
           p = &path[y][x], x = p->from[dim_x], y = p->from[dim_y]) {
        if (mapxy(x, y) != ter_floor_room) {
          mapxy(x, y) = ter_floor_hall;
          hardnessxy(x, y) = 0;
        }
      }
      heap_delete(&h);
      return;
    }
    if ((path[p->pos[dim_y] - 1][p->pos[dim_x]    ].hn) &&
        (path[p->pos[dim_y] - 1][p->pos[dim_x]    ].cost >
         p->cost + (hardnesspair(p->pos) ? hardnesspair(p->pos) : 8) +
         ((p->pos[dim_x] != from[dim_x]) ? 48  : 0))) {
      path[p->pos[dim_y] - 1][p->pos[dim_x]    ].cost =
        p->cost + (hardnesspair(p->pos) ? hardnesspair(p->pos) : 8) +
         ((p->pos[dim_x] != from[dim_x]) ? 48  : 0);
      path[p->pos[dim_y] - 1][p->pos[dim_x]    ].from[dim_y] = p->pos[dim_y];
      path[p->pos[dim_y] - 1][p->pos[dim_x]    ].from[dim_x] = p->pos[dim_x];
      heap_decrease_key_no_replace(&h, path[p->pos[dim_y] - 1]
                                           [p->pos[dim_x]    ].hn);
    }
    if ((path[p->pos[dim_y]    ][p->pos[dim_x] - 1].hn) &&
        (path[p->pos[dim_y]    ][p->pos[dim_x] - 1].cost >
         p->cost + (hardnesspair(p->pos) ? hardnesspair(p->pos) : 8) +
         ((p->pos[dim_y] != from[dim_y]) ? 48  : 0))) {
      path[p->pos[dim_y]    ][p->pos[dim_x] - 1].cost =
        p->cost + (hardnesspair(p->pos) ? hardnesspair(p->pos) : 8) +
         ((p->pos[dim_y] != from[dim_y]) ? 48  : 0);
      path[p->pos[dim_y]    ][p->pos[dim_x] - 1].from[dim_y] = p->pos[dim_y];
      path[p->pos[dim_y]    ][p->pos[dim_x] - 1].from[dim_x] = p->pos[dim_x];
      heap_decrease_key_no_replace(&h, path[p->pos[dim_y]    ]
                                           [p->pos[dim_x] - 1].hn);
    }
    if ((path[p->pos[dim_y]    ][p->pos[dim_x] + 1].hn) &&
        (path[p->pos[dim_y]    ][p->pos[dim_x] + 1].cost >
         p->cost + (hardnesspair(p->pos) ? hardnesspair(p->pos) : 8) +
         ((p->pos[dim_y] != from[dim_y]) ? 48  : 0))) {
      path[p->pos[dim_y]    ][p->pos[dim_x] + 1].cost =
        p->cost + (hardnesspair(p->pos) ? hardnesspair(p->pos) : 8) +
         ((p->pos[dim_y] != from[dim_y]) ? 48  : 0);
      path[p->pos[dim_y]    ][p->pos[dim_x] + 1].from[dim_y] = p->pos[dim_y];
      path[p->pos[dim_y]    ][p->pos[dim_x] + 1].from[dim_x] = p->pos[dim_x];
      heap_decrease_key_no_replace(&h, path[p->pos[dim_y]    ]
                                           [p->pos[dim_x] + 1].hn);
    }
    if ((path[p->pos[dim_y] + 1][p->pos[dim_x]    ].hn) &&
        (path[p->pos[dim_y] + 1][p->pos[dim_x]    ].cost >
         p->cost + (hardnesspair(p->pos) ? hardnesspair(p->pos) : 8) +
         ((p->pos[dim_x] != from[dim_x]) ? 48  : 0))) {
      path[p->pos[dim_y] + 1][p->pos[dim_x]    ].cost =
        p->cost + (hardnesspair(p->pos) ? hardnesspair(p->pos) : 8) +
         ((p->pos[dim_x] != from[dim_x]) ? 48  : 0);
      path[p->pos[dim_y] + 1][p->pos[dim_x]    ].from[dim_y] = p->pos[dim_y];
      path[p->pos[dim_y] + 1][p->pos[dim_x]    ].from[dim_x] = p->pos[dim_x];
      heap_decrease_key_no_replace(&h, path[p->pos[dim_y] + 1]
                                           [p->pos[dim_x]    ].hn);
    }
  }
}
示例#20
0
void myStrategy()
{
    //gchoice = 0;	//-- Striker chase the ball
    //gchoice = 1;	//-- Position Goalie at 90 degrees - Testing Angle() function
    //gchoice = 2;	//-- TO POSITION STRIKER AT THE POINT CLICKED IN THE CAPTURE WINDOW
    //-- Testing Position() function
    //gchoice = 3;
    //gchoice = 4;
    //gchoice = 5;
    //gchoice = 6;
    //gchoice = 7;	//-- State Based GOALIE
    //gchoice = 8;
    //gchoice = 9;
    //gchoice = 10;	//-- State Based kick start & NORMAL Game
    //gchoice = 11;
    //gchoice = 12;

    floatPOINT finalPos;
    floatPOINT clickPoint;
    static floatPOINT oldClickPoint= {0,0};
    float finalAngle;
    float finalVel;
    float desiredAngle;
    int which;

    floatPOINT nearpoint;
    floatPOINT movePos;
    floatPOINT oppgoalbottom;
    float FARPOS;

    switch (gChoice)
    {
    case 0 :
        //-- STRIKER TO CHASE THE BALL --------------------------------

        chaseBall(HROBOT1);

        //-----------------------------------------------------
        break;

    case 1 :
        //-- TO MAKE THE GOALIE'S ANGLE 90 DEGREES ---------------
        desiredAngle = 90;
        angleG(which, desiredAngle);
        //-----------------------------------------------------
        break;

    case 2 :
        //-- TO POSITION STRIKER AT THE POINT CLICKED IN THE CAPTURE WINDOW -----
        //-- -- Testing Position() function

        clickPoint.x = (float)globaldata.capPoint.x;
        clickPoint.y = (float)globaldata.capPoint.y;

        //-- covert the screen coordinates to physical coordinates
        //-- physical coordinates are in the variable finalPos
        mapxy(&clickPoint, &finalPos, &globaldata);

        finalAngle = 0;
        finalVel = 0;
        which = HROBOT1;

        position(which, finalPos, finalAngle, finalVel);
        avoidBound(which, finalPos);
        avoidGoalAreas(which, finalPos);
        //--------------------------------------------------------
        break;

    case 3 :	//Test myShoot()

        testMyShoot(HROBOT1);

        /*
        oppgoalbottom.x = (float)globaldata.oppgoalbottom.x;
        oppgoalbottom.y = (float)globaldata.oppgoalbottom.y;
        mapxy(&oppgoalbottom, &nearpoint, &globaldata);
        FARPOS = nearpoint.x;

        //	which = HGOALIE;	//-- goalie
        	which = HROBOT1;	//-- defender
        // which = HROBOT2;	//-- striker

        finalPos.x = FARPOS;
        finalPos.y = Physical_Yby2;

        myShoot(which, &finalPos);
        //position(which, finalPos, 0, 0);

        //avoidBound(which, finalPos);
        //avoidGoalAreas(which, finalPos);
        */

        break;

    case 4 :
        globaldata.dBehaviour->runAction();
        break;

    case 5 :
        break;

    case 6:
        break;

    case 7://---- State Based goal defense, the goal keeper
    {
        globaldata.gBehaviour->runAction();
    }
    break;

    case 8:
        break;

    case 9:
        break;

    case 10://---- Kick Start + Normal game
        //-- insert code here to play the game
    {
        globaldata.gBehaviour->runAction();
        globaldata.dBehaviour->runAction();
        globaldata.sBehaviour->runAction();
    }

    break;

    case 11:
        break;

    case 12 :
        break;

    default :
        break;

    }	//-- end of switch statement

    switchRobotsIfCan();

    return;
}	//-- myStrategy()