void UnitBase::destroy() { setTarget(NULL); currentGameMap->removeObjectFromMap(getObjectID()); //no map point will reference now currentGame->getObjectManager().removeObject(objectID); currentGame->getHouse(originalHouseID)->decrementUnits(itemID); unitList.remove(this); if(isVisible()) { if(currentGame->randomGen.rand(1,100) <= getInfSpawnProp()) { UnitBase* pNewUnit = currentGame->getHouse(originalHouseID)->createUnit(Unit_Soldier); pNewUnit->setHealth(pNewUnit->getMaxHealth()/2); pNewUnit->deploy(location); if(owner->getHouseID() != originalHouseID) { // deviation is inherited pNewUnit->owner = owner; pNewUnit->graphic = pGFXManager->getObjPic(pNewUnit->graphicID,owner->getHouseID()); pNewUnit->deviationTimer = deviationTimer; } } } delete this; }
void MapPane::unit_inout_fill( UnitBase* punit, bool bin) { //玩家填充 for( UNITOBJ_MAP::iterator iter =players_.begin(); iter != players_.end(); ++iter) { UnitBase* pobj =iter->second; //必须加载数据完成 if( pobj == punit || !pobj->is_initfinish()) continue; ActorSceneExtPane* ext1 =punit->get_scene_ext<ActorSceneExtPane>(); ActorSceneExtPane* ext2 =pobj->get_scene_ext<ActorSceneExtPane>(); if( bin) { ext1->join_inview( pobj); ext2->join_inview( punit); } else { ext1->join_outview( pobj); ext2->join_outview( punit); } } }
bool UnitSync::sendNextUnit(PlayerID toplayer) { UnitBase* unit; do { unit = iter.next(); if(unit == 0) { playerid++; if(playerid >= PlayerInterface::getMaxPlayers()) return false; unitlist = UnitInterface::getUnitList(playerid); iter = unitlist->getAsyncIterator(); } } while(unit == 0); iXY unit_map_loc; MapInterface::pointXYtoMapXY(unit->unit_state.location, &unit_map_loc); UnitIniSyncMessage sync_message; sync_message.unit_type = unit->unit_state.unit_type; sync_message.unit_id = unit->unit_id; sync_message.location_x = unit_map_loc.x; sync_message.location_y = unit_map_loc.y; sync_message.unit_state = unit->unit_state.getNetworkUnitState(); SERVER->sendMessage(toplayer, &sync_message, sizeof(UnitIniSyncMessage), 0); unit->syncUnit(); return true; }
void UnitInterface::selfDestructUnit(const UnitID unit_id) { UnitBase * unit = getUnit(unit_id); if ( unit ) { unit->selfDestruct(); } }
void UnitInterface::destroyPlayerUnits(PlayerID player_id) { PlayerUnitList& unitlist = playerUnitLists[player_id]; for(PlayerUnitList::iterator i = unitlist.begin(); i != unitlist.end(); ++i) { UnitBase* unit = *i; unit->selfDestruct(); } }
void Tile::blitUndergroundUnits(int xPos, int yPos) { if(hasAnUndergroundUnit() && !isFogged(pLocalHouse->getHouseID())) { UnitBase* current = getUndergroundUnit(); if(current->isVisible(pLocalHouse->getTeam())) { if(location == current->getLocation()) { current->blitToScreen(); } } } }
void UnitInterface::destroyPlayerUnits(PlayerID player_id) { UMesgSelfDestruct self_destruct; self_destruct.setHeader(0, _umesg_flag_unique); PlayerUnitList& unitlist = playerUnitLists[player_id]; for(PlayerUnitList::iterator i = unitlist.begin(); i != unitlist.end(); ++i) { UnitBase* unit = *i; unit->processMessage(&self_destruct); } }
void UnitInterface::playerCommand_ManualShoot(const PlayerID player_id, const UnitID unit_id, const iXY& world_point) { UnitBase * unit = getUnit(unit_id); if ( unit ) { if ( unit->player_id == player_id ) { unit->manualShoot(world_point); } } }
void UnitInterface::playerCommand_AttackUnit(const PlayerID player_id, const UnitID unit_id, const UnitID enemy_id) { UnitBase * unit = getUnit(unit_id); if ( unit ) { if ( unit->player_id == player_id ) { unit->attackUnit(unit_id); } } }
void UnitInterface::playerCommand_MoveUnit(const PlayerID player_id, const UnitID unit_id, const iXY& destination) { UnitBase * unit = getUnit(unit_id); if ( unit ) { if ( unit->player_id == player_id ) { unit->moveToLoc(destination); } } }
void UnitInterface::weaponHit( const UnitID from_unit, const iXY& location, const Uint16 damage_factor) { for(Units::iterator i = units.begin(); i != units.end(); ++i) { UnitBase* unit = i->second; if ( unit->unit_state.bounds(location) ) { if ( unit->weaponHit( from_unit, damage_factor) ) { unitKilled(unit, from_unit); } } } }
void UnitInterface::unitOpcodeMessage(const NetMessage *net_message, size_t size) { UnitOpcodeDecoder decoder; decoder.setMessage(net_message, size); UnitOpcode* opcode; while(decoder.decode(&opcode)) { UnitBase* unit = getUnit(opcode->getUnitID()); if(!unit) { LOGGER.debug("Update for non-existant unit: %d", opcode->getUnitID()); continue; } unit->evalCommandOpcode(opcode); } }
void UnitInterface::updateUnitStatus() { for(Units::iterator i = units.begin(); i != units.end(); /*nothing*/ ) { UnitBase* unit = i->second; if (unit->unit_state.lifecycle_state == _UNIT_LIFECYCLE_INACTIVE) { Units::iterator next = i; ++next; removeUnit(i); i = next; continue; } unsigned long pre_update_bucket_index; unsigned long post_update_bucket_index; pre_update_bucket_index = unit_bucket_array.worldLocToBucketIndex( unit->unit_state.location ); unit->updateState(); post_update_bucket_index = unit_bucket_array.worldLocToBucketIndex( unit->unit_state.location ); if ( post_update_bucket_index != pre_update_bucket_index ) { unit_bucket_array.moveUnit(unit->id, pre_update_bucket_index, post_update_bucket_index ); } ++i; } if ( NetworkState::status == _network_state_server ) { if (message_timer.count()) { opcode_encoder.send(); } } }
void UnitInterface::sendMessage(const UnitMessage* message,const PlayerState* player) { if (message->isFlagged(_umesg_flag_unique)) { UnitBase* unit = getUnit(message->getUnitID()); if(unit == 0) return; if(player && unit->player != player) { LOGGER.warning( "Terminal request for unit (%u) not owned by player (%u).\n", unit->id, player->getID()); return; } unit->processMessage(message); } else if (message->isFlagged( _umesg_flag_broadcast) ) { if(message->message_id != _umesg_weapon_hit) { LOGGER.warning("Broadcast flag only allowed for weapon hit."); if(player) { LOGGER.warning("from player %u.\n", player->getID()); } return; } for(Units::iterator i = units.begin(); i != units.end(); ++i) { UnitBase* unit = i->second; unit->processMessage(message); } } else if (message->isFlagged( _umesg_flag_manager_request) ) { if(player) { LOGGER.warning( "UnitManagerMessage sent out by player %u not allowed.", player->getID()); return; } processManagerMessage(message); } }
void Player::skill_used( int skid, S_INT_64 targetid, CHRSTATE_TYPE_ENUM st) { USE_PROTOCOL_NAMESPACE; S_INT_8 ret =0; //1.检查当前状态 if( cur_state_->get_statetype() != st) { if( action_selector_.goto_state( st) == 0) ret =4; } //2.检查技能是否合法 SkillRuntime* sr =0; SkillDesc* pdesc =0; if( ret == 0) { sr =myskills_.get_skillruntime( skid); //技能是否可用 if( sr == 0) ret =1; else { pdesc =sr->get_skilldesc(); if( !pdesc->driving_) { //是否是主动技能 ret =6; } else if( !cur_state_->is_skillinstate( skid)) { //技能是否存在于当前状态的技能列表中 ret =5; } else { //检查cooldown时间 if( !sr->is_cooldown()) ret =2; } } } //3.检查目标是否有效 if( ret == 0 && pdesc->singleattack_) { if( this->fight_target_obj_ == 0 || fight_target_obj_->get_uuid() != targetid) { UnitBase* pTarget =CONTENTSERVICE_INS->get_onlineentity( targetid); if( pTarget == 0 || pTarget == this) { ret =3; } else { //目标是否能被攻击 if( !pTarget->can_beattacked( this)) { ret =3; } else { //设置战斗对象 this->set_fighttargetobj( pTarget); } } } } //4.执行脚本 if( ret == 0) { app::script::ScriptContext& context =CONTENTSERVICE_INS->get_scriptcontext(); try{ ret =luabind::call_function<char>( context.get_luastate(), "skill_use", pdesc->skillidsn_.c_str(), this, sr->get_runtimedata()); } catch( ...){ lua_pop( context.get_luastate(), 1); ret =-1; } } if( ret == 0) { //是否是瞬发技能 if( !sr->is_immediate()) myskills_.set_curskill( sr); //设置最后执行时间 sr->update_lastruntime(); //通知其他人触发技能 } Pro_SkillUsed_ack* ack =PROTOCOL_NEW Pro_SkillUsed_ack(); PRO_UUID_FILL( ack, this->global_index_, this->uuid_); ack->skillid_ =skid; ack->curstate_ =cur_state_->get_statetype(); ack->target_unit_ =( fight_target_obj_?fight_target_obj_->get_uuid():NO_INITVALUE); ack->ret_ =ret; if( ret == 0) ack->skillobj_ =sr->clone_runtimedata(); this->send_to_gts( ack); }
void Tile::blitSelectionRects(int xPos, int yPos) { // draw underground selection rectangles if(hasAnUndergroundUnit() && !isFogged(pLocalHouse->getHouseID())) { UnitBase* current = getUndergroundUnit(); if(current != NULL) { if(current->isVisible(pLocalHouse->getTeam()) && (location == current->getLocation())) { if(current->isSelected()) { current->drawSelectionBox(); } if(current->isSelectedByOtherPlayer()) { current->drawOtherPlayerSelectionBox(); } } } } // draw infantry selection rectangles if(hasInfantry() && !isFogged(pLocalHouse->getHouseID())) { std::list<Uint32>::const_iterator iter; for(iter = assignedInfantryList.begin(); iter != assignedInfantryList.end() ; ++iter) { InfantryBase* current = dynamic_cast<InfantryBase*>(currentGame->getObjectManager().getObject(*iter)); if(current == NULL) { continue; } if(current->isVisible(pLocalHouse->getTeam()) && (location == current->getLocation())) { if(current->isSelected()) { current->drawSelectionBox(); } if(current->isSelectedByOtherPlayer()) { current->drawOtherPlayerSelectionBox(); } } } } // draw non infantry ground object selection rectangles if(hasANonInfantryGroundObject() && !isFogged(pLocalHouse->getHouseID())) { std::list<Uint32>::const_iterator iter; for(iter = assignedNonInfantryGroundObjectList.begin(); iter != assignedNonInfantryGroundObjectList.end() ; ++iter) { ObjectBase* current = currentGame->getObjectManager().getObject(*iter); if(current == NULL) { continue; } if(current->isVisible(pLocalHouse->getTeam()) && (location == current->getLocation())) { if(current->isSelected()) { current->drawSelectionBox(); } if(current->isSelectedByOtherPlayer()) { current->drawOtherPlayerSelectionBox(); } } } } // draw air unit selection rectangles if(hasAnAirUnit() && !isFogged(pLocalHouse->getHouseID())) { std::list<Uint32>::const_iterator iter; for(iter = assignedAirUnitList.begin(); iter != assignedAirUnitList.end() ; ++iter) { AirUnit* airUnit = dynamic_cast<AirUnit*>(currentGame->getObjectManager().getObject(*iter)); if(airUnit == NULL) { continue; } if(airUnit->isVisible(pLocalHouse->getTeam()) && (location == airUnit->getLocation())) { if(airUnit->isSelected()) { airUnit->drawSelectionBox(); } if(airUnit->isSelectedByOtherPlayer()) { airUnit->drawOtherPlayerSelectionBox(); } } } } }
void Tile::triggerSpecialBloom(House* pTrigger) { if(isSpecialBloom()) { setType(Terrain_Sand); switch(currentGame->randomGen.rand(0,3)) { case 0: { // the player gets an randomly choosen amount of credits between 150 and 400 pTrigger->addCredits(currentGame->randomGen.rand(150, 400),false); } break; case 1: { // The house gets a Trike for free. It spawns beside the special bloom. UnitBase* pNewUnit = pTrigger->createUnit(Unit_Trike); if(pNewUnit != NULL) { Coord spot = currentGameMap->findDeploySpot(pNewUnit, location); pNewUnit->deploy(spot); } } break; case 2: { // One of the AI players on the map (one that has at least one unit) gets a Trike for free. It spawns beside the special bloom. int numCandidates = 0; for(int i=0; i<NUM_HOUSES; i++) { House* pHouse = currentGame->getHouse(i); if(pHouse != NULL && pHouse->getTeam() != pTrigger->getTeam() && pHouse->getNumUnits() > 0) { numCandidates++; } } if(numCandidates == 0) { break; } House* pEnemyHouse = NULL; for(int i=0; i<NUM_HOUSES; i++) { House* pHouse = currentGame->getHouse(i); if(pHouse != NULL && pHouse->getTeam() != pTrigger->getTeam() && pHouse->getNumUnits() > 0) { numCandidates--; if(numCandidates == 0) { pEnemyHouse = pHouse; break; } } } UnitBase* pNewUnit = pEnemyHouse->createUnit(Unit_Trike); if(pNewUnit != NULL) { Coord spot = currentGameMap->findDeploySpot(pNewUnit, location); pNewUnit->deploy(spot); } } break; case 3: default: { // One of the AI players on the map (one that has at least one unit) gets an Infantry unit (3 Soldiers) for free. The spawn beside the special bloom. int numCandidates = 0; for(int i=0; i<NUM_HOUSES; i++) { House* pHouse = currentGame->getHouse(i); if(pHouse != NULL && pHouse->getTeam() != pTrigger->getTeam() && pHouse->getNumUnits() > 0) { numCandidates++; } } if(numCandidates == 0) { break; } House* pEnemyHouse = NULL; for(int i=0; i<NUM_HOUSES; i++) { House* pHouse = currentGame->getHouse(i); if(pHouse != NULL && pHouse->getTeam() != pTrigger->getTeam() && pHouse->getNumUnits() > 0) { numCandidates--; if(numCandidates == 0) { pEnemyHouse = pHouse; break; } } } for(int i=0; i<3; i++) { UnitBase* pNewUnit = pEnemyHouse->createUnit(Unit_Soldier); if(pNewUnit != NULL) { Coord spot = currentGameMap->findDeploySpot(pNewUnit, location); pNewUnit->deploy(spot); } } } break; } } }
void WorldInputCmdProcessor::evalLeftMButtonEvents( MouseEvent &event ) { iXY world_pos; unsigned char click_status; if ( (manual_control_state == true) || KeyboardInterface::getKeyState( SDLK_LCTRL ) || KeyboardInterface::getKeyState( SDLK_RCTRL ) ) { if (event.event == MouseEvent::EVENT_DOWN ) //if (event.event == _event_mbutton_click ) { WorldViewInterface::clientXYtoWorldXY( world_win, event.down_pos, &world_pos ); sendManualFireCommand( world_pos ); } } else { if ( event.event == MouseEvent::EVENT_DOWN ) { WorldViewInterface::clientXYtoWorldXY( world_win, event.down_pos, &world_pos ); Objective *objective; PlayerID player_id; player_id = PlayerInterface::getLocalPlayerID(); click_status = ObjectiveInterface::quearyObjectiveLocationStatus( world_pos, player_id, &objective ); if ( (click_status == _player_occupied_objective_found) ) { box_press = world_pos; box_release = world_pos; if ( outpost_goal_selection == -1){ outpost_goal_selection = objective->objective_state.ID; output_pos_press = objective->objective_state.location; } }else{ if ( selection_box_active == false) { WorldViewInterface::clientXYtoWorldXY( world_win, event.down_pos, &world_pos ); box_press = world_pos; box_release = world_pos; }else{ } } } // ** _event_mbutton_down if ( event.event == MouseEvent::EVENT_UP ) { if (outpost_goal_selection != -1 ){ iXY temp; MouseInterface::getMousePosition( &temp.x, &temp.y ); WorldViewInterface::clientXYtoWorldXY( world_win, temp, &world_pos ); Objective *objective; PlayerID player_id = PlayerInterface::getLocalPlayerID(); int cs = ObjectiveInterface::quearyObjectiveLocationStatus( world_pos, player_id, &objective ); if ( (cs == _player_occupied_objective_found) && outpost_goal_selection == objective->objective_state.ID ) { // we've let go of the mouse on the building so we're // not changing the spawn point selected_objective_id = CURRENT_SELECTED_OUTPOST_ID = objective->objective_state.ID; activateVehicleSelectionView( selected_objective_id ); } else { TerminalOutpostOutputLocRequest term_mesg; term_mesg.output_loc_request.set( outpost_goal_selection, world_pos); CLIENT->sendMessage( &term_mesg, sizeof(TerminalOutpostOutputLocRequest), 0 ); if ( NetworkState::status == _network_state_client ) { ObjectiveInterface::sendMessage( &(term_mesg.output_loc_request) ); } } outpost_goal_selection = -1; } } if ( (event.event == MouseEvent::EVENT_CLICK) && (left_button_hold_action_complete == false) ) { WorldViewInterface::clientXYtoWorldXY( world_win, event.down_pos, &world_pos ); click_status = getCursorStatus( world_pos ); switch ( click_status ) { case _cursor_player_unit : { if( (KeyboardInterface::getKeyState( SDLK_LSHIFT ) == true) || (KeyboardInterface::getKeyState( SDLK_RSHIFT ) == true) ) { working_list.addUnit( world_pos ); } else { working_list.selectUnit( world_pos ); } current_selection_list_bits=0; current_selection_list_index = 0xFFFF; if (working_list.unit_list.size() > 0) { UnitBase *unit = UnitInterface::getUnit(working_list.unit_list[0]); unit->soundSelected(); } } break; case _cursor_move: case _cursor_blocked: { if(outpost_goal_selection == -1){ sendMoveCommand( world_pos ); } } break; case _cursor_enemy_unit : { sendAttackCommand( world_pos ); } break; case _cursor_make_allie : { sendAllianceRequest( world_pos, true ); } break; case _cursor_break_allie : { sendAllianceRequest( world_pos, false ); } break; } // ** switch } // ** if _event_mbutton_click } // ** else manual_control_state == false; } // ** evalLeftMButtonEvents
void Command::executeCommand() const { switch(commandID) { case CMD_PLACE_STRUCTURE: { if(parameter.size() != 3) { throw std::invalid_argument("Command::executeCommand(): CMD_PLACE_STRUCTURE needs 3 Parameters!"); } ConstructionYard* pConstYard = dynamic_cast<ConstructionYard*>(currentGame->getObjectManager().getObject(parameter[0])); if(pConstYard == NULL) { return; } pConstYard->doPlaceStructure((int) parameter[1], (int) parameter[2]); } break; case CMD_UNIT_MOVE2POS: { if(parameter.size() != 4) { throw std::invalid_argument("Command::executeCommand(): CMD_UNIT_MOVE2POS needs 4 Parameters!"); } UnitBase* unit = dynamic_cast<UnitBase*>(currentGame->getObjectManager().getObject(parameter[0])); if(unit == NULL) { return; } unit->doMove2Pos((int) parameter[1], (int) parameter[2], (bool) parameter[3]); } break; case CMD_UNIT_MOVE2OBJECT: { if(parameter.size() != 2) { throw std::invalid_argument("Command::executeCommand(): CMD_UNIT_MOVE2OBJECT needs 2 Parameters!"); } UnitBase* unit = dynamic_cast<UnitBase*>(currentGame->getObjectManager().getObject(parameter[0])); if(unit == NULL) { return; } unit->doMove2Object((int) parameter[1]); } break; case CMD_UNIT_ATTACKPOS: { if(parameter.size() != 4) { throw std::invalid_argument("Command::executeCommand(): CMD_UNIT_ATTACKPOS needs 4 Parameters!"); } UnitBase* unit = dynamic_cast<UnitBase*>(currentGame->getObjectManager().getObject(parameter[0])); if(unit == NULL) { return; } unit->doAttackPos((int) parameter[1], (int) parameter[2], (bool) parameter[3]); } break; case CMD_UNIT_ATTACKOBJECT: { if(parameter.size() != 2) { throw std::invalid_argument("Command::executeCommand(): CMD_UNIT_ATTACKOBJECT needs 2 Parameters!"); } UnitBase* pUnit = dynamic_cast<UnitBase*>(currentGame->getObjectManager().getObject(parameter[0])); if(pUnit == NULL) { return; } pUnit->doAttackObject((int) parameter[1], true); } break; case CMD_INFANTRY_CAPTURE: { if(parameter.size() != 2) { throw std::invalid_argument("Command::executeCommand(): CMD_INFANTRY_CAPTURE needs 2 Parameters!"); } InfantryBase* pInfantry = dynamic_cast<InfantryBase*>(currentGame->getObjectManager().getObject(parameter[0])); if(pInfantry == NULL) { return; } pInfantry->doCaptureStructure((int) parameter[1]); } break; case CMD_UNIT_SETMODE: { if(parameter.size() != 2) { throw std::invalid_argument("Command::executeCommand(): CMD_UNIT_SETMODE needs 2 Parameter!"); } UnitBase* pUnit = dynamic_cast<UnitBase*>(currentGame->getObjectManager().getObject(parameter[0])); if(pUnit == NULL) { return; } pUnit->doSetAttackMode((ATTACKMODE) parameter[1]); } break; case CMD_DEVASTATOR_STARTDEVASTATE: { if(parameter.size() != 1) { throw std::invalid_argument("Command::executeCommand(): CMD_DEVASTATOR_STARTDEVASTATE needs 1 Parameter!"); } Devastator* pDevastator = dynamic_cast<Devastator*>(currentGame->getObjectManager().getObject(parameter[0])); if(pDevastator == NULL) { return; } pDevastator->doStartDevastate(); } break; case CMD_MCV_DEPLOY: { if(parameter.size() != 1) { throw std::invalid_argument("Command::executeCommand(): CMD_MCV_DEPLOY needs 1 Parameter!"); } MCV* pMCV = dynamic_cast<MCV*>(currentGame->getObjectManager().getObject(parameter[0])); if(pMCV == NULL) { return; } pMCV->doDeploy(); } break; case CMD_HARVESTER_RETURN: { if(parameter.size() != 1) { throw std::invalid_argument("Command::executeCommand(): CMD_HARVESTER_RETURN needs 1 Parameter!"); } Harvester* pHarvester = dynamic_cast<Harvester*>(currentGame->getObjectManager().getObject(parameter[0])); if(pHarvester == NULL) { return; } pHarvester->doReturn(); } break; case CMD_STRUCTURE_SETDEPLOYPOSITION: { if(parameter.size() != 3) { throw std::invalid_argument("Command::executeCommand(): CMD_STRUCTURE_SETDEPLOYPOSITION needs 3 Parameters!"); } StructureBase* pStructure = dynamic_cast<StructureBase*>(currentGame->getObjectManager().getObject(parameter[0])); if(pStructure == NULL) { return; } pStructure->doSetDeployPosition((int) parameter[1],(int) parameter[2]); } break; case CMD_STRUCTURE_REPAIR: { if(parameter.size() != 1) { throw std::invalid_argument("Command::executeCommand(): CMD_STRUCTURE_REPAIR needs 1 Parameter!"); } StructureBase* pStructure = dynamic_cast<StructureBase*>(currentGame->getObjectManager().getObject(parameter[0])); if(pStructure == NULL) { return; } pStructure->doRepair(); } break; case CMD_BUILDER_UPGRADE: { if(parameter.size() != 1) { throw std::invalid_argument("Command::executeCommand(): CMD_BUILDER_UPGRADE needs 1 Parameter!"); } BuilderBase* pBuilder = dynamic_cast<BuilderBase*>(currentGame->getObjectManager().getObject(parameter[0])); if(pBuilder == NULL) { return; } pBuilder->doUpgrade(); } break; case CMD_BUILDER_PRODUCEITEM: { if(parameter.size() != 3) { throw std::invalid_argument("Command::executeCommand(): CMD_BUILDER_PRODUCEITEM needs 3 Parameter!"); } BuilderBase* pBuilder = dynamic_cast<BuilderBase*>(currentGame->getObjectManager().getObject(parameter[0])); if(pBuilder == NULL) { return; } pBuilder->doProduceItem(parameter[1],(bool) parameter[2]); } break; case CMD_BUILDER_CANCELITEM: { if(parameter.size() != 3) { throw std::invalid_argument("Command::executeCommand(): CMD_BUILDER_CANCELITEM needs 3 Parameter!"); } BuilderBase* pBuilder = dynamic_cast<BuilderBase*>(currentGame->getObjectManager().getObject(parameter[0])); if(pBuilder == NULL) { return; } pBuilder->doCancelItem(parameter[1],(bool) parameter[2]); } break; case CMD_BUILDER_SETONHOLD: { if(parameter.size() != 2) { throw std::invalid_argument("Command::executeCommand(): CMD_BUILDER_SETONHOLD needs 2 Parameters!"); } BuilderBase* pBuilder = dynamic_cast<BuilderBase*>(currentGame->getObjectManager().getObject(parameter[0])); if(pBuilder == NULL) { return; } pBuilder->doSetOnHold((bool) parameter[1]); } break; case CMD_PALACE_SPECIALWEAPON: { if(parameter.size() != 1) { throw std::invalid_argument("Command::executeCommand(): CMD_PALACE_SPECIALWEAPON needs 1 Parameter!"); } Palace* palace = dynamic_cast<Palace*>(currentGame->getObjectManager().getObject(parameter[0])); if(palace == NULL) { return; } palace->doSpecialWeapon(); } break; case CMD_PALACE_DEATHHAND: { if(parameter.size() != 3) { throw std::invalid_argument("Command::executeCommand(): CMD_PALACE_DEATHHAND needs 3 Parameter!"); } Palace* palace = dynamic_cast<Palace*>(currentGame->getObjectManager().getObject(parameter[0])); if(palace == NULL) { return; } palace->doLaunchDeathhand((int) parameter[1], (int) parameter[2]); } break; case CMD_STARPORT_PLACEORDER: { if(parameter.size() != 1) { throw std::invalid_argument("Command::executeCommand(): CMD_STARPORT_PLACEORDER needs 1 Parameter!"); } StarPort* pStarport = dynamic_cast<StarPort*>(currentGame->getObjectManager().getObject(parameter[0])); if(pStarport == NULL) { return; } pStarport->doPlaceOrder(); } break; case CMD_STARPORT_CANCELORDER: { if(parameter.size() != 1) { throw std::invalid_argument("Command::executeCommand(): CMD_STARPORT_CANCELORDER needs 1 Parameter!"); } StarPort* pStarport = dynamic_cast<StarPort*>(currentGame->getObjectManager().getObject(parameter[0])); if(pStarport == NULL) { return; } pStarport->doCancelOrder(); } break; case CMD_TURRET_ATTACKOBJECT: { if(parameter.size() != 2) { throw std::invalid_argument("Command::executeCommand(): CMD_TURRET_ATTACKOBJECT needs 2 Parameters!"); } TurretBase* pTurret = dynamic_cast<TurretBase*>(currentGame->getObjectManager().getObject(parameter[0])); if(pTurret == NULL) { return; } pTurret->doAttackObject((int) parameter[1]); } break; case CMD_TEST_SYNC: { if(parameter.size() != 1) { throw std::invalid_argument("Command::executeCommand(): CMD_TEST_SYNC needs 1 Parameters!"); } Uint32 currentSeed = currentGame->randomGen.getSeed(); if(currentSeed != parameter[0]) { fprintf(stderr, "Game is asynchronous in game cycle %d! Saved seed and current seed do not match: %ud != %ud\n", currentGame->getGameCycleCount(), parameter[0], currentSeed); #ifdef TEST_SYNC currentGame->saveGame("test.sav"); exit(0); #endif } } break; default: { throw std::invalid_argument("Command::executeCommand(): Unknown CommandID!"); } break; } }
void WorldInputCmdProcessor::evalLeftMButtonEvents(const MouseEvent &event) { iXY world_pos; unsigned char click_status; WorldViewInterface::clientXYtoWorldXY(world_win, event.pos, &world_pos); if ( (manual_control_state == true) || KeyboardInterface::getKeyState( SDLK_LCTRL ) || KeyboardInterface::getKeyState( SDLK_RCTRL ) ) { if (event.event == MouseEvent::EVENT_DOWN ) { sendManualFireCommand( world_pos ); } } else if (event.event == MouseEvent::EVENT_DOWN) { Objective *objective = 0; click_status = ObjectiveInterface::quearyObjectiveLocationStatus( world_pos, PlayerInterface::getLocalPlayerIndex(), &objective); if ( click_status == _player_occupied_objective_found ) { selection_box_active = false; outpost_goal_selection = objective->objective_state.ID; output_pos_press = objective->objective_state.location; } else { box_press = world_pos; box_release = world_pos; selection_box_active = true; } } else if(event.event == MouseEvent::EVENT_UP) { if (selection_box_active) { selection_box_active = false; box_release = world_pos; if(abs(box_release.x - box_press.x) > 3 && abs(box_release.y - box_press.y) > 3) { return; } } if (outpost_goal_selection != OBJECTIVE_NONE ) { Objective *objective = 0; int cs = ObjectiveInterface::quearyObjectiveLocationStatus( world_pos, PlayerInterface::getLocalPlayerIndex(), &objective); if ( (cs == _player_occupied_objective_found) && outpost_goal_selection == objective->objective_state.ID ) { // we've let go of the mouse on the building so we're // not changing the spawn point selected_objective_id = objective->objective_state.ID; activateVehicleSelectionView( selected_objective_id ); } else { TerminalOutpostOutputLocRequest term_mesg; term_mesg.output_loc_request.set( outpost_goal_selection, world_pos); CLIENT->sendMessage(&term_mesg, sizeof(TerminalOutpostOutputLocRequest)); if ( NetworkState::status == _network_state_client ) { ObjectiveInterface::sendMessage( &(term_mesg.output_loc_request) ); } } outpost_goal_selection = OBJECTIVE_NONE; return; } click_status = getCursorStatus(world_pos); switch(click_status) { case _cursor_player_unit: { static NTimer dclick_timer(200); static int click_times = 0; bool addunits = false; if( (KeyboardInterface::getKeyState(SDLK_LSHIFT) == true) || (KeyboardInterface::getKeyState(SDLK_RSHIFT) == true)) { addunits = true; } if ( ! dclick_timer.isTimeOut() ) { if ( click_times ) { iRect wr; WorldViewInterface::getViewWindow(&wr); working_list.selectBounded(wr, addunits); click_times=0; } else { working_list.selectSameTypeVisible(world_pos,addunits); dclick_timer.reset(); click_times++; } break; } else if (addunits) { working_list.addUnit(world_pos); } else { working_list.selectUnit(world_pos ); } current_selection_list_bits=0; current_selection_list_index = 0xFFFF; if (working_list.unit_list.size() > 0) { UnitBase *unit = UnitInterface::getUnit( working_list.unit_list[0]); if(unit) unit->soundSelected(); } dclick_timer.reset(); click_times=0; break; } case _cursor_move: case _cursor_blocked: if(outpost_goal_selection == OBJECTIVE_NONE) sendMoveCommand(world_pos); break; case _cursor_enemy_unit: sendAttackCommand(world_pos); break; case _cursor_make_allie: sendAllianceRequest(world_pos, true); break; case _cursor_break_allie: sendAllianceRequest(world_pos, false); break; } } }
void Team::removeUnit( const UnitBase& unit ) { if ( &unit.getTeam() != this ) throw UnitDoesNotBelongException(); //m_units.erase( std::find( m_units.begin(), m_units.end(), std::cref( unit ) ) ); }
void StageDig::Update(void) { // モグルのドリルで敵にダメージ UnitManager &unitManager = UnitManager::GetInstance(); VECTOR position; position.x = 7.5f; position.y = 5.0f; UnitBase* unit = unitManager.GetNearUnit( position, 1.0f, true ); if( unit != NULL ) { VECTOR damageType; unit->AddDamage(1000, UnitBase::DAMAGETYPE_NORMAL, damageType, NULL ); } // ブロック削り判定 BlockManager &blockManager = BlockManager::GetInstance(); BlockBase* base = blockManager.GetBlock( position.x, position.y ); // 指定地点が空なら if( base == NULL || base->m_ID == BLOCK_WATER || base->m_ID == BLOCK_FIRE) { float speed = 0.06f; if( base ) { if(base->m_ID == BLOCK_WATER ) { speed = 0.03f; } else if( base->m_ID == BLOCK_FIRE && GameInput::GetInstance().GetFrame() % 10 == 0) { DataManager::GetInstance().m_MogllStatus.life -= EquipmentFunction_05(1); } } float fallValue = EquipmentFunction_40( speed ); blockManager.AddDepth( fallValue ); DataManager &data = DataManager::GetInstance(); // 記録更新したら代入 int depth = static_cast<int>(blockManager.GetDepth() + data.m_MogllStatus.position.y * 600.0f / 40.0f); if( data.m_SaveData.stageDepth[ data.m_SceneInt["StageNo"] ] < depth ) { data.m_SaveData.stageDepth[ data.m_SceneInt["StageNo"] ] = depth; } //UnitManager::GetInstance().MoveUp( fallValue ); } else if( EquipmentFunction_35( GameInput::GetInstance().GetFrame() ) ) { DataManager &data = DataManager::GetInstance(); // ブロックの削りダメージ int damage = 1; int mogllDamage = EquipmentFunction_11( data.m_SystemData.block[ base->m_ID - 1 ].damage ); m_DigPoint += mogllDamage; if( m_DigPoint >= 100 ) { data.m_MogllStatus.life -= m_DigPoint / 100; m_DigPoint = m_DigPoint % 100; } base->m_Life -= damage; } //-------------------------------------------------------------- 笹井 //今いるブロックをチェック base = blockManager.GetBlock( position.x, position.y ); if(base) { if(base->m_ID == BLOCK_WATER ) { m_SEWaterCnt--; if( m_SEWaterCnt <= 0 && CheckSoundMem(DataManager::GetInstance().Get( DataManager::SoundSE57 )) == 0) { PlaySoundMem( DataManager::GetInstance().Get( DataManager::SoundSE57 ), DX_PLAYTYPE_BACK); m_SEWaterCnt = 90; } } else if( base->m_ID == BLOCK_FIRE) { if(CheckSoundMem(DataManager::GetInstance().Get( DataManager::SoundSE56 )) == 0) PlaySoundMem( DataManager::GetInstance().Get( DataManager::SoundSE56 ), DX_PLAYTYPE_BACK); } if(base->m_ID != BLOCK_WATER ) m_SEWaterCnt = 0; } }