feat: allow queue after Morph commands

This commit is contained in:
pavanvo 2022-08-27 15:16:25 +04:00
parent 35ff02052c
commit 0b1dcc70f5
No known key found for this signature in database
GPG Key ID: 34C1C36681B4AD84
6 changed files with 72 additions and 35 deletions

View File

@ -263,8 +263,12 @@ std::pair<CommandResult,string> Commander::tryGiveCommand(const Selection *selec
int targetId= targetUnit==NULL? Unit::invalidId: targetUnit->getId(); int targetId= targetUnit==NULL? Unit::invalidId: targetUnit->getId();
int unitId= unit->getId(); int unitId= unit->getId();
Vec2i currPos= world->getMap()->computeDestPos(refPos, unit->getPosNotThreadSafe(), pos); 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, NetworkCommand networkCommand(this->world,nctGiveCommand, unitId,
commandType->getId(), currPos, -1, targetId, -1, tryQueue, commandType->getId(), currPos, unitTypeId, targetId, -1, tryQueue,
cst_None, -1, unitCommandGroupId); cst_None, -1, unitCommandGroupId);
//every unit is ordered to a different position //every unit is ordered to a different position
@ -316,13 +320,16 @@ std::pair<CommandResult,string> Commander::tryGiveCommand(const Selection *selec
if(commandType != NULL) { if(commandType != NULL) {
int targetId= targetUnit==NULL? Unit::invalidId: targetUnit->getId(); int targetId= targetUnit==NULL? Unit::invalidId: targetUnit->getId();
int unitId= unit->getId(); int unitId= unit->getId();
int unitTypeId= -1;
auto mct= unit->getCurrMorphCt();
if(mct) unitTypeId= mct->getMorphUnit()->getId();
std::pair<CommandResult,string> resultCur(crFailUndefined,""); std::pair<CommandResult,string> resultCur(crFailUndefined,"");
bool canSubmitCommand=canSubmitCommandType(unit, commandType); bool canSubmitCommand=canSubmitCommandType(unit, commandType);
if(canSubmitCommand == true) { if(canSubmitCommand == true) {
NetworkCommand networkCommand(this->world,nctGiveCommand, NetworkCommand networkCommand(this->world,nctGiveCommand,
unitId, commandType->getId(), currPos, -1, targetId, unitId, commandType->getId(), currPos, unitTypeId, targetId,
-1, tryQueue, cst_None, -1, unitCommandGroupId); -1, tryQueue, cst_None, -1, unitCommandGroupId);
resultCur= pushNetworkCommand(&networkCommand); resultCur= pushNetworkCommand(&networkCommand);
} }
@ -950,7 +957,7 @@ Command* Commander::buildCommand(const NetworkCommand* networkCommand) const {
throw megaglest_runtime_error(szBuf); throw megaglest_runtime_error(szBuf);
} }
ct = unit->getType()->findCommandTypeById(networkCommand->getCommandTypeId()); ct = unit->getType()->findCommandTypeById(networkCommand->getCommandTypeId());
if(unit->getFaction()->getIndex() != networkCommand->getUnitFactionIndex()) { if(unit->getFaction()->getIndex() != networkCommand->getUnitFactionIndex()) {
@ -984,7 +991,11 @@ Command* Commander::buildCommand(const NetworkCommand* networkCommand) const {
throw megaglest_runtime_error(sError); 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! // debug test!
//throw megaglest_runtime_error("Test missing command type!"); //throw megaglest_runtime_error("Test missing command type!");

View File

@ -552,7 +552,7 @@ void Gui::giveTwoClickOrders(int x, int y , bool prepared) {
else { else {
result= commander->tryGiveCommand(&selection, activeCommandClass, result= commander->tryGiveCommand(&selection, activeCommandClass,
targetPos, targetUnit,queueKeyDown); targetPos, targetUnit,queueKeyDown);
} }
} }
else { else {
//selecting building //selecting building
@ -969,6 +969,10 @@ void Gui::computeDisplay(){
//uniform selection //uniform selection
if(u->isBuilt()){ if(u->isBuilt()){
//printf("u->isBuilt()\n"); //printf("u->isBuilt()\n");
auto mct = u->getCurrMorphCt();
if(mct && isKeyDown(queueCommandKey)) {//Morph Queue
ut=mct->getMorphUnit();
}
int morphPos= 8; int morphPos= 8;
for(int i= 0; i < ut->getCommandTypeCount(); ++i){ for(int i= 0; i < ut->getCommandTypeCount(); ++i){

View File

@ -48,43 +48,52 @@ NetworkCommand::NetworkCommand(World *world, int networkCommandType, int unitId,
this->targetId = targetId >= 0 ? targetId : facing; this->targetId = targetId >= 0 ? targetId : facing;
this->fromFactionIndex = world->getThisFactionIndex(); this->fromFactionIndex = world->getThisFactionIndex();
if(this->networkCommandType == nctGiveCommand) { if(this->networkCommandType == nctGiveCommand) {
const Unit *unit= world->findUnitById(this->unitId); const Unit *unit= world->findUnitById(this->unitId);
//validate unit //validate unit
if(unit != NULL) { if(unit != NULL) {
this->unitFactionIndex = unit->getFaction()->getIndex(); this->unitFactionIndex = unit->getFaction()->getIndex();
this->unitFactionUnitCount = unit->getFaction()->getUnitCount(); this->unitFactionUnitCount = unit->getFaction()->getUnitCount();
//const UnitType *unitType= world->findUnitTypeById(unit->getFaction()->getType(), this->unitTypeId); const CommandType *ct= unit->getType()->findCommandTypeById(this->commandTypeId);
const CommandType *ct = unit->getType()->findCommandTypeById(this->commandTypeId); if(unitTypeId > -1) {
if(ct != NULL && ct->getClass() == ccBuild) { const UnitType *unitType= world->findUnitTypeById(unit->getFaction()->getType(), this->unitTypeId);
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,toString().c_str()); ct= unitType->findCommandTypeById(this->commandTypeId);
CardinalDir::assertDirValid(facing); }
assert(targetId == -1);
} 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(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) { void NetworkCommand::preprocessNetworkCommand(World *world) {
if(networkCommandType == nctGiveCommand) { if(networkCommandType == nctGiveCommand) {
const Unit *unit= world->findUnitById(unitId); const Unit *unit= world->findUnitById(unitId);
//validate unit //validate unit
if(unit != NULL) { if(unit != NULL) {
//const UnitType *unitType= world->findUnitTypeById(unit->getFaction()->getType(), unitTypeId);
const CommandType *ct = unit->getType()->findCommandTypeById(commandTypeId); const CommandType *ct= unit->getType()->findCommandTypeById(commandTypeId);
if(ct != NULL && ct->getClass() == ccBuild && targetId >= 0) { 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); CardinalDir::assertDirValid(targetId);
} }
} }
else { 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()); 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());
} }
} }
} }

View File

@ -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 { ParticleSystem * Unit::getFire() const {
if(this->fire != NULL && if(this->fire != NULL &&
Renderer::getInstance().validateParticleSystemStillExists(this->fire,rsGame) == false) { 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) { this->getType()->getFirstRepairCommand(this->getType()) != NULL) {
} }
else if(getCurrMorphCt()->getMorphUnit()->hasCommandType(command->getCommandType())) {
// Allow Current Morph Commands
}
else { else {
//printf("In [%s::%s Line: %d] command = %p\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,command); //printf("In [%s::%s Line: %d] command = %p\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,command);

View File

@ -653,6 +653,7 @@ public:
} }
return NULL; return NULL;
} }
const MorphCommandType* getCurrMorphCt() const;
void replaceCurrCommand(Command *cmd); void replaceCurrCommand(Command *cmd);
int getCountOfProducedUnitsPreExistence(const UnitType *ut) const; int getCountOfProducedUnitsPreExistence(const UnitType *ut) const;
unsigned int getCommandSize() const; unsigned int getCommandSize() const;

View File

@ -425,7 +425,7 @@ public:
virtual string toString(bool translatedValue) const; virtual string toString(bool translatedValue) const;
virtual string getReqDesc(bool translatedValue) const; virtual string getReqDesc(bool translatedValue) const;
virtual const ProducibleType *getProduced() 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 //get
const MorphSkillType *getMorphSkillType() const {return morphSkillType;} const MorphSkillType *getMorphSkillType() const {return morphSkillType;}