equal
deleted
inserted
replaced
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 "ai/default/default.h" |
35 #include "ai/default/default.h" |
35 #include "ai/trolly/trolly.h" |
36 #include "ai/trolly/trolly.h" |
816 */ |
817 */ |
817 CommandCost CmdPlayerCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
818 CommandCost CmdPlayerCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
818 { |
819 { |
819 if (flags & DC_EXEC) _current_player = OWNER_NONE; |
820 if (flags & DC_EXEC) _current_player = OWNER_NONE; |
820 |
821 |
|
822 InvalidateWindowData(WC_COMPANY_LEAGUE, 0, 0); |
|
823 |
821 switch (p1) { |
824 switch (p1) { |
822 case 0: { /* Create a new player */ |
825 case 0: { /* Create a new player */ |
823 /* Joining Client: |
826 /* Joining Client: |
824 * _local_player: PLAYER_SPECTATOR |
827 * _local_player: PLAYER_SPECTATOR |
825 * _network_playas/cid = requested company/player |
828 * _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() |
1036 size_t count = 0; |
1036 size_t 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])); |
1268 Player *p = GetPlayer((PlayerID)index); |
1269 Player *p = GetPlayer((PlayerID)index); |
1269 SaveLoad_PLYR(p); |
1270 SaveLoad_PLYR(p); |
1270 _player_colors[index] = p->player_color; |
1271 _player_colors[index] = p->player_color; |
1271 |
1272 |
1272 /* This is needed so an AI is attached to a loaded AI */ |
1273 /* This is needed so an AI is attached to a loaded AI */ |
1273 if (p->is_ai && (!_networking || _network_server) && _ai.enabled) |
1274 if (p->is_ai && (!_networking || _network_server) && _ai.enabled) { |
|
1275 /* Clear the memory of the new AI, otherwise we might be doing wrong things. */ |
|
1276 memset(&_players_ainew[index], 0, sizeof(PlayerAiNew)); |
1274 AI_StartNewAI(p->index); |
1277 AI_StartNewAI(p->index); |
|
1278 } |
1275 } |
1279 } |
1276 } |
1280 } |
1277 |
1281 |
1278 extern const ChunkHandler _player_chunk_handlers[] = { |
1282 extern const ChunkHandler _player_chunk_handlers[] = { |
1279 { 'PLYR', Save_PLYR, Load_PLYR, CH_ARRAY | CH_LAST}, |
1283 { 'PLYR', Save_PLYR, Load_PLYR, CH_ARRAY | CH_LAST}, |