Skip to content

Commit

Permalink
* Added missing gamecontent/position.h to project file.
Browse files Browse the repository at this point in the history
* Improvements to battle list.
* Now changing visibility of creatures in battle list whenever a creature moves rather than every scene update, and now rebuilding list only when visibility has changed.
  • Loading branch information
Nate Fries committed May 17, 2009
1 parent 3f6ca21 commit c8192da
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 28 deletions.
13 changes: 1 addition & 12 deletions gm_gameworld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,13 +463,6 @@ 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
m_statusStatMsg.paintSelf(0,0,glictGlobals.w-172-4, glictGlobals.h - 150 - 20);
m_statusStatMsg.updateSelf(g_frameDiff / 1000.);
Expand Down Expand Up @@ -1197,11 +1190,7 @@ void GM_Gameworld::onCreatureMove(uint32_t id, const Position& oldPos, const Pos
c->startWalk();
c->confirmWalk();

if(!(Map::getInstance().playerCanSee(newPos.x, newPos.y, newPos.z)))
{
Notifications::onRemoveCreature(id);
Creatures::getInstance().removeCreature(id);
}
sbvlPanel.winBattle.refreshVisibility();
}

void GM_Gameworld::onChangeSkills()
Expand Down
5 changes: 4 additions & 1 deletion net/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,7 @@ bool ProtocolGame::parsePlayerCancelWalk(NetworkMessage& msg)
bool ProtocolGame::parseFloorChangeUp(NetworkMessage& msg)
{
Position& myPos = GlobalVariables::getPlayerPosition();
Position oldPos = myPos;
myPos.z--;
//going to surface
if(myPos.z == 7){
Expand All @@ -1160,11 +1161,13 @@ bool ProtocolGame::parseFloorChangeUp(NetworkMessage& msg)
}
myPos.x++;
myPos.y++;
Notifications::onCreatureMove(GlobalVariables::getPlayerID(), oldPos, myPos);
return true;
}
bool ProtocolGame::parseFloorChangeDown(NetworkMessage& msg)
{
Position& myPos = GlobalVariables::getPlayerPosition();
Position oldPos = myPos;
myPos.z++;
//going from surface to underground
if(myPos.z == 8){
Expand All @@ -1183,7 +1186,7 @@ bool ProtocolGame::parseFloorChangeDown(NetworkMessage& msg)
}
myPos.x--;
myPos.y--;

Notifications::onCreatureMove(GlobalVariables::getPlayerID(), oldPos, myPos);
return true;
}
bool ProtocolGame::parseOutfitWindow(NetworkMessage& msg)
Expand Down
41 changes: 27 additions & 14 deletions ui/battlewindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,25 @@ void winBattle_t::update(uint32_t id)
std::vector<BattleEntry*>::iterator it;
for(it = entries.begin(); it != entries.end(); ++it)
{
if((*it)->creatureId == id)
BattleEntry* e = (*it);
if(e->creatureId == id)
{
int hp = Creatures::getInstance().getCreature(id)->getHealth();
if(hp == 0)
{
list.RemoveObject(&e->pnl);
list.RebuildList();

entries.erase(it);
delete e;
return;
}
oRGBA col = CreatureUI::getHealthColor(hp);
(*it)->pbHealth.SetValue(hp);
e->pbHealth.SetValue(hp);
#if (GLICT_APIREV < 105)
#warning GLICT too old, get 105 or newer for visual improvement on some progressbars
#else
(*it)->pbHealth.SetFGColor(glictColor(col.r/255., col.g/255., col.b/255., col.a/255.));
e->pbHealth.SetFGColor(glictColor(col.r/255., col.g/255., col.b/255., col.a/255.));
#endif
}
}
Expand All @@ -80,43 +90,46 @@ void winBattle_t::remove(uint32_t id)
std::vector<BattleEntry*>::iterator it;
for(it = entries.begin(); it != entries.end(); ++it)
{
if((*it)->creatureId == id)
BattleEntry* e = (*it);
if(e->creatureId == id)
{
delete (*it);
list.RemoveObject(&e->pnl);
list.RebuildList();
entries.erase(it);
delete e;
return;
}
}
}
void winBattle_t::refreshVisibility()
{
std::vector<BattleEntry*>::iterator it;
Position player = GlobalVariables::getPlayerPosition();
bool need_rebuild = false;

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) {
bool visibility = (*it)->pnl.GetVisible();

if (Map::getInstance().playerCanSee(p.x, p.y, p.z) && p.z == player.z && c->getHealth() > 0) {
(*it)->pnl.SetVisible(true);
} else
{
(*it)->pnl.SetVisible(false);
}
if(visibility != (*it)->pnl.GetVisible())
need_rebuild = true;
}
list.RebuildList();

if(need_rebuild)
list.RebuildList();
}

void winBattle_t::paintEntry(glictRect *real, glictRect *clipped, glictContainer *caller)
{
Creature* creature = Creatures::getInstance().getCreature((int)caller->GetCustomData());
int hp = creature->getHealth();
oRGBA col;
if(creature->getID() == GlobalVariables::getAttackID())
col = oRGBA(180, 50, 20, 255);
Expand Down
2 changes: 1 addition & 1 deletion ui/battlewindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class winBattle_t : public yatcStackPanelWindow
void remove(uint32_t id);
void refreshVisibility();

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

static void paintEntry(glictRect *real, glictRect *clipped, glictContainer *caller);
Expand Down
1 change: 1 addition & 0 deletions yatc.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
<Unit filename="gamecontent/map.h" />
<Unit filename="gamecontent/shop.h" />
<Unit filename="gamecontent/thing.h" />
<Unit filename="gamecontent/position.h" />
<Unit filename="gamemode.cpp" />
<Unit filename="gamemode.h" />
<Unit filename="gm_debug.cpp">
Expand Down

0 comments on commit c8192da

Please sign in to comment.