Пример #1
0
const std::vector<const team::shroud_map*>& team::ally_fog(const std::vector<team>& teams) const
{
	if(ally_fog_.empty()) {
		for(size_t i = 0; i < teams.size(); ++i) {
			if(!is_enemy(i + 1) && (&(teams[i]) == this || teams[i].share_view())) {
				ally_fog_.push_back(&(teams[i].fog_));
			}
		}
	}

	return ally_fog_;
}
Пример #2
0
bool move_player(struct player *player, bool keys[4], enum tile map[50][30], struct enemy enemies[100])
{
	int new_x=player->x;
	int new_y=player->y;
	if(player->last_move>1)
	{
		if(keys[KEY_UP] && player->y>0 && map[player->x][player->y-1]==FLOOR)
			new_y--;
		else if(keys[KEY_RIGHT] && player->x<49 && map[player->x+1][player->y]==FLOOR)
			new_x++;
		else if(keys[KEY_DOWN] && player->y<29 && map[player->x][player->y+1]==FLOOR)
			new_y++;
		else if(keys[KEY_LEFT] && player->x>0 && map[player->x-1][player->y]==FLOOR)
			new_x--;

		if(is_enemy(new_x, new_y, enemies)==100)
		{
			player->x=new_x;
			player->y=new_y;
		}
		else
		{
			fight(player, enemies, is_enemy(new_x, new_y, enemies));
		}

		if(keys[KEY_UP] || keys[KEY_DOWN] || keys[KEY_RIGHT] || keys[KEY_LEFT])
		{
			player->last_move=0;
			return true;
		}
	}
	else
	{
		player->last_move++;
	}
	return false;
}
Пример #3
0
bool AttackAbility::can_invoke(Unit &to_modify, const Command &cmd) {
	if (cmd.has_unit()) {
		Unit &target = *cmd.unit();
		bool target_is_resource = has_resource(target);
		return &to_modify != &target &&
		       to_modify.location &&
		       target.location &&
		       target.location->is_placed() &&
		       to_modify.has_attribute(attr_type::attack) &&
		       has_hitpoints(target) &&
		       (is_enemy(to_modify, target) || target_is_resource) &&
		       (cmd.has_flag(command_flag::attack_res) == target_is_resource);
	}
	return false;
}
Пример #4
0
int npc::danger_assessment(game *g)
{
 int ret = 0;
 int sightdist = g->light_level(), junk;
 for (int i = 0; i < g->z.size(); i++) {
  if (g->m.sees(posx, posy, g->z[i].posx, g->z[i].posy, sightdist, junk))
   ret += g->z[i].type->difficulty;
 }
 ret /= 10;
 if (ret <= 2)
  ret = -10 + 5 * ret;	// Low danger if no monsters around

// Mod for the player
 if (is_enemy()) {
  if (rl_dist(posx, posy, g->u.posx, g->u.posy) < 10) {
   if (g->u.weapon.is_gun())
    ret += 10;
   else 
    ret += 10 - rl_dist(posx, posy, g->u.posx, g->u.posy);
  }
 } else if (is_friend()) {
  if (rl_dist(posx, posy, g->u.posx, g->u.posy) < 8) {
   if (g->u.weapon.is_gun())
    ret -= 8;
   else 
    ret -= 8 - rl_dist(posx, posy, g->u.posx, g->u.posy);
  }
 }

 for (int i = 0; i < num_hp_parts; i++) {
  if (i == hp_head || i == hp_torso) {
        if (hp_cur[i] < hp_max[i] / 4)
    ret += 5;
   else if (hp_cur[i] < hp_max[i] / 2)
    ret += 3;
   else if (hp_cur[i] < hp_max[i] * .9)
    ret += 1;
  } else {
        if (hp_cur[i] < hp_max[i] / 4)
    ret += 2;
   else if (hp_cur[i] < hp_max[i] / 2)
    ret += 1;
  }
 }
 return ret;
}
Пример #5
0
bool is_aggressive( char_data* ch, char_data* victim )
{
  char_data* opponent;

  if( ch == victim || ch->position <= POS_SLEEPING )
    return FALSE;

  if( ( opponent = victim->fighting ) != NULL )
    if( join_fight( opponent, victim, ch ) )
      return TRUE;

  if(  ch->pcdata != NULL
    || is_set( &victim->in_room->room_flags, RFLAG_SAFE )
    || !victim->Seen( ch ) )
    return FALSE;

  if( ch->shdata->race == RACE_PLANT
    && is_set( victim->affected_by, AFF_PROT_PLANTS ) )
    return FALSE;

  if( is_evil( victim ) )
    if( is_set( &ch->status, STAT_AGGR_EVIL )
      && is_set( ch->affected_by, AFF_DETECT_EVIL ) ) 
      return TRUE;
  else if( is_good( victim ) )
    if( is_set( &ch->status, STAT_AGGR_GOOD )
      && is_set( ch->affected_by, AFF_DETECT_GOOD ) ) 
      return TRUE;

  if( is_set( &ch->status, STAT_PET ) )
    return FALSE;

  if( victim->species == NULL ) {
    if( victim->shdata->level >= LEVEL_BUILDER )
      return FALSE;
    if( is_set( &ch->status, STAT_AGGR_ALL )
      || is_enemy( ch, victim ) )
      return TRUE;
    }

  return FALSE;
}
Пример #6
0
void npc::die(game *g, bool your_fault)
{
 int j;
 if (g->u_see(posx, posy, j))
  g->add_msg("%s dies!", name.c_str());
 if (your_fault && !g->u.has_trait(PF_HEARTLESS)) {
  if (is_friend())
   g->u.add_morale(MORALE_KILLED_FRIEND, -500);
  else if (!is_enemy())
   g->u.add_morale(MORALE_KILLED_INNOCENT, -100);
 }
  
 item my_body;
 my_body.make_corpse(g->itypes[itm_corpse], g->mtypes[mon_null], g->turn);
 my_body.name = name;
 g->m.add_item(posx, posy, my_body);
 for (int i = 0; i < inv.size(); i++)
  g->m.add_item(posx, posy, inv[i]);
 for (int i = 0; i < worn.size(); i++)
  g->m.add_item(posx, posy, worn[i]);
 if (weapon.type->id != itm_null)
  g->m.add_item(posx, posy, weapon);
}
Пример #7
0
bool team::knows_about_team(size_t index) const
{
	const team& t = resources::gameboard->teams()[index];

	// We know about our own team
	if(this == &t) {
		return true;
	}

	// If we aren't using shroud or fog, then we know about everyone
	if(!uses_shroud() && !uses_fog()) {
		return true;
	}

	// We don't know about enemies
	if(is_enemy(index + 1)) {
		return false;
	}

	// We know our human allies.
	if(t.is_human()) {
		return true;
	}

	// We know about allies we're sharing maps with
	if(share_maps() && t.uses_shroud()) {
		return true;
	}

	// We know about allies we're sharing view with
	if(share_view() && (t.uses_fog() || t.uses_shroud())) {
		return true;
	}

	return false;
}
Пример #8
0
void breed(struct enemy enemies[100], enum tile map[50][30])
{
	//Pick an enemy at random
	int parent;
	int accumulator=1;
	for(int i=0; i<100; i++)
	{
		if(enemies[i].exists)
		{
			if(!(rand()%accumulator))
			{
				parent=i;
			}
			accumulator++;
		}
	}

	int xs[]={enemies[parent].x+1, enemies[parent].x-1, enemies[parent].x, enemies[parent].x};
	int ys[]={enemies[parent].y, enemies[parent].y, enemies[parent].y+1, enemies[parent].y-1};

	int child_x;
	int child_y;

	accumulator=0;

	for(int c=0; c<4; c++)
	{
		if(xs[c]<0 || xs[c]>49 || ys[c]<0 || ys[c]>29 || map[xs[c]][ys[c]]==WALL || is_enemy(xs[c], ys[c], enemies)!=100)
		{
			accumulator++;
			continue;
		}
		child_x=xs[c];
		child_y=ys[c];
	}

	if(accumulator==4)
	{
		return;
	}


	int child_index;


	for(child_index=0; child_index<100; child_index++)
	{
		if(!(enemies[child_index].exists))
		{
			break;
		}
	}

	if(child_index==100)
	{
		return;
	}

	enemies[child_index].x=child_x;
	enemies[child_index].y=child_y;
	enemies[child_index].exists=true;
	enemies[child_index].turns_missed=0;
	enemies[child_index].power=enemies[parent].power+(rand()%3 ? 0 : (1));
	enemies[child_index].speed=enemies[parent].speed+(rand()%3 ? 0 : 1);
	enemies[child_index].max_health=enemies[parent].max_health+(rand()%3 ? 0 : 5);
	enemies[child_index].health=enemies[child_index].max_health;
}
Пример #9
0
int main()
{
	ALLEGRO_DISPLAY *display = NULL;
	ALLEGRO_EVENT_QUEUE *event_queue=NULL;
	ALLEGRO_TIMER *timer=NULL;
	ALLEGRO_FONT *font=NULL;
	bool keys[4]={false, false, false, false};
	bool redraw;
	enum tile map[50][30];
	struct player player;
	struct enemy enemies[100];
	int next;
	int selected_enemy=100;
	int level=1;
	int best=1;

	
	player.power=5;
	player.health=30;
	player.max_health=30;
	player.speed=2;
	player.x=0;
	player.y=0;
	player.turns_missed=0;
	player.kills=0;
	player.upgrades=4;

	if(!init(&display, &event_queue, &timer))
	{
		return 1;
	}

	init_map(map);

	init_enemies(enemies, map, 5);

	font=al_load_font("Xolonium-Regular.otf", 30, 0);

	while(42)
	{
		ALLEGRO_EVENT ev;
		al_wait_for_event(event_queue, &ev);

		if(ev.type == ALLEGRO_EVENT_TIMER)
		{
			redraw=true;
			next=select_mover(player, enemies);
			if(next==100)
			{
				if(move_player(&player, keys, map, enemies))
				{
					player.turns_missed=0;
					inc_turns(&player, enemies);
				}
			}
			else
			{
				int ret_x, ret_y;
				search(enemies[next].x, enemies[next].y, map, player.x, player.y, &ret_x, &ret_y);
				if(!is_player(ret_x, ret_y, player) && is_enemy(ret_x, ret_y, enemies)==100)
				{
					enemies[next].x=ret_x;
					enemies[next].y=ret_y;
				}
				if(is_player(ret_x, ret_y, player))
				{
					fight(&player, enemies, next);
				}
				enemies[next].turns_missed=0;
				inc_turns(&player, enemies);
				if(!(rand()%(150/level)))
				{
					breed(enemies, map);
				}
			}

			if(enemies[selected_enemy].health<=0)
			{
				selected_enemy=100;
			}

			if(all_enemies_dead(enemies))
			{
				level++;
				init_map(map);
				init_enemies(enemies, map, level*5);
				player.x=0;
				player.y=0;
				if(level>best)
				{
					best=level;
				}
			}

			if(player.health<=0)
			{
				level=1;
				init_map(map);
				init_enemies(enemies, map, level*5);
				player.power=5;
				player.health=30;
				player.max_health=30;
				player.speed=2;
				player.x=0;
				player.y=0;
				player.turns_missed=0;
				player.kills=0;
				player.upgrades=0;
			}
		}
		else if(ev.type==ALLEGRO_EVENT_DISPLAY_CLOSE)
		{
			break;
		}
		else if(ev.type == ALLEGRO_EVENT_KEY_DOWN)
		{
			switch(ev.keyboard.keycode)
			{
				case ALLEGRO_KEY_UP:
					keys[KEY_UP]=true;
					break;
				case ALLEGRO_KEY_DOWN:
					keys[KEY_DOWN]=true;
					break;
				case ALLEGRO_KEY_RIGHT:
					keys[KEY_RIGHT]=true;
					break;
				case ALLEGRO_KEY_LEFT:
					keys[KEY_LEFT]=true;
					break;
			}
		}
		else if(ev.type == ALLEGRO_EVENT_KEY_UP)
		{
			switch(ev.keyboard.keycode)
			{
				case ALLEGRO_KEY_UP:
					keys[KEY_UP]=false;
					break;
				case ALLEGRO_KEY_DOWN:
					keys[KEY_DOWN]=false;
					break;
				case ALLEGRO_KEY_RIGHT:
					keys[KEY_RIGHT]=false;
					break;
				case ALLEGRO_KEY_LEFT:
					keys[KEY_LEFT]=false;
					break;
			}
		}
		else if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN)
		{
			int old_selected=selected_enemy;

			selected_enemy=is_enemy(ev.mouse.x/18, ev.mouse.y/18, enemies);

			if(selected_enemy==100)
				selected_enemy=old_selected;

			if(ev.mouse.x>900 && player.kills >= (player.upgrades * player.upgrades)/10)
			{
				bool change=false;
				if(ev.mouse.y>10 && ev.mouse.y<40)
				{
					player.max_health+=5;
					player.health=player.max_health;
					change=true;
				}
				else if(ev.mouse.y>50 && ev.mouse.y<80)
				{
					player.power+=2;
					change=true;
				}
				else if(ev.mouse.y>90 && ev.mouse.y<120)
				{
					player.speed+=1;
					change=true;
				}
				
				if(change)
				{
					player.upgrades+=1;
				}
			}
		}

		if(redraw && al_is_event_queue_empty(event_queue))
		{
			redraw=false;
			al_clear_to_color(al_map_rgb(255, 255, 255));
			draw_map(map);
			draw_enemies(enemies);
			al_draw_bitmap(player_img, player.x*18, player.y*18, 0);
			al_draw_textf(font, al_map_rgb(0, 255, 0), 950, 10, ALLEGRO_ALIGN_CENTRE, "%d", player.health);
			al_draw_textf(font, al_map_rgb(0, 255, 0), 950, 50, ALLEGRO_ALIGN_CENTRE, "%d", player.power);
			al_draw_textf(font, al_map_rgb(0, 255, 0), 950, 90, ALLEGRO_ALIGN_CENTRE, "%d", player.speed);
			al_draw_textf(font, al_map_rgb(0, 0, 255), 950, 150, ALLEGRO_ALIGN_CENTRE, "%d", player.kills);
			al_draw_textf(font, al_map_rgb(0, 0, 255), 950, 190, ALLEGRO_ALIGN_CENTRE, "%d", (player.upgrades*player.upgrades)/10);
			if(selected_enemy!=100)
			{
				al_draw_textf(font, al_map_rgb(255, 0, 0), 950, 250, ALLEGRO_ALIGN_CENTRE, "%d", enemies[selected_enemy].health);
				al_draw_textf(font, al_map_rgb(255, 0, 0), 950, 290, ALLEGRO_ALIGN_CENTRE, "%d", enemies[selected_enemy].power);
				al_draw_textf(font, al_map_rgb(255, 0, 0), 950, 330, ALLEGRO_ALIGN_CENTRE, "%d", enemies[selected_enemy].speed);
			}
			al_draw_textf(font, al_map_rgb(0, 0, 0), 950, 390, ALLEGRO_ALIGN_CENTRE, "%d", level);
			al_draw_textf(font, al_map_rgb(0, 0, 0), 950, 430, ALLEGRO_ALIGN_CENTRE, "%d", best);
			al_flip_display();
		}
	}

	return 0;
}
Пример #10
0
void FightEvent::run()
{
  // store all the fighters except the users
  std::vector<Fighter*> all_fighters;
  
  for (int i = 0; i < static_cast<int>(allies.size()); ++i)
    all_fighters.push_back(allies.at(i));
  
  for (int i = 0; i < static_cast<int>(enemies.size()); ++i)
    all_fighters.push_back(enemies.at(i));
  
  // sort from fastest to slowest
  std::sort(all_fighters.begin(), all_fighters.end(), comp_speed);
  
  // find the correct index to insert the user's ship
  int i = 0;
  for (; i < static_cast<int>(all_fighters.size()) && all_fighters.at(i)->get_base_speed() > get_modified_speed(); ++i);
  
  if (i == static_cast<int>(all_fighters.size()))
    all_fighters.push_back(player->get_ship());
  
  else
    all_fighters.insert(all_fighters.begin() + i, player->get_ship());

  int round = 1;
  
  // fight until user's ship destroyed or no more enemies left
  while (get_modified_health() > 0 && enemies.size() > 0)
  {
    usleep(3000000);
    
    utilities::clear_display();
    
    std::cout << "\n==== Fight Round " << round << " ====\n\n";
    
    // let each fighter have a chance to fight
    for (int j = 0; j < static_cast<int>(all_fighters.size()) && get_modified_health() > 0 && enemies.size() > 0; ++j)
    {
      Fighter* cur_fighter = all_fighters.at(j);
      
      // fighter is dead
      if (!is_ally(cur_fighter) && !is_enemy(cur_fighter))
      {
        all_fighters.erase(all_fighters.begin() + j);
        delete cur_fighter;
        cur_fighter = NULL;
        
        // adjust index based on the removed fighter
        j--;
      }
      
      // fighter is still alive and can attack
      else
      {
        int area_wide_attk = 0;
        int reg_attk = 0;
        
        // user gets to attack
        if (cur_fighter == player->get_ship())
        {
          // only one of these can be non-zero
          area_wide_attk = cur_fighter->is_area_wide() ? get_modified_attack() : 0;
          reg_attk = cur_fighter->is_area_wide() ? 0 : get_modified_attack();
          
          // do attack affecting all enemies
          if (area_wide_attk > 0)
            attack_area(cur_fighter, PLAYER, area_wide_attk, enemies);
          
          // do attack targeting a single enemy
          else if (reg_attk > 0)
          {
            // attack a random enemy
            int who_attacked = rand() % enemies.size();
            Fighter *attacked = enemies.at(who_attacked);

            attack_one(cur_fighter, PLAYER, reg_attk, attacked, enemies, who_attacked);
          }
        }
        
        // ally is attacking the enemies
        else if (is_ally(cur_fighter))
        {
          // only one of these can be non-zero
          area_wide_attk = cur_fighter->attack_enemies();
          reg_attk = cur_fighter->attack_enemy();
          
          // do attack affecting all enemies
          if (area_wide_attk > 0)
            attack_area(cur_fighter, AL, area_wide_attk, enemies);
          
          // do attack targeting a single enemy
          else if (reg_attk > 0)
          {
            // attack a random enemy
            int who_attacked = rand() % enemies.size();
            Fighter *attacked = enemies.at(who_attacked);
            
            attack_one(cur_fighter, AL, reg_attk, attacked, enemies, who_attacked);
          }
        }
        
        // enemy is attacking you and your allies
        else
        {
          // only one of these can be non-zero
          area_wide_attk = cur_fighter->attack_enemies();
          reg_attk = cur_fighter->attack_enemy();
          
          // do attack affecting all allies and user
          if (area_wide_attk > 0)
            attack_area(cur_fighter, EN, area_wide_attk, allies);
          
          // do attack targeting a single ally or the user
          else if (reg_attk > 0)
          {
            // attack a random ally
            int who_attacked = 0;
            
            if (allies.size() > 0)
              who_attacked = rand() % allies.size() + 1;
            
            // user's ship was attacked
            if (who_attacked == static_cast<int>(allies.size()))
            {
              const int IGNORE = -1;
              attack_one(cur_fighter, EN, reg_attk, player->get_ship(), allies, IGNORE);
            }
            
            // ally's ship was attacked
            else
            {
              Fighter *attacked = allies.at(who_attacked);
              
              attack_one(cur_fighter, EN, reg_attk, attacked, allies, who_attacked);
            }
          }
        }
      }
    }
    
    // next fight round
    ++round;
  }
  
  std::cout << std::endl;
  
  // clean up all the pointers of ships that weren't defeated
  for (int m = 0; m < static_cast<int>(all_fighters.size()); ++m)
  {
    Fighter *cur = all_fighters.at(m);
    
    if (cur != player->get_ship())
    {
      delete cur;
      cur = NULL;
    }
  }
  
  if (get_modified_health() > 0)
  {
    std::cout << "You managed to survive with " << get_modified_health() << " health!\n\n";
    
    int winnings = rand() % 400 + 1;
    std::cout << "You came up on " << winnings << " ducats!\n\n";
    
    player->gain_money(winnings);
    player->won_battle();
  }
  
  else
  {
    std::cout << "Darn!  You died.  Game over!\n\n";
    player->died();
  }
}