[Gcblue-commits] gcb_wx/src/sim tcChatBox.cpp,NONE,1.1 tcCommandObject.cpp,NONE,1.1 tcLauncher.cpp,N
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2004-05-24 00:15:01
|
Update of /cvsroot/gcblue/gcb_wx/src/sim In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26112/src/sim Modified Files: Game.cpp tcAirObject.cpp tcESMSensor.cpp tcFlightPort.cpp tcLauncherState.cpp tcObjectControl.cpp tcPlatformObject.cpp tcRadar.cpp tcSensorState.cpp tcSimState.cpp Added Files: tcChatBox.cpp tcCommandObject.cpp tcLauncher.cpp Log Message: Multiplayer changes Index: tcFlightPort.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcFlightPort.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** tcFlightPort.cpp 29 Jan 2004 00:05:38 -0000 1.6 --- tcFlightPort.cpp 24 May 2004 00:14:47 -0000 1.7 *************** *** 30,33 **** --- 30,34 ---- #include "tcFlightPort.h" #include "tcAirObject.h" + #include "tcAeroAirObject.h" #include "tcFlightportDBObject.h" #include "tcGenericDBObject.h" *************** *** 432,437 **** unit->mcKin.mfLon_rad += delta_lon; ! tcAirObject *air_unit = dynamic_cast<tcAirObject*>(unit); ! if (air_unit) { air_unit->SetSpeed(air_unit->mpDBObject->mfMaxSpeed_kts); --- 433,443 ---- unit->mcKin.mfLon_rad += delta_lon; ! if (tcAeroAirObject* aa_unit = dynamic_cast<tcAeroAirObject*>(unit)) ! { ! aa_unit->SetThrottleFraction(1.1); ! aa_unit->SetAltitude(unit->mcKin.mfAlt_m + 500.0f); ! aa_unit->SetLandingState(0); ! } ! else if (tcAirObject *air_unit = dynamic_cast<tcAirObject*>(unit)) { air_unit->SetSpeed(air_unit->mpDBObject->mfMaxSpeed_kts); --- NEW FILE: tcChatBox.cpp --- /** tcChatBox.cpp */ /* ** Copyright (C) 2003-2004 Dewitt "Cole" Colclough (de...@tw...) ** 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" #ifdef WIN32 #include "wx/msw/private.h" #endif #endif #include "tcChatBox.h" #include "tcButton.h" #include "tcEditBox.h" #include "tcConsoleBox.h" #include "common/tinyxml.h" #include "network/tcMultiplayerInterface.h" #include "wxcommands.h" #include "common/tcOptions.h" using namespace Gdiplus; BEGIN_EVENT_TABLE(tcChatBox, tcStandardWindow) EVT_COMMAND(1, wxEVT_COMMAND_TEXT_UPDATED, tcChatBox::SendChatText) END_EVENT_TABLE() #ifdef _DEBUG #define new DEBUG_NEW #endif using network::tcMultiplayerInterface; int tcChatBox::Draw() { Graphics *graphics; Erase(); if (!GetGraphics(graphics)) { return false; } DrawBackground(graphics); DrawChildren(graphics); ReleaseGraphics(graphics); return true; } void tcChatBox::OnLButtonDown(wxMouseEvent& event) { } /** * Send chat text to all connections */ void tcChatBox::SendChatText(wxCommandEvent& event) { tcMultiplayerInterface* multiplayerInterface = tcMultiplayerInterface::Get(); bool isServer = multiplayerInterface->IsServer(); std::string chatText = event.GetString().c_str(); if (isServer && (multiplayerInterface->IsCommand(chatText))) { chatHistory->Print(chatText.c_str()); multiplayerInterface->ProcessCommandServer(chatText); return; } /* prepend name tag if server, this is done for clients by server, server has ** to do tagging itself */ if (isServer) { chatText = std::string("<") + multiplayerInterface->GetName() + std::string("> ") + chatText; } unsigned nConnections = multiplayerInterface->GetNumConnections(); for (unsigned n=0;n<nConnections;n++) { int connId = tcMultiplayerInterface::Get()->GetConnectionId(n); tcMultiplayerInterface::Get()->SendChatText(connId, chatText); } // if server, print chat text locally since no echo comes back if (isServer) { chatHistory->Print(chatText.c_str()); } } /** * @param surfaceHost tcWindow to share surface of */ tcChatBox::tcChatBox(wxWindow *parent, tcWindow *surfaceHost, const wxPoint& pos, const wxSize& size, const wxString& name, const wxString& configFile) : tcStandardWindow(parent, pos, size, configFile, name, surfaceHost) { LoadBackgroundImage("background.jpg"); if (config) { AddXMLControls(); } else { std::cerr << "tcChatBox::tcChatBox - NULL xml config node\n"; return; } TiXmlNode* root = config->FirstChild("Window"); if (!root) { std::cerr << "tcChatBox::tcChatBox - Missing top level <Window> tag\n"; return; } // add chat text console TiXmlNode* current = root->FirstChild("ChatBox"); chatHistory = new tcConsoleBox(this, current); tcMultiplayerInterface::Get()->AddChatSubscriber(chatHistory); // add chat text edit box current = root->FirstChild("ChatEntry"); chatEntry = new tcEditBox(this, current); chatEntry->SetCommand(1); chatEntry->SetClearOnReturn(true); chatEntry->SetBuffer("Enter chat text here"); } tcChatBox::~tcChatBox() { tcMultiplayerInterface::Get()->RemoveChatSubscriber(chatHistory); } Index: tcPlatformObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcPlatformObject.cpp,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** tcPlatformObject.cpp 1 May 2004 21:49:06 -0000 1.22 --- tcPlatformObject.cpp 24 May 2004 00:14:47 -0000 1.23 *************** *** 1,4 **** ! /* ! ** Copyright (C) 2003 Dewitt "Cole" Colclough (de...@tw...) ** All rights reserved. --- 1,5 ---- ! /** @file tcPlatformObject.cpp ! ** ! ** Copyright (C) 2003-2004 Dewitt Colclough (de...@tw...) ** All rights reserved. *************** *** 30,33 **** --- 31,35 ---- #include "tcRadar.h" #include "tcESMSensor.h" + #include "tcLauncher.h" #include "tc3DModel.h" #include "common/tcStream.h" *************** *** 36,40 **** using namespace AI; ! void tcPlatformObject::DesignateDatum(tcPoint p) { float fRange_km; --- 38,43 ---- using namespace AI; ! void tcPlatformObject::DesignateDatum(tcPoint p) ! { float fRange_km; *************** *** 44,48 **** fRange_km = mcKin.RangeToKm(&msTargetDatum); tcString s; ! s.Format("datum is %3.1f km from platform",fRange_km); WTLC(s.GetBuffer()); } --- 47,51 ---- fRange_km = mcKin.RangeToKm(&msTargetDatum); tcString s; ! s.Format("datum is %3.1f km from platform", fRange_km); WTLC(s.GetBuffer()); } *************** *** 69,73 **** { mcAI.SetTarget(anID); ! unsigned nLaunchers = mcLauncherState.launchers.size(); for (size_t n=0; n<nLaunchers; n++) { --- 72,76 ---- { mcAI.SetTarget(anID); ! unsigned nLaunchers = mcLauncherState.GetLauncherCount(); for (size_t n=0; n<nLaunchers; n++) { *************** *** 77,82 **** // update guidance to maintain/achieve formation position ! void tcPlatformObject::UpdateFormationGuidance() { ! if (!msFormationParameters.mbFormation) { return; // return without modifying kgoal } --- 80,87 ---- // update guidance to maintain/achieve formation position ! void tcPlatformObject::UpdateFormationGuidance() ! { ! if (!msFormationParameters.mbFormation) ! { return; // return without modifying kgoal } *************** *** 89,111 **** mcGS.mfGoalHeading_deg = fHeading_rad; ! if (fRange_km <= 0.1f) { mcGS.mfGoalSpeed_kts = pFP->mcFormationKin.mfSpeed_kts; mcGS.mfGoalHeading_deg = pFP->mcFormationKin.mfHeading_rad; ! if (fHeading_rad > 0) { ! if (fHeading_rad < C_PIOVER2) { mcGS.mfGoalSpeed_kts += 1.5f; mcGS.mfGoalHeading_deg += 0.5f; } ! else { mcGS.mfGoalSpeed_kts -= 1.5f; mcGS.mfGoalHeading_deg += 0.5f; } } ! else { ! if (fHeading_rad > -C_PIOVER2) { mcGS.mfGoalSpeed_kts += 1.5f; mcGS.mfGoalHeading_deg -= 0.5f; } ! else { mcGS.mfGoalSpeed_kts -= 1.5f; mcGS.mfGoalHeading_deg -= 0.5f; --- 94,123 ---- mcGS.mfGoalHeading_deg = fHeading_rad; ! if (fRange_km <= 0.1f) ! { mcGS.mfGoalSpeed_kts = pFP->mcFormationKin.mfSpeed_kts; mcGS.mfGoalHeading_deg = pFP->mcFormationKin.mfHeading_rad; ! if (fHeading_rad > 0) ! { ! if (fHeading_rad < C_PIOVER2) ! { mcGS.mfGoalSpeed_kts += 1.5f; mcGS.mfGoalHeading_deg += 0.5f; } ! else ! { mcGS.mfGoalSpeed_kts -= 1.5f; mcGS.mfGoalHeading_deg += 0.5f; } } ! else ! { ! if (fHeading_rad > -C_PIOVER2) ! { mcGS.mfGoalSpeed_kts += 1.5f; mcGS.mfGoalHeading_deg -= 0.5f; } ! else ! { mcGS.mfGoalSpeed_kts -= 1.5f; mcGS.mfGoalHeading_deg -= 0.5f; *************** *** 113,128 **** } } ! else if (fRange_km <= 2.0f) { mcGS.mfGoalSpeed_kts = mpDBObject->mfMaxSpeed_kts; ! if ((mcGS.mfGoalSpeed_kts - pFP->mcFormationKin.mfSpeed_kts) > 50.0f) { mcGS.mfGoalSpeed_kts = pFP->mcFormationKin.mfSpeed_kts + 50.0f; } } ! else { mcGS.mfGoalSpeed_kts = mpDBObject->mfMaxSpeed_kts; } if (mcGS.mfGoalSpeed_kts < 0) {mcGS.mfGoalSpeed_kts = 0;} ! if (mcGS.mfGoalSpeed_kts > mpDBObject->mfMaxSpeed_kts) { mcGS.mfGoalSpeed_kts = mpDBObject->mfMaxSpeed_kts; } --- 125,144 ---- } } ! else if (fRange_km <= 2.0f) ! { mcGS.mfGoalSpeed_kts = mpDBObject->mfMaxSpeed_kts; ! if ((mcGS.mfGoalSpeed_kts - pFP->mcFormationKin.mfSpeed_kts) > 50.0f) ! { mcGS.mfGoalSpeed_kts = pFP->mcFormationKin.mfSpeed_kts + 50.0f; } } ! else ! { mcGS.mfGoalSpeed_kts = mpDBObject->mfMaxSpeed_kts; } if (mcGS.mfGoalSpeed_kts < 0) {mcGS.mfGoalSpeed_kts = 0;} ! if (mcGS.mfGoalSpeed_kts > mpDBObject->mfMaxSpeed_kts) ! { mcGS.mfGoalSpeed_kts = mpDBObject->mfMaxSpeed_kts; } *************** *** 130,135 **** } ! // turn by maximum amount toward goal heading ! void tcPlatformObject::UpdateHeading(float dt_s) { float dh_rad = mcGS.mfGoalHeading_deg - mcKin.mfHeading_rad; radtoplusminuspi(dh_rad); // map dh_deg to [-180,180] --- 146,154 ---- } ! /** ! * turn by maximum amount toward goal heading ! */ ! void tcPlatformObject::UpdateHeading(float dt_s) ! { float dh_rad = mcGS.mfGoalHeading_deg - mcKin.mfHeading_rad; radtoplusminuspi(dh_rad); // map dh_deg to [-180,180] *************** *** 169,174 **** } ! // adjust speed to goal speed, limited by max acceleration ! void tcPlatformObject::UpdateSpeed(float dt_s) { float ds_kts = mcGS.mfGoalSpeed_kts - mcKin.mfSpeed_kts; float ds_max = mpDBObject->mfAccel_ktsps*dt_s; --- 188,196 ---- } ! /** ! * adjust speed to goal speed, limited by max acceleration ! */ ! void tcPlatformObject::UpdateSpeed(float dt_s) ! { float ds_kts = mcGS.mfGoalSpeed_kts - mcKin.mfSpeed_kts; float ds_max = mpDBObject->mfAccel_ktsps*dt_s; *************** *** 197,213 **** } ! /*** update launcher state (reload time) ***/ void tcPlatformObject::UpdateLauncherState(float dt_s) { ! for(int i=0;i<mcLauncherState.mnCount;i++) ! { ! if (mcLauncherState.launchers[i].mbActive) ! { ! if (mcLauncherState.launchers[i].mfTimeToReady > 0) ! { ! mcLauncherState.launchers[i].mfTimeToReady -= dt_s; ! } ! } ! } } --- 219,228 ---- } ! /** ! * update launcher state (reload time) ! */ void tcPlatformObject::UpdateLauncherState(float dt_s) { ! mcLauncherState.Update(dt_s); } *************** *** 252,264 **** } ! //---------------------------------------------------------------------------- ! int tcPlatformObject::GetLauncherQuantity(unsigned anLauncher) { return mcLauncherState.GetLauncherQuantity(anLauncher); } ! /******************************************************************************/ ! // consider all active (mbActive) sensors ! bool tcPlatformObject::HasActivatedSensor(void) { int nSensors = (int)mapSensorState.size(); ! for (int k=0;k<nSensors;k++) { tcSensorState *pSensorState = mapSensorState[k]; if (pSensorState->GetActive()) {return true;} --- 267,294 ---- } ! /** ! * ! */ ! int tcPlatformObject::GetLauncherQuantity(unsigned anLauncher) ! { return mcLauncherState.GetLauncherQuantity(anLauncher); } ! ! /** ! * @return number of sensors on platform ! */ ! unsigned tcPlatformObject::GetSensorCount() const ! { ! return (unsigned)mapSensorState.size(); ! } ! ! /** ! * consider all active (mbActive) sensors ! */ ! bool tcPlatformObject::HasActivatedSensor() ! { int nSensors = (int)mapSensorState.size(); ! for (int k=0;k<nSensors;k++) ! { tcSensorState *pSensorState = mapSensorState[k]; if (pSensorState->GetActive()) {return true;} *************** *** 277,287 **** } ! /******************************************************************************/ ! // consider only active radars ! bool tcPlatformObject::IsRadiating() { int nSensors = (int)mapSensorState.size(); ! for (int k=0;k<nSensors;k++) { tcSensorState *pSensorState = mapSensorState[k]; ! if (dynamic_cast<tcRadar*>(pSensorState)) { if (pSensorState->GetActive()) {return true;} } --- 307,321 ---- } ! /** ! * consider only active radars ! */ ! bool tcPlatformObject::IsRadiating() ! { int nSensors = (int)mapSensorState.size(); ! for (int k=0;k<nSensors;k++) ! { tcSensorState *pSensorState = mapSensorState[k]; ! if (dynamic_cast<tcRadar*>(pSensorState)) ! { if (pSensorState->GetActive()) {return true;} } *************** *** 289,293 **** return false; } ! /******************************************************************************/ void tcPlatformObject::Clear() { --- 323,327 ---- return false; } ! void tcPlatformObject::Clear() { *************** *** 301,340 **** fuel_kg = 0; lastHeadingDelta = 0; - - newCommand = false; - commandStatus = 0; } ! tcSensorState* tcPlatformObject::GetSensor(unsigned idx) { ! if (idx >= mapSensorState.size()) return NULL; else return mapSensorState[idx]; } ! /******************************************************************************/ ! // return key of object to launch, otherwise NULL_INDEX ! void tcPlatformObject::Launch(tnPoolIndex& rnKey, unsigned& rnLauncher) { ! int nLaunchers = mcLauncherState.mnCount; ! tsLData *pLauncher; ! for (int n=0;n<nLaunchers;n++) ! { ! pLauncher = &mcLauncherState.launchers[n]; ! if ((pLauncher->mbActive)&&(pLauncher->mnPending > 0)) ! { ! bool bLaunch = (pLauncher->mnCurrent > 0)&&(pLauncher->mfTimeToReady <= 0); ! if (bLaunch) ! { ! pLauncher->mnCurrent--; ! pLauncher->mnPending--; ! rnKey = pLauncher->mnChildDBKey; ! rnLauncher = n; ! pLauncher->mfTimeToReady = 2.0f; // TODO: add db parameter for this ! return; ! } ! } ! } ! rnKey = NULL_INDEX; ! rnLauncher = 0; } --- 335,361 ---- fuel_kg = 0; lastHeadingDelta = 0; } ! const tcSensorState* tcPlatformObject::GetSensor(unsigned idx) { ! if (idx >= mapSensorState.size()) return 0; else return mapSensorState[idx]; } ! /** ! * This version is used for non-const access to the sensor ! */ ! tcSensorState* tcPlatformObject::GetSensorMutable(unsigned idx) ! { ! if (idx >= mapSensorState.size()) return 0; ! else return mapSensorState[idx]; ! } ! /** ! * @return key of object to launch, otherwise NULL_INDEX ! */ ! void tcPlatformObject::Launch(tnPoolIndex& rnKey, unsigned& rnLauncher) ! { ! mcLauncherState.Launch(rnKey, rnLauncher); } *************** *** 345,350 **** { mcGS.SetAltitude(new_altitude_m); ! commandStatus |= ALT_CMD; ! newCommand = true; } --- 366,370 ---- { mcGS.SetAltitude(new_altitude_m); ! commandObj.SetNewCommand(ALT_CMD); } *************** *** 355,360 **** { mcGS.SetHeading(afNewHeading); ! commandStatus |= HEADING_CMD; ! newCommand = true; } --- 375,389 ---- { mcGS.SetHeading(afNewHeading); ! commandObj.SetNewCommand(HEADING_CMD); ! } ! ! /** ! * Used to active/deactive sensor on platform ! */ ! void tcPlatformObject::SetSensorState(unsigned idx, bool state) ! { ! if (idx >= mapSensorState.size()) return; // error ! mapSensorState[idx]->SetActive(state); ! sensorCommandObj.SetNewCommand(0x01 << idx); } *************** *** 367,372 **** { mcGS.SetSpeed(afNewSpeed); ! commandStatus |= SPEED_CMD; ! newCommand = true; } --- 396,400 ---- { mcGS.SetSpeed(afNewSpeed); ! commandObj.SetNewCommand(SPEED_CMD); } *************** *** 378,395 **** int tcPlatformObject::SetLaunch(int anLauncher, int anQuantity) { ! int statusCode; ! ! statusCode = mcLauncherState.GetLauncherStatus(anLauncher); ! if (statusCode != tcLauncherState::LAUNCHER_READY) return statusCode; ! ! tsLData *pLauncher = &mcLauncherState.launchers[anLauncher]; ! ! pLauncher->mnPending += anQuantity; ! if (pLauncher->mnPending > pLauncher->mnCurrent) {pLauncher->mnPending=pLauncher->mnCurrent;} ! return tcLauncherState::LAUNCHER_READY; } ! /******************************************************************************/ void tcPlatformObject::RandInitNear(float afLon_deg, float afLat_deg) { --- 406,414 ---- int tcPlatformObject::SetLaunch(int anLauncher, int anQuantity) { ! return mcLauncherState.SetLaunch(anLauncher, anQuantity); } ! void tcPlatformObject::RandInitNear(float afLon_deg, float afLat_deg) { *************** *** 416,420 **** } ! /******************************************************************************/ void tcPlatformObject::PrintToFile(tcFile& file) { --- 435,439 ---- } ! void tcPlatformObject::PrintToFile(tcFile& file) { *************** *** 433,438 **** for(int i=0;i<nLaunchers;i++) { ! s.Format(" LAU%d: %s x %d\n",i,mcLauncherState.launchers[i].mpLauncherDBObj->mzChildClass.mz, ! mcLauncherState.launchers[i].mnCurrent); file.WriteString(s.GetBuffer()); } --- 452,458 ---- for(int i=0;i<nLaunchers;i++) { ! s.Format(" LAU%d: %s x %d\n",i, ! mcLauncherState.GetLauncherChildClass(i), ! mcLauncherState.GetLauncherQuantity(i)); file.WriteString(s.GetBuffer()); } *************** *** 449,453 **** } } ! /******************************************************************************/ void tcPlatformObject::SaveToFile(tcFile& file) { --- 469,473 ---- } } ! void tcPlatformObject::SaveToFile(tcFile& file) { *************** *** 468,472 **** } /******************************************************************************/ ! void tcPlatformObject::LoadFromFile(tcFile& file) { tcGameObject::LoadFromFile(file); --- 488,493 ---- } /******************************************************************************/ ! void tcPlatformObject::LoadFromFile(tcFile& file) ! { tcGameObject::LoadFromFile(file); *************** *** 475,479 **** // assumes that sensors already created by higher level serialize method int nSensors = (int)mapSensorState.size(); ! for(int i=0;i<nSensors;i++) { tcSensorState*& pss = mapSensorState[i]; pss->Serialize(file,true); --- 496,501 ---- // assumes that sensors already created by higher level serialize method int nSensors = (int)mapSensorState.size(); ! for(int i=0;i<nSensors;i++) ! { tcSensorState*& pss = mapSensorState[i]; pss->Serialize(file,true); *************** *** 487,494 **** /******************************************************************************/ void tcPlatformObject::Serialize(tcFile& file, bool mbLoad) { ! if (mbLoad) { LoadFromFile(file); } ! else { SaveToFile(file); } --- 509,518 ---- /******************************************************************************/ void tcPlatformObject::Serialize(tcFile& file, bool mbLoad) { ! if (mbLoad) ! { LoadFromFile(file); } ! else ! { SaveToFile(file); } *************** *** 497,564 **** /** - * Used with multiplayer client to load a parameter from the server that - * the client can command e.g. heading, speed, altitude. If a client command - * request is outstanding and the server update does not match, then the update - * is ignored. If the update matches, the command flag is cleared representing - * a successful acknowledge of the command. - */ - void tcPlatformObject::LoadCommandParam(tcCommandStream& stream, float& param, int& cmdStatus, int flag) - { - float temp; - stream >> temp; // read into temporary variable - - if (stream.GetAck()) - { - if ((cmdStatus & flag) && (temp == param)) - { - cmdStatus &= (~flag); // clear flag, successful ack - } - } - else // not an ack - { - if (clientMode && (cmdStatus & flag)) - { - // ignore update - } - else - { - param = temp; // apply update - cmdStatus &= (~flag); // clear flag - } - - } - } - - /** - * version that takes int param - */ - void tcPlatformObject::LoadCommandParam(tcCommandStream& stream, int& param, int& cmdStatus, int flag) - { - int temp; - stream >> temp; // read into temporary variable - - if (stream.GetAck()) - { - if ((cmdStatus & flag) && (temp == param)) - { - cmdStatus &= (~flag); // clear flag, successful ack - } - } - else // not an ack - { - if (clientMode && (cmdStatus & flag)) - { - // ignore update - } - else - { - param = temp; // apply update - cmdStatus &= (~flag); // clear flag - } - - } - } - - /** * Loads state from command stream */ --- 521,524 ---- *************** *** 572,578 **** if (updateMask & UPDATE_GUIDANCE) { ! LoadCommandParam(stream, mcGS.mfGoalHeading_deg, commandStatus, HEADING_CMD); ! LoadCommandParam(stream, mcGS.mfGoalSpeed_kts, commandStatus, SPEED_CMD); ! LoadCommandParam(stream, mcGS.mfGoalAltitude_m, commandStatus, ALT_CMD); stream >> mcGS.mbIntercept; --- 532,539 ---- if (updateMask & UPDATE_GUIDANCE) { ! ! commandObj.LoadCommandParam(stream, mcGS.mfGoalHeading_deg, HEADING_CMD); ! commandObj.LoadCommandParam(stream, mcGS.mfGoalSpeed_kts, SPEED_CMD); ! commandObj.LoadCommandParam(stream, mcGS.mfGoalAltitude_m, ALT_CMD); stream >> mcGS.mbIntercept; *************** *** 582,585 **** --- 543,560 ---- } } + + if (updateMask & UPDATE_LAUNCHERS) + { + mcLauncherState << stream; + } + + if (updateMask & UPDATE_SENSORS) + { + size_t nSensors = mapSensorState.size(); + for(size_t n=0; n < nSensors; n++) + { + sensorCommandObj.LoadCommandParam(stream, mapSensorState[n]->mbActive, (0x01) << n); + } + } return stream; *************** *** 593,602 **** tcGameObject::operator>>(stream); unsigned char updateMask = 0; ! ! updateMask = UPDATE_GUIDANCE; stream << updateMask; if (updateMask & UPDATE_GUIDANCE) { --- 568,586 ---- tcGameObject::operator>>(stream); + // form update mask unsigned char updateMask = 0; ! updateMask = UPDATE_GUIDANCE; // always update guidance for now ! if (stream.isAck || mcLauncherState.HasUnacknowledgedCommand()) ! { ! updateMask |= UPDATE_LAUNCHERS; ! } ! if (stream.isAck || sensorCommandObj.HasUnacknowledgedCommand()) ! { ! updateMask |= UPDATE_SENSORS; ! } stream << updateMask; + if (updateMask & UPDATE_GUIDANCE) { *************** *** 611,614 **** --- 595,612 ---- } } + + if (updateMask & UPDATE_LAUNCHERS) + { + mcLauncherState >> stream; + } + + if (updateMask & UPDATE_SENSORS) + { + size_t nSensors = mapSensorState.size(); + for(size_t n=0; n < nSensors; n++) + { + stream << mapSensorState[n]->mbActive; + } + } *************** *** 644,647 **** --- 642,647 ---- tcGameObject::operator<<(stream); + mcLauncherState.operator<<(stream); + return stream; } *************** *** 654,657 **** --- 654,659 ---- tcGameObject::operator>>(stream); + mcLauncherState.operator>>(stream); + return stream; } *************** *** 659,677 **** void tcPlatformObject::ClearNewCommand() { ! newCommand = false; } bool tcPlatformObject::HasNewCommand() const { ! return newCommand; } bool tcPlatformObject::HasUnacknowledgedCommand() const { ! return (commandStatus != 0); } - /******************************************************************************/ tcPlatformObject::tcPlatformObject() --- 661,682 ---- void tcPlatformObject::ClearNewCommand() { ! commandObj.ClearNewCommand(); ! mcLauncherState.ClearNewCommand(); ! sensorCommandObj.ClearNewCommand(); } bool tcPlatformObject::HasNewCommand() const { ! return commandObj.HasNewCommand() || mcLauncherState.HasNewCommand() || ! sensorCommandObj.HasNewCommand(); } bool tcPlatformObject::HasUnacknowledgedCommand() const { ! return commandObj.HasUnacknowledgedCommand() || mcLauncherState.HasNewCommand() || ! sensorCommandObj.HasUnacknowledgedCommand(); } /******************************************************************************/ tcPlatformObject::tcPlatformObject() *************** *** 696,700 **** { std::string fcSensor = ! mcLauncherState.launchers[nLauncher].mpLauncherDBObj->fireControlSensorClass; // search for sensor and add if match bool bSearching = fcSensor.length() > 1; --- 701,705 ---- { std::string fcSensor = ! mcLauncherState.GetFireControlSensorClass(nLauncher); // search for sensor and add if match bool bSearching = fcSensor.length() > 1; *************** *** 720,724 **** tcPlatformObject::tcPlatformObject(tcGenericDBObject *obj) ! : tcGameObject(obj), newCommand(false), commandStatus(0) { using namespace Database; --- 725,729 ---- tcPlatformObject::tcPlatformObject(tcGenericDBObject *obj) ! : tcGameObject(obj) { using namespace Database; *************** *** 790,794 **** } /******************************************************************************/ ! tcPlatformObject::tcPlatformObject(tcPlatformObject& o) : tcGameObject(o) { fuel_kg = o.fuel_kg; --- 795,800 ---- } /******************************************************************************/ ! tcPlatformObject::tcPlatformObject(tcPlatformObject& o) : tcGameObject(o), ! commandObj(o.commandObj) { fuel_kg = o.fuel_kg; *************** *** 802,807 **** msTargetDatum = o.msTargetDatum; ! newCommand = o.newCommand; ! commandStatus = o.commandStatus; // copy sensor state array --- 808,812 ---- msTargetDatum = o.msTargetDatum; ! // copy sensor state array Index: tcObjectControl.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcObjectControl.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** tcObjectControl.cpp 14 May 2004 23:37:08 -0000 1.15 --- tcObjectControl.cpp 24 May 2004 00:14:47 -0000 1.16 *************** *** 2,6 **** ** tcObjectControl.cpp ** ! ** Copyright (C) 2003 Dewitt "Cole" Colclough (de...@tw...) ** All rights reserved. --- 2,6 ---- ** tcObjectControl.cpp ** ! ** Copyright (C) 2003-2004 Dewitt Colclough (de...@tw...) ** All rights reserved. [...2911 lines suppressed...] ! } ! mpFontLarge = new Font(&ff,14,FontStyleBold,UnitPixel); ! if (mpFontLarge == NULL) ! { ! WTL("tcObjectControl - mpFontLarge creation failed\n"); ! } ! mpBrush = new SolidBrush(Color(254,100,255,100)); ! if (mpBrush == NULL) ! { ! WTL("tcObjectControl - mpBrush creation failed\n"); ! } } tcObjectControl::~tcObjectControl() { ! if (mpPen != NULL) {delete mpPen;} ! if (mpFont != NULL) {delete mpFont;} ! if (mpFontLarge != NULL) {delete mpFontLarge;} ! if (mpBrush != NULL) {delete mpBrush;} } Index: tcESMSensor.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcESMSensor.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** tcESMSensor.cpp 23 Apr 2004 00:15:17 -0000 1.4 --- tcESMSensor.cpp 24 May 2004 00:14:47 -0000 1.5 *************** *** 154,158 **** return(*this); } ! /** * Load state from stream --- 154,158 ---- return(*this); } ! #if 0 /** * Load state from stream *************** *** 174,178 **** return stream; } ! /** * --- 174,178 ---- return stream; } ! #endif /** * --- NEW FILE: tcCommandObject.cpp --- /** @file tcCommandObject.cpp ** ** Copyright (C) 2003-2004 Dewitt Colclough (de...@tw...) ** 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 "tcCommandObject.h" #include "tcLauncher.h" #include "common/tcStream.h" #include "common/tcObjStream.h" bool tcCommandObject::clientMode = false; void tcCommandObject::ClearNewCommand() { newCommand = false; } bool tcCommandObject::HasNewCommand() const { return newCommand; } bool tcCommandObject::HasUnacknowledgedCommand() const { return (commandStatus != 0); } /** * Used with multiplayer client to load a parameter from the server that * the client can command e.g. heading, speed, altitude. If a client command * request is outstanding and the server update does not match, then the update * is ignored. If the update matches, the command flag is cleared representing * a successful acknowledge of the command. */ void tcCommandObject::LoadCommandParam(tcCommandStream& stream, float& param, int flag) { float temp; stream >> temp; // read into temporary variable if (stream.GetAck()) { if ((commandStatus & flag) && (temp == param)) { commandStatus &= (~flag); // clear flag, successful ack } } else // not an ack { if (clientMode && (commandStatus & flag)) { // ignore update } else { param = temp; // apply update commandStatus &= (~flag); // clear flag } } } /** * version that takes int param */ void tcCommandObject::LoadCommandParam(tcCommandStream& stream, int& param, int flag) { int temp; stream >> temp; // read into temporary variable if (stream.GetAck()) { if ((commandStatus & flag) && (temp == param)) { commandStatus &= (~flag); // clear flag, successful ack } } else // not an ack { if (clientMode && (commandStatus & flag)) { // ignore update } else { param = temp; // apply update commandStatus &= (~flag); // clear flag } } } /** * version that takes tcLauncher param */ void tcCommandObject::LoadCommandParam(tcCommandStream& stream, tcLauncher& param, int flag) { tcLauncher temp; temp << stream; // read into temporary obj if (stream.GetAck()) { if ((commandStatus & flag) && (temp.CommandInfoMatches(param))) { commandStatus &= (~flag); // clear flag, successful ack } } else // not an ack { if (clientMode && (commandStatus & flag)) { // ignore update } else { param.CopyCommandInfoFrom(temp); // apply update commandStatus &= (~flag); // clear flag } } } /** * Called on new command. Sets bit in commandStatus and * sets newCommand to true. */ void tcCommandObject::SetNewCommand(int flag) { commandStatus |= flag; newCommand = true; } tcCommandObject::tcCommandObject() : commandStatus(0), newCommand(0) { } tcCommandObject::~tcCommandObject() { } Index: tcSimState.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcSimState.cpp,v retrieving revision 1.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** tcSimState.cpp 9 May 2004 20:40:23 -0000 1.43 --- tcSimState.cpp 24 May 2004 00:14:47 -0000 1.44 *************** *** 36,42 **** --- 36,44 ---- #include "tcAirObject.h" #include "tcAeroAirObject.h" + #include "tcLauncher.h" #include "tcAirDBObject.h" #include "tc3DModel.h" #include "tcGameObjIterator.h" + #include "tcCommandObject.h" #include "common/tcStream.h" *************** *** 233,237 **** if (pLauncherState==NULL) {return false;} if (anLauncher>=(unsigned)pLauncherState->mnCount) {return false;} // invalid anLauncher ! tsLData *pLauncher = &pLauncherState->launchers[anLauncher]; if (pLauncher->mnCurrent <= 0) {return false;} // launcher empty if (pLauncher->mfTimeToReady > 0) {return false;} // launcher not ready --- 235,239 ---- if (pLauncherState==NULL) {return false;} if (anLauncher>=(unsigned)pLauncherState->mnCount) {return false;} // invalid anLauncher ! tcLauncher *pLauncher = &pLauncherState->launchers[anLauncher]; if (pLauncher->mnCurrent <= 0) {return false;} // launcher empty if (pLauncher->mfTimeToReady > 0) {return false;} // launcher not ready *************** *** 288,296 **** { tcPlatformObject *pPlatformObj = dynamic_cast<tcPlatformObject*>(pplat); ! if (pPlatformObj != NULL) { ! // TODO: investigate possible problem here with off menu click ??? ! pplat->Launch(nNewKey,nLauncher); ! if (nNewKey != NULL_INDEX) {AddLaunchedPlatform(nNewKey,pplat,nLauncher);} } } --- 290,297 ---- { tcPlatformObject *pPlatformObj = dynamic_cast<tcPlatformObject*>(pplat); ! if ((pPlatformObj != NULL) && (multiplayerMode != MM_CLIENT)) { ! pplat->Launch(nNewKey, nLauncher); ! if (nNewKey != NULL_INDEX) {AddLaunchedPlatform(nNewKey, pplat, nLauncher);} } } *************** *** 553,557 **** { tcLauncherState *pLauncherState; ! tsLData *pLauncher; bool bReadyForLaunch; --- 554,558 ---- { tcLauncherState *pLauncherState; ! bool bReadyForLaunch; *************** *** 560,565 **** apGameObj->GetLauncherState(pLauncherState); if (pLauncherState == NULL) {return false;} ! pLauncher = &pLauncherState->launchers[anLauncher]; ! int nLaunchCount = pLauncher->mnCurrent - pLauncher->mnPending; // determine if launcher is ready for launch --- 561,569 ---- apGameObj->GetLauncherState(pLauncherState); if (pLauncherState == NULL) {return false;} ! ! const tcLauncher* pLauncher = pLauncherState->GetLauncher(anLauncher); ! if (pLauncher == 0) return false; ! ! int nLaunchCount = pLauncher->mnUncommitted; // determine if launcher is ready for launch *************** *** 568,578 **** bool bTrackActive = (pLauncher->mnTargetID != NULL_INDEX); ! if (pLauncher->meLaunchMode == AUTO) { bReadyForLaunch = bLauncherActive; } ! else if (pLauncher->meLaunchMode == DATUM_ONLY) { bReadyForLaunch = bLauncherActive && bDatumActive; } ! else if (pLauncher->meLaunchMode == SEEKER_TRACK) { bReadyForLaunch = bLauncherActive && bTrackActive; } --- 572,585 ---- bool bTrackActive = (pLauncher->mnTargetID != NULL_INDEX); ! if (pLauncher->meLaunchMode == AUTO) ! { bReadyForLaunch = bLauncherActive; } ! else if (pLauncher->meLaunchMode == DATUM_ONLY) ! { bReadyForLaunch = bLauncherActive && bDatumActive; } ! else if (pLauncher->meLaunchMode == SEEKER_TRACK) ! { bReadyForLaunch = bLauncherActive && bTrackActive; } *************** *** 616,623 **** for(int n=0;(n<nLaunchers)&&(bSearching);n++) { ! tsLData *pLauncher = &pSurfaceObj->mcLauncherState.launchers[n]; bool bLauncherReady = (pLauncher->mbActive)&& (pLauncher->mfTimeToReady <= 0)&& ! (pLauncher->mnPending <= 0); if (bLauncherReady) { --- 623,630 ---- for(int n=0;(n<nLaunchers)&&(bSearching);n++) { ! const tcLauncher* pLauncher = pSurfaceObj->mcLauncherState.GetLauncher(n); bool bLauncherReady = (pLauncher->mbActive)&& (pLauncher->mfTimeToReady <= 0)&& ! (pLauncher->mnCurrent == pLauncher->mnUncommitted); if (bLauncherReady) { *************** *** 738,742 **** /********************************************************************/ ! bool tcSimState::IsDetectedESM(tcESMSensor *apESM, tcRadar *apEmitterRadar, float& rfAz_rad) { return apESM->IsDetected(apEmitterRadar, rfAz_rad); --- 745,749 ---- /********************************************************************/ ! bool tcSimState::IsDetectedESM(tcESMSensor *apESM, const tcRadar* apEmitterRadar, float& rfAz_rad) { return apESM->IsDetected(apEmitterRadar, rfAz_rad); *************** *** 768,776 **** { if (!pPlatformObj->IsRadiating()) {return;} ! std::vector<tcSensorState*> *pSensorArray = pPlatformObj->GetSensorStateArray(); ! int nSensors = (int)pSensorArray->size(); ! for (int n=0;n<nSensors;n++) { ! tcRadar *pRadarSS = dynamic_cast<tcRadar*>(pSensorArray->at(n)); if (pRadarSS) { --- 775,784 ---- { if (!pPlatformObj->IsRadiating()) {return;} ! ! unsigned nSensors = pPlatformObj->GetSensorCount(); ! for (unsigned n=0; n<nSensors; n++) { ! const tcSensorState* sensor = pPlatformObj->GetSensor(n); ! const tcRadar* pRadarSS = dynamic_cast<const tcRadar*>(sensor); if (pRadarSS) { *************** *** 1198,1202 **** wxASSERT(pLauncherState); ! tsLData *pLauncher = &pLauncherState->launchers[anLauncher]; pMissileObj->mfGoalHeading_rad = --- 1206,1210 ---- wxASSERT(pLauncherState); ! const tcLauncher* pLauncher = pLauncherState->GetLauncher(anLauncher); pMissileObj->mfGoalHeading_rad = *************** *** 1900,1903 **** --- 1908,1912 ---- RandInit(); tcGameObject::SetClientMode(false); + tcCommandObject::SetClientMode(false); } *************** *** 1917,1920 **** --- 1926,1930 ---- multiplayerMode = MM_CLIENT; tcGameObject::SetClientMode(true); + tcCommandObject::SetClientMode(true); } *************** *** 1928,1931 **** --- 1938,1942 ---- RandInit(); tcGameObject::SetClientMode(false); + tcCommandObject::SetClientMode(false); } --- NEW FILE: tcLauncher.cpp --- /** @file tcLauncher.cpp ** ** Copyright (C) 2003-2004 Dewitt Colclough (de...@tw...) ** 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 "tcLauncher.h" #include "tcDatabase.h" #include "tcGenericDBObject.h" #include "tcLauncherDBObject.h" #include "tcMissileDBObject.h" #include "tcRadar.h" #include "tcSimState.h" #include <iostream> #include "common/tcObjStream.h" /** * */ tcCommandStream& tcLauncher::operator<<(tcCommandStream& stream) { stream >> mnTargetID; stream >> mnUncommitted; stream >> msDatum.mfAlt_m; stream >> msDatum.mfLat_rad; stream >> msDatum.mfLon_rad; return stream; } /** * */ tcCommandStream& tcLauncher::operator>>(tcCommandStream& stream) { stream << mnTargetID; stream << mnUncommitted; stream << msDatum.mfAlt_m; stream << msDatum.mfLat_rad; stream << msDatum.mfLon_rad; return stream; } /** * @return true if multiplayer command info in launcher and this launcher match */ bool tcLauncher::CommandInfoMatches(const tcLauncher& launcher) { if ((mnTargetID != launcher.mnTargetID) || (mnUncommitted != launcher.mnUncommitted) || (msDatum.mfAlt_m != launcher.msDatum.mfAlt_m) || (msDatum.mfLat_rad != launcher.msDatum.mfLat_rad) || (msDatum.mfLon_rad != launcher.msDatum.mfLon_rad) ) { return false; } else { return true; } } /** * Copies multiplayer command parameters from source launcher to * this launcher. Could define operator= instead, but this may be * used for non-multiplayer purposes. Another way might be to derive * a container class that is only used for these multiplayer functions. */ void tcLauncher::CopyCommandInfoFrom(const tcLauncher& launcher) { mnTargetID = launcher.mnTargetID; mnUncommitted = launcher.mnUncommitted; msDatum.mfAlt_m = launcher.msDatum.mfAlt_m; msDatum.mfLat_rad = launcher.msDatum.mfLat_rad; msDatum.mfLon_rad = launcher.msDatum.mfLon_rad; } /** * */ tcCreateStream& tcLauncher::operator<<(tcCreateStream& stream) { return stream; } /** * Loads state from update stream */ tcUpdateStream& tcLauncher::operator<<(tcUpdateStream& stream) { stream >> mfTimeToReady; stream >> mnCurrent; if (mnUncommitted > mnCurrent) mnUncommitted = mnCurrent; return stream; } /** * Saves state to update stream */ tcUpdateStream& tcLauncher::operator>>(tcUpdateStream& stream) { stream << mfTimeToReady; stream << mnCurrent; return stream; } /** * */ tcCreateStream& tcLauncher::operator>>(tcCreateStream& stream) { return stream; } #if 0 /** * Load state from stream */ tcStream& tcLauncher::operator<<(tcStream& buffer) { buffer >> mbActive; buffer >> mnDBKey; buffer >> mnChildDBKey; buffer >> mfTimeToReady; buffer >> mnCurrent; buffer >> mnPending; msDatum << buffer; buffer >> mnTargetID; int temp; buffer >> temp; meLaunchMode = (Database::teWeaponLaunchMode)temp; buffer >> mnTargetFlags; buffer >> pointingAngle; buffer >> fireControlSensorIdx; return buffer; } /** * Save state to stream */ tcStream& tcLauncher::operator >>(tcStream& buffer) { buffer << mbActive; buffer << mnDBKey; buffer << mnChildDBKey; buffer << mfTimeToReady; buffer << mnCurrent; buffer << mnPending; msDatum >> buffer; buffer << mnTargetID; int temp = (int)meLaunchMode; buffer << temp; buffer << mnTargetFlags; buffer << pointingAngle; buffer << fireControlSensorIdx; return buffer; } #endif Index: tcAirObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcAirObject.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** tcAirObject.cpp 1 May 2004 21:49:06 -0000 1.8 --- tcAirObject.cpp 24 May 2004 00:14:47 -0000 1.9 *************** *** 1,4 **** ! /* ! ** Copyright (C) 2003 Dewitt "Cole" Colclough (de...@tw...) ** All rights reserved. --- 1,5 ---- ! /** @file tcAirObject.cpp ! ** ! ** Copyright (C) 2003-2004 Dewitt Colclough (de...@tw...) ** All rights reserved. *************** *** 36,40 **** tcPlatformObject::operator<<(stream); ! LoadCommandParam(stream, readyForLanding, commandStatus, LANDING_CMD); return stream; --- 37,41 ---- tcPlatformObject::operator<<(stream); ! commandObj.LoadCommandParam(stream, readyForLanding, LANDING_CMD); return stream; *************** *** 72,86 **** { tcPlatformObject::ClearNewCommand(); ! newCommand = false; } bool tcAirObject::HasNewCommand() const { ! return tcPlatformObject::HasNewCommand() || newCommand; } bool tcAirObject::HasUnacknowledgedCommand() const { ! return tcPlatformObject::HasUnacknowledgedCommand() || (commandStatus != 0); } --- 73,88 ---- { tcPlatformObject::ClearNewCommand(); ! commandObj.ClearNewCommand(); } bool tcAirObject::HasNewCommand() const { ! return tcPlatformObject::HasNewCommand() || commandObj.HasNewCommand(); } bool tcAirObject::HasUnacknowledgedCommand() const { ! return tcPlatformObject::HasUnacknowledgedCommand() || ! commandObj.HasUnacknowledgedCommand(); } *************** *** 119,124 **** { readyForLanding = state; ! commandStatus |= LANDING_CMD; ! newCommand = true; } --- 121,125 ---- { readyForLanding = state; ! commandObj.SetNewCommand(LANDING_CMD); } *************** *** 327,332 **** ! tcAirObject::tcAirObject(void) ! : newCommand(false), commandStatus(0) { mnModelType = MTYPE_FIXEDWING; --- 328,332 ---- ! tcAirObject::tcAirObject() { mnModelType = MTYPE_FIXEDWING; *************** *** 342,346 **** */ tcAirObject::tcAirObject(tcGenericDBObject *obj) ! : tcPlatformObject(obj), newCommand(false), commandStatus(0) { mpDBObject = obj; --- 342,346 ---- */ tcAirObject::tcAirObject(tcGenericDBObject *obj) ! : tcPlatformObject(obj) { mpDBObject = obj; *************** *** 350,354 **** } ! tcAirObject::~tcAirObject(void) { } --- 350,354 ---- } ! tcAirObject::~tcAirObject() { } Index: tcSensorState.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcSensorState.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** tcSensorState.cpp 23 Apr 2004 00:15:18 -0000 1.8 --- tcSensorState.cpp 24 May 2004 00:14:47 -0000 1.9 *************** *** 22,36 **** #include "tcSimState.h" #include "tcGameObject.h" ! #include "common/tcStream.h" tcSimState* tcSensorState::simState = NULL; /** * Load state from stream */ ! tcStream& tcSensorState::operator<<(tcStream& stream) { stream >> mbActive; ! stream >> mnDBKey; stream >> mfLastScan; --- 22,37 ---- #include "tcSimState.h" #include "tcGameObject.h" ! #include "common/tcObjStream.h" tcSimState* tcSensorState::simState = NULL; + /** * Load state from stream */ ! tcUpdateStream& tcSensorState::operator<<(tcUpdateStream& stream) { stream >> mbActive; ! //stream >> mnDBKey; stream >> mfLastScan; *************** *** 39,44 **** mcTrack << stream; ! stream >> mountAz_rad; ! stream >> mfSensorHeight_m; return stream; --- 40,45 ---- mcTrack << stream; ! //stream >> mountAz_rad; ! //stream >> mfSensorHeight_m; return stream; *************** *** 48,55 **** * Save state to stream */ ! tcStream& tcSensorState::operator>>(tcStream& stream) { stream << mbActive; ! stream << mnDBKey; stream << mfLastScan; --- 49,56 ---- * Save state to stream */ ! tcUpdateStream& tcSensorState::operator>>(tcUpdateStream& stream) { stream << mbActive; ! //stream << mnDBKey; stream << mfLastScan; *************** *** 58,63 **** mcTrack >> stream; ! stream << mountAz_rad; ! stream << mfSensorHeight_m; return stream; --- 59,64 ---- mcTrack >> stream; ! //stream << mountAz_rad; ! //stream << mfSensorHeight_m; return stream; Index: Game.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/Game.cpp,v retrieving revision 1.79 retrieving revision 1.80 diff -C2 -d -r1.79 -r1.80 *** Game.cpp 14 May 2004 23:37:08 -0000 1.79 --- Game.cpp 24 May 2004 00:14:47 -0000 1.80 *************** *** 1417,1422 **** } ! // Draw 2D windows ! UpdateForScreenMode(); --- 1417,1429 ---- } ! // skip frames if lagging and server ! bool doRender = !isLagging || !tcMultiplayerInterface::Get()->IsServer() || ! (snFrameCount % 8 == 0); ! ! if (doRender) ! { ! // Draw 2D windows ! UpdateForScreenMode(); ! } *************** *** 1439,1444 **** viewer->Update(gameDateZulu); ! // skip frames if lagging and server ! if ((directorTime > 0.1f) && (!isLagging || !tcMultiplayerInterface::Get()->IsServer())) { mpGraphicsEngine->RenderAll(); --- 1446,1450 ---- viewer->Update(gameDateZulu); ! if ((directorTime > 0.1f) && doRender) { mpGraphicsEngine->RenderAll(); Index: tcLauncherState.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcLauncherState.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** tcLauncherState.cpp 13 Apr 2004 00:24:39 -0000 1.8 --- tcLauncherState.cpp 24 May 2004 00:14:47 -0000 1.9 *************** *** 1,22 **** ! /* ! * Copyright (C) 2003 Dewitt "Cole" Colclough (de...@tw...) ! * 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 "tcLauncherState.h" #include "tcDatabase.h" #include "tcGenericDBObject.h" --- 1,24 ---- ! /** @file tcLauncherState.cpp ! ** ! ** Copyright (C) 2003-2004 Dewitt Colclough (de...@tw...) ! ** 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 "tcLauncherState.h" + #include "tcLauncher.h" #include "tcDatabase.h" #include "tcGenericDBObject.h" *************** *** 26,85 **** #include "tcSimState.h" #include <iostream> ! #include "common/tcStream.h" ! ! /** ! * Load state from stream ! */ ! tcStream& tsLData::operator <<(tcStream& buffer) ! { ! buffer >> mbActive; ! buffer >> mnDBKey; ! buffer >> mnChildDBKey; ! ! buffer >> mfTimeToReady; ! buffer >> mnCurrent; ! buffer >> mnPending; ! ! msDatum << buffer; ! ! buffer >> mnTargetID; ! ! int temp; ! buffer >> temp; ! meLaunchMode = (Database::teWeaponLaunchMode)temp; ! ! buffer >> mnTargetFlags; ! buffer >> pointingAngle; ! buffer >> fireControlSensorIdx; ! ! return buffer; ! } ! ! /** ! * Save state to stream ! */ ! tcStream& tsLData::operator >>(tcStream& buffer) ! { ! buffer << mbActive; ! buffer << mnDBKey; ! buffer << mnChildDBKey; ! ! buffer << mfTimeToReady; ! buffer << mnCurrent; ! buffer << mnPending; ! ! msDatum >> buffer; ! ! buffer << mnTargetID; ! ! int temp = (int)meLaunchMode; ! buffer << temp; ! ! buffer << mnTargetFlags; ! buffer << pointingAngle; ! buffer << fireControlSensorIdx; ! ! return buffer; ! } --- 28,32 ---- #include "tcSimState.h" #include <iostream> ! #include "common/tcObjStream.h" *************** *** 126,130 **** } ! tsLData new_launcher; new_launcher.mnChildDBKey = nChildKey; --- 73,77 ---- } ! tcLauncher new_launcher; new_launcher.mnChildDBKey = nChildKey; *************** *** 139,143 **** new_launcher.mnTargetID = NULL_INDEX; new_launcher.meLaunchMode = AUTO; ! new_launcher.mnPending = 0; new_launcher.pointingAngle = azimuth_rad; new_launcher.fireControlSensor = NULL; --- 86,90 ---- new_launcher.mnTargetID = NULL_INDEX; new_launcher.meLaunchMode = AUTO; ! new_launcher.mnUncommitted = new_launcher.mnCurrent; new_launcher.pointingAngle = azimuth_rad; new_launcher.fireControlSensor = NULL; *************** *** 158,166 **** } int tcLauncherState::GetLauncherQuantity(unsigned anLauncher) { if (anLauncher > launchers.size()) {return -1;} ! return launchers[anLauncher].mnCurrent - launchers[anLauncher].mnPending; } --- 105,142 ---- } + const char* tcLauncherState::GetFireControlSensorClass(unsigned nLauncher) const + { + wxASSERT((int)nLauncher < mnCount); + + return launchers[nLauncher].mpLauncherDBObj->fireControlSensorClass.c_str(); + } + + const tcLauncher* tcLauncherState::GetLauncher(unsigned nLauncher) const + { + if ((int)nLauncher >= mnCount) return 0; + + return &launchers[nLauncher]; + } + + const char* tcLauncherState::GetLauncherChildClass(unsigned nLauncher) const + { + wxASSERT((int)nLauncher < mnCount); + + return launchers[nLauncher].mpLauncherDBObj->mzChildClass.mz; + } + + /** + * @return number of launchers + */ + int tcLauncherState::GetLauncherCount() const + { + return mnCount; + } + int tcLauncherState::GetLauncherQuantity(unsigned anLauncher) { if (anLauncher > launchers.size()) {return -1;} ! return launchers[anLauncher].mnUncommitted; } *************** *** 183,187 **** return BAD_LAUNCHER; } ! tsLData& ldata = launchers[nLauncher]; if (ldata.mnCurrent <= 0) {return LAUNCHER_EMPTY;} // launcher empty --- 159,163 ---- return BAD_LAUNCHER; } ! tcLauncher& ldata = launchers[nLauncher]; if (ldata.mnCurrent <= 0) {return LAUNCHER_EMPTY;} // launcher empty *************** *** 282,285 **** --- 258,290 ---- /** + * sets key to database id of object to launch, otherwise NULL_INDEX + * nLauncher is set to launcher idx of launching launcher + * This only handles one launch per call (not efficient for simultaneous launches) + */ + void tcLauncherState::Launch(tnPoolIndex& key, unsigned& nLauncher) + { + for (int n=0; n<mnCount; n++) + { + tcLauncher* pLauncher = &launchers[n]; + + if ((pLauncher->mbActive)&&(pLauncher->mnCurrent > pLauncher->mnUncommitted)) + { + bool bLaunch = (pLauncher->mnCurrent > 0)&&(pLauncher->mfTimeToReady <= 0); + if (bLaunch) + { + pLauncher->mnCurrent--; + key = pLauncher->mnChildDBKey; + nLauncher = n; + pLauncher->mfTimeToReady = 2.0f; // TODO: add db parameter for this + return; + } + } + } + key = NULL_INDEX; + nLauncher = 0; + } + + + /** * @param nLauncher launcher index * @param radar pointer to tcRadar object that acts as fire control sensor *************** *** 301,304 **** --- 306,339 ---- } + + + /** + * If launcher is ready, decrement mnUncommitted of nLauncher by quantity. + * This method does not support targeting multiple targets. + * @return tcLauncherState::teLauncherStatus error code, LAUNCHER_READY = 0 for success + */ + int tcLauncherState::SetLaunch(int nLauncher, int quantity) + { + int statusCode; + + statusCode = GetLauncherStatus(nLauncher); + if (statusCode != tcLauncherState::LAUNCHER_READY) return statusCode; + + tcLauncher* pLauncher = &launchers[nLauncher]; + + pLauncher->mnUncommitted -= quantity; + if (pLauncher->mnUncommitted < 0) + { + pLauncher->mnUncommitted = 0; // don't set new cmd here since this is an error case + std::cerr << "Error - tcLauncherState::SetLaunch - negative uncommitted\n"; + } + else + { + commandObj.SetNewCommand(GetLauncherFlag(nLauncher)); + } + + return statusCode; + } + /** * @return true if success *************** *** 312,315 **** --- 347,351 ---- } launchers[nLauncher].msDatum.Set(lon_rad, lat_rad); + commandObj.SetNewCommand(GetLauncherFlag(nLauncher)); return true; } *************** *** 327,330 **** --- 363,367 ---- } launchers[nLauncher].mnTargetID = targetID; + commandObj.SetNewCommand(GetLauncherFlag(nLauncher)); return true; } *************** *** 390,393 **** --- 42... [truncated message content] |