From 75032c328762c73119ceb5339be59599c0300211 Mon Sep 17 00:00:00 2001 From: Titus Tscharntke Date: Tue, 11 Sep 2012 21:16:24 +0000 Subject: [PATCH] reserve unit place while morphing. (first try) --- source/glest_game/game/game.cpp | 7 ++++ source/glest_game/graphics/renderer.cpp | 41 +++++++++++++++++++++++ source/glest_game/graphics/renderer.h | 1 + source/glest_game/type_instances/unit.cpp | 7 +++- source/glest_game/world/map.cpp | 25 +++++++++++++- source/glest_game/world/map.h | 2 +- source/glest_game/world/unit_updater.cpp | 3 ++ 7 files changed, 83 insertions(+), 3 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index bba0d6ad..08130e2a 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -3382,6 +3382,13 @@ void Game::render3d(){ if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderObjects]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); } + + // renderTeamColorCircle + renderer.renderMorphEffects(); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderObjects]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); + + //units renderer.renderUnits(avgRenderFps); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderUnits]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 9923a10b..f1a020a4 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -5062,6 +5062,47 @@ void Renderer::renderTeamColorEffect(Vec3f &v, int heigth, int size, Vec3f color } +void Renderer::renderMorphEffects(){ + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) { + return; + } + + VisibleQuadContainerCache &qCache = getQuadCache(); + if(qCache.visibleQuadUnitList.empty() == false) { + bool initialized=false; + for(int visibleUnitIndex = 0; + visibleUnitIndex < qCache.visibleQuadUnitList.size(); ++visibleUnitIndex) { + Unit *unit = qCache.visibleQuadUnitList[visibleUnitIndex]; + if(unit->getCurrSkill() != NULL && unit->getCurrSkill()->getClass() == scMorph) { + Command *command= unit->getCurrCommand(); + if(command != NULL && command->getCommandType()->commandTypeClass == ccMorph){ + const MorphCommandType *mct= static_cast(command->getCommandType()); + const UnitType* mType=mct->getMorphUnit(); + + if(!initialized){ + glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT); + glDisable(GL_LIGHTING); + glDisable(GL_TEXTURE_2D); + glDepthFunc(GL_ALWAYS); + glDisable(GL_STENCIL_TEST); + glDisable(GL_CULL_FACE); + glEnable(GL_BLEND); + glLineWidth(2.f); + initialized=true; + } + + Vec3f currVec= unit->getCurrVectorFlat(); + glColor4f(0.2f, 0.2f, 0.2f, 0.4f); + renderSelectionCircle(currVec, mType->getSize(), 0.8f, 0.55f); + } + } + } + if(initialized) { + glPopAttrib(); + } + } +} + void Renderer::renderSelectionEffects() { diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index 11b61dfe..2baf7e7a 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -560,6 +560,7 @@ public: inline Quad2i getVisibleQuadFromCamera() const {return visibleQuadFromCamera;} void renderTeamColorPlane(); void renderTeamColorCircle(); + void renderMorphEffects(); //static static Shadows strToShadows(const string &s); diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index cbfd1363..bf66b5d3 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -1012,7 +1012,6 @@ void Unit::setCurrSkill(const SkillType *currSkill) { this->animationRandomCycleCount = 0; } this->currSkill= currSkill; - } void Unit::setCurrSkill(SkillClass sc) { @@ -2951,6 +2950,12 @@ CommandResult Unit::undoCommand(Command *command){ throw megaglest_runtime_error(szBuf); } + if(this->currSkill->getClass() == scMorph){ + // clear cells of morphed unit and set those of current unit! + map->clearUnitCells(this, this->getPos()); + map->putUnitCells(this, this->getPos(),true); + } + //return cost const ProducibleType *produced= command->getCommandType()->getProduced(); if(produced!=NULL){ diff --git a/source/glest_game/world/map.cpp b/source/glest_game/world/map.cpp index 4242a035..394997d4 100644 --- a/source/glest_game/world/map.cpp +++ b/source/glest_game/world/map.cpp @@ -1361,7 +1361,7 @@ bool Map::isInUnitTypeCells(const UnitType *ut, const Vec2i &pos, } //put a units into the cells -void Map::putUnitCells(Unit *unit, const Vec2i &pos) { +void Map::putUnitCells(Unit *unit, const Vec2i &pos, bool ignoreSkill) { assert(unit != NULL); if(unit == NULL) { throw megaglest_runtime_error("ut == NULL"); @@ -1370,6 +1370,19 @@ void Map::putUnitCells(Unit *unit, const Vec2i &pos) { bool canPutInCell = true; const UnitType *ut= unit->getType(); + // block space for morphing units + if(ignoreSkill==false && + unit->getCurrSkill() != NULL && + unit->getCurrSkill()->getClass() == scMorph) { + Command *command= unit->getCurrCommand(); + if(command != NULL && command->getCommandType()->commandTypeClass == ccMorph){ + const MorphCommandType *mct= static_cast(command->getCommandType()); + if(unit->getType()->getSize()<=mct->getMorphUnit()->getSize()){ + ut=mct->getMorphUnit(); + } + } + } + for(int i = 0; i < ut->getSize(); ++i) { for(int j = 0; j < ut->getSize(); ++j) { Vec2i currPos= pos + Vec2i(i, j); @@ -1439,6 +1452,16 @@ void Map::clearUnitCells(Unit *unit, const Vec2i &pos) { const UnitType *ut= unit->getType(); + if(unit->getCurrSkill() != NULL && + unit->getCurrSkill()->getClass() == scMorph) { + Command *command= unit->getCurrCommand(); + const MorphCommandType *mct= static_cast(command->getCommandType()); + if(unit->getType()->getSize()<=mct->getMorphUnit()->getSize()){ + ut=mct->getMorphUnit(); + } + } + + for(int i=0; igetSize(); ++i){ for(int j=0; jgetSize(); ++j){ Vec2i currPos= pos + Vec2i(i, j); diff --git a/source/glest_game/world/map.h b/source/glest_game/world/map.h index bf337b5c..cbb338ca 100644 --- a/source/glest_game/world/map.h +++ b/source/glest_game/world/map.h @@ -396,7 +396,7 @@ public: //unit placement bool aproxCanMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2, std::map > > > > *lookupCache=NULL) const; bool canMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2,std::map > > > *lookupCache=NULL) const; - void putUnitCells(Unit *unit, const Vec2i &pos); + void putUnitCells(Unit *unit, const Vec2i &pos,bool ignoreSkill = false); void clearUnitCells(Unit *unit, const Vec2i &pos); Vec2i computeRefPos(const Selection *selection) const; diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index b09f602e..4109fb09 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -1900,6 +1900,9 @@ void UnitUpdater::updateMorph(Unit *unit, int frameIndex) { //if not morphing, check space if(map->isFreeCellsOrHasUnit(unit->getPos(), mct->getMorphUnit()->getSize(), mct->getMorphUnit()->getField(), unit, mct->getMorphUnit())){ unit->setCurrSkill(mct->getMorphSkillType()); + // block space for morphing units ( block space before and after morph ! ) + map->putUnitCells(unit, unit->getPos()); + map->putUnitCells(unit, unit->getPos(), true); } else{ if(unit->getFactionIndex()==world->getThisFactionIndex()){