1717#define STALKERS_RANKING_XML " stalkers_ranking.xml"
1818#define STALKERS_RANKING_CHARACTER_XML " stalkers_ranking_character.xml"
1919
20- struct SStatData {
21- u16 id;
22- CSE_ALifeTraderAbstract* trader;
23- bool operator == (const SStatData& d1){return (id==d1.id ) ;}
24- };
25-
26- typedef xr_vector<SStatData> TOP_LIST;
20+ typedef xr_vector<u16 > TOP_LIST;
2721TOP_LIST g_all_statistic_humans;
2822
2923void CUIStalkersRankingWnd::Init ()
@@ -82,22 +76,22 @@ void CUIStalkersRankingWnd::Show(bool status)
8276 FillList ();
8377}
8478
85- bool GreaterRankPred (const SStatData& h1, const SStatData& h2)
86- {
87- return (h1.trader ->m_rank > h2.trader ->m_rank );
88- }
89-
9079extern CSE_ALifeTraderAbstract* ch_info_get_from_id (u16 id);
9180
81+ bool GreaterRankPred ( const u16 & h1, const u16 & h2 ) {
82+ CSE_ALifeTraderAbstract* t1 = ch_info_get_from_id ( h1 );
83+ CSE_ALifeTraderAbstract* t2 = ch_info_get_from_id ( h2 );
84+ if ( t1 && t2 )
85+ return t1->m_rank > t2->m_rank ;
86+ else if ( t1 )
87+ return true ;
88+ return false ;
89+ }
90+
9291int get_actor_ranking ()
9392{
9493 std::sort (g_all_statistic_humans.begin (),g_all_statistic_humans.end (),GreaterRankPred);
95- CSE_ALifeTraderAbstract* pActorAbstract = ch_info_get_from_id (Actor ()->ID ());
96- SStatData d;
97- d.id = Actor ()->ID ();
98- d.trader = pActorAbstract;
99-
100- TOP_LIST::iterator it = std::find (g_all_statistic_humans.begin (),g_all_statistic_humans.end (),d);
94+ TOP_LIST::iterator it = std::find ( g_all_statistic_humans.begin (), g_all_statistic_humans.end (), Actor ()->ID () );
10195 if (it!=g_all_statistic_humans.end ())
10296 return (int )std::distance (g_all_statistic_humans.begin (), it);
10397 else
@@ -119,14 +113,19 @@ void CUIStalkersRankingWnd::FillList()
119113 CSE_ALifeTraderAbstract* pActorAbstract = ch_info_get_from_id (Actor ()->ID ());
120114 int actor_place = get_actor_ranking ();
121115
122- int sz = _min (g_all_statistic_humans.size (),20 );
123- for (int i=0 ; i<sz; ++i){
124- CSE_ALifeTraderAbstract* pT = (g_all_statistic_humans[i]).trader ;
125- if (pT==pActorAbstract || (i==19 &&actor_place>19 ) ){
116+ int i = 0 ;
117+ while ( i < 20 && i < g_all_statistic_humans.size () ) {
118+ u16 id = g_all_statistic_humans[ i ];
119+ CSE_ALifeTraderAbstract* pT = ch_info_get_from_id ( id );
120+ if ( pT ) {
121+ if ( pT == pActorAbstract || ( i == 19 && actor_place > 19 ) )
126122 AddActorItem (&uiXml, actor_place+1 , pActorAbstract);
127- } else {
123+ else
128124 AddStalkerItem (&uiXml, i+1 , pT);
129125 }
126+ else
127+ Msg ( " ! [%s]: i[%d] id[%d] not a CSE_ALifeTraderAbstract" , __FUNCTION__, i, id );
128+ i++;
130129 }
131130
132131 UIList->SetSelected (UIList->GetItem (0 ) );
@@ -142,84 +141,65 @@ void CUIStalkersRankingWnd::ShowHumanInfo(u16 id)
142141 UICharacterInfo->InitCharacter (id);
143142}
144143
145- void CUIStalkersRankingWnd::AddStalkerItem (CUIXml* xml, int num, CSE_ALifeTraderAbstract* t)
146- {
147- string128 buff;
148- CUIStalkerRankingInfoItem* itm = xr_new<CUIStalkerRankingInfoItem>(this );
149- itm->Init (xml, " item_human" , 0 );
144+ void CUIStalkersRankingWnd::AddStalkerItem ( CUIXml* xml, int num, CSE_ALifeTraderAbstract* t ) {
145+ CUIStalkerRankingInfoItem* itm = xr_new<CUIStalkerRankingInfoItem>( this );
146+ itm->Init ( xml, " item_human" , 0 );
150147
151- sprintf_s (buff, " %d. " ,num) ;
152- itm->m_text1 ->SetText (buff);
148+ std::string s = std::to_string ( num ) + " . " ;
149+ itm->m_text1 ->SetText ( s. c_str () );
153150
154- sprintf_s (buff," %s" ,t->m_character_name .c_str ());
155- itm->m_text2 ->SetText (buff);
151+ itm->m_text2 ->SetText ( t->m_character_name .c_str () );
156152
157- sprintf_s (buff," %d" ,t->m_rank );
158- itm->m_text3 ->SetText (buff);
159- itm->m_humanID = t->object_id ();
160- UIList->AddWindow (itm, true );
153+ s = std::to_string ( t->m_rank );
154+ itm->m_text3 ->SetText ( s.c_str () );
161155
156+ itm->m_humanID = t->object_id ();
157+ UIList->AddWindow ( itm, true );
162158}
163159
164- void CUIStalkersRankingWnd::AddActorItem (CUIXml* xml, int num, CSE_ALifeTraderAbstract* t)
165- {
166- string128 buff;
167- CUIStalkerRankingInfoItem* itm;
168- if (num>19 ){
169- itm = xr_new<CUIStalkerRankingElipsisItem>(this );
170- itm->Init (xml, " item_ellipsis" , 0 );
171- UIList->AddWindow (itm, true );
172- }
173-
174- itm = xr_new<CUIStalkerRankingInfoItem>(this );
175- itm->Init (xml, " item_actor" , 0 );
160+ void CUIStalkersRankingWnd::AddActorItem ( CUIXml* xml, int num, CSE_ALifeTraderAbstract* t ) {
161+ CUIStalkerRankingInfoItem* itm;
162+ if ( num > 19 ) {
163+ itm = xr_new<CUIStalkerRankingElipsisItem>( this );
164+ itm->Init ( xml, " item_ellipsis" , 0 );
165+ UIList->AddWindow ( itm, true );
166+ }
176167
177- sprintf_s (buff, " %d. " ,num );
178- itm->m_text1 -> SetText (buff);
168+ itm = xr_new<CUIStalkerRankingInfoItem>( this );
169+ itm->Init ( xml, " item_actor " , 0 );
179170
171+ std::string s = std::to_string ( num ) + " ." ;
172+ itm->m_text1 ->SetText ( s.c_str () );
180173
181- sprintf_s (buff," %s" , t->m_character_name .c_str ());
182- itm->m_text2 ->SetText (buff);
174+ itm->m_text2 ->SetText ( t->m_character_name .c_str () );
183175
184- sprintf_s (buff, " %d " , t->m_rank );
185- itm->m_text3 ->SetText (buff );
176+ s = std::to_string ( t->m_rank );
177+ itm->m_text3 ->SetText ( s. c_str () );
186178
187- itm->m_humanID = t->object_id ();
188- UIList->AddWindow ( itm, true );
179+ itm->m_humanID = t->object_id ();
180+ UIList->AddWindow ( itm, true );
189181}
190182
191183void CUIStalkersRankingWnd::Reset ()
192184{
193185 inherited::Reset ();
186+ g_all_statistic_humans.clear ();
194187}
195188
196- void add_human_to_top_list (u16 id)
197- {
198- CSE_ALifeTraderAbstract* t = ch_info_get_from_id (id);
199- SStatData d;
200- d.id = id;
201- d.trader = t;
202-
203- TOP_LIST::iterator it = std::find (g_all_statistic_humans.begin (),g_all_statistic_humans.end (),d);
204-
205- if (it!=g_all_statistic_humans.end ())
206- g_all_statistic_humans.erase (it);
207-
208- g_all_statistic_humans.push_back (d);
209-
210-
211- // t->m_rank = ::Random.randI(20000);
189+ void remove_human_from_top_list ( u16 id ) {
190+ TOP_LIST::iterator it = std::find ( g_all_statistic_humans.begin (), g_all_statistic_humans.end (), id );
191+ if ( it != g_all_statistic_humans.end () )
192+ g_all_statistic_humans.erase ( it );
212193}
213194
214- void remove_human_from_top_list (u16 id)
215- {
216- CSE_ALifeTraderAbstract* t = ch_info_get_from_id (id);
217- SStatData d;
218- d.id = id;
219- d.trader = t;
220- TOP_LIST::iterator it = std::find (g_all_statistic_humans.begin (),g_all_statistic_humans.end (),d);
221- if (it!=g_all_statistic_humans.end ())
222- g_all_statistic_humans.erase (it);
195+ void add_human_to_top_list ( u16 id ) {
196+ CSE_ALifeTraderAbstract* t = ch_info_get_from_id ( id );
197+ if ( t ) {
198+ remove_human_from_top_list ( id );
199+ g_all_statistic_humans.push_back ( id );
200+ }
201+ else
202+ Msg ( " ! [%s]: id[%d] not a CSE_ALifeTraderAbstract" , __FUNCTION__, id );
223203}
224204
225205
0 commit comments