reserve unit place while morphing. (first try)

This commit is contained in:
Titus Tscharntke 2012-09-11 21:16:24 +00:00
parent c2d43c8b86
commit 75032c3287
7 changed files with 83 additions and 3 deletions

View File

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

View File

@ -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<const MorphCommandType*>(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() {

View File

@ -560,6 +560,7 @@ public:
inline Quad2i getVisibleQuadFromCamera() const {return visibleQuadFromCamera;}
void renderTeamColorPlane();
void renderTeamColorCircle();
void renderMorphEffects();
//static
static Shadows strToShadows(const string &s);

View File

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

View File

@ -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<const MorphCommandType*>(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<const MorphCommandType*>(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);

View File

@ -396,7 +396,7 @@ public:
//unit placement
bool aproxCanMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2, std::map<Vec2i, std::map<Vec2i, std::map<int, std::map<int, std::map<Field,bool> > > > > *lookupCache=NULL) const;
bool canMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2,std::map<Vec2i, std::map<Vec2i, std::map<int, std::map<Field,bool> > > > *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;

View File

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