Skip to content

Commit

Permalink
* position for creature is now obtainable from Creature class
Browse files Browse the repository at this point in the history
* creatures that are offscreen are now hidden from battle window
  • Loading branch information
ivucica committed May 17, 2009
1 parent d29511d commit 3f6ca21
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 3 deletions.
3 changes: 2 additions & 1 deletion gamecontent/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ void Creature::setSquare(uint32_t color)
m_squareStartTime = g_frameTime;
}

void Creature::setMoving(const Position& oldPos)
void Creature::setMoving(const Position& oldPos, const Position& newPos)
{
m_moveStartTime = g_frameTime;
m_moveOldPos = oldPos;
m_currentPos = newPos;
}

//*********** Creatures *************
Expand Down
6 changes: 5 additions & 1 deletion gamecontent/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Creature : public CreatureUI, public Thing
uint32_t getSquareColor() const { return m_squareColor;}
uint32_t getSquareStart() const { return m_squareStartTime;}

void setMoving(const Position& oldPos);
void setMoving(const Position& oldPos, const Position& newPos);

void setId(uint32_t id){ m_id = id;}
uint32_t getId() const { return m_id;}
Expand Down Expand Up @@ -85,6 +85,8 @@ class Creature : public CreatureUI, public Thing
void setShield(uint32_t shield) { m_shield = shield;}
uint32_t getShield() const { return m_shield;}

const Position& getCurrentPos() const { return m_currentPos; }
void setCurrentPos(const Position& pos) { m_currentPos = pos; }

void resetSelf() { CreatureUI::resetSelf(); m_id = 0; }
protected:
Expand All @@ -109,6 +111,8 @@ class Creature : public CreatureUI, public Thing

uint32_t m_moveStartTime;
Position m_moveOldPos;

Position m_currentPos;

friend class Creatures;
};
Expand Down
5 changes: 5 additions & 0 deletions gamecontent/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ bool Tile::addThing(Thing *thing, bool pushThing/* = false*/)
}

m_objects.insert(it, thing);

Creature *c = thing->getCreature();
if(c){
c->setCurrentPos(this->getPos());
}
return true;
}

Expand Down
4 changes: 4 additions & 0 deletions gm_gameworld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@ void GM_Gameworld::updateScene()
}


// update battle window
// FIXME (ivucica#1#): someone should move refreshVisibility() into some notifications asap.
#warning EXTREMELY EXTREMELY bad idea to update this every frame. It works but RebuildList()ing so often is bound to be very slow due to abudance of SetPos() calls inside GLICT (ivucica)
sbvlPanel.winBattle.refreshVisibility();


// status messages
Expand Down
2 changes: 1 addition & 1 deletion net/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ bool ProtocolGame::parseCreatureMove(NetworkMessage& msg)

Notifications::onCreatureMove(creature->getId(),oldPos,newPos);

creature->setMoving(oldPos);
creature->setMoving(oldPos, newPos);

//update creature direction
if(oldPos.x > newPos.x){
Expand Down
25 changes: 25 additions & 0 deletions ui/battlewindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,31 @@ void winBattle_t::remove(uint32_t id)
}
}
}
void winBattle_t::refreshVisibility()
{
std::vector<BattleEntry*>::iterator it;
Position player = GlobalVariables::getPlayerPosition();

for(it = entries.begin(); it != entries.end(); ++it)
{
Creature *c = Creatures::getInstance().getCreature((*it)->creatureId);
if (!c) continue;
Position p = c->getCurrentPos();

// FIXME (ivucica#5#): we should somehow query MapUI if the other creature is in visible area... concluding it ourselves is not a good way of handling stuff
if (abs(int(p.x - player.x)) < 9 &&
abs(int(p.y - player.y)) < 7 &&
p.z == player.z &&
c->getHealth() > 0) {
(*it)->pnl.SetVisible(true);
} else
{
(*it)->pnl.SetVisible(false);
}
}
list.RebuildList();

}

void winBattle_t::paintEntry(glictRect *real, glictRect *clipped, glictContainer *caller)
{
Expand Down
1 change: 1 addition & 0 deletions ui/battlewindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class winBattle_t : public yatcStackPanelWindow
void add(uint32_t id);
void update(uint32_t id);
void remove(uint32_t id);
void refreshVisibility();

virtual float GetDefaultHeight(){ return 40.F; }
virtual void OnClose();
Expand Down

0 comments on commit 3f6ca21

Please sign in to comment.