From f091df9954468f8f082db4a8d5b811774553f372 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Mon, 10 May 2010 23:56:55 +0000 Subject: [PATCH] - added a more simpler version of right click to set meeting point from RCL --- source/glest_game/game/commander.cpp | 45 +++++++++++++++++------ source/glest_game/type_instances/unit.cpp | 4 ++ source/glest_game/type_instances/unit.h | 2 + 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/source/glest_game/game/commander.cpp b/source/glest_game/game/commander.cpp index 8507a772..17e4673a 100644 --- a/source/glest_game/game/commander.cpp +++ b/source/glest_game/game/commander.cpp @@ -107,39 +107,60 @@ CommandResult Commander::tryGiveCommand(const Selection *selection, const Comman //auto command CommandResult Commander::tryGiveCommand(const Selection *selection, const Vec2i &pos, const Unit *targetUnit, bool tryQueue) const{ - if(!selection->isEmpty()){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + CommandResult result = crFailUndefined; + + if(selection->isEmpty() == false){ + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); Vec2i refPos, currPos; CommandResultContainer results; //give orders to all selected units refPos= computeRefPos(selection); - for(int i=0; igetCount(); ++i){ - + for(int i=0; igetCount(); ++i) { //every unit is ordered to a different pos - currPos= computeDestPos(refPos, selection->getUnit(i)->getPos(), pos); + const Unit *unit = selection->getUnit(i); + assert(unit != NULL); + + currPos= computeDestPos(refPos, unit->getPos(), pos); //get command type - const CommandType *commandType= selection->getUnit(i)->computeCommandType(pos, targetUnit); + const CommandType *commandType= unit->computeCommandType(pos, targetUnit); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unit = [%s] commandType = %p\n",__FILE__,__FUNCTION__,__LINE__,unit->getFullName().c_str(), commandType); //give commands - if(commandType!=NULL){ + if(commandType!=NULL) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] commandType->toString() [%s]\n",__FILE__,__FUNCTION__,__LINE__,commandType->toString().c_str()); + int targetId= targetUnit==NULL? Unit::invalidId: targetUnit->getId(); - int unitId= selection->getUnit(i)->getId(); + int unitId= unit->getId(); NetworkCommand networkCommand(this->world,nctGiveCommand, unitId, commandType->getId(), currPos, -1, targetId, -1, tryQueue); CommandResult result= pushNetworkCommand(&networkCommand); results.push_back(result); } - else{ + else if(unit->isMeetingPointSettable() == true) { + NetworkCommand command(this->world,nctSetMeetingPoint, unit->getId(), -1, currPos); + + CommandResult result= pushNetworkCommand(&command); + results.push_back(result); + } + else { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + results.push_back(crFailUndefined); } } - return computeResult(results); - } - else{ - return crFailUndefined; + result = computeResult(results); } + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] result = %d\n",__FILE__,__FUNCTION__,__LINE__,result); + + return result; } CommandResult Commander::tryCancelCommand(const Selection *selection) const{ diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index d02d0cdf..0de01f99 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -1194,6 +1194,10 @@ void Unit::setMeetingPos(const Vec2i &meetingPos) { logSynchData(string(__FILE__) + string("::") + string(__FUNCTION__) + string(" Line: ") + intToStr(__LINE__)); } +bool Unit::isMeetingPointSettable() const { + return (type != NULL ? type->getMeetingPoint() : false); +} + int Unit::getFrameCount() { int frameCount = 0; const Game *game = Renderer::getInstance().getGame(); diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index d39982dc..e569b2f1 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -309,6 +309,8 @@ public: void setModelFacing(CardinalDir value); CardinalDir getModelFacing() { return modelFacing; } + bool isMeetingPointSettable() const; + private: float computeHeight(const Vec2i &pos) const; void updateTarget();