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 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!");

View File

@ -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){

View File

@ -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);
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();
//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);
}
}
}
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());
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);
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) {
//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());
}
}
}

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 {
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);

View File

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

View File

@ -425,7 +425,7 @@ public:
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;}