Fix css style order when using external css files
[ryzomcore.git] / ryzom / client / src / interface_v3 / bar_manager.cpp
blobec521955b2b70301d0cc9ae7f502f5c77ad79744
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "stdpch.h"
22 #include "bar_manager.h"
23 #include "interface_manager.h"
24 #include "nel/gui/interface_expr.h"
25 #include "../time_client.h"
28 using namespace std;
29 using namespace NLMISC;
32 // ***************************************************************************
33 // LOG, for debug
34 #define ALLOW_BAR_LOG 0
36 // don't change this (ensure no bug in final version)
37 #if FINAL_VERSION
38 #undef ALLOW_BAR_LOG
39 #define ALLOW_BAR_LOG 0
40 #endif
41 #if ALLOW_BAR_LOG
42 # define barInfoLog nlinfo
43 #else // NL_RELEASE
44 # ifdef NL_COMP_VC71
45 # define barInfoLog __noop
46 # else
47 # define barInfoLog 0&&
48 # endif
49 #endif // NL_RELEASE
52 static const char *entryTypeToStr(CBarManager::TEntryType et)
54 switch(et)
56 case CBarManager::EntityType: return "Entity"; break;
57 case CBarManager::TeamMemberType: return "TeamMember"; break;
58 case CBarManager::AnimalType: return "Animal"; break;
59 case CBarManager::TargetType: return "Target"; break;
60 default: return "Unknown (Error!!)"; break;
65 // ***************************************************************************
66 CBarManager *CBarManager::_Instance= NULL;
69 // ***************************************************************************
70 // ***************************************************************************
71 // ***************************************************************************
72 // ***************************************************************************
75 // ***************************************************************************
76 CBarManager::CBarDataEntry::CBarDataEntry()
78 clear();
79 resetDB();
82 // ***************************************************************************
83 void CBarManager::CBarDataEntry::clear()
85 DataSetId= CLFECOMMON::INVALID_CLIENT_DATASET_INDEX;
86 BarInfo.reset();
89 // ***************************************************************************
90 void CBarManager::CBarDataEntry::resetDB()
92 UIDIn= NULL;
93 PresentIn= NULL;
94 for(uint sc=0;sc<SCORES::NUM_SCORES;sc++)
96 ScoreIn[sc]= NULL;
97 ScoreOut[sc]= NULL;
101 // ***************************************************************************
102 void CBarManager::CBarDataEntry::connectDB(const std::string &baseDBin, const std::string &baseDBout, const std::string &presentDB,
103 const std::string &hpDB, const std::string &sapDB, const std::string &staDB, const std::string &focusDB)
105 CInterfaceManager *pIM= CInterfaceManager::getInstance();
107 // can only manage 4 scores here
108 nlctassert(SCORES::NUM_SCORES==4);
110 // try to connect each input entry (don't create)
111 if(!baseDBin.empty())
113 UIDIn= NLGUI::CDBManager::getInstance()->getDbProp(baseDBin+"UID", false);
114 if(!presentDB.empty())
115 PresentIn= NLGUI::CDBManager::getInstance()->getDbProp(baseDBin+presentDB, false);
116 if(!hpDB.empty())
117 ScoreIn[SCORES::hit_points]= NLGUI::CDBManager::getInstance()->getDbProp(baseDBin+hpDB, false);
118 if(!sapDB.empty())
119 ScoreIn[SCORES::sap]= NLGUI::CDBManager::getInstance()->getDbProp(baseDBin+sapDB, false);
120 if(!staDB.empty())
121 ScoreIn[SCORES::stamina]= NLGUI::CDBManager::getInstance()->getDbProp(baseDBin+staDB, false);
122 if(!focusDB.empty())
123 ScoreIn[SCORES::focus]= NLGUI::CDBManager::getInstance()->getDbProp(baseDBin+focusDB, false);
126 // try to connect each output entry (don't create)
127 if(!baseDBout.empty())
129 if(!hpDB.empty())
130 ScoreOut[SCORES::hit_points]= NLGUI::CDBManager::getInstance()->getDbProp(baseDBout+hpDB, false);
131 if(!sapDB.empty())
132 ScoreOut[SCORES::sap]= NLGUI::CDBManager::getInstance()->getDbProp(baseDBout+sapDB, false);
133 if(!staDB.empty())
134 ScoreOut[SCORES::stamina]= NLGUI::CDBManager::getInstance()->getDbProp(baseDBout+staDB, false);
135 if(!focusDB.empty())
136 ScoreOut[SCORES::focus]= NLGUI::CDBManager::getInstance()->getDbProp(baseDBout+focusDB, false);
140 // ***************************************************************************
141 void CBarManager::CBarDataEntry::flushDBOut()
143 for(uint sc=0;sc<SCORES::NUM_SCORES;sc++)
145 if(ScoreOut[sc])
146 ScoreOut[sc]->setValue8(BarInfo.Score[sc]);
150 // ***************************************************************************
151 void CBarManager::CBarDataEntry::modifyFromDBIn(CBarInfo &barInfo) const
153 for(uint sc=0;sc<SCORES::NUM_SCORES;sc++)
155 if(ScoreIn[sc])
156 barInfo.Score[sc]= ScoreIn[sc]->getValue8();
161 // ***************************************************************************
162 // ***************************************************************************
163 // ***************************************************************************
164 // ***************************************************************************
167 // ***************************************************************************
168 CBarManager::CBarManager()
170 // if more than 256 entities, must change MaxEntity
171 nlctassert(sizeof(CLFECOMMON::TCLEntityId)==1);
173 // Allocate the array now
174 nlctassert(MaxEntryType==4);
175 _EntryBars[EntityType].resize(MaxEntity);
176 _EntryBars[TeamMemberType].resize(MaxTeamMember);
177 _EntryBars[AnimalType].resize(MaxAnimal);
178 _EntryBars[TargetType].resize(MaxTarget);
180 // no msg still sent
181 _LastUserBarMsgNumber= 0;
184 // ***************************************************************************
185 void CBarManager::releaseInstance()
187 if( _Instance )
189 delete _Instance;
190 _Instance = NULL;
194 // ***************************************************************************
195 void CBarManager::initInGame()
197 CInterfaceManager *pIM= CInterfaceManager::getInstance();
199 //resetShardSpecificData(); // directly called by CFarTP::disconnectFromPreviousShard()
201 /* *** Verify that MaxTeamMember is correct according to database
202 change MaxTeamMember if no more the case
204 uint i=0;
205 while( NLGUI::CDBManager::getInstance()->getDbProp(toString("SERVER:GROUP:%d:NAME", i), false) )
206 i++;
207 nlassert(i==MaxTeamMember);
209 // *** create connection to the Local Output database
210 for(i=0;i<_EntryBars[TeamMemberType].size();i++)
212 // don't connect FOCUS, since not setuped by SERVER
213 _EntryBars[TeamMemberType][i].connectDB(
214 toString("SERVER:GROUP:%d:",i),
215 toString("UI:VARIABLES:BARS:TEAM:%d:",i),
216 "PRESENT",
217 "HP", "SAP", "STA", "");
220 for(i=0;i<_EntryBars[AnimalType].size();i++)
222 // don't connect STA, SAP and FOCUS for animal, since they don't have
223 _EntryBars[AnimalType][i].connectDB(
224 toString("SERVER:PACK_ANIMAL:BEAST%d:",i),
225 toString("UI:VARIABLES:BARS:ANIMAL:%d:",i),
226 "STATUS",
227 "HP", "", "", "");
230 nlassert(_EntryBars[TargetType].size()==1);
231 _EntryBars[TargetType][0].connectDB(
232 "SERVER:TARGET:BARS:",
233 "UI:VARIABLES:BARS:TARGET:",
234 "", // no present flag for target (not so important)
235 "HP", "SAP", "STA", "FOCUS");
237 // NB: don't connect the DB for entities, since CEntityCL read it directly from getBarsByEntityId() (simpler and faster)
240 // *** init _EntryScoreFlags
241 nlctassert(MaxEntryType==4);
242 nlctassert(SCORES::NUM_SCORES==4);
243 // For each entry type, tells what score they can affect (see DB connection above)
244 _EntryScoreFlags[EntityType]= HpFlag | SapFlag | StaFlag | FocusFlag; // all
245 _EntryScoreFlags[TeamMemberType]= HpFlag | SapFlag | StaFlag; // anything but focus
246 _EntryScoreFlags[AnimalType]= HpFlag; // Hp only
247 _EntryScoreFlags[TargetType]= HpFlag | SapFlag | StaFlag | FocusFlag; // all
250 // *** create connection for User Bar mgt
251 // user now can only manage 4 scores
252 nlctassert(SCORES::NUM_SCORES==4);
253 // Input max values
254 _UserScores[SCORES::hit_points].DBInMax= NLGUI::CDBManager::getInstance()->getDbProp("SERVER:CHARACTER_INFO:SCORES0:Max", false);
255 _UserScores[SCORES::sap].DBInMax= NLGUI::CDBManager::getInstance()->getDbProp("SERVER:CHARACTER_INFO:SCORES2:Max", false);
256 _UserScores[SCORES::stamina].DBInMax= NLGUI::CDBManager::getInstance()->getDbProp("SERVER:CHARACTER_INFO:SCORES1:Max", false);
257 _UserScores[SCORES::focus].DBInMax= NLGUI::CDBManager::getInstance()->getDbProp("SERVER:CHARACTER_INFO:SCORES3:Max", false);
258 // Output real values
259 _UserScores[SCORES::hit_points].DBOutVal= NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:USER:HP", false);
260 _UserScores[SCORES::sap].DBOutVal= NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:USER:SAP", false);
261 _UserScores[SCORES::stamina].DBOutVal= NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:USER:STA", false);
262 _UserScores[SCORES::focus].DBOutVal= NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:USER:FOCUS", false);
263 // Output ratio values
264 _UserScores[SCORES::hit_points].DBOutRatio= NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:USER:HP_RATIO", false);
265 _UserScores[SCORES::sap].DBOutRatio= NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:USER:SAP_RATIO", false);
266 _UserScores[SCORES::stamina].DBOutRatio= NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:USER:STA_RATIO", false);
267 _UserScores[SCORES::focus].DBOutRatio= NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:USER:FOCUS_RATIO", false);
270 // ***************************************************************************
271 void CBarManager::releaseInGame()
273 // Reset all, and also the DB out
274 for(uint type=0;type<MaxEntryType;type++)
276 for(uint i=0;i<_EntryBars[type].size();i++)
278 _EntryBars[type][i].clear();
279 _EntryBars[type][i].resetDB();
283 // Reset the map
284 _UIDBars.clear();
287 // ***************************************************************************
288 void CBarManager::resetShardSpecificData()
290 // Reset update counter to update properly when reselecting character
291 _LastUserBarMsgNumber = 0;
294 // ***************************************************************************
295 void CBarManager::addEntry(TEntryType type, uint entryId, uint dataSetId)
297 std::vector<CBarDataEntry> &entryArray= _EntryBars[type];
298 nlassert(entryId<entryArray.size());
300 barInfoLog("BARS: addEntry(%s, eid=%d, dsid=%x)", entryTypeToStr(type), entryId, dataSetId);
302 // if bad id, quit
303 if(dataSetId==CLFECOMMON::INVALID_CLIENT_DATASET_INDEX)
304 return;
305 // if already registered, quit
306 if(entryArray[entryId].DataSetId==dataSetId)
307 return;
309 // remove the preceding entry, reseting values if necessary
310 delEntry(type, entryId);
312 // Add me to list of entries
313 CBarDataEntry &bde= entryArray[entryId];
314 bde.DataSetId= dataSetId;
315 // Add the entry connection to map by DataSetId
316 CBarDataUID &barUID= _UIDBars[dataSetId];
317 barUID.EntryId[type].insert(entryId);
319 // Special case: if the entry added is the user (slot 0), then force the correct bars info
320 // This is important because the UserEntity can be created AFTER the receive of USER:BARS message.
321 if(dataSetId==_EntryBars[EntityType][0].DataSetId)
323 barUID.BarInfo= _UserBarInfo;
326 // Copy the current Bar Info from the map by dataSetId in case it exists before...
327 // Eg: an entity comes in vision (EntityType entry) while precedingly available in TeamMemberType Entry
328 bde.BarInfo= barUID.BarInfo;
329 // then report to DB (if any)
330 bde.flushDBOut();
333 // ***************************************************************************
334 void CBarManager::delEntry(TEntryType type, uint entryId)
336 std::vector<CBarDataEntry> &entryArray= _EntryBars[type];
337 nlassert(entryId<entryArray.size());
339 barInfoLog("BARS: delEntry(%s, eid=%d)", entryTypeToStr(type), entryId);
341 // if a DataSetId was registered before
342 uint dataSetId= entryArray[entryId].DataSetId;
343 if(dataSetId!=CLFECOMMON::INVALID_CLIENT_DATASET_INDEX)
345 // then unconnect this from the map by UID
346 _UIDBars[dataSetId].EntryId[type].erase(entryId);
347 // if no more connection are made to this UID
348 if(_UIDBars[dataSetId].noMoreEntry())
350 // erase it
351 _UIDBars.erase(dataSetId);
355 // clear entry
356 entryArray[entryId].clear();
357 // flush the clear to the DB if any
358 entryArray[entryId].flushDBOut();
361 // ***************************************************************************
362 void CBarManager::addEntity(CLFECOMMON::TCLEntityId entityId, uint dataSetId)
364 addEntry(EntityType, entityId, dataSetId);
367 // ***************************************************************************
368 void CBarManager::delEntity(CLFECOMMON::TCLEntityId entityId)
370 delEntry(EntityType, entityId);
373 // ***************************************************************************
374 void CBarManager::addTeamMember(uint teamMemberId, uint dataSetId)
376 addEntry(TeamMemberType, teamMemberId, dataSetId);
379 // ***************************************************************************
380 void CBarManager::delTeamMember(uint teamMemberId)
382 delEntry(TeamMemberType, teamMemberId);
385 // ***************************************************************************
386 void CBarManager::addAnimal(uint paId, uint dataSetId)
388 addEntry(AnimalType, paId, dataSetId);
391 // ***************************************************************************
392 void CBarManager::delAnimal(uint paId)
394 delEntry(AnimalType, paId);
397 // ***************************************************************************
398 void CBarManager::addTarget(uint dataSetId)
400 addEntry(TargetType, 0, dataSetId);
403 // ***************************************************************************
404 void CBarManager::delTarget()
406 delEntry(TargetType, 0);
409 // ***************************************************************************
410 void CBarManager::updateBars(uint dataSetId, CBarInfo barInfo, TGameCycle serverTick, uint scoreFlags)
412 // if dataSetId not registered, quit
413 TUIDToDatas::iterator it= _UIDBars.find(dataSetId);
414 if(it==_UIDBars.end())
415 return;
417 barInfoLog("BARS: updateBars(dsid=%x, biHP=%d, t=%d, sf=%x", dataSetId, barInfo.Score[SCORES::hit_points], serverTick, scoreFlags);
419 // special Case: if the info is for the User (slot 0)
420 if(dataSetId==_EntryBars[EntityType][0].DataSetId)
422 /* Then override the bar info with the one received by USER:BARS message (always take this one)
423 For instance user bars can be received from VP or from TARGET database (if he targets himself)
424 But always consider the message USER:BARS as the most accurate one
426 barInfo= _UserBarInfo;
429 // fill bar info, with relevant values only
430 CBarDataUID &barUid= it->second;
431 for(uint sc=0;sc<SCORES::NUM_SCORES;sc++)
433 // if the update affect this score, and if the modification date is more recent (or at least the same)
434 if( (scoreFlags&(1<<sc)) && serverTick>=barUid.ScoreDate[sc] )
436 // then change this score with the more recent one!
437 barUid.ScoreDate[sc]= serverTick;
438 barUid.BarInfo.Score[sc]= barInfo.Score[sc];
442 // and report result to all connected entries
443 for(uint type=0;type<MaxEntryType;type++)
445 // For any connected entries of this type (see EntryId definitio why a set is necessary)
446 std::set<uint>::iterator itEid= barUid.EntryId[type].begin();
447 std::set<uint>::iterator itEidEnd= barUid.EntryId[type].end();
448 for(;itEid!=itEidEnd;itEid++)
450 uint entryId= *itEid;
451 nlassert(entryId<_EntryBars[type].size());
452 CBarDataEntry &bde= _EntryBars[type][entryId];
453 // copy the bar info (with relevant values)
454 bde.BarInfo= barUid.BarInfo;
455 // and flush DB (if any)
456 bde.flushDBOut();
461 // ***************************************************************************
462 void CBarManager::updateEntryFromDBNoAddDel(TEntryType type, CBarDataEntry &bde)
464 // get the Bar Info, from the input DB of this entry (only values linked)
465 CBarInfo barInfo;
466 bde.modifyFromDBIn(barInfo);
468 // Get the last DB modification server tick
469 TGameCycle serverTick= 0;
470 /* To do this, I test all DB input, and choose the highest changeDate
471 This works because the branch is atomic (all DB are relevant to the others, and
472 therefore relevant agst the most recent one)
474 if(bde.UIDIn && bde.UIDIn->getLastChangeGC() > serverTick )
475 serverTick= bde.UIDIn->getLastChangeGC();
476 if(bde.PresentIn && bde.PresentIn->getLastChangeGC() > serverTick )
477 serverTick= bde.PresentIn->getLastChangeGC();
478 for(uint sc=0;sc<SCORES::NUM_SCORES;sc++)
480 if( bde.ScoreIn[sc] && bde.ScoreIn[sc]->getLastChangeGC() > serverTick )
481 serverTick= bde.ScoreIn[sc]->getLastChangeGC();
484 // then update the bars
485 updateBars(bde.DataSetId, barInfo, serverTick, _EntryScoreFlags[type] );
488 // ***************************************************************************
489 void CBarManager::updateEntryFromDB(TEntryType type, uint entryId)
491 std::vector<CBarDataEntry> &entryArray= _EntryBars[type];
492 nlassert(entryId<entryArray.size());
493 CBarDataEntry &bde= entryArray[entryId];
495 // if the UID db was not found, can't do nothing... => abort
496 if(bde.UIDIn==NULL)
497 return;
499 // get the new UID from the SERVER DB
500 uint newDataSetId= bde.UIDIn->getValue32();
501 // if present flag is linked, and if 0, then force invalid data set id
502 if(bde.PresentIn && bde.PresentIn->getValue32()==0)
503 newDataSetId= CLFECOMMON::INVALID_CLIENT_DATASET_INDEX;
505 // *** if the data set id does not correspond as the cached one
506 if(newDataSetId!=bde.DataSetId)
508 // if deleted, delete this entry
509 if(newDataSetId==CLFECOMMON::INVALID_CLIENT_DATASET_INDEX)
510 delEntry(type, entryId);
511 // else add
512 else
513 addEntry(type, entryId, newDataSetId);
514 // should be changed
515 nlassert(bde.DataSetId==newDataSetId);
518 // *** update from DB
519 if(newDataSetId!=CLFECOMMON::INVALID_CLIENT_DATASET_INDEX)
521 updateEntryFromDBNoAddDel(type, bde);
525 // ***************************************************************************
526 void CBarManager::updateTeamMemberFromDB(uint teamMemberId)
528 updateEntryFromDB(TeamMemberType, teamMemberId);
531 // ***************************************************************************
532 void CBarManager::updateAnimalFromDB(uint paId)
534 updateEntryFromDB(AnimalType, paId);
537 // ***************************************************************************
538 void CBarManager::updateTargetFromDB()
540 /* Special case for Target. The DataSetId is not replaced with those in DB (setuped with setLocalTarget())
541 Instead, we ensure that the 2 match, else ignore DB change
543 CBarDataEntry &bde= _EntryBars[TargetType][0];
545 // if the UID db was not found, can't do nothing... => abort
546 if(bde.UIDIn==NULL)
547 return;
549 // get the new UID from the SERVER DB
550 uint serverDataSetId= bde.UIDIn->getValue32();
552 barInfoLog("BARS: updateTargetFromDB(dsid=%x)", serverDataSetId);
554 // *** if the server data set id correspond to the local one (and not invalid), update from DB
555 if(serverDataSetId==bde.DataSetId && serverDataSetId!=CLFECOMMON::INVALID_CLIENT_DATASET_INDEX)
557 updateEntryFromDBNoAddDel(TargetType, bde);
561 // ***************************************************************************
562 void CBarManager::setLocalTarget(uint dataSetId)
564 CBarDataEntry &bde= _EntryBars[TargetType][0];
566 barInfoLog("BARS: setLocalTarget(dsid=%x)", dataSetId);
568 // *** if the data set id does not correspond as the cached one
569 if(dataSetId!=bde.DataSetId)
571 // if deleted, delete this entry
572 if(dataSetId==CLFECOMMON::INVALID_CLIENT_DATASET_INDEX)
573 delEntry(TargetType, 0);
574 // else add
575 else
576 addEntry(TargetType, 0, dataSetId);
577 // should be changed
578 nlassert(bde.DataSetId==dataSetId);
582 // ***************************************************************************
583 CBarManager::CBarInfo CBarManager::getBarsByEntityId(CLFECOMMON::TCLEntityId entityId) const
585 const std::vector<CBarDataEntry> &entityBars= _EntryBars[EntityType];
586 nlassert(entityId<entityBars.size());
588 return entityBars[entityId].BarInfo;
591 // ***************************************************************************
592 void CBarManager::setupUserBarInfo(uint8 msgNumber, sint32 hp, sint32 sap, sint32 sta, sint32 focus)
595 Since we are not sure of the message order, use a little counter to discard old messages
596 suppose that cannot have more than a jump of 127 messages.
598 If i Receive: 0..1..4..3..2..5
599 This will be applied: 0..1..4........5
602 // compute the difference beetween the msgNumber and the last received
603 sint32 diff;
604 if(msgNumber>=_LastUserBarMsgNumber)
605 diff= (sint32)msgNumber - (sint32)_LastUserBarMsgNumber;
606 else
607 diff= (sint32)msgNumber + 256 - (sint32)_LastUserBarMsgNumber;
608 // if too big difference, suppose a roll (eg last==255, cur=0, real diff==1)
609 if(diff>127)
610 diff-=256;
612 // if diff<0, means that the cur message is actually too old => discard
613 if(diff<0)
614 return;
615 else
617 // bkup last
618 _LastUserBarMsgNumber= msgNumber;
619 // user now can only manage 4 scores
620 nlctassert(SCORES::NUM_SCORES==4);
621 _UserScores[SCORES::hit_points].Score= hp;
622 _UserScores[SCORES::sap].Score= sap;
623 _UserScores[SCORES::stamina].Score= sta;
624 _UserScores[SCORES::focus].Score= focus;
626 // update actual database now.
627 for(uint i=0;i<SCORES::NUM_SCORES;i++)
629 // Clamp To 0, since used only by entries that don't need negative values (for comma mode)
630 if(_UserScores[i].DBOutVal) _UserScores[i].DBOutVal->setValue32(max((sint32)0,_UserScores[i].Score));
633 // Update the Player Entry
634 updateUserBars();
638 // ***************************************************************************
639 void CBarManager::updateUserBars()
641 // for all scores
642 for(uint i=0;i<SCORES::NUM_SCORES;i++)
644 CUserScore &us= _UserScores[i];
646 // get max value
647 sint32 maxVal= 1;
648 if(us.DBInMax)
650 maxVal= us.DBInMax->getValue32();
651 maxVal= max((sint32)1, maxVal);
654 // setup signed ratio. It is used for the view of Player interface
655 if(us.DBOutRatio)
657 sint32 v= UserBarMaxRatio*us.Score / maxVal;
658 clamp(v, (sint32)-UserBarMaxRatio, (sint32)UserBarMaxRatio);
659 us.DBOutRatio->setValue32(v);
662 // compute signed ratio -127 / 127, for CBarInfo replace
664 sint32 v= 127*us.Score / maxVal;
665 clamp(v, -127, 127);
666 _UserBarInfo.Score[i]= (sint8)v;
670 // replace the user Entry with the bar info.
671 // This is used only for the view of bars InScene, and in case the user target himself
672 uint userDataSetId= _EntryBars[EntityType][0].DataSetId;
673 if(userDataSetId!=CLFECOMMON::INVALID_CLIENT_DATASET_INDEX)
675 // Do a little cheat: force the update by retrieving the last update time in the BarData
676 TUIDToDatas::iterator it= _UIDBars.find(userDataSetId);
677 if(it!=_UIDBars.end())
679 TGameCycle serverTick= 0;
680 for(uint sc=0;sc<SCORES::NUM_SCORES;sc++)
682 if(it->second.ScoreDate[sc] > serverTick)
683 serverTick= it->second.ScoreDate[sc];
686 // update (user can only manage 4 scores for now)
687 nlctassert(SCORES::NUM_SCORES==4);
688 updateBars(userDataSetId, _UserBarInfo, serverTick, HpFlag | SapFlag | StaFlag | FocusFlag);
693 // ***************************************************************************
694 sint32 CBarManager::getUserScore(SCORES::TScores score)
696 nlassert((uint) score < SCORES::NUM_SCORES);
697 nlassert(_UserScores[score].DBOutVal); // initInGame() not called ?
698 return _UserScores[score].DBOutVal->getValue32();
702 // ***************************************************************************
703 // ***************************************************************************
704 // ACTION HANDLERS
705 // ***************************************************************************
706 // ***************************************************************************
710 // ***************************************************************************
711 DECLARE_INTERFACE_CONSTANT(getMaxAnimal, CBarManager::MaxAnimal);
712 DECLARE_INTERFACE_CONSTANT(getMaxTeamMember, CBarManager::MaxTeamMember);
715 // ***************************************************************************
716 class CAHBarManagerOnTarget : public IActionHandler
718 public:
719 virtual void execute(CCtrlBase * /* pCaller */, const string &/* Params */)
721 CBarManager::getInstance()->updateTargetFromDB();
724 REGISTER_ACTION_HANDLER(CAHBarManagerOnTarget, "bar_manager_on_target");
726 // ***************************************************************************
727 class CAHBarManagerOnTeam : public IActionHandler
729 public:
730 virtual void execute(CCtrlBase * /* pCaller */, const string &Params)
732 uint index;
733 fromString(Params, index);
734 if(index<CBarManager::MaxTeamMember)
735 CBarManager::getInstance()->updateTeamMemberFromDB(index);
738 REGISTER_ACTION_HANDLER(CAHBarManagerOnTeam, "bar_manager_on_team");
740 // ***************************************************************************
741 class CAHBarManagerOnAnimal : public IActionHandler
743 public:
744 virtual void execute(CCtrlBase * /* pCaller */, const string &Params)
746 uint index;
747 fromString(Params, index);
748 if(index<CBarManager::MaxAnimal)
749 CBarManager::getInstance()->updateAnimalFromDB(index);
752 REGISTER_ACTION_HANDLER(CAHBarManagerOnAnimal, "bar_manager_on_animal");
754 // ***************************************************************************
755 class CAHBarManagerOnUserScores : public IActionHandler
757 public:
758 virtual void execute(CCtrlBase * /* pCaller */, const string &/* Params */)
760 CBarManager::getInstance()->updateUserBars();
763 REGISTER_ACTION_HANDLER(CAHBarManagerOnUserScores, "bar_manager_on_user_scores");