// --------- begin of function BulletHoming::init --------// void BulletHoming::init(char parentType, short parentRecno, short targetXLoc, short targetYLoc, char targetMobileType) { Bullet::init(parentType, parentRecno, targetXLoc, targetYLoc, targetMobileType); // ------- find the maximum range --------// BaseObj *baseObjPtr = base_obj_array[parent_base_obj_recno]; if( baseObjPtr->cast_to_Unit() ) { Unit *parentUnit = base_obj_array[parent_base_obj_recno]->cast_to_Unit(); AttackInfo* attackInfo = parentUnit->attack_info_array+parentUnit->cur_attack; speed = attackInfo->bullet_speed; max_step = char((attackInfo->attack_range * LOCATE_WIDTH + speed-1)/ speed); } else if( baseObjPtr->cast_to_Firm() && baseObjPtr->cast_to_Firm()->cast_to_FirmFort() ) { FirmFort *firmFort = baseObjPtr->cast_to_Firm()->cast_to_FirmFort(); speed = firmFort->bullet_speed(); max_step = 100; // unlimited range } else { err_here(); } //--------- keep backup of centre of the bullet ---------// SpriteFrame *spriteFrame = cur_sprite_frame(); // origin_x/y and origin2_x/y are pointing at the centre of the bullet bitmap // origin_x += spriteFrame->offset_x + spriteFrame->width/2; origin_y += spriteFrame->offset_y + spriteFrame->height/2; origin2_x = origin_x; origin2_y = origin_y; go_x += spriteFrame->offset_x + spriteFrame->width/2; go_y += spriteFrame->offset_y + spriteFrame->height/2; // ------- find the target_type and target_recno ------// Location *locPtr = world.get_loc(targetXLoc, targetYLoc); target_base_obj_recno = locPtr->base_obj_recno(targetMobileType); }
// ----- begin of function ScenarioEditor::disp_monster_view ------// // void ScenarioEditor::disp_monster_view() { if( power.command_id ) return; int drawMarker = 0; int validAction = 0; int markerX1, markerY1, markerX2, markerY2; int xLoc, yLoc; char mobileType; if( mouse.in_area(ZOOM_X1, ZOOM_Y1, ZOOM_X2, ZOOM_Y2) ) { // destruction marker if there is a human Location *locPtr = power.test_detect(mouse.cur_x, mouse.cur_y, &mobileType, &xLoc, &yLoc); if( locPtr && locPtr->base_obj_recno() ) { BaseObj *baseObj = base_obj_array[locPtr->base_obj_recno()]; drawMarker = 1; validAction = 1; markerX1 = baseObj->obj_loc_x1(); markerY1 = baseObj->obj_loc_y1(); markerX2 = baseObj->obj_loc_x2(); markerY2 = baseObj->obj_loc_y2(); } // construction marker else if( world.zoom_matrix->get_detect_location(mouse.cur_x, mouse.cur_y, &xLoc, &yLoc, NULL) ) { locPtr = world.get_loc( xLoc, yLoc ); if( unit_or_struct == 0 && !vbrowse_unit_id.none_record ) { // put unit monster_unit_id_array[monster_unit_id_browse_recno-1] // on (xLoc, yLoc) int unitId = monster_unit_id_array[monster_unit_id_browse_recno-1]; UnitInfo *unitInfo = unit_res[unitId]; SpriteInfo *spriteInfo = sprite_res[unitInfo->sprite_id]; if( world.check_unit_space(xLoc, yLoc, xLoc+spriteInfo->loc_width-1, yLoc+spriteInfo->loc_height-1, unitInfo->mobile_type) ) { validAction = 1; } markerX1 = xLoc; markerY1 = yLoc; markerX2 = xLoc + spriteInfo->loc_width -1; markerY2 = yLoc + spriteInfo->loc_height -1; drawMarker = markerX2 < MAX_WORLD_X_LOC && markerY2 < MAX_WORLD_Y_LOC; } else if( unit_or_struct == 1 && !vbrowse_firm_build.none_record ) { err_when( monster_firm_group_array[monster_firm_group_browse_recno-1] == 0 ); // put firm group monster_firm_group_array[monster_firm_group_browse_recno] // on (xLoc, yLoc) FirmGroup *firmGroup = firm_res.get_group(monster_firm_group_array[monster_firm_group_browse_recno-1]); if( world.can_build_firm( xLoc, yLoc, firmGroup->firm_id, 0) ) { validAction = 1; } markerX1 = xLoc; markerY1 = yLoc; markerX2 = xLoc + firm_res[firmGroup->firm_id]->loc_width - 1; markerY2 = yLoc + firm_res[firmGroup->firm_id]->loc_height - 1; drawMarker = markerX2 < MAX_WORLD_X_LOC && markerY2 < MAX_WORLD_Y_LOC; } } } // ------ draw marker -------// if( drawMarker ) { draw_marker( validAction, markerX1, markerY1, markerX2, markerY2 ); } }
void UnitGroup::exe_assign(int destXLoc, int destYLoc, int targetMobileType, int actionNationRecno) { //---------------------------------------// Unit* unitPtr; int locX, locY; int right = 0; int left = 0; int midX = 0; int top = 0; int bottom = 0; int midY = 0; if(size() == 1) { unitPtr = get_unit(1); unitPtr->set_no_longer_in_formation(); unitPtr->assign(destXLoc, destYLoc, actionNationRecno); return; } Location* locPtr; locPtr = world.get_loc(destXLoc, destYLoc); int baseObjRecno = locPtr->base_obj_recno(targetMobileType); // ###### begin Gilbert 6/5 #######// if( !baseObjRecno ) return; // ###### end Gilbert 6/5 #######// BaseObj* thePlace = base_obj_array[baseObjRecno]; int destWidth = thePlace->obj_loc_width(); int destHeight = thePlace->obj_loc_height(); for(int i = 1; i<=size(); i++) { unitPtr = get_unit(i); unitPtr->set_no_longer_in_formation(); locX = unitPtr->next_x_loc(); locY = unitPtr->next_y_loc(); if(locX < destXLoc) //left left++; else if(locX > destXLoc+destWidth-1) //right right++; else midX++; if(locY < destYLoc) //top top++; else if(locY > destYLoc+destHeight-1) //bottom bottom++; else midY++; } if(!left && !midX) //all at right side { run_action( destXLoc, destYLoc, UNIT_ASSIGN, baseObjRecno ); return; } if(!right && !midX) //all at left side { run_action( destXLoc, destYLoc, UNIT_ASSIGN, baseObjRecno ); return; } if(!top && !midY) //all at bottom side { run_action( destXLoc, destYLoc, UNIT_ASSIGN, baseObjRecno); return; } if(!bottom && !midY) //all at top side { run_action(destXLoc, destYLoc, UNIT_ASSIGN, baseObjRecno); return; } for(i=1; i<=size(); i++) { unitPtr = get_unit(i); unitPtr->assign(destXLoc, destYLoc, actionNationRecno); } }
//--------- Begin of function UnitGroup::right_click ---------// // // This function is called when this unit is currenlty selected // and the player right clicks on a location. // void UnitGroup::right_click(int xLoc, int yLoc, char remoteAction, bool addWayPoint, bool shiftKeyAttack, bool forceMoveFlag ) { //### begin juliet 28/1/99 ###// if(size() == 0) return; //### end juliet 28/1/99 #####// err_when( &unit_group_land==this || &unit_group_air==this ); // unit_group_land & unit_group_air are for storing the result, this UnitGroup cannot be one of them //--- reset has_way_point if this is a player action ---// if( remoteAction == COMMAND_PLAYER ) { unit_array[unit_array.selected_recno]->sound("ACK"); //---- if ALT is pressed, add a way point ----// if( addWayPoint ) { if( !remote.is_enable() ) // disable way point in multiplayer { way_point_array.add_point(xLoc, yLoc); } return; } //--- reset has_way_point when a new order is issued by the player ---// // if( !remoteAction && remote.is_enable() ) // { // // packet structure : <write_mem> // short *shortPtr = (short *)remote.new_send_queue_msg( MSG_UNITS_CLEAR_HAS_WAY_POINT, get_write_len() ); // write_mem(shortPtr); // } // else // { for( int i=size() ; i>0 ; i-- ) get_unit(i)->has_way_point = false; // } } //--------- group the unit by mobile type -------// // group_by_mobile_type(); //-------- check the clicked location --------// Location* locPtr = world.get_loc(xLoc, yLoc); int baseObjRecno = locPtr->base_obj_recno(); Unit* unitPtr = get_unit(1); int curNationRecno = unitPtr->nation_recno; // the nation recno of the selected unit, it is not necessarily the player's nation, as the unit can be a spy //----- if click on a location with an object -----// // ###### begin Gilbert 19/2 #########// if( baseObjRecno && !base_obj_array[baseObjRecno]->is_stealth() ) // ###### end Gilbert 19/2 #########// { int targetNationRecno = base_obj_array[baseObjRecno]->nation_recno; int attackNow=0; //--- Special case: if the target is a Porcupine, own units can attack it ---// if( targetNationRecno == nation_array.player_recno ) { Unit* thisUnit = base_obj_array[baseObjRecno]->cast_to_Unit(); if( thisUnit && thisUnit->unit_id == UNIT_EXPLOSIVE_CART && shiftKeyAttack ) attackNow=1; } //--- if the target obj's nation is the same as this unit, assign ---// if( !attackNow && // ######## begin Gilbert 24/2 ####### // // targetNationRecno==curNationRecno && // may be different from trevor's version base_obj_array[baseObjRecno]->can_accept_assign(unitPtr->sprite_recno, nation_array.player_recno) ) // this is for the cases like inn where the assignee must be independent while the target is not independent // ######## end Gilbert 24/2 ####### // { //--- whether the target object accepts this unit assigning to it ---// assign(xLoc, yLoc, base_obj_array[baseObjRecno]->obj_mobile_type(), remoteAction, nation_array.player_recno); // if( unit_group_land.size() > 0 ) // unit_group_land.assign( xLoc, yLoc, remoteAction, nation_array.player_recno ); // // if( unit_group_air.size() > 0 ) // unit_group_air.assign( xLoc, yLoc, remoteAction, nation_array.player_recno ); return; } else //--- if the nations are different, attack -----// { /* if( unit_group_land.size() > 0 ) unit_group_land.attack( baseObjRecno, remoteAction ); if( unit_group_air.size() > 0 ) unit_group_air.attack( baseObjRecno, remoteAction ); */ attack(baseObjRecno, remoteAction); return; } } //---- if all conditions failed, move to the destination ----// /* if( unit_group_land.size() > 0 ) unit_group_land.move( xLoc, yLoc, forceMoveFlag, remoteAction ); if( unit_group_air.size() > 0 ) unit_group_air.move( xLoc, yLoc, forceMoveFlag, remoteAction ); */ move(xLoc, yLoc, forceMoveFlag, remoteAction); }