[Gcblue-commits] gcb_wx/src/ai tcAttackMission.cpp, NONE, 1.1 tcMissionManager.cpp, 1.4, 1.5
Status: Alpha
Brought to you by:
ddcforge
From: Dewitt C. <ddc...@us...> - 2006-12-15 03:38:51
|
Update of /cvsroot/gcblue/gcb_wx/src/ai In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv32056/src/ai Modified Files: tcMissionManager.cpp Added Files: tcAttackMission.cpp Log Message: --- NEW FILE: tcAttackMission.cpp --- /** ** @file tcAttackMission.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/tcAttackMission.h" #include "ai/tcMissionManager.h" #include "ai/Brain.h" #include "ai/BlackboardInterface.h" #include "tcWeaponDBObject.h" #include "tcAirObject.h" #include "tcPlatformObject.h" #include "tcSimState.h" #ifdef _DEBUG #define new DEBUG_NEW #endif using namespace ai; void tcAttackMission::UpdateTargetInfo() { wxASSERT(missionManager != 0); if (missionManager == 0) return; tcGameObject* host = missionManager->GetFlightportParent(); if (host == 0) { EndMission(); return; } tcSimState* simState = tcSimState::Get(); tcSensorMapTrack targetTrack; if (!simState->GetTrack(targetId, host->GetAlliance(), targetTrack)) { EndMission(); // target doesn't exist return; } if (targetTrack.IsSurface()) { targetType = SURFACE_TARGET; } else if (targetTrack.IsAir()) { targetType = AIR_TARGET; } else if (targetTrack.IsMissile()) { targetType = MISSILE_TARGET; } else if (targetTrack.IsSub()) { targetType = SUBSURFACE_TARGET; } else if (targetTrack.IsGround()) { targetType = LAND_TARGET; } else { targetType = 0; // error, unknown target type } } /** * If no mission aircraft are in flight with an active "CAP" task, * then restart the mission */ void tcAttackMission::MonitorMissionInProgress() { tcSimState* simState = tcSimState::Get(); bool anyInFlight = false; for (size_t n=0; (n<missionAircraft.size()) && (!anyInFlight); n++) { tcPlatformObject* obj = dynamic_cast<tcPlatformObject*>(simState->GetObjectByName(missionAircraft[n].name)); if (obj != 0) { if (obj->GetBrain()->TaskExists("CAP")) anyInFlight = true; } } if (!anyInFlight) stage = "init"; // launch another patrol } void tcAttackMission::SetTarget(long id) { targetId = id; } void tcAttackMission::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, wait until aircraft landed // step 6, start over if target not destroyed if (stage == "init") { UpdateTargetInfo(); // query available aircraft and take first from list std::vector<MissionAircraftInfo> candidates = missionManager->GetAvailableAircraft(targetType); 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].id); if (aircraft != 0) { if (!aircraft->IsEquippedForTargetType(targetType)) { aircraft->EquipForTargetType(targetType); allOutfitted = false; } } } if (allOutfitted) stage = "task"; } else if (stage == "task") { wxString s; for (size_t n=0; n<missionAircraft.size(); n++) { tcAirObject* aircraft = missionManager->GetAircraft(missionAircraft[n].id); if (aircraft != 0) { aircraft->DesignateTarget(targetId); ai::Brain* brain = aircraft->GetBrain(); brain->AddTask("InterceptTarget", 2.0); } } stage = "launch"; } else if (stage == "launch") { for (size_t n=0; n<missionAircraft.size(); n++) { missionManager->LaunchAircraft(missionAircraft[n].id); } stage = "waitlaunch"; } else if (stage == "waitlaunch") { // verify all aircraft have launched and end mission if (AllMissionAircraftDeparted()) { stage = "waitland"; } } // do following at slower update double dt = t - lastUpdate; if (dt < 20.0) return; lastUpdate = t; if (stage == "waitland") { EndMission(); //MonitorMissionInProgress(); } } const tcAttackMission& tcAttackMission::operator=(const tcAttackMission& src) { tcMission::operator=(src); quantity = src.quantity; targetId = src.targetId; targetType = src.targetType; return *this; } tcAttackMission::tcAttackMission(const tcAttackMission& src) : tcMission(src), quantity(src.quantity), targetId(src.targetId), targetType(src.targetType) { } tcAttackMission::tcAttackMission() : tcMission(), quantity(2), targetId(-1), targetType(0) { } tcAttackMission::~tcAttackMission() { } Index: tcMissionManager.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/ai/tcMissionManager.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** tcMissionManager.cpp 13 Dec 2006 02:10:58 -0000 1.4 --- tcMissionManager.cpp 15 Dec 2006 03:38:49 -0000 1.5 *************** *** 31,34 **** --- 31,36 ---- #include "tcPlatformObject.h" #include "tcAirObject.h" + #include "tcHeloObject.h" + #include "tcWeaponDBObject.h" #ifdef _DEBUG *************** *** 60,63 **** --- 62,67 ---- availableAircraft.clear(); + const bool subsurfaceTarget = (targetMask == SUBSURFACE_TARGET); + UpdateReserved(); *************** *** 73,77 **** tcPlatformObject* platform = dynamic_cast<tcPlatformObject*>(airState->obj); wxASSERT(platform != 0); ! if ((platform != 0) && (platform->IsCapableVsTargetType(targetMask))) { MissionAircraftInfo info; --- 77,83 ---- tcPlatformObject* platform = dynamic_cast<tcPlatformObject*>(airState->obj); wxASSERT(platform != 0); ! bool isHelo = dynamic_cast<tcHeloObject*>(platform) != 0; ! ! if ((platform != 0) && (!isHelo || subsurfaceTarget) && (platform->IsCapableVsTargetType(targetMask))) { MissionAircraftInfo info; |