26 #include "functions.h" |
26 #include "functions.h" |
27 #include "date_func.h" |
27 #include "date_func.h" |
28 #include "vehicle_func.h" |
28 #include "vehicle_func.h" |
29 #include "sound_func.h" |
29 #include "sound_func.h" |
30 #include "core/alloc_func.hpp" |
30 #include "core/alloc_func.hpp" |
|
31 #include "core/sort_func.hpp" |
31 #include "autoreplace_func.h" |
32 #include "autoreplace_func.h" |
32 #include "autoreplace_gui.h" |
33 #include "autoreplace_gui.h" |
33 #include "string_func.h" |
34 #include "string_func.h" |
34 #include "road_func.h" |
35 #include "road_func.h" |
35 #include "rail.h" |
36 #include "rail.h" |
814 */ |
815 */ |
815 CommandCost CmdPlayerCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
816 CommandCost CmdPlayerCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
816 { |
817 { |
817 if (flags & DC_EXEC) _current_player = OWNER_NONE; |
818 if (flags & DC_EXEC) _current_player = OWNER_NONE; |
818 |
819 |
|
820 InvalidateWindowData(WC_COMPANY_LEAGUE, 0, 0); |
|
821 |
819 switch (p1) { |
822 switch (p1) { |
820 case 0: { /* Create a new player */ |
823 case 0: { /* Create a new player */ |
821 /* Joining Client: |
824 /* Joining Client: |
822 * _local_player: PLAYER_SPECTATOR |
825 * _local_player: PLAYER_SPECTATOR |
823 * _network_playas/cid = requested company/player |
826 * _network_playas/cid = requested company/player |
1017 |
1020 |
1018 return -1; // too bad; we did not make it into the top5 |
1021 return -1; // too bad; we did not make it into the top5 |
1019 } |
1022 } |
1020 |
1023 |
1021 /** Sort all players given their performance */ |
1024 /** Sort all players given their performance */ |
1022 static int CDECL HighScoreSorter(const void *a, const void *b) |
1025 static int CDECL HighScoreSorter(const Player* const *a, const Player* const *b) |
1023 { |
1026 { |
1024 const Player *pa = *(const Player* const*)a; |
1027 return (*b)->old_economy[0].performance_history - (*a)->old_economy[0].performance_history; |
1025 const Player *pb = *(const Player* const*)b; |
|
1026 |
|
1027 return pb->old_economy[0].performance_history - pa->old_economy[0].performance_history; |
|
1028 } |
1028 } |
1029 |
1029 |
1030 /* Save the highscores in a network game when it has ended */ |
1030 /* Save the highscores in a network game when it has ended */ |
1031 #define LAST_HS_ITEM lengthof(_highscore_table) - 1 |
1031 #define LAST_HS_ITEM lengthof(_highscore_table) - 1 |
1032 int8 SaveHighScoreValueNetwork() |
1032 int8 SaveHighScoreValueNetwork() |
1033 { |
1033 { |
1034 const Player* p; |
1034 const Player* p; |
1035 const Player* pl[MAX_PLAYERS]; |
1035 const Player* pl[MAX_PLAYERS]; |
1036 size_t count = 0; |
1036 uint count = 0; |
1037 int8 player = -1; |
1037 int8 player = -1; |
1038 |
1038 |
1039 /* Sort all active players with the highest score first */ |
1039 /* Sort all active players with the highest score first */ |
1040 FOR_ALL_PLAYERS(p) if (p->is_active) pl[count++] = p; |
1040 FOR_ALL_PLAYERS(p) if (p->is_active) pl[count++] = p; |
1041 qsort((Player*)pl, count, sizeof(pl[0]), HighScoreSorter); |
1041 |
|
1042 GSortT(pl, count, &HighScoreSorter); |
1042 |
1043 |
1043 { |
1044 { |
1044 uint i; |
1045 uint i; |
1045 |
1046 |
1046 memset(_highscore_table[LAST_HS_ITEM], 0, sizeof(_highscore_table[0])); |
1047 memset(_highscore_table[LAST_HS_ITEM], 0, sizeof(_highscore_table[0])); |