//--------- Begin of function Unit::handle_blocked_attack_town ---------// // handle the case that the way of this unit to the target town is blocked by // another unit // // <Unit*> unitPtr - the blocking unit // void Unit::handle_blocked_attack_town(Unit *unitPtr) { if(action_x_loc==unitPtr->action_x_loc && action_y_loc==unitPtr->action_y_loc && action_para==unitPtr->action_para && action_mode==unitPtr->action_mode) { //---------------- both attacks the same town ----------------------// Location *locPtr = world.get_loc(action_x_loc, action_y_loc); if(!locPtr->is_town()) stop2(KEEP_DEFENSE_MODE); // stop since town is deleted else if(space_for_attack(action_x_loc, action_y_loc, UNIT_LAND, STD_TOWN_LOC_WIDTH, STD_TOWN_LOC_HEIGHT)) { //------------ found surrounding place to attack the town -------------// Town *townPtr = town_array[action_para]; { if(mobile_type==UNIT_LAND) set_move_to_surround(townPtr->loc_x1, townPtr->loc_y1, STD_TOWN_LOC_WIDTH, STD_TOWN_LOC_HEIGHT, BUILDING_TYPE_TOWN_MOVE_TO); else attack_town(townPtr->loc_x1, townPtr->loc_y1); } } else // no surrounding place found, stop now stop(KEEP_PRESERVE_ACTION); } else stop(); }
//--------- Begin of function Unit::defense_attack_town ---------// // defensive attack town // // <short> targetXLoc - x location of the town // <short> targetYLoc - y location of the town // void Unit::defense_attack_town(int targetXLoc, int targetYLoc) { action_mode2 = ACTION_AUTO_DEFENSE_ATTACK_TARGET; attack_town(targetXLoc, targetYLoc); }
//--------- Begin of function Unit::monster_defend_attack_town ---------// // set monster to attack town // // <int> targetXLoc - x location of the town // <int> targetYLoc - y location of the town // void Unit::monster_defend_attack_town(int targetXLoc, int targetYLoc) { action_mode2 = ACTION_MONSTER_DEFEND_ATTACK_TARGET; attack_town(targetXLoc, targetYLoc); }
//--------- 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; }