mirror of
https://github.com/glest/glest-source.git
synced 2025-02-25 04:02:30 +01:00
- modified command object to support special states which flow through network play as well. This allows for better handling of multi-unit build and allows for better future expanding of command processing.
This commit is contained in:
parent
13173788da
commit
e32eb9c162
@ -52,6 +52,10 @@ CommandResult Commander::tryGiveCommand(const Selection *selection, const Comman
|
|||||||
|
|
||||||
refPos= computeRefPos(selection);
|
refPos= computeRefPos(selection);
|
||||||
|
|
||||||
|
int builderUnitId = -1;
|
||||||
|
CommandStateType commandStateType = cst_None;
|
||||||
|
int commandStateValue = -1;
|
||||||
|
|
||||||
bool unitSignalledToBuild = false;
|
bool unitSignalledToBuild = false;
|
||||||
//give orders to all selected units
|
//give orders to all selected units
|
||||||
for(int i=0; i<selection->getCount(); ++i) {
|
for(int i=0; i<selection->getCount(); ++i) {
|
||||||
@ -64,20 +68,23 @@ CommandResult Commander::tryGiveCommand(const Selection *selection, const Comman
|
|||||||
if(dynamic_cast<const BuildCommandType *>(commandType) != NULL) {
|
if(dynamic_cast<const BuildCommandType *>(commandType) != NULL) {
|
||||||
usePos = pos;
|
usePos = pos;
|
||||||
if(unitSignalledToBuild == false) {
|
if(unitSignalledToBuild == false) {
|
||||||
|
builderUnitId = unitId;
|
||||||
unitSignalledToBuild = true;
|
unitSignalledToBuild = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
useCommandtype = unit->getType()->getFirstRepairCommand(unitType);
|
useCommandtype = unit->getType()->getFirstRepairCommand(unitType);
|
||||||
tryQueue = true;
|
commandStateType = cst_linkedUnit;
|
||||||
|
commandStateValue = builderUnitId;
|
||||||
|
//tryQueue = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkCommand networkCommand(this->world,nctGiveCommand, unitId,
|
NetworkCommand networkCommand(this->world,nctGiveCommand, unitId,
|
||||||
useCommandtype->getId(), usePos, unitType->getId(),
|
useCommandtype->getId(), usePos, unitType->getId(),
|
||||||
(targetUnit != NULL ? targetUnit->getId() : -1),
|
(targetUnit != NULL ? targetUnit->getId() : -1),
|
||||||
facing, tryQueue);
|
facing, tryQueue, commandStateType,commandStateValue);
|
||||||
|
|
||||||
//every unit is ordered to a different position
|
//every unit is ordered to a the position
|
||||||
CommandResult result= pushNetworkCommand(&networkCommand);
|
CommandResult result= pushNetworkCommand(&networkCommand);
|
||||||
results.push_back(result);
|
results.push_back(result);
|
||||||
}
|
}
|
||||||
@ -290,7 +297,7 @@ CommandResult Commander::computeResult(const CommandResultContainer &results) co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandResult Commander::pushNetworkCommand(const NetworkCommand* networkCommand) const{
|
CommandResult Commander::pushNetworkCommand(const NetworkCommand* networkCommand) const {
|
||||||
GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface();
|
GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface();
|
||||||
const Unit* unit= world->findUnitById(networkCommand->getUnitId());
|
const Unit* unit= world->findUnitById(networkCommand->getUnitId());
|
||||||
CommandResult cr= crSuccess;
|
CommandResult cr= crSuccess;
|
||||||
@ -432,7 +439,7 @@ void Commander::giveNetworkCommand(NetworkCommand* networkCommand) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Command* Commander::buildCommand(const NetworkCommand* networkCommand) const{
|
Command* Commander::buildCommand(const NetworkCommand* networkCommand) const {
|
||||||
assert(networkCommand->getNetworkCommandType()==nctGiveCommand);
|
assert(networkCommand->getNetworkCommandType()==nctGiveCommand);
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] networkCommand [%s]\n",__FILE__,__FUNCTION__,__LINE__,networkCommand->toString().c_str());
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] networkCommand [%s]\n",__FILE__,__FUNCTION__,__LINE__,networkCommand->toString().c_str());
|
||||||
@ -523,6 +530,13 @@ Command* Commander::buildCommand(const NetworkCommand* networkCommand) const{
|
|||||||
command= new Command(ct, target);
|
command= new Command(ct, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add in any special state
|
||||||
|
CommandStateType commandStateType = networkCommand->getCommandStateType();
|
||||||
|
int commandStateValue = networkCommand->getCommandStateValue();
|
||||||
|
|
||||||
|
command->setStateType(commandStateType);
|
||||||
|
command->setStateValue(commandStateValue);
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
//issue command
|
//issue command
|
||||||
|
@ -314,7 +314,7 @@ bool NetworkMessageCommandList::addCommand(const NetworkCommand* networkCommand)
|
|||||||
|
|
||||||
bool NetworkMessageCommandList::receive(Socket* socket) {
|
bool NetworkMessageCommandList::receive(Socket* socket) {
|
||||||
// _peek_ type, commandCount & frame num first.
|
// _peek_ type, commandCount & frame num first.
|
||||||
for(int peekAttempt = 1; peekAttempt < 15; peekAttempt++) {
|
for(int peekAttempt = 1; peekAttempt < 1000; peekAttempt++) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] peekAttempt = %d\n",__FILE__,__FUNCTION__,__LINE__,peekAttempt);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] peekAttempt = %d\n",__FILE__,__FUNCTION__,__LINE__,peekAttempt);
|
||||||
|
|
||||||
if (NetworkMessage::peek(socket, &data, commandListHeaderSize) == true) {
|
if (NetworkMessage::peek(socket, &data, commandListHeaderSize) == true) {
|
||||||
@ -337,7 +337,7 @@ bool NetworkMessageCommandList::receive(Socket* socket) {
|
|||||||
int totalMsgSize = commandListHeaderSize + (sizeof(NetworkCommand) * data.header.commandCount);
|
int totalMsgSize = commandListHeaderSize + (sizeof(NetworkCommand) * data.header.commandCount);
|
||||||
|
|
||||||
// _peek_ type, commandCount & frame num first.
|
// _peek_ type, commandCount & frame num first.
|
||||||
for(int peekAttempt = 1; peekAttempt < 15; peekAttempt++) {
|
for(int peekAttempt = 1; peekAttempt < 1000; peekAttempt++) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] peekAttempt = %d\n",__FILE__,__FUNCTION__,__LINE__,peekAttempt);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] peekAttempt = %d\n",__FILE__,__FUNCTION__,__LINE__,peekAttempt);
|
||||||
|
|
||||||
if (NetworkMessage::peek(socket, &data, totalMsgSize) == true) {
|
if (NetworkMessage::peek(socket, &data, totalMsgSize) == true) {
|
||||||
|
@ -27,14 +27,21 @@ namespace Glest{ namespace Game{
|
|||||||
// class NetworkCommand
|
// class NetworkCommand
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
NetworkCommand::NetworkCommand(World *world, int networkCommandType, int unitId, int commandTypeId, const Vec2i &pos, int unitTypeId, int targetId, int facing, bool wantQueue)
|
NetworkCommand::NetworkCommand(World *world, int networkCommandType, int unitId,
|
||||||
|
int commandTypeId, const Vec2i &pos, int unitTypeId,
|
||||||
|
int targetId, int facing, bool wantQueue,
|
||||||
|
CommandStateType commandStateType,
|
||||||
|
int commandStateValue)
|
||||||
: networkCommandType(networkCommandType)
|
: networkCommandType(networkCommandType)
|
||||||
, unitId(unitId)
|
, unitId(unitId)
|
||||||
, commandTypeId(commandTypeId)
|
, commandTypeId(commandTypeId)
|
||||||
, positionX(pos.x)
|
, positionX(pos.x)
|
||||||
, positionY(pos.y)
|
, positionY(pos.y)
|
||||||
, unitTypeId(unitTypeId)
|
, unitTypeId(unitTypeId)
|
||||||
, wantQueue(wantQueue) {
|
, wantQueue(wantQueue)
|
||||||
|
, commandStateType(commandStateType)
|
||||||
|
, commandStateValue(commandStateValue) {
|
||||||
|
|
||||||
assert(targetId == -1 || facing == -1);
|
assert(targetId == -1 || facing == -1);
|
||||||
this->targetId = targetId >= 0 ? targetId : facing;
|
this->targetId = targetId >= 0 ? targetId : facing;
|
||||||
this->fromFactionIndex = world->getThisFactionIndex();
|
this->fromFactionIndex = world->getThisFactionIndex();
|
||||||
@ -76,10 +83,12 @@ void NetworkCommand::preprocessNetworkCommand(World *world) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string NetworkCommand::toString() const {
|
string NetworkCommand::toString() const {
|
||||||
char szBuf[1024]="";
|
char szBuf[1024]="";
|
||||||
sprintf(szBuf,"networkCommandType = %d\nunitId = %d\ncommandTypeId = %d\npositionX = %d\npositionY = %d\nunitTypeId = %d\ntargetId = %d\nwantQueue= %d\nfromFactionIndex = %d\nunitFactionUnitCount = %d\nunitFactionIndex = %d",
|
sprintf(szBuf,"networkCommandType = %d\nunitId = %d\ncommandTypeId = %d\npositionX = %d\npositionY = %d\nunitTypeId = %d\ntargetId = %d\nwantQueue= %d\nfromFactionIndex = %d\nunitFactionUnitCount = %d\nunitFactionIndex = %d, commandStateType = %d, commandStateValue = %d",
|
||||||
networkCommandType,unitId,commandTypeId,positionX,this->positionY,unitTypeId,targetId,wantQueue,fromFactionIndex,unitFactionUnitCount,unitFactionIndex);
|
networkCommandType,unitId,commandTypeId,positionX,positionY,unitTypeId,targetId,wantQueue,
|
||||||
|
fromFactionIndex,unitFactionUnitCount,unitFactionIndex,commandStateType,commandStateValue);
|
||||||
|
|
||||||
string result = szBuf;
|
string result = szBuf;
|
||||||
return result;
|
return result;
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "vec.h"
|
#include "vec.h"
|
||||||
|
#include "command.h"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::min;
|
using std::min;
|
||||||
@ -83,6 +84,8 @@ private:
|
|||||||
int8 fromFactionIndex;
|
int8 fromFactionIndex;
|
||||||
uint16 unitFactionUnitCount;
|
uint16 unitFactionUnitCount;
|
||||||
int8 unitFactionIndex;
|
int8 unitFactionIndex;
|
||||||
|
int8 commandStateType;
|
||||||
|
int32 commandStateValue;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NetworkCommand(){};
|
NetworkCommand(){};
|
||||||
@ -95,9 +98,9 @@ public:
|
|||||||
int unitTypeId= -1,
|
int unitTypeId= -1,
|
||||||
int targetId= -1,
|
int targetId= -1,
|
||||||
int facing= -1,
|
int facing= -1,
|
||||||
bool wantQueue = false);
|
bool wantQueue = false,
|
||||||
|
CommandStateType commandStateType = cst_None,
|
||||||
//NetworkCommand(int networkCommandType, NetworkCommandSubType ncstType, int unitId, int value1, int value2=-1);
|
int commandTypeStateValue = -1);
|
||||||
|
|
||||||
NetworkCommandType getNetworkCommandType() const {return static_cast<NetworkCommandType>(networkCommandType);}
|
NetworkCommandType getNetworkCommandType() const {return static_cast<NetworkCommandType>(networkCommandType);}
|
||||||
int getUnitId() const {return unitId;}
|
int getUnitId() const {return unitId;}
|
||||||
@ -110,6 +113,9 @@ public:
|
|||||||
int getUnitFactionUnitCount() const {return unitFactionUnitCount;}
|
int getUnitFactionUnitCount() const {return unitFactionUnitCount;}
|
||||||
int getUnitFactionIndex() const {return unitFactionIndex;}
|
int getUnitFactionIndex() const {return unitFactionIndex;}
|
||||||
|
|
||||||
|
CommandStateType getCommandStateType() const {return static_cast<CommandStateType>(commandStateType);}
|
||||||
|
int getCommandStateValue() const {return commandStateValue;}
|
||||||
|
|
||||||
void preprocessNetworkCommand(World *world);
|
void preprocessNetworkCommand(World *world);
|
||||||
string toString() const;
|
string toString() const;
|
||||||
};
|
};
|
||||||
|
@ -31,6 +31,8 @@ Command::Command(const CommandType *ct, const Vec2i &pos){
|
|||||||
this->commandType= ct;
|
this->commandType= ct;
|
||||||
this->pos= pos;
|
this->pos= pos;
|
||||||
unitType= NULL;
|
unitType= NULL;
|
||||||
|
stateType = cst_None;
|
||||||
|
stateValue = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Command::Command(const CommandType *ct, Unit* unit){
|
Command::Command(const CommandType *ct, Unit* unit){
|
||||||
@ -38,10 +40,12 @@ Command::Command(const CommandType *ct, Unit* unit){
|
|||||||
this->pos= Vec2i(0);
|
this->pos= Vec2i(0);
|
||||||
this->unitRef= unit;
|
this->unitRef= unit;
|
||||||
unitType= NULL;
|
unitType= NULL;
|
||||||
if(unit!=NULL){
|
if(unit!=NULL) {
|
||||||
unit->resetHighlight();
|
unit->resetHighlight();
|
||||||
pos= unit->getCellPos();
|
pos= unit->getCellPos();
|
||||||
}
|
}
|
||||||
|
stateType = cst_None;
|
||||||
|
stateValue = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Command::Command(const CommandType *ct, const Vec2i &pos, const UnitType *unitType, CardinalDir facing){
|
Command::Command(const CommandType *ct, const Vec2i &pos, const UnitType *unitType, CardinalDir facing){
|
||||||
@ -49,6 +53,8 @@ Command::Command(const CommandType *ct, const Vec2i &pos, const UnitType *unitTy
|
|||||||
this->pos= pos;
|
this->pos= pos;
|
||||||
this->unitType= unitType;
|
this->unitType= unitType;
|
||||||
this->facing = facing;
|
this->facing = facing;
|
||||||
|
stateType = cst_None;
|
||||||
|
stateValue = -1;
|
||||||
|
|
||||||
if(this->unitType != NULL) {
|
if(this->unitType != NULL) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unitType = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->unitType->toString().c_str());
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unitType = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->unitType->toString().c_str());
|
||||||
@ -97,6 +103,8 @@ std::string Command::toString() const {
|
|||||||
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__, __LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__, __LINE__);
|
||||||
|
|
||||||
|
result = ", stateType = " + intToStr(stateType) + ", stateValue = " + intToStr(stateValue);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,13 +24,18 @@ using Shared::Graphics::Vec2i;
|
|||||||
|
|
||||||
class CommandType;
|
class CommandType;
|
||||||
|
|
||||||
|
enum CommandStateType {
|
||||||
|
cst_None,
|
||||||
|
cst_linkedUnit
|
||||||
|
};
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class Command
|
// class Command
|
||||||
//
|
//
|
||||||
/// A unit command
|
/// A unit command
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
class Command{
|
class Command {
|
||||||
private:
|
private:
|
||||||
const CommandType *commandType;
|
const CommandType *commandType;
|
||||||
Vec2i pos;
|
Vec2i pos;
|
||||||
@ -38,6 +43,9 @@ private:
|
|||||||
CardinalDir facing; // facing, for build command
|
CardinalDir facing; // facing, for build command
|
||||||
const UnitType *unitType; //used for build
|
const UnitType *unitType; //used for build
|
||||||
|
|
||||||
|
CommandStateType stateType;
|
||||||
|
int stateValue;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//constructor
|
//constructor
|
||||||
Command(const CommandType *ct, const Vec2i &pos=Vec2i(0));
|
Command(const CommandType *ct, const Vec2i &pos=Vec2i(0));
|
||||||
@ -56,6 +64,13 @@ public:
|
|||||||
void setPos(const Vec2i &pos);
|
void setPos(const Vec2i &pos);
|
||||||
void setUnit(Unit *unit);
|
void setUnit(Unit *unit);
|
||||||
|
|
||||||
|
void setStateType(CommandStateType value) { stateType = value; }
|
||||||
|
CommandStateType getStateType() const { return stateType; }
|
||||||
|
|
||||||
|
void setStateValue(int value) { stateValue = value; }
|
||||||
|
int getStateValue() const { return stateValue; }
|
||||||
|
|
||||||
|
|
||||||
std::string toString() const;
|
std::string toString() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ enum Queueability {
|
|||||||
/// A complex action performed by a unit, composed by skills
|
/// A complex action performed by a unit, composed by skills
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
class CommandType: public RequirableType{
|
class CommandType: public RequirableType {
|
||||||
protected:
|
protected:
|
||||||
CommandClass commandTypeClass;
|
CommandClass commandTypeClass;
|
||||||
Clicks clicks;
|
Clicks clicks;
|
||||||
@ -74,6 +74,11 @@ public:
|
|||||||
static const int invalidId= -1;
|
static const int invalidId= -1;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
CommandType() {
|
||||||
|
commandTypeClass = ccNull;
|
||||||
|
clicks = cOne;
|
||||||
|
id = -1;
|
||||||
|
}
|
||||||
virtual void update(UnitUpdater *unitUpdater, Unit *unit) const= 0;
|
virtual void update(UnitUpdater *unitUpdater, Unit *unit) const= 0;
|
||||||
virtual void load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut);
|
virtual void load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut);
|
||||||
virtual string getDesc(const TotalUpgrade *totalUpgrade) const= 0;
|
virtual string getDesc(const TotalUpgrade *totalUpgrade) const= 0;
|
||||||
|
@ -753,10 +753,10 @@ Unit * UnitUpdater::findPeerUnitBuilder(Unit *unit) {
|
|||||||
|
|
||||||
Unit *foundUnitBuilder = NULL;
|
Unit *foundUnitBuilder = NULL;
|
||||||
if(unit->getCommandSize() > 0 ) {
|
if(unit->getCommandSize() > 0 ) {
|
||||||
Command *command= unit->getCurrCommand();
|
Command *command = unit->getCurrCommand();
|
||||||
if(command != NULL) {
|
if(command != NULL) {
|
||||||
const RepairCommandType *rct= dynamic_cast<const RepairCommandType*>(command->getCommandType());
|
const RepairCommandType *rct= dynamic_cast<const RepairCommandType*>(command->getCommandType());
|
||||||
if(rct) {
|
if(rct != NULL && command->getStateType() == cst_linkedUnit) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
for(int i = 0; i < unit->getFaction()->getUnitCount(); ++i) {
|
for(int i = 0; i < unit->getFaction()->getUnitCount(); ++i) {
|
||||||
@ -770,7 +770,8 @@ Unit * UnitUpdater::findPeerUnitBuilder(Unit *unit) {
|
|||||||
if(bct != NULL) {
|
if(bct != NULL) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
if(command->getPos() == peerCommand->getPos()) {
|
//if(command->getPos() == peerCommand->getPos()) {
|
||||||
|
if(command->getStateValue() == peerUnit->getId()) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
foundUnitBuilder = peerUnit;
|
foundUnitBuilder = peerUnit;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user