示例#1
0
文件: OUNITHB.cpp 项目: brianV/7kaa
//--------- Begin of function Unit::handle_blocked_attack_wall ---------//
// handle the case that the way of this unit to the target wall is blocked by
// another unit
//
// <Unit*> unitPtr	- the blocking unit
//
void Unit::handle_blocked_attack_wall(Unit *unitPtr)
{
	if(action_x_loc==unitPtr->action_x_loc && action_y_loc==unitPtr->action_y_loc && action_mode==unitPtr->action_mode)
	{
		//------------- both attacks the same wall ------------//
		Location *locPtr = world.get_loc(action_x_loc, action_y_loc);
		if(!locPtr->is_wall())
			stop2(KEEP_DEFENSE_MODE);	// stop since wall is deleted
		else if(space_for_attack(action_x_loc, action_y_loc, UNIT_LAND, 1, 1))
		{
			//------------ found surrounding place to attack the wall -------------//
			if(mobile_type==UNIT_LAND)
				set_move_to_surround(action_x_loc, action_y_loc, 1, 1, BUILDING_TYPE_WALL); // search for a unit only, not for a group
			else
				attack_wall(action_x_loc, action_y_loc);
		}
		else // no surrounding place found, stop now
			stop(KEEP_PRESERVE_ACTION); // no space available, so stop to wait for space to attack the wall
	}
	else
	{
		if(action_x_loc==-1 || action_y_loc==-1)
			stop();
		else
			set_wait();
	}
}
示例#2
0
文件: OUNITD.cpp 项目: AMDmi3/7kaa
//--------- Begin of function Unit::defense_attack_wall ---------//
// defensive attack wall
//
// <short>	targetXLoc	-	x location of wall
// <short>	targetYLoc	-	y location of wall
//
void Unit::defense_attack_wall(int targetXLoc, int targetYLoc)
{
	action_mode2 = ACTION_AUTO_DEFENSE_ATTACK_TARGET;
	attack_wall(targetXLoc, targetYLoc);
}
示例#3
0
文件: OUNITD.cpp 项目: AMDmi3/7kaa
//--------- Begin of function Unit::monster_defend_attack_wall ---------//
// set monster to attack wall
//
// <int>	targetXLoc	-	x location of wall
// <int>	targetYLoc	-	y location of wall
//
void Unit::monster_defend_attack_wall(int targetXLoc, int targetYLoc)
{
	action_mode2 = ACTION_MONSTER_DEFEND_ATTACK_TARGET;
	attack_wall(targetXLoc, targetYLoc);
}
示例#4
0
文件: OUNITD.cpp 项目: AMDmi3/7kaa
//--------- Begin of function Unit::general_defend_mode_process_attack_target ---------//
// process unit defense action. If target is dead, action_mode changes to detect_mode
//
// return 1 if action mode changes to detect mode
// return 0 otherwise
//
int Unit::general_defend_mode_process_attack_target()
{
	Location *locPtr;
	Unit *unitPtr;
	Town *townPtr;
	Firm *firmPtr;
	SpriteInfo	*spriteInfo;
	FirmInfo		*firmInfo;
	int clearToDetect = 0;

	//------------------------------------------------------------------------------//
	// if the unit's action mode is in defensive attack action, process the corresponding
	// checking.
	//------------------------------------------------------------------------------//
	switch(action_mode)
	{
		case ACTION_ATTACK_UNIT:
				if(unit_array.is_deleted(action_para2))
					clearToDetect++;
				else
				{
					err_when(unit_array.is_deleted(action_para2));
					unitPtr = unit_array[action_para2];
					
					//if(unitPtr->cur_action==SPRITE_IDLE)
					//	clearToDetect++;

					if(!nation_can_attack(unitPtr->nation_recno)) // cannot attack this nation
						clearToDetect++;
				}
				break;

		case ACTION_ATTACK_FIRM:
				if(firm_array.is_deleted(action_para2))
					clearToDetect++;
				else
				{
					err_when(firm_array.is_deleted(action_para2));
					firmPtr = firm_array[action_para2];
					
					if(!nation_can_attack(firmPtr->nation_recno)) // cannot attack this nation
						clearToDetect++;
				}
				break;

		case ACTION_ATTACK_TOWN:
				if(town_array.is_deleted(action_para2))
					clearToDetect++;
				else
				{
					err_when(town_array.is_deleted(action_para2));
					townPtr = town_array[action_para2];
					
					if(!nation_can_attack(townPtr->nation_recno)) // cannot attack this nation
						clearToDetect++;
				}
				break;

		case ACTION_ATTACK_WALL:
				locPtr = world.get_loc(action_x_loc2, action_y_loc2);
				
				if(!locPtr->is_wall() || !nation_can_attack(locPtr->power_nation_recno))
					clearToDetect++;
				break;

		default: clearToDetect++;
					break;
	}

	//------------------------------------------------------------------------------//
	// suitation changed to defensive detecting mode
	//------------------------------------------------------------------------------//
	if(clearToDetect)
	{
		//----------------------------------------------------------//
		// target is dead, change to detect state for another target
		//----------------------------------------------------------//
		reset_action_para();
		return 1;
	}
	else if(waiting_term<ATTACK_WAITING_TERM)
		waiting_term++;
	else
	{
		//------------------------------------------------------------------------------//
		// process the corresponding attacking procedure.
		//------------------------------------------------------------------------------//
		waiting_term = 0;
		switch(action_mode)
		{
			case ACTION_ATTACK_UNIT:
				err_when(unit_array.is_deleted(action_para2) || !unitPtr);
				spriteInfo = unitPtr->sprite_info;
				
				//-----------------------------------------------------------------//
				// attack the target if able to reach the target surrounding, otherwise
				// continue to wait
				//-----------------------------------------------------------------//
				action_x_loc2 = unitPtr->next_x_loc(); // update target location
				action_y_loc2 = unitPtr->next_y_loc();
				if(space_for_attack(action_x_loc2, action_y_loc2, unitPtr->mobile_type, spriteInfo->loc_width, spriteInfo->loc_height))
					attack_unit(unitPtr->sprite_recno);
				break;

			case ACTION_ATTACK_FIRM:
				err_when(firm_array.is_deleted(action_para2) || !firmPtr);
				firmInfo = firm_res[firmPtr->firm_id];
				
				//-----------------------------------------------------------------//
				// attack the target if able to reach the target surrounding, otherwise
				// continue to wait
				//-----------------------------------------------------------------//
				attack_firm(action_x_loc2, action_y_loc2);

				if(!is_in_surrounding(move_to_x_loc, move_to_y_loc, sprite_info->loc_width, action_x_loc2, action_y_loc2,
					firmInfo->loc_width, firmInfo->loc_height))
					waiting_term = 0;
				break;

			case ACTION_ATTACK_TOWN:
				err_when(town_array.is_deleted(action_para2) || !townPtr);

				//-----------------------------------------------------------------//
				// attack the target if able to reach the target surrounding, otherwise
				// continue to wait
				//-----------------------------------------------------------------//
				attack_town(action_x_loc2, action_y_loc2);

				if(!is_in_surrounding(move_to_x_loc, move_to_y_loc, sprite_info->loc_width, action_x_loc2, action_y_loc2,
					STD_TOWN_LOC_WIDTH, STD_TOWN_LOC_HEIGHT))
					waiting_term = 0;
				break;

			case ACTION_ATTACK_WALL:
				err_when(action_para || action_para2);

				attack_wall(action_x_loc2, action_y_loc2);
				if(!is_in_surrounding(move_to_x_loc, move_to_y_loc, sprite_info->loc_width, action_x_loc2, action_y_loc2, 1, 1))
					waiting_term = 0;
				break;

			default:
				err_here();
				break;
		}
	}

	return 0;
}