![]() |
VR-Forces 4.0.4 Class Documentation
|
The DtRetreatTask is a new class that contains information as to how an entity should retreat.
Used in conjunction with the DtRetreatController
/******************************************************************************* ** Copyright (c) 2002 MAK Technologies, Inc. ** All rights reserved. *******************************************************************************/ /******************************************************************************* ** $RCSfile: retreatTask.h,v $ $Revision: 1.4 $ $State: Exp $ *******************************************************************************/ #ifndef DtRetreatTask_H_ #define DtRetreatTask_H_ #include "vrftasks/simTask.h" #include <vlutil/vlNetTypes.h> #include "vrfutil/rwString.h" #include "vrftasks/radioMsgTypes.h" //class DtRetreatTask: // //Instances of DtRetreatTask are an example of a new kind of task that tells //an entity to either "retreat-immediately", or "hold-ground" (and retreat //only if you come under fire). //This number is used to identify the type of DtSimTask, and is returned //by DtRetreatTask::type(). To be sure that it doesn't conflict with any //existing types use a number greater than MIN_USER_RADIO_MESSAGE_TYPE as //defined in radioMsgTypes.h. const int DtRetreatTaskType = MIN_USER_RADIO_MESSAGE_TYPE + 1; //DtRetreatTaskTypeString must be a unique string representing the task //(existing string types are defined in msgTypes.h). const char DtRetreatTaskTypeString[] = "retreat-task"; class DtRetreatTask : public DtSimTask { public: //default constructor DtRetreatTask(); //constructor DtRetreatTask(const DtString & writeName, DtReaderWriterRegistry * parentRegistry = 0); //destructor virtual ~DtRetreatTask(); //copy constructor - not implemented DtRetreatTask(const DtString & writeName, const DtRetreatTask & orig, DtReaderWriterRegistry * parentRegistry = 0); //assignment operator - not implemented DtRetreatTask& operator=(const DtRetreatTask& orig); //Returns DtRetreatTaskType (defined above). virtual int type() const; //Creates a copy of the task. virtual DtSimTask * clone(const DtString & name, DtReaderWriterRegistry * parentRegistry = 0) const; //Get a readable string representation of this task. virtual DtString stringRep() const; //A character string representing the kind of retreat task. The allowed //retreat task strings are "retreat-immediately" and "hold-ground". virtual const DtString & retreatKind() const; virtual void setRetreatKind(const DtString & retreatKind); //Returns the size of the full network representation //padded to an 8-byte boundary. Be sure to call the base class's //netRepSize() and add the returned value in computation of overall size //of network representation. virtual int netRepSize() const; //Fills in the task from the network buffer. Be sure to call down to the //base class's setFromNet() to ensure that the entire message is set from //the network representation. virtual bool setFromNet(const char* contentBuffer, unsigned contentSize); //Fills in the network buffer (created by base class simTask) with the //task contents. Be sure to call down to base class's setToNet() to ensure //complete contents of the message are set in the network representation. virtual bool setToNet(); static DtSimTask * creator(); protected: DtRwString myRetreatKind; }; #endif
/******************************************************************************* ** Copyright (c) 2011 MAK Technologies, Inc. ** All rights reserved. *******************************************************************************/ #include <math.h> #include <memory.h> #include "../addTaskSim/retreatTask.h" #include <vlutil/vlPrint.h> #include "vrfutil/bufferSerialize.h" DtRetreatTask::DtRetreatTask() : DtSimTask(), myRetreatKind("retreat-task-kind", &myRegistry) { myRetreatKind = "retreat-immediately"; } DtRetreatTask::DtRetreatTask(const DtString & writeName, DtReaderWriterRegistry * parentRegistry) : DtSimTask(writeName, parentRegistry), myRetreatKind("retreat-task-kind", &myRegistry) { myRetreatKind = "retreat-immediately"; } DtRetreatTask::~DtRetreatTask() { } DtRetreatTask::DtRetreatTask(const DtString & writeName, const DtRetreatTask & orig, DtReaderWriterRegistry * parentRegistry) : DtSimTask(writeName, orig, parentRegistry), myRetreatKind(orig.myRetreatKind.name(), &myRegistry) { myRetreatKind = orig.myRetreatKind; } DtRetreatTask& DtRetreatTask::operator=(const DtRetreatTask& orig) { if(this == &orig) { return *this; } DtSimTask::operator=(orig); myRetreatKind = orig.myRetreatKind; return *this; } int DtRetreatTask::type() const { //Defined in retreatTask.h, must be greater than MIN_USER_RADIO_MESSAGE_TYPE return DtRetreatTaskType; } DtSimTask* DtRetreatTask::clone(const DtString & name, DtReaderWriterRegistry * parentRegistry) const { return new DtRetreatTask(name, *this, parentRegistry); } DtString DtRetreatTask::stringRep() const { return "Retreat Task=\"" + myRetreatKind + "\""; } const DtString & DtRetreatTask::retreatKind() const { return myRetreatKind; } void DtRetreatTask::setRetreatKind(const DtString & retreatKind) { myRetreatKind = retreatKind; } int DtRetreatTask::netRepSize() const { int size; //Add the size of the header information from the base class size = DtSimTask::netRepSize(); //Add the size of all the items size += DtBufferSerialize::getSize(myRetreatKind); return size; } bool DtRetreatTask::setFromNet(const char* contentBuffer, unsigned contentSize) { if(!DtSimTask::setFromNet(contentBuffer,contentSize)) { return false; } const char* bufferOffset = contentBuffer + DtSimTask::netRepSize(); bufferOffset = DtBufferSerialize::decode(myRetreatKind, bufferOffset); return true; } bool DtRetreatTask::setToNet() { //Allow the base class to write out its header information if(!DtSimTask::setToNet()) { return false; } if (!netRep()) { return false; } char* bufferOffset = myNetRep + DtSimTask::netRepSize(); bufferOffset = DtBufferSerialize::encode(myRetreatKind, bufferOffset); return true; } DtSimTask * DtRetreatTask::creator() { return new DtRetreatTask(); }