[Gcblue-commits] gcb_wx/src/ai tcCAPMission.cpp, NONE, 1.1 tcMission.cpp, NONE, 1.1 tcMissionManage
Status: Alpha
Brought to you by:
ddcforge
From: Dewitt C. <ddc...@us...> - 2006-09-28 02:01:57
|
Update of /cvsroot/gcblue/gcb_wx/src/ai In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv32752/src/ai Added Files: tcCAPMission.cpp tcMission.cpp tcMissionManager.cpp Log Message: Initial airbase automation work --- NEW FILE: tcMission.cpp --- /** ** @file tcMission.cpp */ /* Copyright (C) 2006 Dewitt Colclough (de...@gc...) ** All rights reserved. ** This file is part of the Global Conflict Blue (GCB) program. ** GCB is free software; you can redistribute it and/or modify ** it under the terms of version 2 of the GNU General Public License as ** published by the Free Software Foundation. ** GCB is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** You should have received a copy of the GNU General Public License ** along with GCB; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "stdwx.h" #ifndef WX_PRECOMP #include "wx/wx.h" #endif #include "ai/tcMission.h" #include "ai/tcMissionManager.h" #ifdef _DEBUG #define new DEBUG_NEW #endif unsigned long tcMission::nextId = 1; unsigned int tcMission::GetId() const { return id; } const std::vector<long>& tcMission::GetMissionAircraft() const { return missionAircraft; } void tcMission::SetMissionManager(tcMissionManager* mm) { missionManager = mm; } void tcMission::Update(double t) { } const tcMission& tcMission::operator=(const tcMission& src) { missionManager = src.missionManager; id = src.id; stage = src.stage; missionAircraft = src.missionAircraft; return *this; } tcMission::tcMission(const tcMission& src) : missionManager(src.missionManager), id(src.id), stage(src.stage), missionAircraft(src.missionAircraft) { } tcMission::tcMission() : missionManager(0), id(nextId++), stage("init") { } tcMission::~tcMission() { } --- NEW FILE: tcCAPMission.cpp --- /** ** @file tcCAPMission.cpp */ /* Copyright (C) 2006 Dewitt Colclough (de...@gc...) ** All rights reserved. ** This file is part of the Global Conflict Blue (GCB) program. ** GCB is free software; you can redistribute it and/or modify ** it under the terms of version 2 of the GNU General Public License as ** published by the Free Software Foundation. ** GCB is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** You should have received a copy of the GNU General Public License ** along with GCB; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "stdwx.h" #ifndef WX_PRECOMP #include "wx/wx.h" #endif #include "ai/tcCAPMission.h" #include "ai/tcMissionManager.h" #include "tcWeaponDBObject.h" #include "tcAirObject.h" #ifdef _DEBUG #define new DEBUG_NEW #endif void tcCAPMission::SetStation(float lon_rad, float lat_rad) { station.x = lon_rad; station.y = lat_rad; } void tcCAPMission::Update(double t) { wxASSERT(missionManager != 0); if (missionManager == 0) return; // step 1, get aircraft for mission // step 2, outfit aircraft // step 3, create tasks for mission on each aircraft // step 4, order launch of aircraft // step 5, when all aircraft launched, delete mission if (stage == "init") { // query available aircraft and take first from list std::vector<long> candidates = missionManager->GetAvailableAircraft(AIR_TARGET); missionAircraft.clear(); for (size_t n=0; (n<quantity)&&(n<candidates.size()); n++) { missionAircraft.push_back(candidates[n]); } if (missionAircraft.size() == 0) return; // none available stage = "outfit"; } else if (stage == "outfit") { bool allOutfitted = true; for (size_t n=0; n<missionAircraft.size(); n++) { tcAirObject* aircraft = missionManager->GetAircraft(missionAircraft[n]); if (aircraft != 0) { if (!aircraft->IsEquippedForTargetType(AIR_TARGET)) { aircraft->EquipForTargetType(AIR_TARGET); allOutfitted = false; } } } if (allOutfitted) stage = "task"; } else if (stage == "task") { stage = "launch"; } else if (stage == "launch") { for (size_t n=0; n<missionAircraft.size(); n++) { missionManager->LaunchAircraft(missionAircraft[n]); } stage = "finish"; } else if (stage == "finish") { // verify all aircraft have launched and end mission } } const tcCAPMission& tcCAPMission::operator=(const tcCAPMission& src) { tcMission::operator=(src); quantity = src.quantity; station = src.station; return *this; } tcCAPMission::tcCAPMission(const tcCAPMission& src) : tcMission(src) { } tcCAPMission::tcCAPMission() : tcMission(), quantity(2) { } tcCAPMission::~tcCAPMission() { } --- NEW FILE: tcMissionManager.cpp --- /** ** @file tcMissionManager.cpp */ /* Copyright (C) 2006 Dewitt Colclough (de...@gc...) ** All rights reserved. ** This file is part of the Global Conflict Blue (GCB) program. ** GCB is free software; you can redistribute it and/or modify ** it under the terms of version 2 of the GNU General Public License as ** published by the Free Software Foundation. ** GCB is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** You should have received a copy of the GNU General Public License ** along with GCB; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "stdwx.h" #ifndef WX_PRECOMP #include "wx/wx.h" #endif #include "ai/tcMissionManager.h" #include "ai/tcMission.h" #include "tcFlightPort.h" #include "tcPlatformObject.h" #include "tcAirObject.h" #ifdef _DEBUG #define new DEBUG_NEW #endif void tcMissionManager::AddMission(tcMission* mission_) { mission_->SetMissionManager(this); missions.push_back(mission_); } tcAirObject* tcMissionManager::GetAircraft(long id) { return dynamic_cast<tcAirObject*>(flightPort->GetObjectById(id)); } std::vector<long>& tcMissionManager::GetAvailableAircraft(int targetMask) { static std::vector<long> availableAircraft; availableAircraft.clear(); UpdateReserved(); size_t nAircraft = flightPort->GetCount(); for (size_t n=0; n<nAircraft; n++) { tcAirState* airState = flightPort->GetAirState(n); long id = airState->obj->mnID; if (!IsAircraftReserved(id)) { tcPlatformObject* platform = dynamic_cast<tcPlatformObject*>(airState->obj); wxASSERT(platform != 0); if ((platform != 0) && (platform->IsCapableVsTargetType(targetMask))) { availableAircraft.push_back(id); } } } return availableAircraft; } bool tcMissionManager::IsAircraftReserved(long id) const { std::map<long, unsigned int>::const_iterator iter = reserved.find(id); return (iter != reserved.end()); } void tcMissionManager::LaunchAircraft(long id) { flightPort->LaunchID(id); } void tcMissionManager::Update(double t) { if ((t - lastUpdate) < 1.0f) return; lastUpdate = t; for (size_t n=0; n<missions.size(); n++) { missions[n]->Update(t); } } void tcMissionManager::UpdateReserved() { reserved.clear(); for (size_t n=0; n<missions.size(); n++) { const std::vector<long>& missionAircraft = missions[n]->GetMissionAircraft(); unsigned int missionId = missions[n]->GetId(); for (size_t k=0; k<missionAircraft.size(); k++) { reserved[missionAircraft[k]] = missionId; } } } tcMissionManager::tcMissionManager(tcFlightPort* fp) : flightPort(fp), lastUpdate(randf()) { wxASSERT(fp != 0); } tcMissionManager::~tcMissionManager() { for (size_t n=0; n<missions.size(); n++) { delete missions[n]; } } |