Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature command queue after morph commands #257

Draft
wants to merge 18 commits into
base: develop
Choose a base branch
from
Prev Previous commit
Next Next commit
feat: allow queue after Morph commands
pavanvo committed Sep 5, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 0b1dcc70f5591bfbb715aea251dd9cd84ab35f15
19 changes: 15 additions & 4 deletions source/glest_game/game/commander.cpp
Original file line number Diff line number Diff line change
@@ -263,8 +263,12 @@ std::pair<CommandResult,string> Commander::tryGiveCommand(const Selection *selec
int targetId= targetUnit==NULL? Unit::invalidId: targetUnit->getId();
int unitId= unit->getId();
Vec2i currPos= world->getMap()->computeDestPos(refPos, unit->getPosNotThreadSafe(), pos);
int unitTypeId= -1;
auto mct= unit->getCurrMorphCt();
if(mct) unitTypeId= mct->getMorphUnit()->getId();

NetworkCommand networkCommand(this->world,nctGiveCommand, unitId,
commandType->getId(), currPos, -1, targetId, -1, tryQueue,
commandType->getId(), currPos, unitTypeId, targetId, -1, tryQueue,
cst_None, -1, unitCommandGroupId);

//every unit is ordered to a different position
@@ -316,13 +320,16 @@ std::pair<CommandResult,string> Commander::tryGiveCommand(const Selection *selec
if(commandType != NULL) {
int targetId= targetUnit==NULL? Unit::invalidId: targetUnit->getId();
int unitId= unit->getId();
int unitTypeId= -1;
auto mct= unit->getCurrMorphCt();
if(mct) unitTypeId= mct->getMorphUnit()->getId();

std::pair<CommandResult,string> resultCur(crFailUndefined,"");

bool canSubmitCommand=canSubmitCommandType(unit, commandType);
if(canSubmitCommand == true) {
NetworkCommand networkCommand(this->world,nctGiveCommand,
unitId, commandType->getId(), currPos, -1, targetId,
unitId, commandType->getId(), currPos, unitTypeId, targetId,
-1, tryQueue, cst_None, -1, unitCommandGroupId);
resultCur= pushNetworkCommand(&networkCommand);
}
@@ -950,7 +957,7 @@ Command* Commander::buildCommand(const NetworkCommand* networkCommand) const {
throw megaglest_runtime_error(szBuf);
}

ct = unit->getType()->findCommandTypeById(networkCommand->getCommandTypeId());
ct = unit->getType()->findCommandTypeById(networkCommand->getCommandTypeId());

if(unit->getFaction()->getIndex() != networkCommand->getUnitFactionIndex()) {

@@ -984,7 +991,11 @@ Command* Commander::buildCommand(const NetworkCommand* networkCommand) const {
throw megaglest_runtime_error(sError);
}

const UnitType* unitType= world->findUnitTypeById(unit->getFaction()->getType(), networkCommand->getUnitTypeId());
const UnitType* unitType= world->findUnitTypeById(unit->getFaction()->getType(), networkCommand->getUnitTypeId());

if( networkCommand->getUnitTypeId() > -1 && networkCommand->getWantQueue()) { //Morph Queue
ct = unitType->findCommandTypeById(networkCommand->getCommandTypeId());
}

// debug test!
//throw megaglest_runtime_error("Test missing command type!");
6 changes: 5 additions & 1 deletion source/glest_game/gui/gui.cpp
Original file line number Diff line number Diff line change
@@ -552,7 +552,7 @@ void Gui::giveTwoClickOrders(int x, int y , bool prepared) {
else {
result= commander->tryGiveCommand(&selection, activeCommandClass,
targetPos, targetUnit,queueKeyDown);
}
}
}
else {
//selecting building
@@ -969,6 +969,10 @@ void Gui::computeDisplay(){
//uniform selection
if(u->isBuilt()){
//printf("u->isBuilt()\n");
auto mct = u->getCurrMorphCt();
if(mct && isKeyDown(queueCommandKey)) {//Morph Queue
ut=mct->getMorphUnit();
}

int morphPos= 8;
for(int i= 0; i < ut->getCommandTypeCount(); ++i){
75 changes: 42 additions & 33 deletions source/glest_game/network/network_types.cpp
Original file line number Diff line number Diff line change
@@ -48,43 +48,52 @@ NetworkCommand::NetworkCommand(World *world, int networkCommandType, int unitId,
this->targetId = targetId >= 0 ? targetId : facing;
this->fromFactionIndex = world->getThisFactionIndex();

if(this->networkCommandType == nctGiveCommand) {
const Unit *unit= world->findUnitById(this->unitId);

//validate unit
if(unit != NULL) {
this->unitFactionIndex = unit->getFaction()->getIndex();
this->unitFactionUnitCount = unit->getFaction()->getUnitCount();

//const UnitType *unitType= world->findUnitTypeById(unit->getFaction()->getType(), this->unitTypeId);
const CommandType *ct = unit->getType()->findCommandTypeById(this->commandTypeId);
if(ct != NULL && ct->getClass() == ccBuild) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,toString().c_str());
CardinalDir::assertDirValid(facing);
assert(targetId == -1);
}
}
}

if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] Created NetworkCommand as follows:\n%s\n",__FILE__,__FUNCTION__,__LINE__,toString().c_str());
if(this->networkCommandType == nctGiveCommand) {
const Unit *unit= world->findUnitById(this->unitId);

//validate unit
if(unit != NULL) {
this->unitFactionIndex = unit->getFaction()->getIndex();
this->unitFactionUnitCount = unit->getFaction()->getUnitCount();

const CommandType *ct= unit->getType()->findCommandTypeById(this->commandTypeId);
if(unitTypeId > -1) {
const UnitType *unitType= world->findUnitTypeById(unit->getFaction()->getType(), this->unitTypeId);
ct= unitType->findCommandTypeById(this->commandTypeId);
}

if(ct != NULL && ct->getClass() == ccBuild) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,toString().c_str());
CardinalDir::assertDirValid(facing);
assert(targetId == -1);
}
}
}

if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] Created NetworkCommand as follows:\n%s\n",__FILE__,__FUNCTION__,__LINE__,toString().c_str());
}

void NetworkCommand::preprocessNetworkCommand(World *world) {
if(networkCommandType == nctGiveCommand) {
const Unit *unit= world->findUnitById(unitId);

//validate unit
if(unit != NULL) {
//const UnitType *unitType= world->findUnitTypeById(unit->getFaction()->getType(), unitTypeId);
const CommandType *ct = unit->getType()->findCommandTypeById(commandTypeId);
if(ct != NULL && ct->getClass() == ccBuild && targetId >= 0) {
if(networkCommandType == nctGiveCommand) {
const Unit *unit= world->findUnitById(unitId);

//validate unit
if(unit != NULL) {

const CommandType *ct= unit->getType()->findCommandTypeById(commandTypeId);
if(unitTypeId > -1) {
const UnitType *unitType= world->findUnitTypeById(unit->getFaction()->getType(), unitTypeId);
ct= unitType->findCommandTypeById(this->commandTypeId);
}

if(ct != NULL && ct->getClass() == ccBuild && targetId >= 0) {
CardinalDir::assertDirValid(targetId);
}
}
else {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] (unit == NULL) %s\n",__FILE__,__FUNCTION__,__LINE__,toString().c_str());
}
}
}
}
else {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] (unit == NULL) %s\n",__FILE__,__FUNCTION__,__LINE__,toString().c_str());
}
}
}


12 changes: 12 additions & 0 deletions source/glest_game/type_instances/unit.cpp
Original file line number Diff line number Diff line change
@@ -745,6 +745,15 @@ void Unit::cleanupAllParticlesystems() {

}

const MorphCommandType* Unit::getCurrMorphCt() const {
auto result = std::find_if(commands.rbegin(), commands.rend(),[](Command *i)
{ return i->getCommandType()->getClass() == ccMorph? true: false; });
if(result != commands.rend()) {
return static_cast<const MorphCommandType*>((*result)->getCommandType());
}
else return NULL;
}

ParticleSystem * Unit::getFire() const {
if(this->fire != NULL &&
Renderer::getInstance().validateParticleSystemStillExists(this->fire,rsGame) == false) {
@@ -3826,6 +3835,9 @@ std::pair<CommandResult,string> Unit::checkCommand(Command *command) const {
this->getType()->getFirstRepairCommand(this->getType()) != NULL) {

}
else if(getCurrMorphCt()->getMorphUnit()->hasCommandType(command->getCommandType())) {
// Allow Current Morph Commands
}
else {
//printf("In [%s::%s Line: %d] command = %p\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,command);

1 change: 1 addition & 0 deletions source/glest_game/type_instances/unit.h
Original file line number Diff line number Diff line change
@@ -653,6 +653,7 @@ class Unit : public BaseColorPickEntity, ValueCheckerVault, public ParticleOwner
}
return NULL;
}
const MorphCommandType* getCurrMorphCt() const;
void replaceCurrCommand(Command *cmd);
int getCountOfProducedUnitsPreExistence(const UnitType *ut) const;
unsigned int getCommandSize() const;
2 changes: 1 addition & 1 deletion source/glest_game/types/command_type.h
Original file line number Diff line number Diff line change
@@ -425,7 +425,7 @@ class MorphCommandType: public CommandType {
virtual string toString(bool translatedValue) const;
virtual string getReqDesc(bool translatedValue) const;
virtual const ProducibleType *getProduced() const;
Queueability isQueuable() const {return qOnlyLast;} //After morph anything can happen
Queueability isQueuable() const {return qAlways;} //After morph anything can happen

//get
const MorphSkillType *getMorphSkillType() const {return morphSkillType;}