mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
This commit is contained in:
parent
cc1e761eda
commit
3b798599b6
|
@ -16,16 +16,16 @@
|
|||
#include "../signal_func.h"
|
||||
|
||||
AIStruct _ai;
|
||||
AIPlayer _ai_player[MAX_PLAYERS];
|
||||
AICompany _ai_company[MAX_COMPANIES];
|
||||
|
||||
/**
|
||||
* Dequeues commands put in the queue via AI_PutCommandInQueue.
|
||||
*/
|
||||
static void AI_DequeueCommands(PlayerID player)
|
||||
static void AI_DequeueCommands(CompanyID company)
|
||||
{
|
||||
AICommand *com, *entry_com;
|
||||
|
||||
entry_com = _ai_player[player].queue;
|
||||
entry_com = _ai_company[company].queue;
|
||||
|
||||
/* It happens that DoCommandP issues a new DoCommandAI which adds a new command
|
||||
* to this very same queue (don't argue about this, if it currently doesn't
|
||||
|
@ -33,12 +33,12 @@ static void AI_DequeueCommands(PlayerID player)
|
|||
* do not make the queue NULL, that commands will be dequeued immediatly.
|
||||
* Therefor we safe the entry-point to entry_com, and make the queue NULL, so
|
||||
* the new queue can be safely built up. */
|
||||
_ai_player[player].queue = NULL;
|
||||
_ai_player[player].queue_tail = NULL;
|
||||
_ai_company[company].queue = NULL;
|
||||
_ai_company[company].queue_tail = NULL;
|
||||
|
||||
/* Dequeue all commands */
|
||||
while ((com = entry_com) != NULL) {
|
||||
_current_player = player;
|
||||
_current_company = company;
|
||||
|
||||
_cmd_text = com->text;
|
||||
DoCommandP(com->tile, com->p1, com->p2, com->callback, com->procc);
|
||||
|
@ -54,22 +54,22 @@ static void AI_DequeueCommands(PlayerID player)
|
|||
* Needed for SP; we need to delay DoCommand with 1 tick, because else events
|
||||
* will make infinite loops (AIScript).
|
||||
*/
|
||||
static void AI_PutCommandInQueue(PlayerID player, TileIndex tile, uint32 p1, uint32 p2, uint32 procc, CommandCallback* callback)
|
||||
static void AI_PutCommandInQueue(CompanyID company, TileIndex tile, uint32 p1, uint32 p2, uint32 procc, CommandCallback* callback)
|
||||
{
|
||||
AICommand *com;
|
||||
|
||||
if (_ai_player[player].queue_tail == NULL) {
|
||||
if (_ai_company[company].queue_tail == NULL) {
|
||||
/* There is no item in the queue yet, create the queue */
|
||||
_ai_player[player].queue = MallocT<AICommand>(1);
|
||||
_ai_player[player].queue_tail = _ai_player[player].queue;
|
||||
_ai_company[company].queue = MallocT<AICommand>(1);
|
||||
_ai_company[company].queue_tail = _ai_company[company].queue;
|
||||
} else {
|
||||
/* Add an item at the end */
|
||||
_ai_player[player].queue_tail->next = MallocT<AICommand>(1);
|
||||
_ai_player[player].queue_tail = _ai_player[player].queue_tail->next;
|
||||
_ai_company[company].queue_tail->next = MallocT<AICommand>(1);
|
||||
_ai_company[company].queue_tail = _ai_company[company].queue_tail->next;
|
||||
}
|
||||
|
||||
/* This is our new item */
|
||||
com = _ai_player[player].queue_tail;
|
||||
com = _ai_company[company].queue_tail;
|
||||
|
||||
/* Assign the info */
|
||||
com->tile = tile;
|
||||
|
@ -92,7 +92,7 @@ static void AI_PutCommandInQueue(PlayerID player, TileIndex tile, uint32 p1, uin
|
|||
*/
|
||||
CommandCost AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint32 procc, CommandCallback* callback)
|
||||
{
|
||||
PlayerID old_lp;
|
||||
CompanyID old_local_company;
|
||||
CommandCost res;
|
||||
const char* tmp_cmdtext;
|
||||
|
||||
|
@ -113,10 +113,10 @@ CommandCost AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, u
|
|||
/* Restore _cmd_text */
|
||||
_cmd_text = tmp_cmdtext;
|
||||
|
||||
/* NetworkSend_Command needs _local_player to be set correctly, so
|
||||
/* NetworkSend_Command needs _local_company to be set correctly, so
|
||||
* adjust it, and put it back right after the function */
|
||||
old_lp = _local_player;
|
||||
_local_player = _current_player;
|
||||
old_local_company = _local_company;
|
||||
_local_company = _current_company;
|
||||
|
||||
#ifdef ENABLE_NETWORK
|
||||
/* Send the command */
|
||||
|
@ -129,11 +129,11 @@ CommandCost AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, u
|
|||
#endif
|
||||
/* If we execute BuildCommands directly in SP, we have a big problem with events
|
||||
* so we need to delay is for 1 tick */
|
||||
AI_PutCommandInQueue(_current_player, tile, p1, p2, procc, callback);
|
||||
AI_PutCommandInQueue(_current_company, tile, p1, p2, procc, callback);
|
||||
}
|
||||
|
||||
/* Set _local_player back */
|
||||
_local_player = old_lp;
|
||||
/* Set _local_company back */
|
||||
_local_company = old_local_company;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -148,20 +148,20 @@ CommandCost AI_DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uin
|
|||
/**
|
||||
* Run 1 tick of the AI. Don't overdo it, keep it realistic.
|
||||
*/
|
||||
static void AI_RunTick(PlayerID player)
|
||||
static void AI_RunTick(CompanyID company)
|
||||
{
|
||||
extern void AiNewDoGameLoop(Player *p);
|
||||
extern void AiNewDoGameLoop(Company *c);
|
||||
|
||||
Player *p = GetPlayer(player);
|
||||
_current_player = player;
|
||||
Company *c = GetCompany(company);
|
||||
_current_company = company;
|
||||
|
||||
if (_settings_game.ai.ainew_active) {
|
||||
AiNewDoGameLoop(p);
|
||||
AiNewDoGameLoop(c);
|
||||
} else {
|
||||
/* Enable all kind of cheats the old AI needs in order to operate correctly... */
|
||||
_is_old_ai_player = true;
|
||||
AiDoGameLoop(p);
|
||||
_is_old_ai_player = false;
|
||||
_is_old_ai_company = true;
|
||||
AiDoGameLoop(c);
|
||||
_is_old_ai_company = false;
|
||||
}
|
||||
|
||||
/* AI could change some track, so update signals */
|
||||
|
@ -191,47 +191,47 @@ void AI_RunGameLoop()
|
|||
/* Check for AI-client (so joining a network with an AI) */
|
||||
if (!_networking || _network_server) {
|
||||
/* Check if we want to run AIs (server or SP only) */
|
||||
const Player* p;
|
||||
const Company *c;
|
||||
|
||||
FOR_ALL_PLAYERS(p) {
|
||||
if (p->is_ai) {
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
if (c->is_ai) {
|
||||
/* This should always be true, else something went wrong... */
|
||||
assert(_ai_player[p->index].active);
|
||||
assert(_ai_company[c->index].active);
|
||||
|
||||
/* Run the script */
|
||||
AI_DequeueCommands(p->index);
|
||||
AI_RunTick(p->index);
|
||||
AI_DequeueCommands(c->index);
|
||||
AI_RunTick(c->index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_current_player = OWNER_NONE;
|
||||
_current_company = OWNER_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* A new AI sees the day of light. You can do here what ever you think is needed.
|
||||
*/
|
||||
void AI_StartNewAI(PlayerID player)
|
||||
void AI_StartNewAI(CompanyID company)
|
||||
{
|
||||
assert(IsValidPlayerID(player));
|
||||
assert(IsValidCompanyID(company));
|
||||
|
||||
/* Called if a new AI is booted */
|
||||
_ai_player[player].active = true;
|
||||
_ai_company[company].active = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This AI player died. Give it some chance to make a final puf.
|
||||
* This AI company died. Give it some chance to make a final puf.
|
||||
*/
|
||||
void AI_PlayerDied(PlayerID player)
|
||||
void AI_CompanyDied(CompanyID company)
|
||||
{
|
||||
/* Called if this AI died */
|
||||
_ai_player[player].active = false;
|
||||
_ai_company[company].active = false;
|
||||
|
||||
if (_players_ainew[player].pathfinder == NULL) return;
|
||||
if (_companies_ainew[company].pathfinder == NULL) return;
|
||||
|
||||
AyStarMain_Free(_players_ainew[player].pathfinder);
|
||||
delete _players_ainew[player].pathfinder;
|
||||
_players_ainew[player].pathfinder = NULL;
|
||||
AyStarMain_Free(_companies_ainew[company].pathfinder);
|
||||
delete _companies_ainew[company].pathfinder;
|
||||
_companies_ainew[company].pathfinder = NULL;
|
||||
|
||||
}
|
||||
|
||||
|
@ -244,7 +244,7 @@ void AI_Initialize()
|
|||
AI_Uninitialize();
|
||||
|
||||
memset(&_ai, 0, sizeof(_ai));
|
||||
memset(&_ai_player, 0, sizeof(_ai_player));
|
||||
memset(&_ai_company, 0, sizeof(_ai_company));
|
||||
|
||||
_ai.enabled = true;
|
||||
}
|
||||
|
@ -254,5 +254,5 @@ void AI_Initialize()
|
|||
*/
|
||||
void AI_Uninitialize()
|
||||
{
|
||||
for (PlayerID p = PLAYER_FIRST; p < MAX_PLAYERS; p++) AI_PlayerDied(p);
|
||||
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) AI_CompanyDied(c);
|
||||
}
|
||||
|
|
10
src/ai/ai.h
10
src/ai/ai.h
|
@ -24,8 +24,8 @@ struct AICommand {
|
|||
AICommand *next;
|
||||
};
|
||||
|
||||
/* The struct for an AIScript Player */
|
||||
struct AIPlayer {
|
||||
/* The struct for an AIScript Company */
|
||||
struct AICompany {
|
||||
bool active; ///< Is this AI active?
|
||||
AICommand *queue; ///< The commands that he has in his queue
|
||||
AICommand *queue_tail; ///< The tail of this queue
|
||||
|
@ -39,11 +39,11 @@ struct AIStruct {
|
|||
};
|
||||
|
||||
extern AIStruct _ai;
|
||||
extern AIPlayer _ai_player[MAX_PLAYERS];
|
||||
extern AICompany _ai_company[MAX_COMPANIES];
|
||||
|
||||
// ai.c
|
||||
void AI_StartNewAI(PlayerID player);
|
||||
void AI_PlayerDied(PlayerID player);
|
||||
void AI_StartNewAI(CompanyID company);
|
||||
void AI_CompanyDied(CompanyID company);
|
||||
void AI_RunGameLoop();
|
||||
void AI_Initialize();
|
||||
void AI_Uninitialize();
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -9,8 +9,8 @@
|
|||
#include "../../vehicle_type.h"
|
||||
#include "../../rail_type.h"
|
||||
|
||||
void AiDoGameLoop(Player*);
|
||||
void SaveLoad_AI(PlayerID id);
|
||||
void AiDoGameLoop(Company *c);
|
||||
void SaveLoad_AI(CompanyID company);
|
||||
|
||||
struct AiBuildRec {
|
||||
TileIndex spec_tile;
|
||||
|
@ -25,7 +25,7 @@ struct AiBuildRec {
|
|||
CargoID cargo;
|
||||
};
|
||||
|
||||
struct PlayerAI {
|
||||
struct CompanyAI {
|
||||
byte state;
|
||||
byte tick; ///< Used to determine how often to move
|
||||
uint32 state_counter; ///< Can hold tile index!
|
||||
|
@ -65,6 +65,6 @@ struct PlayerAI {
|
|||
byte banned_val[16];
|
||||
};
|
||||
|
||||
extern PlayerAI _players_ai[MAX_PLAYERS];
|
||||
extern CompanyAI _companies_ai[MAX_COMPANIES];
|
||||
|
||||
#endif
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
// Build HQ
|
||||
// Params:
|
||||
// tile : tile where HQ is going to be build
|
||||
bool AiNew_Build_CompanyHQ(Player *p, TileIndex tile)
|
||||
bool AiNew_Build_CompanyHQ(Company *c, TileIndex tile)
|
||||
{
|
||||
if (CmdFailed(AI_DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_BUILD_COMPANY_HQ)))
|
||||
return false;
|
||||
|
@ -40,7 +40,7 @@ bool AiNew_Build_CompanyHQ(Player *p, TileIndex tile)
|
|||
// numtracks : in case of AI_TRAIN: tracks of station
|
||||
// direction : the direction of the station
|
||||
// flag : flag passed to DoCommand (normally 0 to get the cost or DC_EXEC to build it)
|
||||
CommandCost AiNew_Build_Station(Player *p, byte type, TileIndex tile, byte length, byte numtracks, byte direction, byte flag)
|
||||
CommandCost AiNew_Build_Station(Company *c, byte type, TileIndex tile, byte length, byte numtracks, byte direction, byte flag)
|
||||
{
|
||||
if (type == AI_TRAIN)
|
||||
return AI_DoCommand(tile, direction + (numtracks << 8) + (length << 16), 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_RAILROAD_STATION);
|
||||
|
@ -52,12 +52,12 @@ CommandCost AiNew_Build_Station(Player *p, byte type, TileIndex tile, byte lengt
|
|||
}
|
||||
|
||||
|
||||
// Builds a brdige. The second best out of the ones available for this player
|
||||
// Builds a brdige. The second best out of the ones available for this company
|
||||
// Params:
|
||||
// tile_a : starting point
|
||||
// tile_b : end point
|
||||
// flag : flag passed to DoCommand
|
||||
CommandCost AiNew_Build_Bridge(Player *p, TileIndex tile_a, TileIndex tile_b, byte flag)
|
||||
CommandCost AiNew_Build_Bridge(Company *c, TileIndex tile_a, TileIndex tile_b, byte flag)
|
||||
{
|
||||
int bridge_type, bridge_len, type, type2;
|
||||
|
||||
|
@ -76,7 +76,7 @@ CommandCost AiNew_Build_Bridge(Player *p, TileIndex tile_a, TileIndex tile_b, by
|
|||
if (type2 == 0 && type != 0) type2 = type;
|
||||
|
||||
// Now, simply, build the bridge!
|
||||
if (_players_ainew[p->index].tbt == AI_TRAIN) {
|
||||
if (_companies_ainew[c->index].tbt == AI_TRAIN) {
|
||||
return AI_DoCommand(tile_a, tile_b, type2 | RAILTYPE_RAIL << 8 | TRANSPORT_RAIL << 15, flag | DC_AUTO, CMD_BUILD_BRIDGE);
|
||||
} else {
|
||||
return AI_DoCommand(tile_a, tile_b, type2 | ROADTYPES_ROAD << 8 | TRANSPORT_ROAD << 15, flag | DC_AUTO, CMD_BUILD_BRIDGE);
|
||||
|
@ -94,7 +94,7 @@ CommandCost AiNew_Build_Bridge(Player *p, TileIndex tile_a, TileIndex tile_b, by
|
|||
// part : Which part we need to build
|
||||
//
|
||||
// TODO: skip already builded road-pieces (e.g.: cityroad)
|
||||
CommandCost AiNew_Build_RoutePart(Player *p, Ai_PathFinderInfo *PathFinderInfo, byte flag)
|
||||
CommandCost AiNew_Build_RoutePart(Company *c, Ai_PathFinderInfo *PathFinderInfo, byte flag)
|
||||
{
|
||||
int part = PathFinderInfo->position;
|
||||
byte *route_extra = PathFinderInfo->route_extra;
|
||||
|
@ -127,7 +127,7 @@ CommandCost AiNew_Build_RoutePart(Player *p, Ai_PathFinderInfo *PathFinderInfo,
|
|||
}
|
||||
// Bridge code
|
||||
if ((AI_PATHFINDER_FLAG_BRIDGE & route_extra[part]) != 0) {
|
||||
cost.AddCost(AiNew_Build_Bridge(p, route[part], route[part - 1], flag));
|
||||
cost.AddCost(AiNew_Build_Bridge(c, route[part], route[part - 1], flag));
|
||||
PathFinderInfo->position++;
|
||||
// TODO: problems!
|
||||
if (CmdFailed(cost)) {
|
||||
|
@ -150,7 +150,7 @@ CommandCost AiNew_Build_RoutePart(Player *p, Ai_PathFinderInfo *PathFinderInfo,
|
|||
res = AI_DoCommand(route[part], 0, dir, flag, CMD_BUILD_SINGLE_RAIL);
|
||||
if (CmdFailed(res)) {
|
||||
// Problem.. let's just abort it all!
|
||||
_players_ainew[p->index].state = AI_STATE_NOTHING;
|
||||
_companies_ainew[c->index].state = AI_STATE_NOTHING;
|
||||
return CommandCost();
|
||||
}
|
||||
cost.AddCost(res);
|
||||
|
@ -177,7 +177,7 @@ CommandCost AiNew_Build_RoutePart(Player *p, Ai_PathFinderInfo *PathFinderInfo,
|
|||
}
|
||||
// Bridge code
|
||||
if ((AI_PATHFINDER_FLAG_BRIDGE & route_extra[part]) != 0) {
|
||||
cost.AddCost(AiNew_Build_Bridge(p, route[part], route[part + 1], flag));
|
||||
cost.AddCost(AiNew_Build_Bridge(c, route[part], route[part + 1], flag));
|
||||
PathFinderInfo->position++;
|
||||
// TODO: problems!
|
||||
if (CmdFailed(cost)) {
|
||||
|
@ -206,7 +206,7 @@ CommandCost AiNew_Build_RoutePart(Player *p, Ai_PathFinderInfo *PathFinderInfo,
|
|||
if (CmdFailed(res) && flag == DC_EXEC && !IsTileType(route[part], MP_ROAD) && !EnsureNoVehicleOnGround(route[part])) {
|
||||
// Problem.. let's just abort it all!
|
||||
DEBUG(ai, 0, "[BuidPath] route building failed at tile 0x%X, aborting", route[part]);
|
||||
_players_ainew[p->index].state = AI_STATE_NOTHING;
|
||||
_companies_ainew[c->index].state = AI_STATE_NOTHING;
|
||||
return CommandCost();
|
||||
}
|
||||
|
||||
|
@ -230,9 +230,9 @@ CommandCost AiNew_Build_RoutePart(Player *p, Ai_PathFinderInfo *PathFinderInfo,
|
|||
|
||||
// This functions tries to find the best vehicle for this type of cargo
|
||||
// It returns INVALID_ENGINE if not suitable engine is found
|
||||
EngineID AiNew_PickVehicle(Player *p)
|
||||
EngineID AiNew_PickVehicle(Company *c)
|
||||
{
|
||||
if (_players_ainew[p->index].tbt == AI_TRAIN) {
|
||||
if (_companies_ainew[c->index].tbt == AI_TRAIN) {
|
||||
// Not supported yet
|
||||
return INVALID_ENGINE;
|
||||
} else {
|
||||
|
@ -246,14 +246,14 @@ EngineID AiNew_PickVehicle(Player *p)
|
|||
const RoadVehicleInfo *rvi = &e->u.road;
|
||||
|
||||
/* Skip vehicles which can't take our cargo type */
|
||||
if (rvi->cargo_type != _players_ainew[p->index].cargo && !CanRefitTo(i, _players_ainew[p->index].cargo)) continue;
|
||||
if (rvi->cargo_type != _companies_ainew[c->index].cargo && !CanRefitTo(i, _companies_ainew[c->index].cargo)) continue;
|
||||
|
||||
/* Skip trams */
|
||||
if (HasBit(EngInfo(i)->misc_flags, EF_ROAD_TRAM)) continue;
|
||||
|
||||
// Is it availiable?
|
||||
// Also, check if the reliability of the vehicle is above the AI_VEHICLE_MIN_RELIABILTY
|
||||
if (!HasBit(e->player_avail, _current_player) || e->reliability * 100 < AI_VEHICLE_MIN_RELIABILTY << 16) continue;
|
||||
if (!HasBit(e->company_avail, _current_company) || e->reliability * 100 < AI_VEHICLE_MIN_RELIABILTY << 16) continue;
|
||||
|
||||
/* Rate and compare the engine by speed & capacity */
|
||||
int rating = rvi->max_speed * rvi->capacity;
|
||||
|
@ -274,34 +274,34 @@ EngineID AiNew_PickVehicle(Player *p)
|
|||
|
||||
void CcAI(bool success, TileIndex tile, uint32 p1, uint32 p2)
|
||||
{
|
||||
Player* p = GetPlayer(_current_player);
|
||||
Company *c = GetCompany(_current_company);
|
||||
|
||||
if (success) {
|
||||
_players_ainew[p->index].state = AI_STATE_GIVE_ORDERS;
|
||||
_players_ainew[p->index].veh_id = _new_vehicle_id;
|
||||
_companies_ainew[c->index].state = AI_STATE_GIVE_ORDERS;
|
||||
_companies_ainew[c->index].veh_id = _new_vehicle_id;
|
||||
|
||||
if (GetVehicle(_players_ainew[p->index].veh_id)->cargo_type != _players_ainew[p->index].cargo) {
|
||||
if (GetVehicle(_companies_ainew[c->index].veh_id)->cargo_type != _companies_ainew[c->index].cargo) {
|
||||
/* Cargo type doesn't match, so refit it */
|
||||
if (CmdFailed(DoCommand(tile, _players_ainew[p->index].veh_id, _players_ainew[p->index].cargo, DC_EXEC, CMD_REFIT_ROAD_VEH))) {
|
||||
if (CmdFailed(DoCommand(tile, _companies_ainew[c->index].veh_id, _companies_ainew[c->index].cargo, DC_EXEC, CMD_REFIT_ROAD_VEH))) {
|
||||
/* Refit failed, so sell the vehicle */
|
||||
DoCommand(tile, _players_ainew[p->index].veh_id, 0, DC_EXEC, CMD_SELL_ROAD_VEH);
|
||||
_players_ainew[p->index].state = AI_STATE_NOTHING;
|
||||
DoCommand(tile, _companies_ainew[c->index].veh_id, 0, DC_EXEC, CMD_SELL_ROAD_VEH);
|
||||
_companies_ainew[c->index].state = AI_STATE_NOTHING;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* XXX this should be handled more gracefully */
|
||||
_players_ainew[p->index].state = AI_STATE_NOTHING;
|
||||
_companies_ainew[c->index].state = AI_STATE_NOTHING;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Builds the best vehicle possible
|
||||
CommandCost AiNew_Build_Vehicle(Player *p, TileIndex tile, byte flag)
|
||||
CommandCost AiNew_Build_Vehicle(Company *c, TileIndex tile, byte flag)
|
||||
{
|
||||
EngineID i = AiNew_PickVehicle(p);
|
||||
EngineID i = AiNew_PickVehicle(c);
|
||||
|
||||
if (i == INVALID_ENGINE) return CMD_ERROR;
|
||||
if (_players_ainew[p->index].tbt == AI_TRAIN) return CMD_ERROR;
|
||||
if (_companies_ainew[c->index].tbt == AI_TRAIN) return CMD_ERROR;
|
||||
|
||||
if (flag & DC_EXEC) {
|
||||
return AI_DoCommandCc(tile, i, 0, flag, CMD_BUILD_ROAD_VEH, CcAI);
|
||||
|
@ -310,10 +310,10 @@ CommandCost AiNew_Build_Vehicle(Player *p, TileIndex tile, byte flag)
|
|||
}
|
||||
}
|
||||
|
||||
CommandCost AiNew_Build_Depot(Player* p, TileIndex tile, DiagDirection direction, byte flag)
|
||||
CommandCost AiNew_Build_Depot(Company *c, TileIndex tile, DiagDirection direction, byte flag)
|
||||
{
|
||||
CommandCost ret, ret2;
|
||||
if (_players_ainew[p->index].tbt == AI_TRAIN) {
|
||||
if (_companies_ainew[c->index].tbt == AI_TRAIN) {
|
||||
return AI_DoCommand(tile, 0, direction, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_TRAIN_DEPOT);
|
||||
} else {
|
||||
ret = AI_DoCommand(tile, direction, 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD_DEPOT);
|
||||
|
|
|
@ -24,21 +24,21 @@
|
|||
// TODO: make it train compatible
|
||||
static bool TestCanBuildStationHere(TileIndex tile, byte dir)
|
||||
{
|
||||
Player *p = GetPlayer(_current_player);
|
||||
Company *c = GetCompany(_current_company);
|
||||
|
||||
if (dir == TEST_STATION_NO_DIR) {
|
||||
CommandCost ret;
|
||||
// TODO: currently we only allow spots that can be access from al 4 directions...
|
||||
// should be fixed!!!
|
||||
for (dir = 0; dir < 4; dir++) {
|
||||
ret = AiNew_Build_Station(p, _players_ainew[p->index].tbt, tile, 1, 1, dir, DC_QUERY_COST);
|
||||
ret = AiNew_Build_Station(c, _companies_ainew[c->index].tbt, tile, 1, 1, dir, DC_QUERY_COST);
|
||||
if (CmdSucceeded(ret)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// return true if command succeeded, so the inverse of CmdFailed()
|
||||
return CmdSucceeded(AiNew_Build_Station(p, _players_ainew[p->index].tbt, tile, 1, 1, dir, DC_QUERY_COST));
|
||||
return CmdSucceeded(AiNew_Build_Station(c, _companies_ainew[c->index].tbt, tile, 1, 1, dir, DC_QUERY_COST));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -78,13 +78,13 @@ DiagDirection AiNew_GetDirection(TileIndex tile_a, TileIndex tile_b)
|
|||
|
||||
// This functions looks up if this vehicle is special for this AI
|
||||
// and returns his flag
|
||||
uint AiNew_GetSpecialVehicleFlag(Player* p, Vehicle* v)
|
||||
uint AiNew_GetSpecialVehicleFlag(Company *c, Vehicle *v)
|
||||
{
|
||||
uint i;
|
||||
|
||||
for (i = 0; i < AI_MAX_SPECIAL_VEHICLES; i++) {
|
||||
if (_players_ainew[p->index].special_vehicles[i].veh_id == v->index) {
|
||||
return _players_ainew[p->index].special_vehicles[i].flag;
|
||||
if (_companies_ainew[c->index].special_vehicles[i].veh_id == v->index) {
|
||||
return _companies_ainew[c->index].special_vehicles[i].flag;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,19 +93,19 @@ uint AiNew_GetSpecialVehicleFlag(Player* p, Vehicle* v)
|
|||
}
|
||||
|
||||
|
||||
bool AiNew_SetSpecialVehicleFlag(Player* p, Vehicle* v, uint flag)
|
||||
bool AiNew_SetSpecialVehicleFlag(Company *c, Vehicle *v, uint flag)
|
||||
{
|
||||
int new_id = -1;
|
||||
uint i;
|
||||
|
||||
for (i = 0; i < AI_MAX_SPECIAL_VEHICLES; i++) {
|
||||
if (_players_ainew[p->index].special_vehicles[i].veh_id == v->index) {
|
||||
_players_ainew[p->index].special_vehicles[i].flag |= flag;
|
||||
if (_companies_ainew[c->index].special_vehicles[i].veh_id == v->index) {
|
||||
_companies_ainew[c->index].special_vehicles[i].flag |= flag;
|
||||
return true;
|
||||
}
|
||||
if (new_id == -1 &&
|
||||
_players_ainew[p->index].special_vehicles[i].veh_id == 0 &&
|
||||
_players_ainew[p->index].special_vehicles[i].flag == 0) {
|
||||
_companies_ainew[c->index].special_vehicles[i].veh_id == 0 &&
|
||||
_companies_ainew[c->index].special_vehicles[i].flag == 0) {
|
||||
new_id = i;
|
||||
}
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ bool AiNew_SetSpecialVehicleFlag(Player* p, Vehicle* v, uint flag)
|
|||
DEBUG(ai, 1, "special_vehicles list is too small");
|
||||
return false;
|
||||
}
|
||||
_players_ainew[p->index].special_vehicles[new_id].veh_id = v->index;
|
||||
_players_ainew[p->index].special_vehicles[new_id].flag = flag;
|
||||
_companies_ainew[c->index].special_vehicles[new_id].veh_id = v->index;
|
||||
_companies_ainew[c->index].special_vehicles[new_id].flag = flag;
|
||||
return true;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -120,7 +120,7 @@
|
|||
// Minimum % of reliabilty a vehicle has to have before the AI buys it
|
||||
#define AI_VEHICLE_MIN_RELIABILTY 60
|
||||
|
||||
// The minimum amount of money a player should always have
|
||||
// The minimum amount of money a company should always have
|
||||
#define AI_MINIMUM_MONEY 15000
|
||||
|
||||
// If the most cheap route is build, how much is it going to cost..
|
||||
|
@ -148,7 +148,7 @@
|
|||
|
||||
// How many days must there between vehicle checks
|
||||
// The more often, the less non-money-making lines there will be
|
||||
// but the unfair it may seem to a human player
|
||||
// but the unfair it may seem to a human company
|
||||
#define AI_DAYS_BETWEEN_VEHICLE_CHECKS 30
|
||||
|
||||
// How money profit does a vehicle needs to make to stay in order
|
||||
|
@ -239,10 +239,10 @@ enum {
|
|||
#define AI_PATHFINDER_FLAG_BRIDGE 1
|
||||
#define AI_PATHFINDER_FLAG_TUNNEL 2
|
||||
|
||||
typedef void AiNew_StateFunction(Player *p);
|
||||
typedef void AiNew_StateFunction(Company *c);
|
||||
|
||||
// ai_new.c
|
||||
void AiNewDoGameLoop(Player *p);
|
||||
void AiNewDoGameLoop(Company *c);
|
||||
|
||||
struct Ai_PathFinderInfo {
|
||||
TileIndex start_tile_tl; ///< tl = top-left
|
||||
|
@ -268,17 +268,17 @@ void clean_AyStar_AiPathFinder(AyStar *aystar, Ai_PathFinderInfo *PathFinderInfo
|
|||
int AiNew_GetRailDirection(TileIndex tile_a, TileIndex tile_b, TileIndex tile_c);
|
||||
int AiNew_GetRoadDirection(TileIndex tile_a, TileIndex tile_b, TileIndex tile_c);
|
||||
DiagDirection AiNew_GetDirection(TileIndex tile_a, TileIndex tile_b);
|
||||
bool AiNew_SetSpecialVehicleFlag(Player *p, Vehicle *v, uint flag);
|
||||
uint AiNew_GetSpecialVehicleFlag(Player *p, Vehicle *v);
|
||||
bool AiNew_SetSpecialVehicleFlag(Company *c, Vehicle *v, uint flag);
|
||||
uint AiNew_GetSpecialVehicleFlag(Company *c, Vehicle *v);
|
||||
|
||||
// ai_build.c
|
||||
bool AiNew_Build_CompanyHQ(Player *p, TileIndex tile);
|
||||
CommandCost AiNew_Build_Station(Player *p, byte type, TileIndex tile, byte length, byte numtracks, byte direction, byte flag);
|
||||
CommandCost AiNew_Build_Bridge(Player *p, TileIndex tile_a, TileIndex tile_b, byte flag);
|
||||
CommandCost AiNew_Build_RoutePart(Player *p, Ai_PathFinderInfo *PathFinderInfo, byte flag);
|
||||
EngineID AiNew_PickVehicle(Player *p);
|
||||
CommandCost AiNew_Build_Vehicle(Player *p, TileIndex tile, byte flag);
|
||||
CommandCost AiNew_Build_Depot(Player* p, TileIndex tile, DiagDirection direction, byte flag);
|
||||
bool AiNew_Build_CompanyHQ(Company *c, TileIndex tile);
|
||||
CommandCost AiNew_Build_Station(Company *c, byte type, TileIndex tile, byte length, byte numtracks, byte direction, byte flag);
|
||||
CommandCost AiNew_Build_Bridge(Company *c, TileIndex tile_a, TileIndex tile_b, byte flag);
|
||||
CommandCost AiNew_Build_RoutePart(Company *c, Ai_PathFinderInfo *PathFinderInfo, byte flag);
|
||||
EngineID AiNew_PickVehicle(Company *c);
|
||||
CommandCost AiNew_Build_Vehicle(Company *c, TileIndex tile, byte flag);
|
||||
CommandCost AiNew_Build_Depot(Company *c, TileIndex tile, DiagDirection direction, byte flag);
|
||||
|
||||
/* The amount of memory reserved for the AI-special-vehicles */
|
||||
#define AI_MAX_SPECIAL_VEHICLES 100
|
||||
|
@ -288,7 +288,7 @@ struct Ai_SpecialVehicle {
|
|||
uint32 flag;
|
||||
};
|
||||
|
||||
struct PlayerAiNew {
|
||||
struct CompanyAiNew {
|
||||
uint8 state;
|
||||
uint tick;
|
||||
uint idle;
|
||||
|
@ -338,6 +338,6 @@ struct PlayerAiNew {
|
|||
int to_ic;
|
||||
byte to_type;
|
||||
};
|
||||
extern PlayerAiNew _players_ainew[MAX_PLAYERS];
|
||||
extern CompanyAiNew _companies_ainew[MAX_COMPANIES];
|
||||
|
||||
#endif /* AI_TROLLY_H */
|
||||
|
|
|
@ -104,7 +104,7 @@ enum HelicopterRotorStates {
|
|||
};
|
||||
|
||||
/** Find the nearest hangar to v
|
||||
* INVALID_STATION is returned, if the player does not have any suitable
|
||||
* INVALID_STATION is returned, if the company does not have any suitable
|
||||
* airports (like helipads only)
|
||||
* @param v vehicle looking for a hangar
|
||||
* @return the StationID if one is found, otherwise, INVALID_STATION
|
||||
|
@ -266,7 +266,7 @@ uint16 AircraftDefaultCargoCapacity(CargoID cid, const AircraftVehicleInfo *avi)
|
|||
*/
|
||||
CommandCost CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
||||
{
|
||||
if (!IsEngineBuildable(p1, VEH_AIRCRAFT, _current_player)) return_cmd_error(STR_AIRCRAFT_NOT_AVAILABLE);
|
||||
if (!IsEngineBuildable(p1, VEH_AIRCRAFT, _current_company)) return_cmd_error(STR_AIRCRAFT_NOT_AVAILABLE);
|
||||
|
||||
const AircraftVehicleInfo *avi = AircraftVehInfo(p1);
|
||||
CommandCost value = EstimateAircraftCost(p1, avi);
|
||||
|
@ -274,7 +274,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
/* to just query the cost, it is not neccessary to have a valid tile (automation/AI) */
|
||||
if (flags & DC_QUERY_COST) return value;
|
||||
|
||||
if (!IsHangarTile(tile) || !IsTileOwner(tile, _current_player)) return CMD_ERROR;
|
||||
if (!IsHangarTile(tile) || !IsTileOwner(tile, _current_company)) return CMD_ERROR;
|
||||
|
||||
/* Prevent building aircraft types at places which can't handle them */
|
||||
if (!CanAircraftUseStation(p1, tile)) return CMD_ERROR;
|
||||
|
@ -299,7 +299,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
v->unitnumber = unit_num;
|
||||
v->direction = DIR_SE;
|
||||
|
||||
v->owner = u->owner = _current_player;
|
||||
v->owner = u->owner = _current_company;
|
||||
|
||||
v->tile = tile;
|
||||
// u->tile = 0;
|
||||
|
@ -428,7 +428,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
|
||||
w = new (w) Aircraft();
|
||||
w->direction = DIR_N;
|
||||
w->owner = _current_player;
|
||||
w->owner = _current_company;
|
||||
w->x_pos = v->x_pos;
|
||||
w->y_pos = v->y_pos;
|
||||
w->z_pos = v->z_pos + 5;
|
||||
|
@ -448,10 +448,10 @@ CommandCost CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
|
||||
InvalidateWindowClassesData(WC_AIRCRAFT_LIST, 0);
|
||||
InvalidateWindow(WC_COMPANY, v->owner);
|
||||
if (IsLocalPlayer())
|
||||
if (IsLocalCompany())
|
||||
InvalidateAutoreplaceWindow(v->engine_type, v->group_id); //updates the replace Aircraft window
|
||||
|
||||
GetPlayer(_current_player)->num_engines[p1]++;
|
||||
GetCompany(_current_company)->num_engines[p1]++;
|
||||
}
|
||||
|
||||
return value;
|
||||
|
@ -529,7 +529,7 @@ CommandCost CmdSendAircraftToHangar(TileIndex tile, uint32 flags, uint32 p1, uin
|
|||
if (p2 & DEPOT_MASS_SEND) {
|
||||
/* Mass goto depot requested */
|
||||
if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR;
|
||||
return SendAllVehiclesToDepot(VEH_AIRCRAFT, flags, p2 & DEPOT_SERVICE, _current_player, (p2 & VLW_MASK), p1);
|
||||
return SendAllVehiclesToDepot(VEH_AIRCRAFT, flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1);
|
||||
}
|
||||
|
||||
if (!IsValidVehicleID(p1)) return CMD_ERROR;
|
||||
|
@ -597,7 +597,7 @@ CommandCost CmdRefitAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
_returned_refit_capacity = pass;
|
||||
|
||||
CommandCost cost;
|
||||
if (IsHumanPlayer(v->owner) && new_cid != v->cargo_type) {
|
||||
if (IsHumanCompany(v->owner) && new_cid != v->cargo_type) {
|
||||
cost = GetRefitCost(v->engine_type);
|
||||
}
|
||||
|
||||
|
@ -660,7 +660,7 @@ void Aircraft::OnNewDay()
|
|||
this->profit_this_year -= cost.GetCost();
|
||||
this->running_ticks = 0;
|
||||
|
||||
SubtractMoneyFromPlayerFract(this->owner, cost);
|
||||
SubtractMoneyFromCompanyFract(this->owner, cost);
|
||||
|
||||
InvalidateWindow(WC_VEHICLE_DETAILS, this->index);
|
||||
InvalidateWindowClasses(WC_AIRCRAFT_LIST);
|
||||
|
@ -1312,11 +1312,11 @@ void HandleMissingAircraftOrders(Vehicle *v)
|
|||
const Station *st = GetTargetAirportIfValid(v);
|
||||
if (st == NULL) {
|
||||
CommandCost ret;
|
||||
PlayerID old_player = _current_player;
|
||||
CompanyID old_company = _current_company;
|
||||
|
||||
_current_player = v->owner;
|
||||
_current_company = v->owner;
|
||||
ret = DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR);
|
||||
_current_player = old_player;
|
||||
_current_company = old_company;
|
||||
|
||||
if (CmdFailed(ret)) CrashAirplane(v);
|
||||
} else if (!v->current_order.IsType(OT_GOTO_DEPOT)) {
|
||||
|
@ -1413,7 +1413,7 @@ static void AircraftEntersTerminal(Vehicle *v)
|
|||
/* show newsitem of celebrating citizens */
|
||||
AddNewsItem(
|
||||
STR_A033_CITIZENS_CELEBRATE_FIRST,
|
||||
(v->owner == _local_player) ? NS_ARRIVAL_PLAYER : NS_ARRIVAL_OTHER,
|
||||
(v->owner == _local_company) ? NS_ARRIVAL_COMPANY : NS_ARRIVAL_OTHER,
|
||||
v->index,
|
||||
st->index
|
||||
);
|
||||
|
@ -1477,28 +1477,28 @@ static void AircraftLeaveHangar(Vehicle *v)
|
|||
static inline bool CheckSendAircraftToHangarForReplacement(const Vehicle *v)
|
||||
{
|
||||
EngineID new_engine;
|
||||
Player *p = GetPlayer(v->owner);
|
||||
Company *c = GetCompany(v->owner);
|
||||
|
||||
if (VehicleHasDepotOrders(v)) return false; // The aircraft will end up in the hangar eventually on it's own
|
||||
|
||||
new_engine = EngineReplacementForPlayer(p, v->engine_type, v->group_id);
|
||||
new_engine = EngineReplacementForCompany(c, v->engine_type, v->group_id);
|
||||
|
||||
if (new_engine == INVALID_ENGINE) {
|
||||
/* There is no autoreplace assigned to this EngineID so we will set it to renew to the same type if needed */
|
||||
new_engine = v->engine_type;
|
||||
|
||||
if (!v->NeedsAutorenewing(p)) {
|
||||
if (!v->NeedsAutorenewing(c)) {
|
||||
/* No need to replace the aircraft */
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!HasBit(GetEngine(new_engine)->player_avail, v->owner)) {
|
||||
if (!HasBit(GetEngine(new_engine)->company_avail, v->owner)) {
|
||||
/* Engine is not buildable anymore */
|
||||
return false;
|
||||
}
|
||||
|
||||
if (p->player_money < (p->engine_renew_money + (2 * DoCommand(0, new_engine, 0, DC_QUERY_COST, CMD_BUILD_AIRCRAFT).GetCost()))) {
|
||||
if (c->money < (c->engine_renew_money + (2 * DoCommand(0, new_engine, 0, DC_QUERY_COST, CMD_BUILD_AIRCRAFT).GetCost()))) {
|
||||
/* We lack enough money to request the replacement right away.
|
||||
* We want 2*(the price of the new vehicle) and not looking at the value of the vehicle we are going to sell.
|
||||
* The reason is that we don't want to send a whole lot of vehicles to the hangars when we only have enough money to replace a single one.
|
||||
|
@ -1652,9 +1652,9 @@ static void AircraftEventHandler_HeliTakeOff(Vehicle *v, const AirportFTAClass *
|
|||
|
||||
/* Send the helicopter to a hangar if needed for replacement */
|
||||
if (CheckSendAircraftToHangarForReplacement(v)) {
|
||||
_current_player = v->owner;
|
||||
_current_company = v->owner;
|
||||
DoCommand(v->tile, v->index, DEPOT_SERVICE | DEPOT_LOCATE_HANGAR, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR);
|
||||
_current_player = OWNER_NONE;
|
||||
_current_company = OWNER_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1704,9 +1704,9 @@ static void AircraftEventHandler_Landing(Vehicle *v, const AirportFTAClass *apc)
|
|||
|
||||
/* check if the aircraft needs to be replaced or renewed and send it to a hangar if needed */
|
||||
if (CheckSendAircraftToHangarForReplacement(v)) {
|
||||
_current_player = v->owner;
|
||||
_current_company = v->owner;
|
||||
DoCommand(v->tile, v->index, DEPOT_SERVICE, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR);
|
||||
_current_player = OWNER_NONE;
|
||||
_current_company = OWNER_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -146,7 +146,7 @@ static const WindowDesc _air_toolbar_desc = {
|
|||
|
||||
void ShowBuildAirToolbar()
|
||||
{
|
||||
if (!IsValidPlayerID(_current_player)) return;
|
||||
if (!IsValidCompanyID(_current_company)) return;
|
||||
|
||||
DeleteWindowByClass(WC_BUILD_TOOLBAR);
|
||||
AllocateWindowDescFront<BuildAirToolbarWindow>(&_air_toolbar_desc, TRANSPORT_AIR);
|
||||
|
|
|
@ -39,10 +39,10 @@ static bool EnginesGotCargoInCommon(EngineID engine_a, EngineID engine_b, Vehicl
|
|||
* Checks some basic properties whether autoreplace is allowed
|
||||
* @param from Origin engine
|
||||
* @param to Destination engine
|
||||
* @param player Player to check for
|
||||
* @param company Company to check for
|
||||
* @return true if autoreplace is allowed
|
||||
*/
|
||||
bool CheckAutoreplaceValidity(EngineID from, EngineID to, PlayerID player)
|
||||
bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company)
|
||||
{
|
||||
/* First we make sure that it's a valid type the user requested
|
||||
* check that it's an engine that is in the engine array */
|
||||
|
@ -53,8 +53,8 @@ bool CheckAutoreplaceValidity(EngineID from, EngineID to, PlayerID player)
|
|||
|
||||
VehicleType type = GetEngine(from)->type;
|
||||
|
||||
/* check that the new vehicle type is available to the player and its type is the same as the original one */
|
||||
if (!IsEngineBuildable(to, type, player)) return false;
|
||||
/* check that the new vehicle type is available to the company and its type is the same as the original one */
|
||||
if (!IsEngineBuildable(to, type, company)) return false;
|
||||
|
||||
switch (type) {
|
||||
case VEH_TRAIN: {
|
||||
|
@ -213,10 +213,10 @@ static CargoID GetNewCargoTypeForReplace(Vehicle *v, EngineID engine_type, bool
|
|||
|
||||
/** Get the EngineID of the replacement for a vehicle
|
||||
* @param v The vehicle to find a replacement for
|
||||
* @param p The vehicle's owner (it's faster to forward the pointer than refinding it)
|
||||
* @param c The vehicle's owner (it's faster to forward the pointer than refinding it)
|
||||
* @return the EngineID of the replacement. INVALID_ENGINE if no buildable replacement is found
|
||||
*/
|
||||
static EngineID GetNewEngineType(const Vehicle *v, const Player *p)
|
||||
static EngineID GetNewEngineType(const Vehicle *v, const Company *c)
|
||||
{
|
||||
assert(v->type != VEH_TRAIN || !IsArticulatedPart(v));
|
||||
|
||||
|
@ -225,14 +225,14 @@ static EngineID GetNewEngineType(const Vehicle *v, const Player *p)
|
|||
return INVALID_ENGINE;
|
||||
}
|
||||
|
||||
EngineID e = EngineReplacementForPlayer(p, v->engine_type, v->group_id);
|
||||
EngineID e = EngineReplacementForCompany(c, v->engine_type, v->group_id);
|
||||
|
||||
if (e != INVALID_ENGINE && IsEngineBuildable(e, v->type, _current_player)) {
|
||||
if (e != INVALID_ENGINE && IsEngineBuildable(e, v->type, _current_company)) {
|
||||
return e;
|
||||
}
|
||||
|
||||
if (v->NeedsAutorenewing(p) && // replace if engine is too old
|
||||
IsEngineBuildable(v->engine_type, v->type, _current_player)) { // engine can still be build
|
||||
if (v->NeedsAutorenewing(c) && // replace if engine is too old
|
||||
IsEngineBuildable(v->engine_type, v->type, _current_company)) { // engine can still be build
|
||||
return v->engine_type;
|
||||
}
|
||||
|
||||
|
@ -251,8 +251,8 @@ static CommandCost BuildReplacementVehicle(Vehicle *old_veh, Vehicle **new_vehic
|
|||
*new_vehicle = NULL;
|
||||
|
||||
/* Shall the vehicle be replaced? */
|
||||
const Player *p = GetPlayer(_current_player);
|
||||
EngineID e = GetNewEngineType(old_veh, p);
|
||||
const Company *c = GetCompany(_current_company);
|
||||
EngineID e = GetNewEngineType(old_veh, c);
|
||||
if (e == INVALID_ENGINE) return CommandCost(); // neither autoreplace is set, nor autorenew is triggered
|
||||
|
||||
/* Does it need to be refitted */
|
||||
|
@ -627,14 +627,14 @@ CommandCost CmdAutoreplaceVehicle(TileIndex tile, uint32 flags, uint32 p1, uint3
|
|||
if (!v->IsPrimaryVehicle()) return CMD_ERROR;
|
||||
}
|
||||
|
||||
const Player *p = GetPlayer(_current_player);
|
||||
bool wagon_removal = p->renew_keep_length;
|
||||
const Company *c = GetCompany(_current_company);
|
||||
bool wagon_removal = c->renew_keep_length;
|
||||
|
||||
/* Test whether any replacement is set, before issuing a whole lot of commands that would end in nothing changed */
|
||||
Vehicle *w = v;
|
||||
bool any_replacements = false;
|
||||
while (w != NULL && !any_replacements) {
|
||||
any_replacements = (GetNewEngineType(w, p) != INVALID_ENGINE);
|
||||
any_replacements = (GetNewEngineType(w, c) != INVALID_ENGINE);
|
||||
w = (!free_wagon && w->type == VEH_TRAIN ? GetNextUnit(w) : NULL);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
#include "player_base.h"
|
||||
|
||||
/**
|
||||
* Remove all engine replacement settings for the player.
|
||||
* @param erl The renewlist for a given player.
|
||||
* @return The new renewlist for the player.
|
||||
* Remove all engine replacement settings for the company.
|
||||
* @param erl The renewlist for a given company.
|
||||
* @return The new renewlist for the company.
|
||||
*/
|
||||
void RemoveAllEngineReplacement(EngineRenewList *erl);
|
||||
|
||||
|
@ -44,62 +44,62 @@ CommandCost AddEngineReplacement(EngineRenewList *erl, EngineID old_engine, Engi
|
|||
CommandCost RemoveEngineReplacement(EngineRenewList *erl, EngineID engine, GroupID group, uint32 flags);
|
||||
|
||||
/**
|
||||
* Remove all engine replacement settings for the given player.
|
||||
* @param p Player.
|
||||
* Remove all engine replacement settings for the given company.
|
||||
* @param c the company.
|
||||
*/
|
||||
static inline void RemoveAllEngineReplacementForPlayer(Player *p)
|
||||
static inline void RemoveAllEngineReplacementForCompany(Company *c)
|
||||
{
|
||||
RemoveAllEngineReplacement(&p->engine_renew_list);
|
||||
RemoveAllEngineReplacement(&c->engine_renew_list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the engine replacement for the given player and original engine type.
|
||||
* @param p Player.
|
||||
* Retrieve the engine replacement for the given company and original engine type.
|
||||
* @param c company.
|
||||
* @param engine Engine type.
|
||||
* @return The engine type to replace with, or INVALID_ENGINE if no
|
||||
* replacement is in the list.
|
||||
*/
|
||||
static inline EngineID EngineReplacementForPlayer(const Player *p, EngineID engine, GroupID group)
|
||||
static inline EngineID EngineReplacementForCompany(const Company *c, EngineID engine, GroupID group)
|
||||
{
|
||||
return EngineReplacement(p->engine_renew_list, engine, group);
|
||||
return EngineReplacement(c->engine_renew_list, engine, group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a player has a replacement set up for the given engine.
|
||||
* @param p Player.
|
||||
* Check if a company has a replacement set up for the given engine.
|
||||
* @param c Company.
|
||||
* @param engine Engine type to be replaced.
|
||||
* @return true if a replacement was set up, false otherwise.
|
||||
*/
|
||||
static inline bool EngineHasReplacementForPlayer(const Player *p, EngineID engine, GroupID group)
|
||||
static inline bool EngineHasReplacementForCompany(const Company *c, EngineID engine, GroupID group)
|
||||
{
|
||||
return EngineReplacementForPlayer(p, engine, group) != INVALID_ENGINE;
|
||||
return EngineReplacementForCompany(c, engine, group) != INVALID_ENGINE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an engine replacement for the player.
|
||||
* @param p Player.
|
||||
* Add an engine replacement for the company.
|
||||
* @param c Company.
|
||||
* @param old_engine The original engine type.
|
||||
* @param new_engine The replacement engine type.
|
||||
* @param flags The calling command flags.
|
||||
* @return 0 on success, CMD_ERROR on failure.
|
||||
*/
|
||||
static inline CommandCost AddEngineReplacementForPlayer(Player *p, EngineID old_engine, EngineID new_engine, GroupID group, uint32 flags)
|
||||
static inline CommandCost AddEngineReplacementForCompany(Company *c, EngineID old_engine, EngineID new_engine, GroupID group, uint32 flags)
|
||||
{
|
||||
return AddEngineReplacement(&p->engine_renew_list, old_engine, new_engine, group, flags);
|
||||
return AddEngineReplacement(&c->engine_renew_list, old_engine, new_engine, group, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an engine replacement for the player.
|
||||
* @param p Player.
|
||||
* Remove an engine replacement for the company.
|
||||
* @param c Company.
|
||||
* @param engine The original engine type.
|
||||
* @param flags The calling command flags.
|
||||
* @return 0 on success, CMD_ERROR on failure.
|
||||
*/
|
||||
static inline CommandCost RemoveEngineReplacementForPlayer(Player *p, EngineID engine, GroupID group, uint32 flags)
|
||||
static inline CommandCost RemoveEngineReplacementForCompany(Company *c, EngineID engine, GroupID group, uint32 flags)
|
||||
{
|
||||
return RemoveEngineReplacement(&p->engine_renew_list, engine, group, flags);
|
||||
return RemoveEngineReplacement(&c->engine_renew_list, engine, group, flags);
|
||||
}
|
||||
|
||||
bool CheckAutoreplaceValidity(EngineID from, EngineID to, PlayerID player);
|
||||
bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company);
|
||||
|
||||
#endif /* AUTOREPLACE_FUNC_H */
|
||||
|
|
|
@ -71,10 +71,10 @@ static int CDECL EngineNumberSorter(const void *a, const void *b)
|
|||
*/
|
||||
void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g)
|
||||
{
|
||||
Player *p = GetPlayer(_local_player);
|
||||
uint num_engines = GetGroupNumEngines(_local_player, id_g, e);
|
||||
Company *c = GetCompany(_local_company);
|
||||
uint num_engines = GetGroupNumEngines(_local_company, id_g, e);
|
||||
|
||||
if (num_engines == 0 || p->num_engines[e] == 0) {
|
||||
if (num_engines == 0 || c->num_engines[e] == 0) {
|
||||
/* We don't have any of this engine type.
|
||||
* Either we just sold the last one, we build a new one or we stopped replacing it.
|
||||
* In all cases, we need to update the left list */
|
||||
|
@ -147,12 +147,12 @@ class ReplaceVehicleWindow : public Window {
|
|||
|
||||
if (draw_left) {
|
||||
const GroupID selected_group = this->sel_group;
|
||||
const uint num_engines = GetGroupNumEngines(_local_player, selected_group, eid);
|
||||
const uint num_engines = GetGroupNumEngines(_local_company, selected_group, eid);
|
||||
|
||||
/* Skip drawing the engines we don't have any of and haven't set for replacement */
|
||||
if (num_engines == 0 && EngineReplacementForPlayer(GetPlayer(_local_player), eid, selected_group) == INVALID_ENGINE) continue;
|
||||
if (num_engines == 0 && EngineReplacementForCompany(GetCompany(_local_company), eid, selected_group) == INVALID_ENGINE) continue;
|
||||
} else {
|
||||
if (!CheckAutoreplaceValidity(this->sel_engine[0], eid, _local_player)) continue;
|
||||
if (!CheckAutoreplaceValidity(this->sel_engine[0], eid, _local_company)) continue;
|
||||
}
|
||||
|
||||
*list->Append() = eid;
|
||||
|
@ -244,7 +244,7 @@ public:
|
|||
this->resize.width = this->width;
|
||||
this->resize.height = this->height;
|
||||
|
||||
this->caption_color = _local_player;
|
||||
this->caption_color = _local_company;
|
||||
this->sel_group = id_g;
|
||||
this->vscroll2.cap = this->vscroll.cap; // these two are always the same
|
||||
|
||||
|
@ -262,7 +262,7 @@ public:
|
|||
|
||||
if (this->update_left || this->update_right) this->GenerateLists();
|
||||
|
||||
Player *p = GetPlayer(_local_player);
|
||||
Company *c = GetCompany(_local_company);
|
||||
EngineID selected_id[2];
|
||||
const GroupID selected_group = this->sel_group;
|
||||
|
||||
|
@ -276,29 +276,29 @@ public:
|
|||
this->SetWidgetDisabledState(RVW_WIDGET_START_REPLACE,
|
||||
selected_id[0] == INVALID_ENGINE ||
|
||||
selected_id[1] == INVALID_ENGINE ||
|
||||
EngineReplacementForPlayer(p, selected_id[1], selected_group) != INVALID_ENGINE ||
|
||||
EngineReplacementForPlayer(p, selected_id[0], selected_group) == selected_id[1]);
|
||||
EngineReplacementForCompany(c, selected_id[1], selected_group) != INVALID_ENGINE ||
|
||||
EngineReplacementForCompany(c, selected_id[0], selected_group) == selected_id[1]);
|
||||
|
||||
/* Disable the "Stop Replacing" button if:
|
||||
* The left list (existing vehicle) is empty
|
||||
* or The selected vehicle has no replacement set up */
|
||||
this->SetWidgetDisabledState(RVW_WIDGET_STOP_REPLACE,
|
||||
selected_id[0] == INVALID_ENGINE ||
|
||||
!EngineHasReplacementForPlayer(p, selected_id[0], selected_group));
|
||||
!EngineHasReplacementForCompany(c, selected_id[0], selected_group));
|
||||
|
||||
/* now the actual drawing of the window itself takes place */
|
||||
SetDParam(0, _vehicle_type_names[this->window_number]);
|
||||
|
||||
if (this->window_number == VEH_TRAIN) {
|
||||
/* set on/off for renew_keep_length */
|
||||
SetDParam(1, p->renew_keep_length ? STR_CONFIG_PATCHES_ON : STR_CONFIG_PATCHES_OFF);
|
||||
SetDParam(1, c->renew_keep_length ? STR_CONFIG_PATCHES_ON : STR_CONFIG_PATCHES_OFF);
|
||||
|
||||
/* set wagon/engine button */
|
||||
SetDParam(2, this->wagon_btnstate ? STR_ENGINES : STR_WAGONS);
|
||||
|
||||
/* sets the colour of that art thing */
|
||||
this->widget[RVW_WIDGET_TRAIN_FLUFF_LEFT].color = _player_colors[_local_player];
|
||||
this->widget[RVW_WIDGET_TRAIN_FLUFF_RIGHT].color = _player_colors[_local_player];
|
||||
this->widget[RVW_WIDGET_TRAIN_FLUFF_LEFT].color = _company_colours[_local_company];
|
||||
this->widget[RVW_WIDGET_TRAIN_FLUFF_RIGHT].color = _company_colours[_local_company];
|
||||
}
|
||||
|
||||
if (this->window_number == VEH_TRAIN) {
|
||||
|
@ -311,11 +311,11 @@ public:
|
|||
|
||||
/* sets up the string for the vehicle that is being replaced to */
|
||||
if (selected_id[0] != INVALID_ENGINE) {
|
||||
if (!EngineHasReplacementForPlayer(p, selected_id[0], selected_group)) {
|
||||
if (!EngineHasReplacementForCompany(c, selected_id[0], selected_group)) {
|
||||
SetDParam(0, STR_NOT_REPLACING);
|
||||
} else {
|
||||
SetDParam(0, STR_ENGINE_NAME);
|
||||
SetDParam(1, EngineReplacementForPlayer(p, selected_id[0], selected_group));
|
||||
SetDParam(1, EngineReplacementForCompany(c, selected_id[0], selected_group));
|
||||
}
|
||||
} else {
|
||||
SetDParam(0, STR_NOT_REPLACING_VEHICLE_SELECTED);
|
||||
|
@ -358,19 +358,19 @@ public:
|
|||
break;
|
||||
|
||||
case RVW_WIDGET_TRAIN_RAILTYPE_DROPDOWN: { /* Railtype selection dropdown menu */
|
||||
const Player *p = GetPlayer(_local_player);
|
||||
const Company *c = GetCompany(_local_company);
|
||||
DropDownList *list = new DropDownList();
|
||||
for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) {
|
||||
const RailtypeInfo *rti = GetRailTypeInfo(rt);
|
||||
|
||||
list->push_back(new DropDownListStringItem(rti->strings.replace_text, rt, !HasBit(p->avail_railtypes, rt)));
|
||||
list->push_back(new DropDownListStringItem(rti->strings.replace_text, rt, !HasBit(c->avail_railtypes, rt)));
|
||||
}
|
||||
ShowDropDownList(this, list, sel_railtype, RVW_WIDGET_TRAIN_RAILTYPE_DROPDOWN);
|
||||
break;
|
||||
}
|
||||
|
||||
case RVW_WIDGET_TRAIN_WAGONREMOVE_TOGGLE: /* toggle renew_keep_length */
|
||||
DoCommandP(0, 5, GetPlayer(_local_player)->renew_keep_length ? 0 : 1, NULL, CMD_SET_AUTOREPLACE);
|
||||
DoCommandP(0, 5, GetCompany(_local_company)->renew_keep_length ? 0 : 1, NULL, CMD_SET_AUTOREPLACE);
|
||||
break;
|
||||
|
||||
case RVW_WIDGET_START_REPLACE: { /* Start replacing */
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
struct EngineRenew;
|
||||
|
||||
/**
|
||||
* A list to group EngineRenew directives together (such as per-player).
|
||||
* A list to group EngineRenew directives together (such as per-company).
|
||||
*/
|
||||
typedef EngineRenew* EngineRenewList;
|
||||
typedef EngineRenew *EngineRenewList;
|
||||
|
||||
#endif /* AUTOREPLACE_TYPE_H */
|
||||
|
|
|
@ -30,17 +30,17 @@ static inline bool AutoslopeCheckForEntranceEdge(TileIndex tile, uint z_new, Slo
|
|||
}
|
||||
|
||||
/**
|
||||
* Tests if autoslope is enabled for _current_player.
|
||||
* Tests if autoslope is enabled for _current_company.
|
||||
*
|
||||
* Autoslope is disabled for town/industry construction and old ai players.
|
||||
* Autoslope is disabled for town/industry construction and old ai companies.
|
||||
*
|
||||
* @return true iff autoslope is enabled.
|
||||
*/
|
||||
static inline bool AutoslopeEnabled()
|
||||
{
|
||||
return (_settings_game.construction.autoslope &&
|
||||
((_current_player < MAX_PLAYERS && !_is_old_ai_player) ||
|
||||
(_current_player == OWNER_NONE && _game_mode == GM_EDITOR)));
|
||||
((_current_company < MAX_COMPANIES && !_is_old_ai_company) ||
|
||||
(_current_company == OWNER_NONE && _game_mode == GM_EDITOR)));
|
||||
}
|
||||
|
||||
#endif /* AUTOSLOPE_H */
|
||||
|
|
|
@ -776,12 +776,12 @@ void DrawEngineList(VehicleType type, int x, int r, int y, const GUIEngineList *
|
|||
|
||||
for (; min < max; min++, y += step_size) {
|
||||
const EngineID engine = (*eng_list)[min];
|
||||
/* Note: num_engines is only used in the autoreplace GUI, so it is correct to use _local_player here. */
|
||||
const uint num_engines = GetGroupNumEngines(_local_player, selected_group, engine);
|
||||
/* Note: num_engines is only used in the autoreplace GUI, so it is correct to use _local_company here. */
|
||||
const uint num_engines = GetGroupNumEngines(_local_company, selected_group, engine);
|
||||
|
||||
SetDParam(0, engine);
|
||||
DrawStringTruncated(x + x_offset, y, STR_ENGINE_NAME, engine == selected_id ? TC_WHITE : TC_BLACK, maxw);
|
||||
DrawVehicleEngine(type, x, y + y_offset, engine, (count_location != 0 && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_player));
|
||||
DrawVehicleEngine(type, x, y + y_offset, engine, (count_location != 0 && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_company));
|
||||
if (count_location != 0) {
|
||||
SetDParam(0, num_engines);
|
||||
DrawStringRightAligned(count_location, y + (GetVehicleListHeight(type) == 14 ? 3 : 8), STR_TINY_BLACK, TC_FROMSTRING);
|
||||
|
@ -818,7 +818,7 @@ struct BuildVehicleWindow : Window {
|
|||
this->resize.width = this->width;
|
||||
this->resize.height = this->height;
|
||||
|
||||
this->caption_color = (tile != 0) ? GetTileOwner(tile) : _local_player;
|
||||
this->caption_color = (tile != 0) ? GetTileOwner(tile) : _local_company;
|
||||
|
||||
this->sel_engine = INVALID_ENGINE;
|
||||
this->regenerate_list = false;
|
||||
|
@ -925,7 +925,7 @@ struct BuildVehicleWindow : Window {
|
|||
const RailVehicleInfo *rvi = &e->u.rail;
|
||||
|
||||
if (this->filter.railtype != RAILTYPE_END && !HasPowerOnRail(rvi->railtype, this->filter.railtype)) continue;
|
||||
if (!IsEngineBuildable(eid, VEH_TRAIN, _local_player)) continue;
|
||||
if (!IsEngineBuildable(eid, VEH_TRAIN, _local_company)) continue;
|
||||
|
||||
*this->eng_list.Append() = eid;
|
||||
|
||||
|
@ -962,7 +962,7 @@ struct BuildVehicleWindow : Window {
|
|||
const Engine *e;
|
||||
FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) {
|
||||
EngineID eid = e->index;
|
||||
if (!IsEngineBuildable(eid, VEH_ROAD, _local_player)) continue;
|
||||
if (!IsEngineBuildable(eid, VEH_ROAD, _local_company)) continue;
|
||||
if (!HasBit(this->filter.roadtypes, HasBit(EngInfo(eid)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD)) continue;
|
||||
*this->eng_list.Append() = eid;
|
||||
|
||||
|
@ -980,7 +980,7 @@ struct BuildVehicleWindow : Window {
|
|||
const Engine *e;
|
||||
FOR_ALL_ENGINES_OF_TYPE(e, VEH_SHIP) {
|
||||
EngineID eid = e->index;
|
||||
if (!IsEngineBuildable(eid, VEH_SHIP, _local_player)) continue;
|
||||
if (!IsEngineBuildable(eid, VEH_SHIP, _local_company)) continue;
|
||||
*this->eng_list.Append() = eid;
|
||||
|
||||
if (eid == this->sel_engine) sel_id = eid;
|
||||
|
@ -1002,7 +1002,7 @@ struct BuildVehicleWindow : Window {
|
|||
const Engine *e;
|
||||
FOR_ALL_ENGINES_OF_TYPE(e, VEH_AIRCRAFT) {
|
||||
EngineID eid = e->index;
|
||||
if (!IsEngineBuildable(eid, VEH_AIRCRAFT, _local_player)) continue;
|
||||
if (!IsEngineBuildable(eid, VEH_AIRCRAFT, _local_company)) continue;
|
||||
/* First VEH_END window_numbers are fake to allow a window open for all different types at once */
|
||||
if (!this->listview_mode && !CanAircraftUseStation(eid, this->window_number)) continue;
|
||||
|
||||
|
@ -1207,7 +1207,7 @@ void ShowBuildVehicleWindow(TileIndex tile, VehicleType type)
|
|||
* number. */
|
||||
uint num = (tile == 0) ? (int)type : tile;
|
||||
|
||||
assert(IsPlayerBuildableVehicleType(type));
|
||||
assert(IsCompanyBuildableVehicleType(type));
|
||||
|
||||
DeleteWindowById(WC_BUILD_VEHICLE, num);
|
||||
|
||||
|
|
|
@ -39,22 +39,22 @@ static int32 ClickMoneyCheat(int32 p1, int32 p2)
|
|||
}
|
||||
|
||||
/**
|
||||
* @param p1 player to set to
|
||||
* @param p1 company to set to
|
||||
* @param p2 is -1 or +1 (down/up)
|
||||
*/
|
||||
static int32 ClickChangePlayerCheat(int32 p1, int32 p2)
|
||||
static int32 ClickChangeCompanyCheat(int32 p1, int32 p2)
|
||||
{
|
||||
while ((uint)p1 < GetPlayerPoolSize()) {
|
||||
if (IsValidPlayerID((PlayerID)p1)) {
|
||||
SetLocalPlayer((PlayerID)p1);
|
||||
while ((uint)p1 < GetCompanyPoolSize()) {
|
||||
if (IsValidCompanyID((CompanyID)p1)) {
|
||||
SetLocalCompany((CompanyID)p1);
|
||||
|
||||
MarkWholeScreenDirty();
|
||||
return _local_player;
|
||||
return _local_company;
|
||||
}
|
||||
p1 += p2;
|
||||
}
|
||||
|
||||
return _local_player;
|
||||
return _local_company;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -106,15 +106,15 @@ struct CheatEntry {
|
|||
};
|
||||
|
||||
static const CheatEntry _cheats_ui[] = {
|
||||
{SLE_INT32, STR_CHEAT_MONEY, &_money_cheat_amount, &_cheats.money.been_used, &ClickMoneyCheat },
|
||||
{SLE_UINT8, STR_CHEAT_CHANGE_PLAYER, &_local_player, &_cheats.switch_player.been_used, &ClickChangePlayerCheat },
|
||||
{SLE_BOOL, STR_CHEAT_EXTRA_DYNAMITE, &_cheats.magic_bulldozer.value, &_cheats.magic_bulldozer.been_used, NULL },
|
||||
{SLE_BOOL, STR_CHEAT_CROSSINGTUNNELS, &_cheats.crossing_tunnels.value, &_cheats.crossing_tunnels.been_used, NULL },
|
||||
{SLE_BOOL, STR_CHEAT_BUILD_IN_PAUSE, &_cheats.build_in_pause.value, &_cheats.build_in_pause.been_used, NULL },
|
||||
{SLE_BOOL, STR_CHEAT_NO_JETCRASH, &_cheats.no_jetcrash.value, &_cheats.no_jetcrash.been_used, NULL },
|
||||
{SLE_BOOL, STR_CHEAT_SETUP_PROD, &_cheats.setup_prod.value, &_cheats.setup_prod.been_used, NULL },
|
||||
{SLE_UINT8, STR_CHEAT_SWITCH_CLIMATE, &_settings_game.game_creation.landscape, &_cheats.switch_climate.been_used, &ClickChangeClimateCheat},
|
||||
{SLE_INT32, STR_CHEAT_CHANGE_DATE, &_cur_year, &_cheats.change_date.been_used, &ClickChangeDateCheat },
|
||||
{SLE_INT32, STR_CHEAT_MONEY, &_money_cheat_amount, &_cheats.money.been_used, &ClickMoneyCheat },
|
||||
{SLE_UINT8, STR_CHEAT_CHANGE_PLAYER, &_local_company, &_cheats.switch_company.been_used, &ClickChangeCompanyCheat },
|
||||
{SLE_BOOL, STR_CHEAT_EXTRA_DYNAMITE, &_cheats.magic_bulldozer.value, &_cheats.magic_bulldozer.been_used, NULL },
|
||||
{SLE_BOOL, STR_CHEAT_CROSSINGTUNNELS, &_cheats.crossing_tunnels.value, &_cheats.crossing_tunnels.been_used, NULL },
|
||||
{SLE_BOOL, STR_CHEAT_BUILD_IN_PAUSE, &_cheats.build_in_pause.value, &_cheats.build_in_pause.been_used, NULL },
|
||||
{SLE_BOOL, STR_CHEAT_NO_JETCRASH, &_cheats.no_jetcrash.value, &_cheats.no_jetcrash.been_used, NULL },
|
||||
{SLE_BOOL, STR_CHEAT_SETUP_PROD, &_cheats.setup_prod.value, &_cheats.setup_prod.been_used, NULL },
|
||||
{SLE_UINT8, STR_CHEAT_SWITCH_CLIMATE, &_settings_game.game_creation.landscape, &_cheats.switch_climate.been_used, &ClickChangeClimateCheat },
|
||||
{SLE_INT32, STR_CHEAT_CHANGE_DATE, &_cur_year, &_cheats.change_date.been_used, &ClickChangeDateCheat },
|
||||
};
|
||||
|
||||
|
||||
|
@ -163,11 +163,11 @@ struct CheatWindow : Window {
|
|||
/* Display date for change date cheat */
|
||||
case STR_CHEAT_CHANGE_DATE: SetDParam(0, _date); break;
|
||||
|
||||
/* Draw colored flag for change player cheat */
|
||||
/* Draw colored flag for change company cheat */
|
||||
case STR_CHEAT_CHANGE_PLAYER:
|
||||
SetDParam(0, val);
|
||||
GetString(buf, STR_CHEAT_CHANGE_PLAYER, lastof(buf));
|
||||
DrawPlayerIcon(_current_player, 60 + GetStringBoundingBox(buf).width, y + 2);
|
||||
DrawCompanyIcon(_current_company, 60 + GetStringBoundingBox(buf).width, y + 2);
|
||||
break;
|
||||
|
||||
/* Set correct string for switch climate cheat */
|
||||
|
|
|
@ -20,7 +20,7 @@ struct Cheat {
|
|||
*/
|
||||
struct Cheats {
|
||||
Cheat magic_bulldozer; ///< dynamite industries, unmovables
|
||||
Cheat switch_player; ///< change to another player
|
||||
Cheat switch_company; ///< change to another company
|
||||
Cheat money; ///< get rich or poor
|
||||
Cheat crossing_tunnels; ///< allow tunnels that cross each other
|
||||
Cheat build_in_pause; ///< build while in pause mode
|
||||
|
|
|
@ -339,7 +339,7 @@ static void GetTileDesc_Clear(TileIndex tile, TileDesc *td)
|
|||
td->owner[0] = GetTileOwner(tile);
|
||||
}
|
||||
|
||||
static void ChangeTileOwner_Clear(TileIndex tile, PlayerID old_player, PlayerID new_player)
|
||||
static void ChangeTileOwner_Clear(TileIndex tile, Owner old_owner, Owner new_owner)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -105,8 +105,8 @@ DEF_COMMAND(CmdRestoreOrderIndex);
|
|||
DEF_COMMAND(CmdBuildIndustry);
|
||||
|
||||
DEF_COMMAND(CmdBuildCompanyHQ);
|
||||
DEF_COMMAND(CmdSetPlayerFace);
|
||||
DEF_COMMAND(CmdSetPlayerColor);
|
||||
DEF_COMMAND(CmdSetCompanyManagerFace);
|
||||
DEF_COMMAND(CmdSetCompanyColor);
|
||||
|
||||
DEF_COMMAND(CmdIncreaseLoan);
|
||||
DEF_COMMAND(CmdDecreaseLoan);
|
||||
|
@ -165,7 +165,7 @@ DEF_COMMAND(CmdMoneyCheat);
|
|||
DEF_COMMAND(CmdBuildCanal);
|
||||
DEF_COMMAND(CmdBuildLock);
|
||||
|
||||
DEF_COMMAND(CmdPlayerCtrl);
|
||||
DEF_COMMAND(CmdCompanyCtrl);
|
||||
|
||||
DEF_COMMAND(CmdLevelLand);
|
||||
|
||||
|
@ -255,8 +255,8 @@ static const Command _command_proc_table[] = {
|
|||
|
||||
{CmdBuildIndustry, 0}, /* CMD_BUILD_INDUSTRY */
|
||||
{CmdBuildCompanyHQ, CMD_AUTO}, /* CMD_BUILD_COMPANY_HQ */
|
||||
{CmdSetPlayerFace, 0}, /* CMD_SET_PLAYER_FACE */
|
||||
{CmdSetPlayerColor, 0}, /* CMD_SET_PLAYER_COLOR */
|
||||
{CmdSetCompanyManagerFace, 0}, /* CMD_SET_COMPANY_MANAGER_FACE */
|
||||
{CmdSetCompanyColor, 0}, /* CMD_SET_COMPANY_COLOR */
|
||||
|
||||
{CmdIncreaseLoan, 0}, /* CMD_INCREASE_LOAN */
|
||||
{CmdDecreaseLoan, 0}, /* CMD_DECREASE_LOAN */
|
||||
|
@ -310,7 +310,7 @@ static const Command _command_proc_table[] = {
|
|||
|
||||
{CmdMoneyCheat, CMD_OFFLINE}, /* CMD_MONEY_CHEAT */
|
||||
{CmdBuildCanal, CMD_AUTO}, /* CMD_BUILD_CANAL */
|
||||
{CmdPlayerCtrl, 0}, /* CMD_PLAYER_CTRL */
|
||||
{CmdCompanyCtrl, 0}, /* CMD_COMPANY_CTRL */
|
||||
|
||||
{CmdLevelLand, CMD_AUTO}, /* CMD_LEVEL_LAND */
|
||||
|
||||
|
@ -417,7 +417,7 @@ CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint32
|
|||
!(flags & DC_QUERY_COST) &&
|
||||
!(flags & DC_BANKRUPT) &&
|
||||
res.GetCost() != 0 &&
|
||||
!CheckPlayerHasMoney(res)) {
|
||||
!CheckCompanyHasMoney(res)) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
@ -441,10 +441,10 @@ error:
|
|||
|
||||
/* if toplevel, subtract the money. */
|
||||
if (--_docommand_recursive == 0 && !(flags & DC_BANKRUPT)) {
|
||||
SubtractMoneyFromPlayer(res);
|
||||
/* XXX - Old AI hack which doesn't use DoCommandDP; update last build coord of player */
|
||||
if (tile != 0 && IsValidPlayerID(_current_player)) {
|
||||
GetPlayer(_current_player)->last_build_coordinate = tile;
|
||||
SubtractMoneyFromCompany(res);
|
||||
/* XXX - Old AI hack which doesn't use DoCommandDP; update last build coord of company */
|
||||
if (tile != 0 && IsValidCompanyID(_current_company)) {
|
||||
GetCompany(_current_company)->last_build_coordinate = tile;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -454,30 +454,30 @@ error:
|
|||
|
||||
/*!
|
||||
* This functions returns the money which can be used to execute a command.
|
||||
* This is either the money of the current player or INT64_MAX if there
|
||||
* is no such a player "at the moment" like the server itself.
|
||||
* This is either the money of the current company or INT64_MAX if there
|
||||
* is no such a company "at the moment" like the server itself.
|
||||
*
|
||||
* @return The available money of a player or INT64_MAX
|
||||
* @return The available money of a company or INT64_MAX
|
||||
*/
|
||||
Money GetAvailableMoneyForCommand()
|
||||
{
|
||||
PlayerID pid = _current_player;
|
||||
if (!IsValidPlayerID(pid)) return INT64_MAX;
|
||||
return GetPlayer(pid)->player_money;
|
||||
CompanyID company = _current_company;
|
||||
if (!IsValidCompanyID(company)) return INT64_MAX;
|
||||
return GetCompany(company)->money;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Toplevel network safe docommand function for the current player. Must not be called recursively.
|
||||
* Toplevel network safe docommand function for the current company. Must not be called recursively.
|
||||
* The callback is called when the command succeeded or failed. The parameters
|
||||
* tile, p1 and p2 are from the #CommandProc function. The paramater cmd is the command to execute.
|
||||
* The parameter my_cmd is used to indicate if the command is from a player or the server.
|
||||
* The parameter my_cmd is used to indicate if the command is from a company or the server.
|
||||
*
|
||||
* @param tile The tile to perform a command on (see #CommandProc)
|
||||
* @param p1 Additional data for the command (see #CommandProc)
|
||||
* @param p2 Additional data for the command (see #CommandProc)
|
||||
* @param callback A callback function to call after the command is finished
|
||||
* @param cmd The command to execute (a CMD_* value)
|
||||
* @param my_cmd indicator if the command is from a player or server (to display error messages for a user)
|
||||
* @param my_cmd indicator if the command is from a company or server (to display error messages for a user)
|
||||
* @return true if the command succeeded, else false
|
||||
*/
|
||||
bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, uint32 cmd, bool my_cmd)
|
||||
|
@ -505,7 +505,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
|
|||
|
||||
/** Spectator has no rights except for the (dedicated) server which
|
||||
* is/can be a spectator but as the server it can do anything */
|
||||
if (_current_player == PLAYER_SPECTATOR && !_network_server) {
|
||||
if (_current_company == COMPANY_SPECTATOR && !_network_server) {
|
||||
if (my_cmd) ShowErrorMessage(_error_message, error_part1, x, y);
|
||||
_cmd_text = NULL;
|
||||
return false;
|
||||
|
@ -547,7 +547,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
|
|||
/* cost estimation only? */
|
||||
if (!IsGeneratingWorld() &&
|
||||
_shift_pressed &&
|
||||
IsLocalPlayer() &&
|
||||
IsLocalCompany() &&
|
||||
!(cmd & (CMD_NETWORK_COMMAND | CMD_SHOW_NO_ERROR)) &&
|
||||
(cmd & 0xFF) != CMD_PAUSE) {
|
||||
/* estimate the cost. */
|
||||
|
@ -578,33 +578,33 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
|
|||
goto show_error;
|
||||
}
|
||||
/* no money? Only check if notest is off */
|
||||
if (!notest && res.GetCost() != 0 && !CheckPlayerHasMoney(res)) goto show_error;
|
||||
if (!notest && res.GetCost() != 0 && !CheckCompanyHasMoney(res)) goto show_error;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_NETWORK
|
||||
/** If we are in network, and the command is not from the network
|
||||
* send it to the command-queue and abort execution
|
||||
* If we are a dedicated server temporarily switch local player, otherwise
|
||||
* If we are a dedicated server temporarily switch local company, otherwise
|
||||
* the other parties won't be able to execute our command and will desync.
|
||||
* We also need to do this if the server's company has gone bankrupt
|
||||
* @todo Rewrite (dedicated) server to something more than a dirty hack!
|
||||
*/
|
||||
if (_networking && !(cmd & CMD_NETWORK_COMMAND)) {
|
||||
PlayerID pbck = _local_player;
|
||||
if (_network_dedicated || (_network_server && pbck == PLAYER_SPECTATOR)) _local_player = PLAYER_FIRST;
|
||||
CompanyID pbck = _local_company;
|
||||
if (_network_dedicated || (_network_server && pbck == COMPANY_SPECTATOR)) _local_company = COMPANY_FIRST;
|
||||
NetworkSend_Command(tile, p1, p2, cmd, callback);
|
||||
if (_network_dedicated || (_network_server && pbck == PLAYER_SPECTATOR)) _local_player = pbck;
|
||||
if (_network_dedicated || (_network_server && pbck == COMPANY_SPECTATOR)) _local_company = pbck;
|
||||
_docommand_recursive = 0;
|
||||
_cmd_text = NULL;
|
||||
ClearStorageChanges(false);
|
||||
return true;
|
||||
}
|
||||
#endif /* ENABLE_NETWORK */
|
||||
DebugDumpCommands("ddc:cmd:%d;%d;%d;%d;%d;%d;%d;%s\n", _date, _date_fract, (int)_current_player, tile, p1, p2, cmd, _cmd_text);
|
||||
DebugDumpCommands("ddc:cmd:%d;%d;%d;%d;%d;%d;%d;%s\n", _date, _date_fract, (int)_current_company, tile, p1, p2, cmd, _cmd_text);
|
||||
|
||||
/* update last build coordinate of player. */
|
||||
if (tile != 0 && IsValidPlayerID(_current_player)) {
|
||||
GetPlayer(_current_player)->last_build_coordinate = tile;
|
||||
/* update last build coordinate of company. */
|
||||
if (tile != 0 && IsValidCompanyID(_current_company)) {
|
||||
GetCompany(_current_company)->last_build_coordinate = tile;
|
||||
}
|
||||
|
||||
/* Actually try and execute the command. If no cost-type is given
|
||||
|
@ -622,12 +622,12 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
|
|||
}
|
||||
}
|
||||
|
||||
SubtractMoneyFromPlayer(res2);
|
||||
SubtractMoneyFromCompany(res2);
|
||||
|
||||
/* update signals if needed */
|
||||
UpdateSignalsInBuffer();
|
||||
|
||||
if (IsLocalPlayer() && _game_mode != GM_EDITOR) {
|
||||
if (IsLocalCompany() && _game_mode != GM_EDITOR) {
|
||||
if (res2.GetCost() != 0 && tile != 0) ShowCostOrIncomeAnimation(x, y, GetSlopeZ(x, y), res2.GetCost());
|
||||
if (_additional_cash_required != 0) {
|
||||
SetDParam(0, _additional_cash_required);
|
||||
|
@ -645,7 +645,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
|
|||
|
||||
show_error:
|
||||
/* show error message if the command fails? */
|
||||
if (IsLocalPlayer() && error_part1 != 0 && my_cmd) {
|
||||
if (IsLocalCompany() && error_part1 != 0 && my_cmd) {
|
||||
ShowErrorMessage(_error_message, error_part1, x, y);
|
||||
}
|
||||
|
||||
|
|
|
@ -201,8 +201,8 @@ enum {
|
|||
CMD_BUILD_INDUSTRY, ///< build a new industry
|
||||
|
||||
CMD_BUILD_COMPANY_HQ, ///< build the company headquarter
|
||||
CMD_SET_PLAYER_FACE, ///< set the face of the player/company
|
||||
CMD_SET_PLAYER_COLOR, ///< set the color of the player/company
|
||||
CMD_SET_COMPANY_MANAGER_FACE, ///< set the manager's face of the company
|
||||
CMD_SET_COMPANY_COLOR, ///< set the color of the company
|
||||
|
||||
CMD_INCREASE_LOAN, ///< increase the loan from the bank
|
||||
CMD_DECREASE_LOAN, ///< decrease the loan from the bank
|
||||
|
@ -254,7 +254,7 @@ enum {
|
|||
CMD_MONEY_CHEAT, ///< do the money cheat
|
||||
CMD_BUILD_CANAL, ///< build a canal
|
||||
|
||||
CMD_PLAYER_CTRL, ///< used in multiplayer to create a new player etc.
|
||||
CMD_COMPANY_CTRL, ///< used in multiplayer to create a new companies etc.
|
||||
CMD_LEVEL_LAND, ///< level land
|
||||
|
||||
CMD_REFIT_RAIL_VEHICLE, ///< refit the cargo space of a train
|
||||
|
@ -264,7 +264,7 @@ enum {
|
|||
CMD_BUILD_SIGNAL_TRACK, ///< add signals along a track (by dragging)
|
||||
CMD_REMOVE_SIGNAL_TRACK, ///< remove signals along a track (by dragging)
|
||||
|
||||
CMD_GIVE_MONEY, ///< give money to an other player
|
||||
CMD_GIVE_MONEY, ///< give money to another company
|
||||
CMD_CHANGE_PATCH_SETTING, ///< change a patch setting
|
||||
|
||||
CMD_SET_AUTOREPLACE, ///< set an autoreplace entry
|
||||
|
|
|
@ -79,7 +79,7 @@ void IConsoleFree()
|
|||
|
||||
/**
|
||||
* Handle the printing of text entered into the console or redirected there
|
||||
* by any other means. Text can be redirected to other players in a network game
|
||||
* by any other means. Text can be redirected to other clients in a network game
|
||||
* as well as to a logfile. If the network server is a dedicated server, all activities
|
||||
* are also logged. All lines to print are added to a temporary buffer which can be
|
||||
* used as a history to print them onscreen
|
||||
|
|
|
@ -375,7 +375,7 @@ DEF_CONSOLE_CMD(ConBan)
|
|||
uint32 index;
|
||||
|
||||
if (argc == 0) {
|
||||
IConsoleHelp("Ban a player from a network game. Usage: 'ban <ip | client-id>'");
|
||||
IConsoleHelp("Ban a client from a network game. Usage: 'ban <ip | client-id>'");
|
||||
IConsoleHelp("For client-id's, see the command 'clients'");
|
||||
IConsoleHelp("If the client is no longer online, you can still ban his/her IP");
|
||||
return true;
|
||||
|
@ -408,7 +408,7 @@ DEF_CONSOLE_CMD(ConBan)
|
|||
|
||||
if (ci != NULL) {
|
||||
IConsolePrint(CC_DEFAULT, "Client banned");
|
||||
banip = GetPlayerIP(ci);
|
||||
banip = GetClientIP(ci);
|
||||
NetworkServerSendError(index, NETWORK_ERROR_KICKED);
|
||||
} else {
|
||||
IConsolePrint(CC_DEFAULT, "Client not online, banned IP");
|
||||
|
@ -430,7 +430,7 @@ DEF_CONSOLE_CMD(ConUnBan)
|
|||
uint i, index;
|
||||
|
||||
if (argc == 0) {
|
||||
IConsoleHelp("Unban a player from a network game. Usage: 'unban <ip | client-id>'");
|
||||
IConsoleHelp("Unban a client from a network game. Usage: 'unban <ip | client-id>'");
|
||||
IConsoleHelp("For a list of banned IP's, see the command 'banlist'");
|
||||
return true;
|
||||
}
|
||||
|
@ -540,13 +540,13 @@ DEF_CONSOLE_CMD(ConStatus)
|
|||
DEF_CONSOLE_CMD(ConServerInfo)
|
||||
{
|
||||
if (argc == 0) {
|
||||
IConsoleHelp("List current and maximum client/player limits. Usage 'server_info'");
|
||||
IConsoleHelp("List current and maximum client/company limits. Usage 'server_info'");
|
||||
IConsoleHelp("You can change these values by setting the variables 'max_clients', 'max_companies' and 'max_spectators'");
|
||||
return true;
|
||||
}
|
||||
|
||||
IConsolePrintF(CC_DEFAULT, "Current/maximum clients: %2d/%2d", _network_game_info.clients_on, _settings_client.network.max_clients);
|
||||
IConsolePrintF(CC_DEFAULT, "Current/maximum companies: %2d/%2d", ActivePlayerCount(), _settings_client.network.max_companies);
|
||||
IConsolePrintF(CC_DEFAULT, "Current/maximum companies: %2d/%2d", ActiveCompanyCount(), _settings_client.network.max_companies);
|
||||
IConsolePrintF(CC_DEFAULT, "Current/maximum spectators: %2d/%2d", NetworkSpectatorCount(), _settings_client.network.max_spectators);
|
||||
|
||||
return true;
|
||||
|
@ -558,7 +558,7 @@ DEF_CONSOLE_CMD(ConKick)
|
|||
uint32 index;
|
||||
|
||||
if (argc == 0) {
|
||||
IConsoleHelp("Kick a player from a network game. Usage: 'kick <ip | client-id>'");
|
||||
IConsoleHelp("Kick a client from a network game. Usage: 'kick <ip | client-id>'");
|
||||
IConsoleHelp("For client-id's, see the command 'clients'");
|
||||
return true;
|
||||
}
|
||||
|
@ -594,32 +594,32 @@ DEF_CONSOLE_CMD(ConKick)
|
|||
|
||||
DEF_CONSOLE_CMD(ConResetCompany)
|
||||
{
|
||||
PlayerID index;
|
||||
CompanyID index;
|
||||
|
||||
if (argc == 0) {
|
||||
IConsoleHelp("Remove an idle company from the game. Usage: 'reset_company <company-id>'");
|
||||
IConsoleHelp("For company-id's, see the list of companies from the dropdown menu. Player 1 is 1, etc.");
|
||||
IConsoleHelp("For company-id's, see the list of companies from the dropdown menu. Company 1 is 1, etc.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (argc != 2) return false;
|
||||
|
||||
index = (PlayerID)(atoi(argv[1]) - 1);
|
||||
index = (CompanyID)(atoi(argv[1]) - 1);
|
||||
|
||||
/* Check valid range */
|
||||
if (!IsValidPlayerID(index)) {
|
||||
IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_PLAYERS);
|
||||
if (!IsValidCompanyID(index)) {
|
||||
IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_COMPANIES);
|
||||
return true;
|
||||
}
|
||||
|
||||
const Player *p = GetPlayer(index);
|
||||
const Company *c = GetCompany(index);
|
||||
|
||||
if (p->is_ai) {
|
||||
if (c->is_ai) {
|
||||
IConsoleError("Company is owned by an AI.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (NetworkCompanyHasPlayers(index)) {
|
||||
if (NetworkCompanyHasClients(index)) {
|
||||
IConsoleError("Cannot remove company: a client is connected to that company.");
|
||||
return false;
|
||||
}
|
||||
|
@ -630,7 +630,7 @@ DEF_CONSOLE_CMD(ConResetCompany)
|
|||
}
|
||||
|
||||
/* It is safe to remove this company */
|
||||
DoCommandP(0, 2, index, NULL, CMD_PLAYER_CTRL);
|
||||
DoCommandP(0, 2, index, NULL, CMD_COMPANY_CTRL);
|
||||
IConsolePrint(CC_DEFAULT, "Company deleted.");
|
||||
|
||||
return true;
|
||||
|
@ -648,8 +648,8 @@ DEF_CONSOLE_CMD(ConNetworkClients)
|
|||
FOR_ALL_ACTIVE_CLIENT_INFOS(ci) {
|
||||
IConsolePrintF(CC_INFO, "Client #%1d name: '%s' company: %1d IP: %s",
|
||||
ci->client_index, ci->client_name,
|
||||
ci->client_playas + (IsValidPlayerID(ci->client_playas) ? 1 : 0),
|
||||
GetPlayerIP(ci));
|
||||
ci->client_playas + (IsValidCompanyID(ci->client_playas) ? 1 : 0),
|
||||
GetClientIP(ci));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -659,13 +659,13 @@ DEF_CONSOLE_CMD(ConNetworkConnect)
|
|||
{
|
||||
char *ip;
|
||||
const char *port = NULL;
|
||||
const char *player = NULL;
|
||||
const char *company = NULL;
|
||||
uint16 rport;
|
||||
|
||||
if (argc == 0) {
|
||||
IConsoleHelp("Connect to a remote OTTD server and join the game. Usage: 'connect <ip>'");
|
||||
IConsoleHelp("IP can contain port and player: 'IP[[#Player]:Port]', eg: 'server.ottd.org#2:443'");
|
||||
IConsoleHelp("Player #255 is spectator all others are a certain company with Company 1 being #1");
|
||||
IConsoleHelp("IP can contain port and company: 'IP[[#Company]:Port]', eg: 'server.ottd.org#2:443'");
|
||||
IConsoleHelp("Company #255 is spectator all others are a certain company with Company 1 being #1");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -675,20 +675,20 @@ DEF_CONSOLE_CMD(ConNetworkConnect)
|
|||
ip = argv[1];
|
||||
/* Default settings: default port and new company */
|
||||
rport = NETWORK_DEFAULT_PORT;
|
||||
_network_playas = PLAYER_NEW_COMPANY;
|
||||
_network_playas = COMPANY_NEW_COMPANY;
|
||||
|
||||
ParseConnectionString(&player, &port, ip);
|
||||
ParseConnectionString(&company, &port, ip);
|
||||
|
||||
IConsolePrintF(CC_DEFAULT, "Connecting to %s...", ip);
|
||||
if (player != NULL) {
|
||||
_network_playas = (PlayerID)atoi(player);
|
||||
IConsolePrintF(CC_DEFAULT, " player-no: %d", _network_playas);
|
||||
if (company != NULL) {
|
||||
_network_playas = (CompanyID)atoi(company);
|
||||
IConsolePrintF(CC_DEFAULT, " company-no: %d", _network_playas);
|
||||
|
||||
/* From a user pov 0 is a new player, internally it's different and all
|
||||
* players are offset by one to ease up on users (eg players 1-8 not 0-7) */
|
||||
if (_network_playas != PLAYER_SPECTATOR) {
|
||||
/* From a user pov 0 is a new company, internally it's different and all
|
||||
* companies are offset by one to ease up on users (eg companies 1-8 not 0-7) */
|
||||
if (_network_playas != COMPANY_SPECTATOR) {
|
||||
_network_playas--;
|
||||
if (!IsValidPlayerID(_network_playas)) return false;
|
||||
if (!IsValidCompanyID(_network_playas)) return false;
|
||||
}
|
||||
}
|
||||
if (port != NULL) {
|
||||
|
@ -1138,24 +1138,24 @@ DEF_CONSOLE_CMD(ConSay)
|
|||
return true;
|
||||
}
|
||||
|
||||
DEF_CONSOLE_CMD(ConPlayers)
|
||||
DEF_CONSOLE_CMD(ConCompanies)
|
||||
{
|
||||
Player *p;
|
||||
Company *c;
|
||||
|
||||
if (argc == 0) {
|
||||
IConsoleHelp("List the in-game details of all clients connected to the server. Usage 'players'");
|
||||
IConsoleHelp("List the in-game details of all clients connected to the server. Usage 'companies'");
|
||||
return true;
|
||||
}
|
||||
NetworkPopulateCompanyInfo();
|
||||
|
||||
FOR_ALL_PLAYERS(p) {
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
char buffer[512];
|
||||
|
||||
const NetworkPlayerInfo *npi = &_network_player_info[p->index];
|
||||
const NetworkCompanyInfo *npi = &_network_company_info[c->index];
|
||||
|
||||
GetString(buffer, STR_00D1_DARK_BLUE + _player_colors[p->index], lastof(buffer));
|
||||
GetString(buffer, STR_00D1_DARK_BLUE + _company_colours[c->index], lastof(buffer));
|
||||
IConsolePrintF(CC_INFO, "#:%d(%s) Company Name: '%s' Year Founded: %d Money: %" OTTD_PRINTF64 "d Loan: %" OTTD_PRINTF64 "d Value: %" OTTD_PRINTF64 "d (T:%d, R:%d, P:%d, S:%d) %sprotected",
|
||||
p->index + 1, buffer, npi->company_name, p->inaugurated_year, (int64)p->player_money, (int64)p->current_loan, (int64)CalculateCompanyValue(p),
|
||||
c->index + 1, buffer, npi->company_name, c->inaugurated_year, (int64)c->money, (int64)c->current_loan, (int64)CalculateCompanyValue(c),
|
||||
/* trains */ npi->num_vehicle[0],
|
||||
/* lorry + bus */ npi->num_vehicle[1] + npi->num_vehicle[2],
|
||||
/* planes */ npi->num_vehicle[3],
|
||||
|
@ -1166,26 +1166,26 @@ DEF_CONSOLE_CMD(ConPlayers)
|
|||
return true;
|
||||
}
|
||||
|
||||
DEF_CONSOLE_CMD(ConSayPlayer)
|
||||
DEF_CONSOLE_CMD(ConSayCompany)
|
||||
{
|
||||
if (argc == 0) {
|
||||
IConsoleHelp("Chat to a certain player in a multiplayer game. Usage: 'say_player <player-no> \"<msg>\"'");
|
||||
IConsoleHelp("PlayerNo is the player that plays as company <playerno>, 1 through max_players");
|
||||
IConsoleHelp("Chat to a certain company in a multiplayer game. Usage: 'say_company <company-no> \"<msg>\"'");
|
||||
IConsoleHelp("CompanyNo is the company that plays as company <companyno>, 1 through max_companies");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (argc != 3) return false;
|
||||
|
||||
PlayerID player_id = (PlayerID)(atoi(argv[1]) - 1);
|
||||
if (!IsValidPlayerID(player_id)) {
|
||||
IConsolePrintF(CC_DEFAULT, "Unknown player. Player range is between 1 and %d.", MAX_PLAYERS);
|
||||
CompanyID company_id = (CompanyID)(atoi(argv[1]) - 1);
|
||||
if (!IsValidCompanyID(company_id)) {
|
||||
IConsolePrintF(CC_DEFAULT, "Unknown company. Company range is between 1 and %d.", MAX_COMPANIES);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!_network_server) {
|
||||
NetworkClientSendChat(NETWORK_ACTION_CHAT_COMPANY, DESTTYPE_TEAM, player_id, argv[2]);
|
||||
NetworkClientSendChat(NETWORK_ACTION_CHAT_COMPANY, DESTTYPE_TEAM, company_id, argv[2]);
|
||||
} else {
|
||||
NetworkServerSendChat(NETWORK_ACTION_CHAT_COMPANY, DESTTYPE_TEAM, player_id, argv[2], NETWORK_SERVER_INDEX);
|
||||
NetworkServerSendChat(NETWORK_ACTION_CHAT_COMPANY, DESTTYPE_TEAM, company_id, argv[2], NETWORK_SERVER_INDEX);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -1194,7 +1194,7 @@ DEF_CONSOLE_CMD(ConSayPlayer)
|
|||
DEF_CONSOLE_CMD(ConSayClient)
|
||||
{
|
||||
if (argc == 0) {
|
||||
IConsoleHelp("Chat to a certain player in a multiplayer game. Usage: 'say_client <client-no> \"<msg>\"'");
|
||||
IConsoleHelp("Chat to a certain client in a multiplayer game. Usage: 'say_client <client-no> \"<msg>\"'");
|
||||
IConsoleHelp("For client-id's, see the command 'clients'");
|
||||
return true;
|
||||
}
|
||||
|
@ -1212,16 +1212,16 @@ DEF_CONSOLE_CMD(ConSayClient)
|
|||
|
||||
extern void HashCurrentCompanyPassword();
|
||||
|
||||
/* Also use from within player_gui to change the password graphically */
|
||||
/* Also use from within company_gui to change the password graphically */
|
||||
bool NetworkChangeCompanyPassword(byte argc, char *argv[])
|
||||
{
|
||||
if (argc == 0) {
|
||||
if (!IsValidPlayerID(_local_player)) return true; // dedicated server
|
||||
IConsolePrintF(CC_WARNING, "Current value for 'company_pw': %s", _network_player_info[_local_player].password);
|
||||
if (!IsValidCompanyID(_local_company)) return true; // dedicated server
|
||||
IConsolePrintF(CC_WARNING, "Current value for 'company_pw': %s", _network_company_info[_local_company].password);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!IsValidPlayerID(_local_player)) {
|
||||
if (!IsValidCompanyID(_local_company)) {
|
||||
IConsoleError("You have to own a company to make use of this command.");
|
||||
return false;
|
||||
}
|
||||
|
@ -1230,7 +1230,7 @@ bool NetworkChangeCompanyPassword(byte argc, char *argv[])
|
|||
|
||||
if (strcmp(argv[0], "*") == 0) argv[0][0] = '\0';
|
||||
|
||||
ttd_strlcpy(_network_player_info[_local_player].password, argv[0], sizeof(_network_player_info[_local_player].password));
|
||||
ttd_strlcpy(_network_company_info[_local_company].password, argv[0], sizeof(_network_company_info[_local_company].password));
|
||||
|
||||
if (!_network_server) {
|
||||
NetworkClientSetPassword();
|
||||
|
@ -1238,7 +1238,7 @@ bool NetworkChangeCompanyPassword(byte argc, char *argv[])
|
|||
HashCurrentCompanyPassword();
|
||||
}
|
||||
|
||||
IConsolePrintF(CC_WARNING, "'company_pw' changed to: %s", _network_player_info[_local_player].password);
|
||||
IConsolePrintF(CC_WARNING, "'company_pw' changed to: %s", _network_company_info[_local_company].password);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1248,7 +1248,7 @@ bool NetworkChangeCompanyPassword(byte argc, char *argv[])
|
|||
DEF_CONSOLE_CMD(ConPatch)
|
||||
{
|
||||
if (argc == 0) {
|
||||
IConsoleHelp("Change patch variables for all players. Usage: 'patch <name> [<value>]'");
|
||||
IConsoleHelp("Change patch variables for all clients. Usage: 'patch <name> [<value>]'");
|
||||
IConsoleHelp("Omitting <value> will print out the current value of the patch-setting.");
|
||||
return true;
|
||||
}
|
||||
|
@ -1384,10 +1384,12 @@ void IConsoleStdLibRegister()
|
|||
/*** Networking commands ***/
|
||||
IConsoleCmdRegister("say", ConSay);
|
||||
IConsoleCmdHookAdd("say", ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);
|
||||
IConsoleCmdRegister("players", ConPlayers);
|
||||
IConsoleCmdHookAdd("players", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
|
||||
IConsoleCmdRegister("say_player", ConSayPlayer);
|
||||
IConsoleCmdHookAdd("say_player", ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);
|
||||
IConsoleCmdRegister("companies", ConCompanies);
|
||||
IConsoleCmdHookAdd("companies", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
|
||||
IConsoleAliasRegister("players", "companies");
|
||||
IConsoleCmdRegister("say_company", ConSayCompany);
|
||||
IConsoleCmdHookAdd("say_company", ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);
|
||||
IConsoleAliasRegister("say_player", "say_company %+");
|
||||
IConsoleCmdRegister("say_client", ConSayClient);
|
||||
IConsoleCmdHookAdd("say_client", ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);
|
||||
|
||||
|
@ -1433,7 +1435,7 @@ void IConsoleStdLibRegister()
|
|||
IConsoleAliasRegister("server_password", "patch server_password %+");
|
||||
IConsoleAliasRegister("rcon_pw", "patch rcon_password %+");
|
||||
IConsoleAliasRegister("rcon_password", "patch rcon_password %+");
|
||||
IConsoleAliasRegister("name", "patch player_name %+");
|
||||
IConsoleAliasRegister("name", "patch client_name %+");
|
||||
IConsoleAliasRegister("server_name", "patch server_name %+");
|
||||
IConsoleAliasRegister("server_port", "patch server_port %+");
|
||||
IConsoleAliasRegister("server_ip", "patch server_bind_ip %+");
|
||||
|
@ -1450,7 +1452,7 @@ void IConsoleStdLibRegister()
|
|||
IConsoleAliasRegister("autoclean_protected", "patch autoclean_protected %+");
|
||||
IConsoleAliasRegister("autoclean_unprotected", "patch autoclean_unprotected %+");
|
||||
IConsoleAliasRegister("restart_game_year", "patch restart_game_year %+");
|
||||
IConsoleAliasRegister("min_players", "patch min_players %+");
|
||||
IConsoleAliasRegister("min_players", "patch min_clients %+");
|
||||
IConsoleAliasRegister("reload_cfg", "patch reload_cfg %+");
|
||||
#endif /* ENABLE_NETWORK */
|
||||
|
||||
|
|
|
@ -436,7 +436,7 @@ static void IConsoleHistoryNavigate(int direction)
|
|||
|
||||
/**
|
||||
* Handle the printing of text entered into the console or redirected there
|
||||
* by any other means. Text can be redirected to other players in a network game
|
||||
* by any other means. Text can be redirected to other clients in a network game
|
||||
* as well as to a logfile. If the network server is a dedicated server, all activities
|
||||
* are also logged. All lines to print are added to a temporary buffer which can be
|
||||
* used as a history to print them onscreen
|
||||
|
|
|
@ -42,7 +42,7 @@ void SetRandomSeed(uint32 seed)
|
|||
uint32 DoRandom(int line, const char *file)
|
||||
{
|
||||
if (_networking && (DEREF_CLIENT(0)->status != STATUS_INACTIVE || !_network_server)) {
|
||||
printf("Random [%d/%d] %s:%d\n",_frame_counter, (byte)_current_player, file, line);
|
||||
printf("Random [%d/%d] %s:%d\n",_frame_counter, (byte)_current_company, file, line);
|
||||
}
|
||||
|
||||
return _random.Next();
|
||||
|
|
|
@ -160,13 +160,13 @@ extern void WaypointsDailyLoop();
|
|||
extern void EnginesDailyLoop();
|
||||
extern void DisasterDailyLoop();
|
||||
extern void IndustryDailyLoop();
|
||||
extern void PlayersMonthlyLoop();
|
||||
extern void CompaniesMonthlyLoop();
|
||||
extern void EnginesMonthlyLoop();
|
||||
extern void TownsMonthlyLoop();
|
||||
extern void IndustryMonthlyLoop();
|
||||
extern void StationMonthlyLoop();
|
||||
|
||||
extern void PlayersYearlyLoop();
|
||||
extern void CompaniesYearlyLoop();
|
||||
extern void TrainsYearlyLoop();
|
||||
extern void RoadVehiclesYearlyLoop();
|
||||
extern void AircraftYearlyLoop();
|
||||
|
@ -255,7 +255,7 @@ void IncreaseDate()
|
|||
}
|
||||
|
||||
InvalidateWindowClasses(WC_CHEATS);
|
||||
PlayersMonthlyLoop();
|
||||
CompaniesMonthlyLoop();
|
||||
EnginesMonthlyLoop();
|
||||
TownsMonthlyLoop();
|
||||
IndustryMonthlyLoop();
|
||||
|
@ -270,7 +270,7 @@ void IncreaseDate()
|
|||
_cur_year = ymd.year;
|
||||
|
||||
/* yes, call various yearly loops */
|
||||
PlayersYearlyLoop();
|
||||
CompaniesYearlyLoop();
|
||||
TrainsYearlyLoop();
|
||||
RoadVehiclesYearlyLoop();
|
||||
AircraftYearlyLoop();
|
||||
|
|
|
@ -314,7 +314,7 @@ struct DepotWindow : Window {
|
|||
uint16 boxes_in_each_row = this->widget[DEPOT_WIDGET_MATRIX].data & 0xFF;
|
||||
|
||||
/* setup disabled buttons */
|
||||
this->SetWidgetsDisabledState(!IsTileOwner(tile, _local_player),
|
||||
this->SetWidgetsDisabledState(!IsTileOwner(tile, _local_company),
|
||||
DEPOT_WIDGET_STOP_ALL,
|
||||
DEPOT_WIDGET_START_ALL,
|
||||
DEPOT_WIDGET_SELL,
|
||||
|
@ -702,7 +702,7 @@ struct DepotWindow : Window {
|
|||
this->type = type;
|
||||
_backup_orders_tile = 0;
|
||||
|
||||
assert(IsPlayerBuildableVehicleType(type)); // ensure that we make the call with a valid type
|
||||
assert(IsCompanyBuildableVehicleType(type)); // ensure that we make the call with a valid type
|
||||
|
||||
/* Resize the window according to the vehicle type */
|
||||
|
||||
|
|
|
@ -69,11 +69,11 @@ static void DisasterClearSquare(TileIndex tile)
|
|||
|
||||
switch (GetTileType(tile)) {
|
||||
case MP_RAILWAY:
|
||||
if (IsHumanPlayer(GetTileOwner(tile)) && !IsRailWaypoint(tile)) {
|
||||
PlayerID p = _current_player;
|
||||
_current_player = OWNER_WATER;
|
||||
if (IsHumanCompany(GetTileOwner(tile)) && !IsRailWaypoint(tile)) {
|
||||
CompanyID old_company = _current_company;
|
||||
_current_company = OWNER_WATER;
|
||||
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
||||
_current_player = p;
|
||||
_current_company = old_company;
|
||||
|
||||
/* update signals in buffer */
|
||||
UpdateSignalsInBuffer();
|
||||
|
@ -81,10 +81,10 @@ static void DisasterClearSquare(TileIndex tile)
|
|||
break;
|
||||
|
||||
case MP_HOUSE: {
|
||||
PlayerID p = _current_player;
|
||||
_current_player = OWNER_NONE;
|
||||
CompanyID old_company = _current_company;
|
||||
_current_company = OWNER_NONE;
|
||||
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
||||
_current_player = p;
|
||||
_current_company = old_company;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -229,7 +229,7 @@ static void DisasterTick_Zeppeliner(Vehicle *v)
|
|||
if (IsValidTile(tile) &&
|
||||
IsTileType(tile, MP_STATION) &&
|
||||
IsAirport(tile) &&
|
||||
IsHumanPlayer(GetTileOwner(tile))) {
|
||||
IsHumanCompany(GetTileOwner(tile))) {
|
||||
v->current_order.SetDestination(1);
|
||||
v->age = 0;
|
||||
|
||||
|
@ -253,7 +253,7 @@ static void DisasterTick_Zeppeliner(Vehicle *v)
|
|||
if (IsValidTile(tile) &&
|
||||
IsTileType(tile, MP_STATION) &&
|
||||
IsAirport(tile) &&
|
||||
IsHumanPlayer(GetTileOwner(tile))) {
|
||||
IsHumanCompany(GetTileOwner(tile))) {
|
||||
st = GetStationByTile(tile);
|
||||
CLRBITS(st->airport_flags, RUNWAY_IN_block);
|
||||
}
|
||||
|
@ -294,7 +294,7 @@ static void DisasterTick_Zeppeliner(Vehicle *v)
|
|||
if (IsValidTile(tile) &&
|
||||
IsTileType(tile, MP_STATION) &&
|
||||
IsAirport(tile) &&
|
||||
IsHumanPlayer(GetTileOwner(tile))) {
|
||||
IsHumanCompany(GetTileOwner(tile))) {
|
||||
st = GetStationByTile(tile);
|
||||
SETBITS(st->airport_flags, RUNWAY_IN_block);
|
||||
}
|
||||
|
@ -331,7 +331,7 @@ static void DisasterTick_Ufo(Vehicle *v)
|
|||
v->current_order.SetDestination(1);
|
||||
|
||||
FOR_ALL_VEHICLES(u) {
|
||||
if (u->type == VEH_ROAD && IsRoadVehFront(u) && IsHumanPlayer(u->owner)) {
|
||||
if (u->type == VEH_ROAD && IsRoadVehFront(u) && IsHumanCompany(u->owner)) {
|
||||
v->dest_tile = u->index;
|
||||
v->age = 0;
|
||||
return;
|
||||
|
@ -644,7 +644,7 @@ static void DisasterTick_Big_Ufo(Vehicle *v)
|
|||
do {
|
||||
if (IsTileType(tile, MP_RAILWAY) &&
|
||||
IsPlainRailTile(tile) &&
|
||||
IsHumanPlayer(GetTileOwner(tile))) {
|
||||
IsHumanCompany(GetTileOwner(tile))) {
|
||||
break;
|
||||
}
|
||||
tile = TILE_MASK(tile + 1);
|
||||
|
@ -773,7 +773,7 @@ static void Disaster_Zeppeliner_Init()
|
|||
FOR_ALL_STATIONS(st) {
|
||||
if (st->airport_tile != 0 &&
|
||||
st->airport_type <= 1 &&
|
||||
IsHumanPlayer(st->owner)) {
|
||||
IsHumanCompany(st->owner)) {
|
||||
x = (TileX(st->xy) + 2) * TILE_SIZE;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -278,7 +278,7 @@ static const WindowDesc _build_docks_toolbar_desc = {
|
|||
|
||||
void ShowBuildDocksToolbar()
|
||||
{
|
||||
if (!IsValidPlayerID(_current_player)) return;
|
||||
if (!IsValidCompanyID(_current_company)) return;
|
||||
|
||||
DeleteWindowByClass(WC_BUILD_TOOLBAR);
|
||||
AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_toolbar_desc, TRANSPORT_WATER);
|
||||
|
|
|
@ -59,7 +59,7 @@ static void ClickTile_Dummy(TileIndex tile)
|
|||
/* not used */
|
||||
}
|
||||
|
||||
static void ChangeTileOwner_Dummy(TileIndex tile, PlayerID old_player, PlayerID new_player)
|
||||
static void ChangeTileOwner_Dummy(TileIndex tile, Owner old_owner, Owner new_owner)
|
||||
{
|
||||
/* not used */
|
||||
}
|
||||
|
|
417
src/economy.cpp
417
src/economy.cpp
|
@ -96,18 +96,18 @@ const ScoreInfo _score_info[] = {
|
|||
{ SCORE_TOTAL, 0, 0 }
|
||||
};
|
||||
|
||||
int _score_part[MAX_PLAYERS][SCORE_END];
|
||||
int _score_part[MAX_COMPANIES][SCORE_END];
|
||||
Economy _economy;
|
||||
Subsidy _subsidies[MAX_PLAYERS];
|
||||
Subsidy _subsidies[MAX_COMPANIES];
|
||||
Prices _price;
|
||||
uint16 _price_frac[NUM_PRICES];
|
||||
Money _cargo_payment_rates[NUM_CARGO];
|
||||
uint16 _cargo_payment_rates_frac[NUM_CARGO];
|
||||
Money _additional_cash_required;
|
||||
|
||||
Money CalculateCompanyValue(const Player* p)
|
||||
Money CalculateCompanyValue(const Company *c)
|
||||
{
|
||||
PlayerID owner = p->index;
|
||||
Owner owner = c->index;
|
||||
Money value = 0;
|
||||
|
||||
Station *st;
|
||||
|
@ -132,8 +132,8 @@ Money CalculateCompanyValue(const Player* p)
|
|||
}
|
||||
|
||||
/* Add real money value */
|
||||
value -= p->current_loan;
|
||||
value += p->player_money;
|
||||
value -= c->current_loan;
|
||||
value += c->money;
|
||||
|
||||
return max(value, (Money)1);
|
||||
}
|
||||
|
@ -141,17 +141,17 @@ Money CalculateCompanyValue(const Player* p)
|
|||
/** if update is set to true, the economy is updated with this score
|
||||
* (also the house is updated, should only be true in the on-tick event)
|
||||
* @param update the economy with calculated score
|
||||
* @param p player been evaluated
|
||||
* @return actual score of this player
|
||||
* @param c company been evaluated
|
||||
* @return actual score of this company
|
||||
* */
|
||||
int UpdateCompanyRatingAndValue(Player *p, bool update)
|
||||
int UpdateCompanyRatingAndValue(Company *c, bool update)
|
||||
{
|
||||
byte owner = p->index;
|
||||
Owner owner = c->index;
|
||||
int score = 0;
|
||||
|
||||
memset(_score_part[owner], 0, sizeof(_score_part[owner]));
|
||||
|
||||
/* Count vehicles */
|
||||
/* Count vehicles */
|
||||
{
|
||||
Vehicle *v;
|
||||
Money min_profit = 0;
|
||||
|
@ -160,7 +160,7 @@ int UpdateCompanyRatingAndValue(Player *p, bool update)
|
|||
|
||||
FOR_ALL_VEHICLES(v) {
|
||||
if (v->owner != owner) continue;
|
||||
if (IsPlayerBuildableVehicleType(v->type) && v->IsPrimaryVehicle()) {
|
||||
if (IsCompanyBuildableVehicleType(v->type) && v->IsPrimaryVehicle()) {
|
||||
num++;
|
||||
if (v->age > 730) {
|
||||
/* Find the vehicle with the lowest amount of profit */
|
||||
|
@ -180,7 +180,7 @@ int UpdateCompanyRatingAndValue(Player *p, bool update)
|
|||
_score_part[owner][SCORE_MIN_PROFIT] = ClampToI32(min_profit);
|
||||
}
|
||||
|
||||
/* Count stations */
|
||||
/* Count stations */
|
||||
{
|
||||
uint num = 0;
|
||||
const Station* st;
|
||||
|
@ -191,61 +191,62 @@ int UpdateCompanyRatingAndValue(Player *p, bool update)
|
|||
_score_part[owner][SCORE_STATIONS] = num;
|
||||
}
|
||||
|
||||
/* Generate statistics depending on recent income statistics */
|
||||
/* Generate statistics depending on recent income statistics */
|
||||
{
|
||||
int numec = min(p->num_valid_stat_ent, 12);
|
||||
int numec = min(c->num_valid_stat_ent, 12);
|
||||
if (numec != 0) {
|
||||
const PlayerEconomyEntry *pee = p->old_economy;
|
||||
Money min_income = pee->income + pee->expenses;
|
||||
Money max_income = pee->income + pee->expenses;
|
||||
const CompanyEconomyEntry *cee = c->old_economy;
|
||||
Money min_income = cee->income + cee->expenses;
|
||||
Money max_income = cee->income + cee->expenses;
|
||||
|
||||
do {
|
||||
min_income = min(min_income, pee->income + pee->expenses);
|
||||
max_income = max(max_income, pee->income + pee->expenses);
|
||||
} while (++pee,--numec);
|
||||
min_income = min(min_income, cee->income + cee->expenses);
|
||||
max_income = max(max_income, cee->income + cee->expenses);
|
||||
} while (++cee,--numec);
|
||||
|
||||
if (min_income > 0)
|
||||
if (min_income > 0) {
|
||||
_score_part[owner][SCORE_MIN_INCOME] = ClampToI32(min_income);
|
||||
}
|
||||
|
||||
_score_part[owner][SCORE_MAX_INCOME] = ClampToI32(max_income);
|
||||
}
|
||||
}
|
||||
|
||||
/* Generate score depending on amount of transported cargo */
|
||||
/* Generate score depending on amount of transported cargo */
|
||||
{
|
||||
const PlayerEconomyEntry* pee;
|
||||
const CompanyEconomyEntry *cee;
|
||||
int numec;
|
||||
uint32 total_delivered;
|
||||
|
||||
numec = min(p->num_valid_stat_ent, 4);
|
||||
numec = min(c->num_valid_stat_ent, 4);
|
||||
if (numec != 0) {
|
||||
pee = p->old_economy;
|
||||
cee = c->old_economy;
|
||||
total_delivered = 0;
|
||||
do {
|
||||
total_delivered += pee->delivered_cargo;
|
||||
} while (++pee,--numec);
|
||||
total_delivered += cee->delivered_cargo;
|
||||
} while (++cee,--numec);
|
||||
|
||||
_score_part[owner][SCORE_DELIVERED] = total_delivered;
|
||||
}
|
||||
}
|
||||
|
||||
/* Generate score for variety of cargo */
|
||||
/* Generate score for variety of cargo */
|
||||
{
|
||||
uint num = CountBits(p->cargo_types);
|
||||
uint num = CountBits(c->cargo_types);
|
||||
_score_part[owner][SCORE_CARGO] = num;
|
||||
if (update) p->cargo_types = 0;
|
||||
if (update) c->cargo_types = 0;
|
||||
}
|
||||
|
||||
/* Generate score for player money */
|
||||
/* Generate score for company's money */
|
||||
{
|
||||
if (p->player_money > 0) {
|
||||
_score_part[owner][SCORE_MONEY] = ClampToI32(p->player_money);
|
||||
if (c->money > 0) {
|
||||
_score_part[owner][SCORE_MONEY] = ClampToI32(c->money);
|
||||
}
|
||||
}
|
||||
|
||||
/* Generate score for loan */
|
||||
/* Generate score for loan */
|
||||
{
|
||||
_score_part[owner][SCORE_LOAN] = ClampToI32(_score_info[SCORE_LOAN].needed - p->current_loan);
|
||||
_score_part[owner][SCORE_LOAN] = ClampToI32(_score_info[SCORE_LOAN].needed - c->current_loan);
|
||||
}
|
||||
|
||||
/* Now we calculate the score for each item.. */
|
||||
|
@ -269,92 +270,92 @@ int UpdateCompanyRatingAndValue(Player *p, bool update)
|
|||
}
|
||||
|
||||
if (update) {
|
||||
p->old_economy[0].performance_history = score;
|
||||
UpdateCompanyHQ(p, score);
|
||||
p->old_economy[0].company_value = CalculateCompanyValue(p);
|
||||
c->old_economy[0].performance_history = score;
|
||||
UpdateCompanyHQ(c, score);
|
||||
c->old_economy[0].company_value = CalculateCompanyValue(c);
|
||||
}
|
||||
|
||||
InvalidateWindow(WC_PERFORMANCE_DETAIL, 0);
|
||||
return score;
|
||||
}
|
||||
|
||||
/* use PLAYER_SPECTATOR as new_player to delete the player. */
|
||||
void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player)
|
||||
/* use INVALID_OWNER as new_owner to delete the company. */
|
||||
void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
|
||||
{
|
||||
Town *t;
|
||||
PlayerID old = _current_player;
|
||||
CompanyID old = _current_company;
|
||||
|
||||
assert(old_player != new_player);
|
||||
assert(old_owner != new_owner);
|
||||
|
||||
{
|
||||
Player *p;
|
||||
Company *c;
|
||||
uint i;
|
||||
|
||||
/* See if the old_player had shares in other companies */
|
||||
_current_player = old_player;
|
||||
FOR_ALL_PLAYERS(p) {
|
||||
/* See if the old_owner had shares in other companies */
|
||||
_current_company = old_owner;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (i = 0; i < 4; i++) {
|
||||
if (p->share_owners[i] == old_player) {
|
||||
if (c->share_owners[i] == old_owner) {
|
||||
/* Sell his shares */
|
||||
CommandCost res = DoCommand(0, p->index, 0, DC_EXEC, CMD_SELL_SHARE_IN_COMPANY);
|
||||
CommandCost res = DoCommand(0, c->index, 0, DC_EXEC, CMD_SELL_SHARE_IN_COMPANY);
|
||||
/* Because we are in a DoCommand, we can't just execute an other one and
|
||||
* expect the money to be removed. We need to do it ourself! */
|
||||
SubtractMoneyFromPlayer(res);
|
||||
SubtractMoneyFromCompany(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Sell all the shares that people have on this company */
|
||||
p = GetPlayer(old_player);
|
||||
c = GetCompany(old_owner);
|
||||
for (i = 0; i < 4; i++) {
|
||||
_current_player = p->share_owners[i];
|
||||
if (_current_player != PLAYER_SPECTATOR) {
|
||||
_current_company = c->share_owners[i];
|
||||
if (_current_company != INVALID_OWNER) {
|
||||
/* Sell the shares */
|
||||
CommandCost res = DoCommand(0, old_player, 0, DC_EXEC, CMD_SELL_SHARE_IN_COMPANY);
|
||||
CommandCost res = DoCommand(0, old_owner, 0, DC_EXEC, CMD_SELL_SHARE_IN_COMPANY);
|
||||
/* Because we are in a DoCommand, we can't just execute an other one and
|
||||
* expect the money to be removed. We need to do it ourself! */
|
||||
SubtractMoneyFromPlayer(res);
|
||||
SubtractMoneyFromCompany(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_current_player = old_player;
|
||||
_current_company = old_owner;
|
||||
|
||||
/* Temporarily increase the player's money, to be sure that
|
||||
/* Temporarily increase the company's money, to be sure that
|
||||
* removing his/her property doesn't fail because of lack of money.
|
||||
* Not too drastically though, because it could overflow */
|
||||
if (new_player == PLAYER_SPECTATOR) {
|
||||
GetPlayer(old_player)->player_money = UINT64_MAX >> 2; // jackpot ;p
|
||||
if (new_owner == INVALID_OWNER) {
|
||||
GetCompany(old_owner)->money = UINT64_MAX >> 2; // jackpot ;p
|
||||
}
|
||||
|
||||
if (new_player == PLAYER_SPECTATOR) {
|
||||
if (new_owner == INVALID_OWNER) {
|
||||
Subsidy *s;
|
||||
|
||||
for (s = _subsidies; s != endof(_subsidies); s++) {
|
||||
if (s->cargo_type != CT_INVALID && s->age >= 12) {
|
||||
if (GetStation(s->to)->owner == old_player) s->cargo_type = CT_INVALID;
|
||||
if (GetStation(s->to)->owner == old_owner) s->cargo_type = CT_INVALID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Take care of rating in towns */
|
||||
FOR_ALL_TOWNS(t) {
|
||||
/* If a player takes over, give the ratings to that player. */
|
||||
if (new_player != PLAYER_SPECTATOR) {
|
||||
if (HasBit(t->have_ratings, old_player)) {
|
||||
if (HasBit(t->have_ratings, new_player)) {
|
||||
/* If a company takes over, give the ratings to that company. */
|
||||
if (new_owner != INVALID_OWNER) {
|
||||
if (HasBit(t->have_ratings, old_owner)) {
|
||||
if (HasBit(t->have_ratings, new_owner)) {
|
||||
// use max of the two ratings.
|
||||
t->ratings[new_player] = max(t->ratings[new_player], t->ratings[old_player]);
|
||||
t->ratings[new_owner] = max(t->ratings[new_owner], t->ratings[old_owner]);
|
||||
} else {
|
||||
SetBit(t->have_ratings, new_player);
|
||||
t->ratings[new_player] = t->ratings[old_player];
|
||||
SetBit(t->have_ratings, new_owner);
|
||||
t->ratings[new_owner] = t->ratings[old_owner];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Reset the ratings for the old player */
|
||||
t->ratings[old_player] = RATING_INITIAL;
|
||||
ClrBit(t->have_ratings, old_player);
|
||||
/* Reset the ratings for the old owner */
|
||||
t->ratings[old_owner] = RATING_INITIAL;
|
||||
ClrBit(t->have_ratings, old_owner);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -366,7 +367,7 @@ void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player)
|
|||
|
||||
/* Determine Ids for the new vehicles */
|
||||
FOR_ALL_VEHICLES(v) {
|
||||
if (v->owner == new_player) {
|
||||
if (v->owner == new_owner) {
|
||||
switch (v->type) {
|
||||
case VEH_TRAIN: if (IsFrontEngine(v)) num_train++; break;
|
||||
case VEH_ROAD: if (IsRoadVehFront(v)) num_road++; break;
|
||||
|
@ -378,8 +379,8 @@ void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player)
|
|||
}
|
||||
|
||||
FOR_ALL_VEHICLES(v) {
|
||||
if (v->owner == old_player && IsInsideMM(v->type, VEH_TRAIN, VEH_AIRCRAFT + 1)) {
|
||||
if (new_player == PLAYER_SPECTATOR) {
|
||||
if (v->owner == old_owner && IsInsideMM(v->type, VEH_TRAIN, VEH_AIRCRAFT + 1)) {
|
||||
if (new_owner == INVALID_OWNER) {
|
||||
DeleteWindowById(WC_VEHICLE_VIEW, v->index);
|
||||
DeleteWindowById(WC_VEHICLE_DETAILS, v->index);
|
||||
DeleteWindowById(WC_VEHICLE_ORDERS, v->index);
|
||||
|
@ -408,10 +409,10 @@ void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player)
|
|||
}
|
||||
}
|
||||
} else {
|
||||
v->owner = new_player;
|
||||
v->owner = new_owner;
|
||||
v->colormap = PAL_NONE;
|
||||
v->group_id = DEFAULT_GROUP;
|
||||
if (IsEngineCountable(v)) GetPlayer(new_player)->num_engines[v->engine_type]++;
|
||||
if (IsEngineCountable(v)) GetCompany(new_owner)->num_engines[v->engine_type]++;
|
||||
switch (v->type) {
|
||||
case VEH_TRAIN: if (IsFrontEngine(v)) v->unitnumber = ++num_train; break;
|
||||
case VEH_ROAD: if (IsRoadVehFront(v)) v->unitnumber = ++num_road; break;
|
||||
|
@ -428,24 +429,24 @@ void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player)
|
|||
{
|
||||
TileIndex tile = 0;
|
||||
do {
|
||||
ChangeTileOwner(tile, old_player, new_player);
|
||||
ChangeTileOwner(tile, old_owner, new_owner);
|
||||
} while (++tile != MapSize());
|
||||
|
||||
if (new_player != PLAYER_SPECTATOR) {
|
||||
/* Update all signals because there can be new segment that was owned by two players
|
||||
if (new_owner != INVALID_OWNER) {
|
||||
/* Update all signals because there can be new segment that was owned by two companies
|
||||
* and signals were not propagated
|
||||
* Similiar with crossings - it is needed to bar crossings that weren't before
|
||||
* because of different owner of crossing and approaching train */
|
||||
tile = 0;
|
||||
|
||||
do {
|
||||
if (IsTileType(tile, MP_RAILWAY) && IsTileOwner(tile, new_player) && HasSignals(tile)) {
|
||||
if (IsTileType(tile, MP_RAILWAY) && IsTileOwner(tile, new_owner) && HasSignals(tile)) {
|
||||
TrackBits tracks = GetTrackBits(tile);
|
||||
do { // there may be two tracks with signals for TRACK_BIT_HORZ and TRACK_BIT_VERT
|
||||
Track track = RemoveFirstTrack(&tracks);
|
||||
if (HasSignalOnTrack(tile, track)) AddTrackToSignalBuffer(tile, track, new_player);
|
||||
if (HasSignalOnTrack(tile, track)) AddTrackToSignalBuffer(tile, track, new_owner);
|
||||
} while (tracks != TRACK_BIT_NONE);
|
||||
} else if (IsLevelCrossingTile(tile) && IsTileOwner(tile, new_player)) {
|
||||
} else if (IsLevelCrossingTile(tile) && IsTileOwner(tile, new_owner)) {
|
||||
UpdateLevelCrossing(tile);
|
||||
}
|
||||
} while (++tile != MapSize());
|
||||
|
@ -457,60 +458,60 @@ void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player)
|
|||
|
||||
/* In all cases clear replace engine rules.
|
||||
* Even if it was copied, it could interfere with new owner's rules */
|
||||
RemoveAllEngineReplacementForPlayer(GetPlayer(old_player));
|
||||
RemoveAllEngineReplacementForCompany(GetCompany(old_owner));
|
||||
|
||||
if (new_player == PLAYER_SPECTATOR) {
|
||||
RemoveAllGroupsForPlayer(old_player);
|
||||
if (new_owner == INVALID_OWNER) {
|
||||
RemoveAllGroupsForCompany(old_owner);
|
||||
} else {
|
||||
Group *g;
|
||||
FOR_ALL_GROUPS(g) {
|
||||
if (g->owner == old_player) g->owner = new_player;
|
||||
if (g->owner == old_owner) g->owner = new_owner;
|
||||
}
|
||||
}
|
||||
|
||||
Sign *si;
|
||||
FOR_ALL_SIGNS(si) {
|
||||
if (si->owner == old_player) si->owner = new_player == PLAYER_SPECTATOR ? OWNER_NONE : new_player;
|
||||
if (si->owner == old_owner) si->owner = new_owner == INVALID_OWNER ? OWNER_NONE : new_owner;
|
||||
}
|
||||
|
||||
/* Change color of existing windows */
|
||||
if (new_player != PLAYER_SPECTATOR) ChangeWindowOwner(old_player, new_player);
|
||||
if (new_owner != INVALID_OWNER) ChangeWindowOwner(old_owner, new_owner);
|
||||
|
||||
_current_player = old;
|
||||
_current_company = old;
|
||||
|
||||
MarkWholeScreenDirty();
|
||||
}
|
||||
|
||||
static void ChangeNetworkOwner(PlayerID current_player, PlayerID new_player)
|
||||
static void ChangeNetworkOwner(Owner current_owner, Owner new_owner)
|
||||
{
|
||||
#ifdef ENABLE_NETWORK
|
||||
if (!_networking) return;
|
||||
|
||||
if (current_player == _local_player) {
|
||||
_network_playas = new_player;
|
||||
SetLocalPlayer(new_player);
|
||||
if (current_owner == _local_company) {
|
||||
_network_playas = new_owner;
|
||||
SetLocalCompany(new_owner);
|
||||
}
|
||||
|
||||
if (!_network_server) return;
|
||||
|
||||
NetworkServerChangeOwner(current_player, new_player);
|
||||
NetworkServerChangeOwner(current_owner, new_owner);
|
||||
#endif /* ENABLE_NETWORK */
|
||||
}
|
||||
|
||||
static void PlayersCheckBankrupt(Player *p)
|
||||
static void CompanyCheckBankrupt(Company *c)
|
||||
{
|
||||
/* If the player has money again, it does not go bankrupt */
|
||||
if (p->player_money >= 0) {
|
||||
p->quarters_of_bankrupcy = 0;
|
||||
/* If the company has money again, it does not go bankrupt */
|
||||
if (c->money >= 0) {
|
||||
c->quarters_of_bankrupcy = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
p->quarters_of_bankrupcy++;
|
||||
c->quarters_of_bankrupcy++;
|
||||
|
||||
CompanyNewsInformation *cni = MallocT<CompanyNewsInformation>(1);
|
||||
cni->FillData(p);
|
||||
cni->FillData(c);
|
||||
|
||||
switch (p->quarters_of_bankrupcy) {
|
||||
switch (c->quarters_of_bankrupcy) {
|
||||
default:
|
||||
free(cni);
|
||||
break;
|
||||
|
@ -522,9 +523,9 @@ static void PlayersCheckBankrupt(Player *p)
|
|||
AddNewsItem(STR_02B6, NS_COMPANY_TROUBLE, 0, 0, cni);
|
||||
break;
|
||||
case 3: {
|
||||
/* XXX - In multiplayer, should we ask other players if it wants to take
|
||||
/* XXX - In multiplayer, should we ask other companies if it wants to take
|
||||
over when it is a human company? -- TrueLight */
|
||||
if (IsHumanPlayer(p->index)) {
|
||||
if (IsHumanCompany(c->index)) {
|
||||
SetDParam(0, STR_7056_TRANSPORT_COMPANY_IN_TROUBLE);
|
||||
SetDParam(1, STR_7057_WILL_BE_SOLD_OFF_OR_DECLARED);
|
||||
SetDParamStr(2, cni->company_name);
|
||||
|
@ -534,11 +535,11 @@ static void PlayersCheckBankrupt(Player *p)
|
|||
|
||||
/* Check if the company has any value.. if not, declare it bankrupt
|
||||
* right now */
|
||||
Money val = CalculateCompanyValue(p);
|
||||
Money val = CalculateCompanyValue(c);
|
||||
if (val > 0) {
|
||||
p->bankrupt_value = val;
|
||||
p->bankrupt_asked = 1 << p->index; // Don't ask the owner
|
||||
p->bankrupt_timeout = 0;
|
||||
c->bankrupt_value = val;
|
||||
c->bankrupt_asked = 1 << c->index; // Don't ask the owner
|
||||
c->bankrupt_timeout = 0;
|
||||
free(cni);
|
||||
break;
|
||||
}
|
||||
|
@ -546,7 +547,7 @@ static void PlayersCheckBankrupt(Player *p)
|
|||
}
|
||||
case 4: {
|
||||
/* Close everything the owner has open */
|
||||
DeletePlayerWindows(p->index);
|
||||
DeleteCompanyWindows(c->index);
|
||||
|
||||
/* Show bankrupt news */
|
||||
SetDParam(0, STR_705C_BANKRUPT);
|
||||
|
@ -554,56 +555,56 @@ static void PlayersCheckBankrupt(Player *p)
|
|||
SetDParamStr(2, cni->company_name);
|
||||
AddNewsItem(STR_02B6, NS_COMPANY_BANKRUPT, 0, 0, cni);
|
||||
|
||||
if (IsHumanPlayer(p->index)) {
|
||||
/* XXX - If we are in offline mode, leave the player playing. Eg. there
|
||||
* is no THE-END, otherwise mark the player as spectator to make sure
|
||||
if (IsHumanCompany(c->index)) {
|
||||
/* XXX - If we are in offline mode, leave the company playing. Eg. there
|
||||
* is no THE-END, otherwise mark the client as spectator to make sure
|
||||
* he/she is no long in control of this company */
|
||||
if (!_networking) {
|
||||
p->bankrupt_asked = 0xFF;
|
||||
p->bankrupt_timeout = 0x456;
|
||||
c->bankrupt_asked = 0xFF;
|
||||
c->bankrupt_timeout = 0x456;
|
||||
break;
|
||||
}
|
||||
|
||||
ChangeNetworkOwner(p->index, PLAYER_SPECTATOR);
|
||||
ChangeNetworkOwner(c->index, COMPANY_SPECTATOR);
|
||||
}
|
||||
|
||||
/* Remove the player */
|
||||
ChangeOwnershipOfPlayerItems(p->index, PLAYER_SPECTATOR);
|
||||
/* Register the player as not-active */
|
||||
/* Remove the company */
|
||||
ChangeOwnershipOfCompanyItems(c->index, INVALID_OWNER);
|
||||
/* Register the company as not-active */
|
||||
|
||||
if (!IsHumanPlayer(p->index) && (!_networking || _network_server) && _ai.enabled)
|
||||
AI_PlayerDied(p->index);
|
||||
if (!IsHumanCompany(c->index) && (!_networking || _network_server) && _ai.enabled)
|
||||
AI_CompanyDied(c->index);
|
||||
|
||||
delete p;
|
||||
delete c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void PlayersGenStatistics()
|
||||
static void CompaniesGenStatistics()
|
||||
{
|
||||
Station *st;
|
||||
Player *p;
|
||||
Company *c;
|
||||
|
||||
FOR_ALL_STATIONS(st) {
|
||||
_current_player = st->owner;
|
||||
_current_company = st->owner;
|
||||
CommandCost cost(EXPENSES_PROPERTY, _price.station_value >> 1);
|
||||
SubtractMoneyFromPlayer(cost);
|
||||
SubtractMoneyFromCompany(cost);
|
||||
}
|
||||
|
||||
if (!HasBit(1 << 0 | 1 << 3 | 1 << 6 | 1 << 9, _cur_month))
|
||||
return;
|
||||
|
||||
FOR_ALL_PLAYERS(p) {
|
||||
memmove(&p->old_economy[1], &p->old_economy[0], sizeof(p->old_economy) - sizeof(p->old_economy[0]));
|
||||
p->old_economy[0] = p->cur_economy;
|
||||
memset(&p->cur_economy, 0, sizeof(p->cur_economy));
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
memmove(&c->old_economy[1], &c->old_economy[0], sizeof(c->old_economy) - sizeof(c->old_economy[0]));
|
||||
c->old_economy[0] = c->cur_economy;
|
||||
memset(&c->cur_economy, 0, sizeof(c->cur_economy));
|
||||
|
||||
if (p->num_valid_stat_ent != 24) p->num_valid_stat_ent++;
|
||||
if (c->num_valid_stat_ent != 24) c->num_valid_stat_ent++;
|
||||
|
||||
UpdateCompanyRatingAndValue(p, true);
|
||||
PlayersCheckBankrupt(p);
|
||||
UpdateCompanyRatingAndValue(c, true);
|
||||
CompanyCheckBankrupt(c);
|
||||
|
||||
if (p->block_preview != 0) p->block_preview--;
|
||||
if (c->block_preview != 0) c->block_preview--;
|
||||
}
|
||||
|
||||
InvalidateWindow(WC_INCOME_GRAPH, 0);
|
||||
|
@ -676,17 +677,17 @@ static void AddInflation(bool check_year = true)
|
|||
InvalidateWindow(WC_PAYMENT_RATES, 0);
|
||||
}
|
||||
|
||||
static void PlayersPayInterest()
|
||||
static void CompaniesPayInterest()
|
||||
{
|
||||
const Player* p;
|
||||
const Company *c;
|
||||
int interest = _economy.interest_rate * 54;
|
||||
|
||||
FOR_ALL_PLAYERS(p) {
|
||||
_current_player = p->index;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
_current_company = c->index;
|
||||
|
||||
SubtractMoneyFromPlayer(CommandCost(EXPENSES_LOAN_INT, (Money)BigMulSU(p->current_loan, interest, 16)));
|
||||
SubtractMoneyFromCompany(CommandCost(EXPENSES_LOAN_INT, (Money)BigMulSU(c->current_loan, interest, 16)));
|
||||
|
||||
SubtractMoneyFromPlayer(CommandCost(EXPENSES_OTHER, _price.station_value >> 2));
|
||||
SubtractMoneyFromCompany(CommandCost(EXPENSES_OTHER, _price.station_value >> 2));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1097,7 +1098,7 @@ static void SubsidyMonthlyHandler()
|
|||
modified = true;
|
||||
} else if (s->age == 2*12-1) {
|
||||
st = GetStation(s->to);
|
||||
if (st->owner == _local_player) {
|
||||
if (st->owner == _local_company) {
|
||||
pair = SetupSubsidyDecodeParam(s, 1);
|
||||
AddNewsItem(STR_202F_SUBSIDY_WITHDRAWN_SERVICE, NS_SUBSIDIES, pair.a, pair.b);
|
||||
}
|
||||
|
@ -1352,7 +1353,7 @@ static bool CheckSubsidised(Station *from, Station *to, CargoID cargo_type)
|
|||
pair = SetupSubsidyDecodeParam(s, 0);
|
||||
InjectDParam(1);
|
||||
|
||||
SetDParam(0, _current_player);
|
||||
SetDParam(0, _current_company);
|
||||
AddNewsItem(
|
||||
STR_2031_SERVICE_SUBSIDY_AWARDED + _settings_game.difficulty.subsidy_multiplier,
|
||||
NS_SUBSIDIES,
|
||||
|
@ -1374,11 +1375,11 @@ static Money DeliverGoods(int num_pieces, CargoID cargo_type, StationID source,
|
|||
|
||||
assert(num_pieces > 0);
|
||||
|
||||
/* Update player statistics */
|
||||
/* Update company statistics */
|
||||
{
|
||||
Player *p = GetPlayer(_current_player);
|
||||
p->cur_economy.delivered_cargo += num_pieces;
|
||||
SetBit(p->cargo_types, cargo_type);
|
||||
Company *c = GetCompany(_current_company);
|
||||
c->cur_economy.delivered_cargo += num_pieces;
|
||||
SetBit(c->cargo_types, cargo_type);
|
||||
}
|
||||
|
||||
/* Get station pointers. */
|
||||
|
@ -1428,8 +1429,8 @@ void VehiclePayment(Vehicle *front_v)
|
|||
Station *st = GetStation(last_visited);
|
||||
|
||||
/* The owner of the train wants to be paid */
|
||||
PlayerID old_player = _current_player;
|
||||
_current_player = front_v->owner;
|
||||
CompanyID old_company = _current_company;
|
||||
_current_company = front_v->owner;
|
||||
|
||||
/* At this moment loading cannot be finished */
|
||||
ClrBit(front_v->vehicle_flags, VF_LOADING_FINISHED);
|
||||
|
@ -1496,16 +1497,16 @@ void VehiclePayment(Vehicle *front_v)
|
|||
|
||||
if (route_profit != 0) {
|
||||
front_v->profit_this_year += vehicle_profit << 8;
|
||||
SubtractMoneyFromPlayer(CommandCost(front_v->GetExpenseType(true), -route_profit));
|
||||
SubtractMoneyFromCompany(CommandCost(front_v->GetExpenseType(true), -route_profit));
|
||||
|
||||
if (IsLocalPlayer() && !PlayVehicleSound(front_v, VSE_LOAD_UNLOAD)) {
|
||||
if (IsLocalCompany() && !PlayVehicleSound(front_v, VSE_LOAD_UNLOAD)) {
|
||||
SndPlayVehicleFx(SND_14_CASHTILL, front_v);
|
||||
}
|
||||
|
||||
ShowCostOrIncomeAnimation(front_v->x_pos, front_v->y_pos, front_v->z_pos, -vehicle_profit);
|
||||
}
|
||||
|
||||
_current_player = old_player;
|
||||
_current_company = old_company;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1726,10 +1727,10 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left)
|
|||
/* Calculate the loading indicator fill percent and display
|
||||
* In the Game Menu do not display indicators
|
||||
* If _settings_client.gui.loading_indicators == 2, show indicators (bool can be promoted to int as 0 or 1 - results in 2 > 0,1 )
|
||||
* if _settings_client.gui.loading_indicators == 1, _local_player must be the owner or must be a spectator to show ind., so 1 > 0
|
||||
* if _settings_client.gui.loading_indicators == 1, _local_company must be the owner or must be a spectator to show ind., so 1 > 0
|
||||
* if _settings_client.gui.loading_indicators == 0, do not display indicators ... 0 is never greater than anything
|
||||
*/
|
||||
if (_game_mode != GM_MENU && (_settings_client.gui.loading_indicators > (uint)(v->owner != _local_player && _local_player != PLAYER_SPECTATOR))) {
|
||||
if (_game_mode != GM_MENU && (_settings_client.gui.loading_indicators > (uint)(v->owner != _local_company && _local_company != COMPANY_SPECTATOR))) {
|
||||
StringID percent_up_down = STR_NULL;
|
||||
int percent = CalcPercentVehicleFilled(v, &percent_up_down);
|
||||
if (v->fill_percent_te_id == INVALID_TE_ID) {
|
||||
|
@ -1774,68 +1775,68 @@ void LoadUnloadStation(Station *st)
|
|||
}
|
||||
}
|
||||
|
||||
void PlayersMonthlyLoop()
|
||||
void CompaniesMonthlyLoop()
|
||||
{
|
||||
PlayersGenStatistics();
|
||||
CompaniesGenStatistics();
|
||||
if (_settings_game.economy.inflation) AddInflation();
|
||||
PlayersPayInterest();
|
||||
/* Reset the _current_player flag */
|
||||
_current_player = OWNER_NONE;
|
||||
CompaniesPayInterest();
|
||||
/* Reset the _current_company flag */
|
||||
_current_company = OWNER_NONE;
|
||||
HandleEconomyFluctuations();
|
||||
SubsidyMonthlyHandler();
|
||||
}
|
||||
|
||||
static void DoAcquireCompany(Player *p)
|
||||
static void DoAcquireCompany(Company *c)
|
||||
{
|
||||
Player *owner;
|
||||
Company *owner;
|
||||
int i;
|
||||
Money value;
|
||||
|
||||
CompanyNewsInformation *cni = MallocT<CompanyNewsInformation>(1);
|
||||
cni->FillData(p, GetPlayer(_current_player));
|
||||
cni->FillData(c, GetCompany(_current_company));
|
||||
|
||||
SetDParam(0, STR_7059_TRANSPORT_COMPANY_MERGER);
|
||||
SetDParam(1, p->bankrupt_value == 0 ? STR_707F_HAS_BEEN_TAKEN_OVER_BY : STR_705A_HAS_BEEN_SOLD_TO_FOR);
|
||||
SetDParam(1, c->bankrupt_value == 0 ? STR_707F_HAS_BEEN_TAKEN_OVER_BY : STR_705A_HAS_BEEN_SOLD_TO_FOR);
|
||||
SetDParamStr(2, cni->company_name);
|
||||
SetDParamStr(3, cni->other_company_name);
|
||||
SetDParam(4, p->bankrupt_value);
|
||||
SetDParam(4, c->bankrupt_value);
|
||||
AddNewsItem(STR_02B6, NS_COMPANY_MERGER, 0, 0, cni);
|
||||
|
||||
/* original code does this a little bit differently */
|
||||
PlayerID pi = p->index;
|
||||
ChangeNetworkOwner(pi, _current_player);
|
||||
ChangeOwnershipOfPlayerItems(pi, _current_player);
|
||||
CompanyID ci = c->index;
|
||||
ChangeNetworkOwner(ci, _current_company);
|
||||
ChangeOwnershipOfCompanyItems(ci, _current_company);
|
||||
|
||||
if (p->bankrupt_value == 0) {
|
||||
owner = GetPlayer(_current_player);
|
||||
owner->current_loan += p->current_loan;
|
||||
if (c->bankrupt_value == 0) {
|
||||
owner = GetCompany(_current_company);
|
||||
owner->current_loan += c->current_loan;
|
||||
}
|
||||
|
||||
value = CalculateCompanyValue(p) >> 2;
|
||||
PlayerID old_player = _current_player;
|
||||
value = CalculateCompanyValue(c) >> 2;
|
||||
CompanyID old_company = _current_company;
|
||||
for (i = 0; i != 4; i++) {
|
||||
if (p->share_owners[i] != PLAYER_SPECTATOR) {
|
||||
_current_player = p->share_owners[i];
|
||||
SubtractMoneyFromPlayer(CommandCost(EXPENSES_OTHER, -value));
|
||||
if (c->share_owners[i] != COMPANY_SPECTATOR) {
|
||||
_current_company = c->share_owners[i];
|
||||
SubtractMoneyFromCompany(CommandCost(EXPENSES_OTHER, -value));
|
||||
}
|
||||
}
|
||||
_current_player = old_player;
|
||||
_current_company = old_company;
|
||||
|
||||
DeletePlayerWindows(pi);
|
||||
DeleteCompanyWindows(ci);
|
||||
InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
|
||||
InvalidateWindowClassesData(WC_SHIPS_LIST, 0);
|
||||
InvalidateWindowClassesData(WC_ROADVEH_LIST, 0);
|
||||
InvalidateWindowClassesData(WC_AIRCRAFT_LIST, 0);
|
||||
|
||||
delete p;
|
||||
delete c;
|
||||
}
|
||||
|
||||
extern int GetAmountOwnedBy(const Player *p, PlayerID owner);
|
||||
extern int GetAmountOwnedBy(const Company *c, Owner owner);
|
||||
|
||||
/** Acquire shares in an opposing company.
|
||||
* @param tile unused
|
||||
* @param flags type of operation
|
||||
* @param p1 player to buy the shares from
|
||||
* @param p1 company to buy the shares from
|
||||
* @param p2 unused
|
||||
*/
|
||||
CommandCost CmdBuyShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
||||
|
@ -1844,31 +1845,31 @@ CommandCost CmdBuyShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32
|
|||
|
||||
/* Check if buying shares is allowed (protection against modified clients) */
|
||||
/* Cannot buy own shares */
|
||||
if (!IsValidPlayerID((PlayerID)p1) || !_settings_game.economy.allow_shares || _current_player == (PlayerID)p1) return CMD_ERROR;
|
||||
if (!IsValidCompanyID((CompanyID)p1) || !_settings_game.economy.allow_shares || _current_company == (CompanyID)p1) return CMD_ERROR;
|
||||
|
||||
Player *p = GetPlayer((PlayerID)p1);
|
||||
Company *c = GetCompany((CompanyID)p1);
|
||||
|
||||
/* Protect new companies from hostile takeovers */
|
||||
if (_cur_year - p->inaugurated_year < 6) return_cmd_error(STR_PROTECTED);
|
||||
if (_cur_year - c->inaugurated_year < 6) return_cmd_error(STR_PROTECTED);
|
||||
|
||||
/* Those lines are here for network-protection (clients can be slow) */
|
||||
if (GetAmountOwnedBy(p, PLAYER_SPECTATOR) == 0) return cost;
|
||||
if (GetAmountOwnedBy(c, COMPANY_SPECTATOR) == 0) return cost;
|
||||
|
||||
/* We can not buy out a real player (temporarily). TODO: well, enable it obviously */
|
||||
if (GetAmountOwnedBy(p, PLAYER_SPECTATOR) == 1 && !p->is_ai) return cost;
|
||||
/* We can not buy out a real company (temporarily). TODO: well, enable it obviously */
|
||||
if (GetAmountOwnedBy(c, COMPANY_SPECTATOR) == 1 && !c->is_ai) return cost;
|
||||
|
||||
cost.AddCost(CalculateCompanyValue(p) >> 2);
|
||||
cost.AddCost(CalculateCompanyValue(c) >> 2);
|
||||
if (flags & DC_EXEC) {
|
||||
PlayerByte* b = p->share_owners;
|
||||
OwnerByte *b = c->share_owners;
|
||||
int i;
|
||||
|
||||
while (*b != PLAYER_SPECTATOR) b++; /* share owners is guaranteed to contain at least one PLAYER_SPECTATOR */
|
||||
*b = _current_player;
|
||||
while (*b != COMPANY_SPECTATOR) b++; /* share owners is guaranteed to contain at least one COMPANY_SPECTATOR */
|
||||
*b = _current_company;
|
||||
|
||||
for (i = 0; p->share_owners[i] == _current_player;) {
|
||||
for (i = 0; c->share_owners[i] == _current_company;) {
|
||||
if (++i == 4) {
|
||||
p->bankrupt_value = 0;
|
||||
DoAcquireCompany(p);
|
||||
c->bankrupt_value = 0;
|
||||
DoAcquireCompany(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1880,28 +1881,28 @@ CommandCost CmdBuyShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32
|
|||
/** Sell shares in an opposing company.
|
||||
* @param tile unused
|
||||
* @param flags type of operation
|
||||
* @param p1 player to sell the shares from
|
||||
* @param p1 company to sell the shares from
|
||||
* @param p2 unused
|
||||
*/
|
||||
CommandCost CmdSellShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
||||
{
|
||||
/* Check if selling shares is allowed (protection against modified clients) */
|
||||
/* Cannot sell own shares */
|
||||
if (!IsValidPlayerID((PlayerID)p1) || !_settings_game.economy.allow_shares || _current_player == (PlayerID)p1) return CMD_ERROR;
|
||||
if (!IsValidCompanyID((CompanyID)p1) || !_settings_game.economy.allow_shares || _current_company == (CompanyID)p1) return CMD_ERROR;
|
||||
|
||||
Player *p = GetPlayer((PlayerID)p1);
|
||||
Company *c = GetCompany((CompanyID)p1);
|
||||
|
||||
/* Those lines are here for network-protection (clients can be slow) */
|
||||
if (GetAmountOwnedBy(p, _current_player) == 0) return CommandCost();
|
||||
if (GetAmountOwnedBy(c, _current_company) == 0) return CommandCost();
|
||||
|
||||
/* adjust it a little to make it less profitable to sell and buy */
|
||||
Money cost = CalculateCompanyValue(p) >> 2;
|
||||
Money cost = CalculateCompanyValue(c) >> 2;
|
||||
cost = -(cost - (cost >> 7));
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
PlayerByte* b = p->share_owners;
|
||||
while (*b != _current_player) b++; // share owners is guaranteed to contain player
|
||||
*b = PLAYER_SPECTATOR;
|
||||
OwnerByte *b = c->share_owners;
|
||||
while (*b != _current_company) b++; // share owners is guaranteed to contain company
|
||||
*b = COMPANY_SPECTATOR;
|
||||
InvalidateWindow(WC_COMPANY, p1);
|
||||
}
|
||||
return CommandCost(EXPENSES_OTHER, cost);
|
||||
|
@ -1910,30 +1911,30 @@ CommandCost CmdSellShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint3
|
|||
/** Buy up another company.
|
||||
* When a competing company is gone bankrupt you get the chance to purchase
|
||||
* that company.
|
||||
* @todo currently this only works for AI players
|
||||
* @todo currently this only works for AI companies
|
||||
* @param tile unused
|
||||
* @param flags type of operation
|
||||
* @param p1 player/company to buy up
|
||||
* @param p1 company to buy up
|
||||
* @param p2 unused
|
||||
*/
|
||||
CommandCost CmdBuyCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
||||
{
|
||||
PlayerID pid = (PlayerID)p1;
|
||||
CompanyID cid = (CompanyID)p1;
|
||||
|
||||
/* Disable takeovers in multiplayer games */
|
||||
if (!IsValidPlayerID(pid) || _networking) return CMD_ERROR;
|
||||
if (!IsValidCompanyID(cid) || _networking) return CMD_ERROR;
|
||||
|
||||
/* Do not allow players to take over themselves */
|
||||
if (pid == _current_player) return CMD_ERROR;
|
||||
/* Do not allow companies to take over themselves */
|
||||
if (cid == _current_company) return CMD_ERROR;
|
||||
|
||||
Player *p = GetPlayer(pid);
|
||||
Company *c = GetCompany(cid);
|
||||
|
||||
if (!p->is_ai) return CMD_ERROR;
|
||||
if (!c->is_ai) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
DoAcquireCompany(p);
|
||||
DoAcquireCompany(c);
|
||||
}
|
||||
return CommandCost(EXPENSES_OTHER, p->bankrupt_value);
|
||||
return CommandCost(EXPENSES_OTHER, c->bankrupt_value);
|
||||
}
|
||||
|
||||
/** Prices */
|
||||
|
|
|
@ -15,23 +15,21 @@
|
|||
#include "player_type.h"
|
||||
#include "station_type.h"
|
||||
|
||||
struct Player;
|
||||
|
||||
void ResetPriceBaseMultipliers();
|
||||
void SetPriceBaseMultiplier(uint price, byte factor);
|
||||
void ResetEconomy();
|
||||
|
||||
extern const ScoreInfo _score_info[];
|
||||
extern int _score_part[MAX_PLAYERS][SCORE_END];
|
||||
extern int _score_part[MAX_COMPANIES][SCORE_END];
|
||||
extern Economy _economy;
|
||||
extern Subsidy _subsidies[MAX_PLAYERS];
|
||||
extern Subsidy _subsidies[MAX_COMPANIES];
|
||||
/* Prices and also the fractional part. */
|
||||
extern Prices _price;
|
||||
extern uint16 _price_frac[NUM_PRICES];
|
||||
extern Money _cargo_payment_rates[NUM_CARGO];
|
||||
extern uint16 _cargo_payment_rates_frac[NUM_CARGO];
|
||||
|
||||
int UpdateCompanyRatingAndValue(Player *p, bool update);
|
||||
int UpdateCompanyRatingAndValue(Company *c, bool update);
|
||||
Pair SetupSubsidyDecodeParam(const Subsidy *s, bool mode);
|
||||
void DeleteSubsidyWithTown(TownID index);
|
||||
void DeleteSubsidyWithIndustry(IndustryID index);
|
||||
|
|
|
@ -465,7 +465,7 @@ void DrawCatenary(const TileInfo *ti)
|
|||
int32 SettingsDisableElrail(int32 p1)
|
||||
{
|
||||
Vehicle *v;
|
||||
Player *p;
|
||||
Company *c;
|
||||
bool disable = (p1 != 0);
|
||||
|
||||
/* we will now walk through all electric train engines and change their railtypes if it is the wrong one*/
|
||||
|
@ -506,7 +506,7 @@ int32 SettingsDisableElrail(int32 p1)
|
|||
}
|
||||
}
|
||||
|
||||
FOR_ALL_PLAYERS(p) p->avail_railtypes = GetPlayerRailtypes(p->index);
|
||||
FOR_ALL_COMPANIES(c) c->avail_railtypes = GetCompanyRailtypes(c->index);
|
||||
|
||||
/* This resets the _last_built_railtype, which will be invalid for electric
|
||||
* rails. It may have unintended consequences if that function is ever
|
||||
|
|
154
src/engine.cpp
154
src/engine.cpp
|
@ -114,17 +114,17 @@ Engine::~Engine()
|
|||
free(this->name);
|
||||
}
|
||||
|
||||
/** Sets cached values in Player::num_vehicles and Group::num_vehicles
|
||||
/** Sets cached values in Company::num_vehicles and Group::num_vehicles
|
||||
*/
|
||||
void SetCachedEngineCounts()
|
||||
{
|
||||
uint engines = GetEnginePoolSize();
|
||||
|
||||
/* Set up the engine count for all players */
|
||||
Player *p;
|
||||
FOR_ALL_PLAYERS(p) {
|
||||
free(p->num_engines);
|
||||
p->num_engines = CallocT<EngineID>(engines);
|
||||
/* Set up the engine count for all companies */
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
free(c->num_engines);
|
||||
c->num_engines = CallocT<EngineID>(engines);
|
||||
}
|
||||
|
||||
/* Recalculate */
|
||||
|
@ -140,7 +140,7 @@ void SetCachedEngineCounts()
|
|||
|
||||
assert(v->engine_type < engines);
|
||||
|
||||
GetPlayer(v->owner)->num_engines[v->engine_type]++;
|
||||
GetCompany(v->owner)->num_engines[v->engine_type]++;
|
||||
|
||||
if (v->group_id == DEFAULT_GROUP) continue;
|
||||
|
||||
|
@ -195,12 +195,12 @@ static void CalcEngineReliability(Engine *e)
|
|||
uint age = e->age;
|
||||
|
||||
/* Check for early retirement */
|
||||
if (e->player_avail != 0 && !_settings_game.vehicle.never_expire_vehicles) {
|
||||
if (e->company_avail != 0 && !_settings_game.vehicle.never_expire_vehicles) {
|
||||
int retire_early = e->info.retire_early;
|
||||
uint retire_early_max_age = max(0, e->duration_phase_1 + e->duration_phase_2 - retire_early * 12);
|
||||
if (retire_early != 0 && age >= retire_early_max_age) {
|
||||
/* Early retirement is enabled and we're past the date... */
|
||||
e->player_avail = 0;
|
||||
e->company_avail = 0;
|
||||
AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
|
||||
}
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ static void CalcEngineReliability(Engine *e)
|
|||
} else {
|
||||
/* time's up for this engine.
|
||||
* We will now completely retire this design */
|
||||
e->player_avail = 0;
|
||||
e->company_avail = 0;
|
||||
e->reliability = e->reliability_final;
|
||||
/* Kick this engine out of the lists */
|
||||
AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
|
||||
|
@ -239,7 +239,7 @@ void StartupEngines()
|
|||
|
||||
e->age = 0;
|
||||
e->flags = 0;
|
||||
e->player_avail = 0;
|
||||
e->company_avail = 0;
|
||||
|
||||
/* The magic value of 729 days below comes from the NewGRF spec. If the
|
||||
* base intro date is before 1922 then the random number of days is not
|
||||
|
@ -248,7 +248,7 @@ void StartupEngines()
|
|||
e->intro_date = ei->base_intro <= ConvertYMDToDate(1922, 0, 1) ? ei->base_intro : (Date)GB(r, 0, 9) + ei->base_intro;
|
||||
if (e->intro_date <= _date) {
|
||||
e->age = (aging_date - e->intro_date) >> 5;
|
||||
e->player_avail = (byte)-1;
|
||||
e->company_avail = (CompanyMask)-1;
|
||||
e->flags |= ENGINE_AVAILABLE;
|
||||
}
|
||||
|
||||
|
@ -275,63 +275,63 @@ void StartupEngines()
|
|||
/* prevent certain engines from ever appearing. */
|
||||
if (!HasBit(ei->climates, _settings_game.game_creation.landscape)) {
|
||||
e->flags |= ENGINE_AVAILABLE;
|
||||
e->player_avail = 0;
|
||||
e->company_avail = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Update the bitmasks for the vehicle lists */
|
||||
Player *p;
|
||||
FOR_ALL_PLAYERS(p) {
|
||||
p->avail_railtypes = GetPlayerRailtypes(p->index);
|
||||
p->avail_roadtypes = GetPlayerRoadtypes(p->index);
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
c->avail_railtypes = GetCompanyRailtypes(c->index);
|
||||
c->avail_roadtypes = GetCompanyRoadtypes(c->index);
|
||||
}
|
||||
}
|
||||
|
||||
static void AcceptEnginePreview(EngineID eid, PlayerID player)
|
||||
static void AcceptEnginePreview(EngineID eid, CompanyID company)
|
||||
{
|
||||
Engine *e = GetEngine(eid);
|
||||
Player *p = GetPlayer(player);
|
||||
Company *c = GetCompany(company);
|
||||
|
||||
SetBit(e->player_avail, player);
|
||||
SetBit(e->company_avail, company);
|
||||
if (e->type == VEH_TRAIN) {
|
||||
const RailVehicleInfo *rvi = RailVehInfo(eid);
|
||||
|
||||
assert(rvi->railtype < RAILTYPE_END);
|
||||
SetBit(p->avail_railtypes, rvi->railtype);
|
||||
SetBit(c->avail_railtypes, rvi->railtype);
|
||||
} else if (e->type == VEH_ROAD) {
|
||||
SetBit(p->avail_roadtypes, HasBit(EngInfo(eid)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
|
||||
SetBit(c->avail_roadtypes, HasBit(EngInfo(eid)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
|
||||
}
|
||||
|
||||
e->preview_player_rank = 0xFF;
|
||||
if (player == _local_player) {
|
||||
e->preview_company_rank = 0xFF;
|
||||
if (company == _local_company) {
|
||||
AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
|
||||
}
|
||||
}
|
||||
|
||||
static PlayerID GetBestPlayer(uint8 pp)
|
||||
static CompanyID GetBestCompany(uint8 pp)
|
||||
{
|
||||
const Player *p;
|
||||
const Company *c;
|
||||
int32 best_hist;
|
||||
PlayerID best_player;
|
||||
CompanyID best_company;
|
||||
uint mask = 0;
|
||||
|
||||
do {
|
||||
best_hist = -1;
|
||||
best_player = PLAYER_SPECTATOR;
|
||||
FOR_ALL_PLAYERS(p) {
|
||||
if (p->block_preview == 0 && !HasBit(mask, p->index) &&
|
||||
p->old_economy[0].performance_history > best_hist) {
|
||||
best_hist = p->old_economy[0].performance_history;
|
||||
best_player = p->index;
|
||||
best_company = INVALID_COMPANY;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
if (c->block_preview == 0 && !HasBit(mask, c->index) &&
|
||||
c->old_economy[0].performance_history > best_hist) {
|
||||
best_hist = c->old_economy[0].performance_history;
|
||||
best_company = c->index;
|
||||
}
|
||||
}
|
||||
|
||||
if (best_player == PLAYER_SPECTATOR) return PLAYER_SPECTATOR;
|
||||
if (best_company == INVALID_COMPANY) return INVALID_COMPANY;
|
||||
|
||||
SetBit(mask, best_player);
|
||||
SetBit(mask, best_company);
|
||||
} while (--pp != 0);
|
||||
|
||||
return best_player;
|
||||
return best_company;
|
||||
}
|
||||
|
||||
void EnginesDailyLoop()
|
||||
|
@ -343,33 +343,33 @@ void EnginesDailyLoop()
|
|||
EngineID i = e->index;
|
||||
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) {
|
||||
if (e->flags & ENGINE_OFFER_WINDOW_OPEN) {
|
||||
if (e->preview_player_rank != 0xFF && !--e->preview_wait) {
|
||||
if (e->preview_company_rank != 0xFF && !--e->preview_wait) {
|
||||
e->flags &= ~ENGINE_OFFER_WINDOW_OPEN;
|
||||
DeleteWindowById(WC_ENGINE_PREVIEW, i);
|
||||
e->preview_player_rank++;
|
||||
e->preview_company_rank++;
|
||||
}
|
||||
} else if (e->preview_player_rank != 0xFF) {
|
||||
PlayerID best_player = GetBestPlayer(e->preview_player_rank);
|
||||
} else if (e->preview_company_rank != 0xFF) {
|
||||
CompanyID best_company = GetBestCompany(e->preview_company_rank);
|
||||
|
||||
if (best_player == PLAYER_SPECTATOR) {
|
||||
e->preview_player_rank = 0xFF;
|
||||
if (best_company == INVALID_COMPANY) {
|
||||
e->preview_company_rank = 0xFF;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!IsHumanPlayer(best_player)) {
|
||||
if (!IsHumanCompany(best_company)) {
|
||||
/* XXX - TTDBUG: TTD has a bug here ???? */
|
||||
AcceptEnginePreview(i, best_player);
|
||||
AcceptEnginePreview(i, best_company);
|
||||
} else {
|
||||
e->flags |= ENGINE_OFFER_WINDOW_OPEN;
|
||||
e->preview_wait = 20;
|
||||
if (IsInteractivePlayer(best_player)) ShowEnginePreviewWindow(i);
|
||||
if (IsInteractiveCompany(best_company)) ShowEnginePreviewWindow(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Accept an engine prototype. XXX - it is possible that the top-player
|
||||
/** Accept an engine prototype. XXX - it is possible that the top-company
|
||||
* changes while you are waiting to accept the offer? Then it becomes invalid
|
||||
* @param tile unused
|
||||
* @param flags operation to perfom
|
||||
|
@ -382,9 +382,9 @@ CommandCost CmdWantEnginePreview(TileIndex tile, uint32 flags, uint32 p1, uint32
|
|||
|
||||
if (!IsEngineIndex(p1)) return CMD_ERROR;
|
||||
e = GetEngine(p1);
|
||||
if (GetBestPlayer(e->preview_player_rank) != _current_player) return CMD_ERROR;
|
||||
if (GetBestCompany(e->preview_company_rank) != _current_company) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) AcceptEnginePreview(p1, _current_player);
|
||||
if (flags & DC_EXEC) AcceptEnginePreview(p1, _current_company);
|
||||
|
||||
return CommandCost();
|
||||
}
|
||||
|
@ -394,26 +394,26 @@ StringID GetEngineCategoryName(EngineID engine);
|
|||
static void NewVehicleAvailable(Engine *e)
|
||||
{
|
||||
Vehicle *v;
|
||||
Player *p;
|
||||
Company *c;
|
||||
EngineID index = e->index;
|
||||
|
||||
/* In case the player didn't build the vehicle during the intro period,
|
||||
* prevent that player from getting future intro periods for a while. */
|
||||
/* In case the company didn't build the vehicle during the intro period,
|
||||
* prevent that company from getting future intro periods for a while. */
|
||||
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) {
|
||||
FOR_ALL_PLAYERS(p) {
|
||||
uint block_preview = p->block_preview;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
uint block_preview = c->block_preview;
|
||||
|
||||
if (!HasBit(e->player_avail, p->index)) continue;
|
||||
if (!HasBit(e->company_avail, c->index)) continue;
|
||||
|
||||
/* We assume the user did NOT build it.. prove me wrong ;) */
|
||||
p->block_preview = 20;
|
||||
c->block_preview = 20;
|
||||
|
||||
FOR_ALL_VEHICLES(v) {
|
||||
if (v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_SHIP ||
|
||||
(v->type == VEH_AIRCRAFT && IsNormalAircraft(v))) {
|
||||
if (v->owner == p->index && v->engine_type == index) {
|
||||
if (v->owner == c->index && v->engine_type == index) {
|
||||
/* The user did prove me wrong, so restore old value */
|
||||
p->block_preview = block_preview;
|
||||
c->block_preview = block_preview;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -424,8 +424,8 @@ static void NewVehicleAvailable(Engine *e)
|
|||
e->flags = (e->flags & ~ENGINE_EXCLUSIVE_PREVIEW) | ENGINE_AVAILABLE;
|
||||
AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
|
||||
|
||||
/* Now available for all players */
|
||||
e->player_avail = (PlayerMask)-1;
|
||||
/* Now available for all companies */
|
||||
e->company_avail = (CompanyMask)-1;
|
||||
|
||||
/* Do not introduce new rail wagons */
|
||||
if (IsWagon(index)) return;
|
||||
|
@ -434,10 +434,10 @@ static void NewVehicleAvailable(Engine *e)
|
|||
/* maybe make another rail type available */
|
||||
RailType railtype = e->u.rail.railtype;
|
||||
assert(railtype < RAILTYPE_END);
|
||||
FOR_ALL_PLAYERS(p) SetBit(p->avail_railtypes, railtype);
|
||||
FOR_ALL_COMPANIES(c) SetBit(c->avail_railtypes, railtype);
|
||||
} else if (e->type == VEH_ROAD) {
|
||||
/* maybe make another road type available */
|
||||
FOR_ALL_PLAYERS(p) SetBit(p->avail_roadtypes, HasBit(e->info.misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
|
||||
FOR_ALL_COMPANIES(c) SetBit(c->avail_roadtypes, HasBit(e->info.misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
|
||||
}
|
||||
|
||||
SetDParam(0, GetEngineCategoryName(index));
|
||||
|
@ -457,15 +457,15 @@ void EnginesMonthlyLoop()
|
|||
}
|
||||
|
||||
if (!(e->flags & ENGINE_AVAILABLE) && _date >= (e->intro_date + 365)) {
|
||||
/* Introduce it to all players */
|
||||
/* Introduce it to all companies */
|
||||
NewVehicleAvailable(e);
|
||||
} else if (!(e->flags & (ENGINE_AVAILABLE|ENGINE_EXCLUSIVE_PREVIEW)) && _date >= e->intro_date) {
|
||||
/* Introduction date has passed.. show introducing dialog to one player. */
|
||||
/* Introduction date has passed.. show introducing dialog to one companies. */
|
||||
e->flags |= ENGINE_EXCLUSIVE_PREVIEW;
|
||||
|
||||
/* Do not introduce new rail wagons */
|
||||
if (!IsWagon(e->index))
|
||||
e->preview_player_rank = 1; // Give to the player with the highest rating.
|
||||
e->preview_company_rank = 1; // Give to the company with the highest rating.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -529,13 +529,13 @@ CommandCost CmdRenameEngine(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
|
||||
|
||||
/** Check if an engine is buildable.
|
||||
* @param engine index of the engine to check.
|
||||
* @param type the type the engine should be.
|
||||
* @param player index of the player.
|
||||
* @param engine index of the engine to check.
|
||||
* @param type the type the engine should be.
|
||||
* @param company index of the company.
|
||||
* @return True if an engine is valid, of the specified type, and buildable by
|
||||
* the given player.
|
||||
* the given company.
|
||||
*/
|
||||
bool IsEngineBuildable(EngineID engine, VehicleType type, PlayerID player)
|
||||
bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
|
||||
{
|
||||
/* check if it's an engine that is in the engine array */
|
||||
if (!IsEngineIndex(engine)) return false;
|
||||
|
@ -546,12 +546,12 @@ bool IsEngineBuildable(EngineID engine, VehicleType type, PlayerID player)
|
|||
if (e->type != type) return false;
|
||||
|
||||
/* check if it's available */
|
||||
if (!HasBit(e->player_avail, player)) return false;
|
||||
if (!HasBit(e->company_avail, company)) return false;
|
||||
|
||||
if (type == VEH_TRAIN) {
|
||||
/* Check if the rail type is available to this player */
|
||||
const Player *p = GetPlayer(player);
|
||||
if (!HasBit(p->avail_railtypes, RailVehInfo(engine)->railtype)) return false;
|
||||
/* Check if the rail type is available to this company */
|
||||
const Company *c = GetCompany(company);
|
||||
if (!HasBit(c->avail_railtypes, RailVehInfo(engine)->railtype)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -602,10 +602,10 @@ static const SaveLoad _engine_desc[] = {
|
|||
|
||||
SLE_VAR(Engine, lifelength, SLE_UINT8),
|
||||
SLE_VAR(Engine, flags, SLE_UINT8),
|
||||
SLE_VAR(Engine, preview_player_rank, SLE_UINT8),
|
||||
SLE_VAR(Engine, preview_company_rank,SLE_UINT8),
|
||||
SLE_VAR(Engine, preview_wait, SLE_UINT8),
|
||||
SLE_CONDNULL(1, 0, 44),
|
||||
SLE_VAR(Engine, player_avail, SLE_UINT8),
|
||||
SLE_VAR(Engine, company_avail, SLE_UINT8),
|
||||
SLE_CONDSTR(Engine, name, SLE_STR, 0, 84, SL_MAX_VERSION),
|
||||
|
||||
/* reserve extra space in savegame here. (currently 16 bytes) */
|
||||
|
@ -664,9 +664,9 @@ void CopyTempEngineData()
|
|||
e->duration_phase_3 = se->duration_phase_3;
|
||||
e->lifelength = se->lifelength;
|
||||
e->flags = se->flags;
|
||||
e->preview_player_rank = se->preview_player_rank;
|
||||
e->preview_company_rank= se->preview_company_rank;
|
||||
e->preview_wait = se->preview_wait;
|
||||
e->player_avail = se->player_avail;
|
||||
e->company_avail = se->company_avail;
|
||||
if (se->name != NULL) e->name = strdup(se->name);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,9 +20,9 @@ struct Engine : PoolItem<Engine, EngineID, &_Engine_pool> {
|
|||
uint16 duration_phase_1, duration_phase_2, duration_phase_3;
|
||||
byte lifelength;
|
||||
byte flags;
|
||||
uint8 preview_player_rank;
|
||||
uint8 preview_company_rank;
|
||||
byte preview_wait;
|
||||
PlayerMask player_avail;
|
||||
CompanyMask company_avail;
|
||||
uint8 image_index; ///< Original vehicle image index
|
||||
VehicleType type; ///< type, ie VEH_ROAD, VEH_TRAIN, etc.
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ void DrawAircraftEngine(int x, int y, EngineID engine, SpriteID pal);
|
|||
void LoadCustomEngineNames();
|
||||
void DeleteCustomEngineNames();
|
||||
|
||||
bool IsEngineBuildable(EngineID engine, VehicleType type, PlayerID player);
|
||||
bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company);
|
||||
CargoID GetEngineCargoType(EngineID engine);
|
||||
void SetCachedEngineCounts();
|
||||
|
||||
|
|
|
@ -134,8 +134,8 @@ enum {
|
|||
*/
|
||||
enum {
|
||||
ENGINE_AVAILABLE = 1, ///< This vehicle is available to everyone.
|
||||
ENGINE_EXCLUSIVE_PREVIEW = 2, ///< This vehicle is in the exclusive preview stage, either being used or being offered to a player.
|
||||
ENGINE_OFFER_WINDOW_OPEN = 4, ///< The exclusive offer window is currently open for a player.
|
||||
ENGINE_EXCLUSIVE_PREVIEW = 2, ///< This vehicle is in the exclusive preview stage, either being used or being offered to a company.
|
||||
ENGINE_OFFER_WINDOW_OPEN = 4, ///< The exclusive offer window is currently open for a company.
|
||||
};
|
||||
|
||||
enum {
|
||||
|
|
|
@ -15,10 +15,10 @@ void DrawClearLandTile(const TileInfo *ti, byte set);
|
|||
void DrawClearLandFence(const TileInfo *ti);
|
||||
void TileLoopClearHelper(TileIndex tile);
|
||||
|
||||
/* players.cpp */
|
||||
bool CheckPlayerHasMoney(CommandCost cost);
|
||||
void SubtractMoneyFromPlayer(CommandCost cost);
|
||||
void SubtractMoneyFromPlayerFract(PlayerID player, CommandCost cost);
|
||||
/* company_cmd.cpp */
|
||||
bool CheckCompanyHasMoney(CommandCost cost);
|
||||
void SubtractMoneyFromCompany(CommandCost cost);
|
||||
void SubtractMoneyFromCompanyFract(CompanyID company, CommandCost cost);
|
||||
bool CheckOwnership(Owner owner);
|
||||
bool CheckTileOwnership(TileIndex tile);
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ bool GenerateTowns();
|
|||
void GenerateTrees();
|
||||
|
||||
void StartupEconomy();
|
||||
void StartupPlayers();
|
||||
void StartupCompanies();
|
||||
void StartupDisasters();
|
||||
|
||||
void InitializeGame(uint size_x, uint size_y, bool reset_date);
|
||||
|
@ -126,7 +126,7 @@ static void _GenerateWorld(void *arg)
|
|||
|
||||
/* These are probably pointless when inside the scenario editor. */
|
||||
SetGeneratingWorldProgress(GWP_GAME_INIT, 3);
|
||||
StartupPlayers();
|
||||
StartupCompanies();
|
||||
IncreaseGeneratingWorldProgress(GWP_GAME_INIT);
|
||||
StartupEngines();
|
||||
IncreaseGeneratingWorldProgress(GWP_GAME_INIT);
|
||||
|
@ -145,7 +145,7 @@ static void _GenerateWorld(void *arg)
|
|||
}
|
||||
|
||||
ResetObjectToPlace();
|
||||
_local_player = _gw.lp;
|
||||
_local_company = _gw.lc;
|
||||
|
||||
SetGeneratingWorldProgress(GWP_GAME_START, 1);
|
||||
/* Call any callback */
|
||||
|
@ -259,15 +259,15 @@ void GenerateWorld(GenerateWorldMode mode, uint size_x, uint size_y)
|
|||
_gw.active = true;
|
||||
_gw.abort = false;
|
||||
_gw.abortp = NULL;
|
||||
_gw.lp = _local_player;
|
||||
_gw.lc = _local_company;
|
||||
_gw.wait_for_draw = false;
|
||||
_gw.quit_thread = false;
|
||||
_gw.threaded = true;
|
||||
|
||||
/* This disables some commands and stuff */
|
||||
SetLocalPlayer(PLAYER_SPECTATOR);
|
||||
SetLocalCompany(COMPANY_SPECTATOR);
|
||||
/* Make sure everything is done via OWNER_NONE */
|
||||
_current_player = OWNER_NONE;
|
||||
_current_company = OWNER_NONE;
|
||||
|
||||
/* Set the date before loading sprites as some newgrfs check it */
|
||||
SetDate(ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1));
|
||||
|
|
|
@ -36,7 +36,7 @@ struct gw_info {
|
|||
bool quit_thread; ///< Do we want to quit the active thread
|
||||
bool threaded; ///< Whether we run _GenerateWorld threaded
|
||||
GenerateWorldMode mode;///< What mode are we making a world in
|
||||
PlayerID lp; ///< The local_player before generating
|
||||
CompanyID lc; ///< The local_company before generating
|
||||
uint size_x; ///< X-size of the map
|
||||
uint size_y; ///< Y-size of the map
|
||||
gw_done_proc *proc; ///< Proc that is called when done (can be NULL)
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
#include "table/strings.h"
|
||||
#include "table/sprites.h"
|
||||
|
||||
/* Bitmasks of player and cargo indices that shouldn't be drawn. */
|
||||
static uint _legend_excluded_players;
|
||||
/* Bitmasks of company and cargo indices that shouldn't be drawn. */
|
||||
static uint _legend_excluded_companies;
|
||||
static uint _legend_excluded_cargo;
|
||||
|
||||
/* Apparently these don't play well with enums. */
|
||||
|
@ -37,7 +37,7 @@ struct GraphLegendWindow : Window {
|
|||
GraphLegendWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
|
||||
{
|
||||
for (uint i = 3; i < this->widget_count; i++) {
|
||||
if (!HasBit(_legend_excluded_players, i - 3)) this->LowerWidget(i);
|
||||
if (!HasBit(_legend_excluded_companies, i - 3)) this->LowerWidget(i);
|
||||
}
|
||||
|
||||
this->FindWindowPlacementAndResize(desc);
|
||||
|
@ -45,22 +45,22 @@ struct GraphLegendWindow : Window {
|
|||
|
||||
virtual void OnPaint()
|
||||
{
|
||||
for (PlayerID p = PLAYER_FIRST; p < MAX_PLAYERS; p++) {
|
||||
if (IsValidPlayerID(p)) continue;
|
||||
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
|
||||
if (IsValidCompanyID(c)) continue;
|
||||
|
||||
SetBit(_legend_excluded_players, p);
|
||||
this->RaiseWidget(p + 3);
|
||||
SetBit(_legend_excluded_companies, c);
|
||||
this->RaiseWidget(c + 3);
|
||||
}
|
||||
|
||||
this->DrawWidgets();
|
||||
|
||||
const Player *p;
|
||||
FOR_ALL_PLAYERS(p) {
|
||||
DrawPlayerIcon(p->index, 4, 18 + p->index * 12);
|
||||
const Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
DrawCompanyIcon(c->index, 4, 18 + c->index * 12);
|
||||
|
||||
SetDParam(0, p->index);
|
||||
SetDParam(1, p->index);
|
||||
DrawString(21, 17 + p->index * 12, STR_7021, HasBit(_legend_excluded_players, p->index) ? TC_BLACK : TC_WHITE);
|
||||
SetDParam(0, c->index);
|
||||
SetDParam(1, c->index);
|
||||
DrawString(21, 17 + c->index * 12, STR_7021, HasBit(_legend_excluded_companies, c->index) ? TC_BLACK : TC_WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ struct GraphLegendWindow : Window {
|
|||
{
|
||||
if (!IsInsideMM(widget, 3, 11)) return;
|
||||
|
||||
ToggleBit(_legend_excluded_players, widget - 3);
|
||||
ToggleBit(_legend_excluded_companies, widget - 3);
|
||||
this->ToggleWidgetLoweredState(widget);
|
||||
this->SetDirty();
|
||||
InvalidateWindow(WC_INCOME_GRAPH, 0);
|
||||
|
@ -155,8 +155,8 @@ protected:
|
|||
int x_axis_offset; ///< Distance from the top of the graph to the x axis.
|
||||
|
||||
/* the colors and cost array of GraphDrawer must accomodate
|
||||
* both values for cargo and players. So if any are higher, quit */
|
||||
assert(GRAPH_MAX_DATASETS >= (int)NUM_CARGO && GRAPH_MAX_DATASETS >= (int)MAX_PLAYERS);
|
||||
* both values for cargo and companies. So if any are higher, quit */
|
||||
assert(GRAPH_MAX_DATASETS >= (int)NUM_CARGO && GRAPH_MAX_DATASETS >= (int)MAX_COMPANIES);
|
||||
assert(this->num_vert_lines > 0);
|
||||
|
||||
byte grid_colour = _colour_gradient[COLOUR_GREY][4];
|
||||
|
@ -354,19 +354,19 @@ public:
|
|||
{
|
||||
this->DrawWidgets();
|
||||
|
||||
uint excluded_players = _legend_excluded_players;
|
||||
uint excluded_companies = _legend_excluded_companies;
|
||||
|
||||
/* Exclude the players which aren't valid */
|
||||
for (PlayerID p = PLAYER_FIRST; p < MAX_PLAYERS; p++) {
|
||||
if (!IsValidPlayerID(p)) SetBit(excluded_players, p);
|
||||
/* Exclude the companies which aren't valid */
|
||||
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
|
||||
if (!IsValidCompanyID(c)) SetBit(excluded_companies, c);
|
||||
}
|
||||
this->excluded_data = excluded_players;
|
||||
this->excluded_data = excluded_companies;
|
||||
this->num_vert_lines = 24;
|
||||
|
||||
byte nums = 0;
|
||||
const Player *p;
|
||||
FOR_ALL_PLAYERS(p) {
|
||||
nums = max(nums, p->num_valid_stat_ent);
|
||||
const Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
nums = max(nums, c->num_valid_stat_ent);
|
||||
}
|
||||
this->num_on_x_axis = min(nums, 24);
|
||||
|
||||
|
@ -381,12 +381,12 @@ public:
|
|||
this->month = mo;
|
||||
|
||||
int numd = 0;
|
||||
for (PlayerID k = PLAYER_FIRST; k < MAX_PLAYERS; k++) {
|
||||
if (IsValidPlayerID(k)) {
|
||||
p = GetPlayer(k);
|
||||
this->colors[numd] = _colour_gradient[p->player_color][6];
|
||||
for (CompanyID k = COMPANY_FIRST; k < MAX_COMPANIES; k++) {
|
||||
if (IsValidCompanyID(k)) {
|
||||
c = GetCompany(k);
|
||||
this->colors[numd] = _colour_gradient[c->colour][6];
|
||||
for (int j = this->num_on_x_axis, i = 0; --j >= 0;) {
|
||||
this->cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_DATAPOINT : GetGraphData(p, j);
|
||||
this->cost[numd][i] = (j >= c->num_valid_stat_ent) ? INVALID_DATAPOINT : GetGraphData(c, j);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
@ -398,7 +398,7 @@ public:
|
|||
this->DrawGraph();
|
||||
}
|
||||
|
||||
virtual OverflowSafeInt64 GetGraphData(const Player *p, int j)
|
||||
virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
|
||||
{
|
||||
return INVALID_DATAPOINT;
|
||||
}
|
||||
|
@ -421,9 +421,9 @@ struct OperatingProfitGraphWindow : BaseGraphWindow {
|
|||
this->FindWindowPlacementAndResize(desc);
|
||||
}
|
||||
|
||||
virtual OverflowSafeInt64 GetGraphData(const Player *p, int j)
|
||||
virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
|
||||
{
|
||||
return p->old_economy[j].income + p->old_economy[j].expenses;
|
||||
return c->old_economy[j].income + c->old_economy[j].expenses;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -460,9 +460,9 @@ struct IncomeGraphWindow : BaseGraphWindow {
|
|||
this->FindWindowPlacementAndResize(desc);
|
||||
}
|
||||
|
||||
virtual OverflowSafeInt64 GetGraphData(const Player *p, int j)
|
||||
virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
|
||||
{
|
||||
return p->old_economy[j].income;
|
||||
return c->old_economy[j].income;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -497,9 +497,9 @@ struct DeliveredCargoGraphWindow : BaseGraphWindow {
|
|||
this->FindWindowPlacementAndResize(desc);
|
||||
}
|
||||
|
||||
virtual OverflowSafeInt64 GetGraphData(const Player *p, int j)
|
||||
virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
|
||||
{
|
||||
return p->old_economy[j].delivered_cargo;
|
||||
return c->old_economy[j].delivered_cargo;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -534,9 +534,9 @@ struct PerformanceHistoryGraphWindow : BaseGraphWindow {
|
|||
this->FindWindowPlacementAndResize(desc);
|
||||
}
|
||||
|
||||
virtual OverflowSafeInt64 GetGraphData(const Player *p, int j)
|
||||
virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
|
||||
{
|
||||
return p->old_economy[j].performance_history;
|
||||
return c->old_economy[j].performance_history;
|
||||
}
|
||||
|
||||
virtual void OnClick(Point pt, int widget)
|
||||
|
@ -578,9 +578,9 @@ struct CompanyValueGraphWindow : BaseGraphWindow {
|
|||
this->FindWindowPlacementAndResize(desc);
|
||||
}
|
||||
|
||||
virtual OverflowSafeInt64 GetGraphData(const Player *p, int j)
|
||||
virtual OverflowSafeInt64 GetGraphData(const Company *c, int j)
|
||||
{
|
||||
return p->old_economy[j].company_value;
|
||||
return c->old_economy[j].company_value;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -668,13 +668,13 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
|
|||
if (!cs->IsValid()) continue;
|
||||
|
||||
/* Only draw labels for widgets that exist. If the widget doesn't
|
||||
* exist then the local player has used the climate cheat or
|
||||
* changed the NewGRF configuration with this window open. */
|
||||
* exist then the local company has used the climate cheat or
|
||||
* changed the NewGRF configuration with this window open. */
|
||||
if (i + 3 < this->widget_count) {
|
||||
/* Since the buttons have no text, no images,
|
||||
* both the text and the colored box have to be manually painted.
|
||||
* clk_dif will move one pixel down and one pixel to the right
|
||||
* when the button is clicked */
|
||||
* both the text and the colored box have to be manually painted.
|
||||
* clk_dif will move one pixel down and one pixel to the right
|
||||
* when the button is clicked */
|
||||
byte clk_dif = this->IsWidgetLowered(i + 3) ? 1 : 0;
|
||||
|
||||
GfxFillRect(x + clk_dif, y + clk_dif, x + 8 + clk_dif, y + 5 + clk_dif, 0);
|
||||
|
@ -759,63 +759,63 @@ static inline StringID GetPerformanceTitleFromValue(uint value)
|
|||
|
||||
class CompanyLeagueWindow : public Window {
|
||||
private:
|
||||
GUIList<const Player*> players;
|
||||
GUIList<const Company*> companies;
|
||||
|
||||
/**
|
||||
* (Re)Build the company league list
|
||||
*/
|
||||
void BuildPlayerList()
|
||||
void BuildCompanyList()
|
||||
{
|
||||
if (!this->players.NeedRebuild()) return;
|
||||
if (!this->companies.NeedRebuild()) return;
|
||||
|
||||
this->players.Clear();
|
||||
this->companies.Clear();
|
||||
|
||||
const Player *p;
|
||||
FOR_ALL_PLAYERS(p) {
|
||||
*this->players.Append() = p;
|
||||
const Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
*this->companies.Append() = c;
|
||||
}
|
||||
|
||||
this->players.Compact();
|
||||
this->players.RebuildDone();
|
||||
this->companies.Compact();
|
||||
this->companies.RebuildDone();
|
||||
}
|
||||
|
||||
/** Sort the company league by performance history */
|
||||
static int CDECL PerformanceSorter(const Player* const *p1, const Player* const *p2)
|
||||
static int CDECL PerformanceSorter(const Company* const *c1, const Company* const *c2)
|
||||
{
|
||||
return (*p2)->old_economy[1].performance_history - (*p1)->old_economy[1].performance_history;
|
||||
return (*c2)->old_economy[1].performance_history - (*c1)->old_economy[1].performance_history;
|
||||
}
|
||||
|
||||
public:
|
||||
CompanyLeagueWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
|
||||
{
|
||||
this->players.ForceRebuild();
|
||||
this->players.NeedResort();
|
||||
this->companies.ForceRebuild();
|
||||
this->companies.NeedResort();
|
||||
|
||||
this->FindWindowPlacementAndResize(desc);
|
||||
}
|
||||
|
||||
virtual void OnPaint()
|
||||
{
|
||||
this->BuildPlayerList();
|
||||
this->players.Sort(&PerformanceSorter);
|
||||
this->BuildCompanyList();
|
||||
this->companies.Sort(&PerformanceSorter);
|
||||
|
||||
this->DrawWidgets();
|
||||
|
||||
for (uint i = 0; i != this->players.Length(); i++) {
|
||||
const Player *p = this->players[i];
|
||||
for (uint i = 0; i != this->companies.Length(); i++) {
|
||||
const Company *c = this->companies[i];
|
||||
SetDParam(0, i + STR_01AC_1ST);
|
||||
SetDParam(1, p->index);
|
||||
SetDParam(2, p->index);
|
||||
SetDParam(3, GetPerformanceTitleFromValue(p->old_economy[1].performance_history));
|
||||
SetDParam(1, c->index);
|
||||
SetDParam(2, c->index);
|
||||
SetDParam(3, GetPerformanceTitleFromValue(c->old_economy[1].performance_history));
|
||||
|
||||
DrawString(2, 15 + i * 10, i == 0 ? STR_7054 : STR_7055, TC_FROMSTRING);
|
||||
DrawPlayerIcon(p->index, 27, 16 + i * 10);
|
||||
DrawCompanyIcon(c->index, 27, 16 + i * 10);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnTick()
|
||||
{
|
||||
if (this->players.NeedResort()) {
|
||||
if (this->companies.NeedResort()) {
|
||||
this->SetDirty();
|
||||
}
|
||||
}
|
||||
|
@ -823,9 +823,9 @@ public:
|
|||
virtual void OnInvalidateData(int data)
|
||||
{
|
||||
if (data == 0) {
|
||||
this->players.ForceRebuild();
|
||||
this->companies.ForceRebuild();
|
||||
} else {
|
||||
this->players.ForceResort();
|
||||
this->companies.ForceResort();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -858,35 +858,35 @@ void ShowCompanyLeagueTable()
|
|||
struct PerformanceRatingDetailWindow : Window {
|
||||
private:
|
||||
enum PerformanteRatingWidgets {
|
||||
PRW_PLAYER_FIRST = 13,
|
||||
PRW_PLAYER_LAST = 20,
|
||||
PRW_COMPANY_FIRST = 13,
|
||||
PRW_COMPANY_LAST = 20,
|
||||
};
|
||||
|
||||
public:
|
||||
static PlayerID player;
|
||||
static CompanyID company;
|
||||
int timeout;
|
||||
|
||||
PerformanceRatingDetailWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
|
||||
{
|
||||
/* Disable the players who are not active */
|
||||
for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) {
|
||||
this->SetWidgetDisabledState(i + PRW_PLAYER_FIRST, !IsValidPlayerID(i));
|
||||
/* Disable the companies who are not active */
|
||||
for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
|
||||
this->SetWidgetDisabledState(i + PRW_COMPANY_FIRST, !IsValidCompanyID(i));
|
||||
}
|
||||
|
||||
this->UpdatePlayerStats();
|
||||
this->UpdateCompanyStats();
|
||||
|
||||
if (player != INVALID_PLAYER) this->LowerWidget(player + PRW_PLAYER_FIRST);
|
||||
if (company != INVALID_COMPANY) this->LowerWidget(company + PRW_COMPANY_FIRST);
|
||||
|
||||
this->FindWindowPlacementAndResize(desc);
|
||||
}
|
||||
|
||||
void UpdatePlayerStats()
|
||||
void UpdateCompanyStats()
|
||||
{
|
||||
/* Update all player stats with the current data
|
||||
/* Update all company stats with the current data
|
||||
* (this is because _score_info is not saved to a savegame) */
|
||||
Player *p;
|
||||
FOR_ALL_PLAYERS(p) {
|
||||
UpdateCompanyRatingAndValue(p, false);
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
UpdateCompanyRatingAndValue(c, false);
|
||||
}
|
||||
|
||||
this->timeout = DAY_TICKS * 5;
|
||||
|
@ -903,39 +903,39 @@ public:
|
|||
/* Draw standard stuff */
|
||||
this->DrawWidgets();
|
||||
|
||||
/* Check if the currently selected player is still active. */
|
||||
if (player == INVALID_PLAYER || !IsValidPlayerID(player)) {
|
||||
if (player != INVALID_PLAYER) {
|
||||
/* Check if the currently selected company is still active. */
|
||||
if (company == INVALID_COMPANY || !IsValidCompanyID(company)) {
|
||||
if (company != INVALID_COMPANY) {
|
||||
/* Raise and disable the widget for the previous selection. */
|
||||
this->RaiseWidget(player + PRW_PLAYER_FIRST);
|
||||
this->DisableWidget(player + PRW_PLAYER_FIRST);
|
||||
this->RaiseWidget(company + PRW_COMPANY_FIRST);
|
||||
this->DisableWidget(company + PRW_COMPANY_FIRST);
|
||||
this->SetDirty();
|
||||
|
||||
player = INVALID_PLAYER;
|
||||
company = INVALID_COMPANY;
|
||||
}
|
||||
|
||||
for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) {
|
||||
if (IsValidPlayerID(i)) {
|
||||
/* Lower the widget corresponding to this player. */
|
||||
this->LowerWidget(i + PRW_PLAYER_FIRST);
|
||||
for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
|
||||
if (IsValidCompanyID(i)) {
|
||||
/* Lower the widget corresponding to this company. */
|
||||
this->LowerWidget(i + PRW_COMPANY_FIRST);
|
||||
this->SetDirty();
|
||||
|
||||
player = i;
|
||||
company = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* If there are no active players, don't display anything else. */
|
||||
if (player == INVALID_PLAYER) return;
|
||||
/* If there are no active companies, don't display anything else. */
|
||||
if (company == INVALID_COMPANY) return;
|
||||
|
||||
/* Paint the player icons */
|
||||
for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) {
|
||||
if (!IsValidPlayerID(i)) {
|
||||
/* Check if we have the player as an active player */
|
||||
if (!this->IsWidgetDisabled(i + PRW_PLAYER_FIRST)) {
|
||||
/* Bah, player gone :( */
|
||||
this->DisableWidget(i + PRW_PLAYER_FIRST);
|
||||
/* Paint the company icons */
|
||||
for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
|
||||
if (!IsValidCompanyID(i)) {
|
||||
/* Check if we have the company as an active company */
|
||||
if (!this->IsWidgetDisabled(i + PRW_COMPANY_FIRST)) {
|
||||
/* Bah, company gone :( */
|
||||
this->DisableWidget(i + PRW_COMPANY_FIRST);
|
||||
|
||||
/* We need a repaint */
|
||||
this->SetDirty();
|
||||
|
@ -943,16 +943,16 @@ public:
|
|||
continue;
|
||||
}
|
||||
|
||||
/* Check if we have the player marked as inactive */
|
||||
if (this->IsWidgetDisabled(i + PRW_PLAYER_FIRST)) {
|
||||
/* New player! Yippie :p */
|
||||
this->EnableWidget(i + PRW_PLAYER_FIRST);
|
||||
/* Check if we have the company marked as inactive */
|
||||
if (this->IsWidgetDisabled(i + PRW_COMPANY_FIRST)) {
|
||||
/* New company! Yippie :p */
|
||||
this->EnableWidget(i + PRW_COMPANY_FIRST);
|
||||
/* We need a repaint */
|
||||
this->SetDirty();
|
||||
}
|
||||
|
||||
x = (i == player) ? 1 : 0;
|
||||
DrawPlayerIcon(i, i * 37 + 13 + x, 16 + x);
|
||||
x = (i == company) ? 1 : 0;
|
||||
DrawCompanyIcon(i, i * 37 + 13 + x, 16 + x);
|
||||
}
|
||||
|
||||
/* The colors used to show how the progress is going */
|
||||
|
@ -961,7 +961,7 @@ public:
|
|||
|
||||
/* Draw all the score parts */
|
||||
for (ScoreID i = SCORE_BEGIN; i < SCORE_END; i++) {
|
||||
int val = _score_part[player][i];
|
||||
int val = _score_part[company][i];
|
||||
int needed = _score_info[i].needed;
|
||||
int score = _score_info[i].score;
|
||||
|
||||
|
@ -1024,12 +1024,12 @@ public:
|
|||
virtual void OnClick(Point pt, int widget)
|
||||
{
|
||||
/* Check which button is clicked */
|
||||
if (IsInsideMM(widget, PRW_PLAYER_FIRST, PRW_PLAYER_LAST + 1)) {
|
||||
if (IsInsideMM(widget, PRW_COMPANY_FIRST, PRW_COMPANY_LAST + 1)) {
|
||||
/* Is it no on disable? */
|
||||
if (!this->IsWidgetDisabled(widget)) {
|
||||
this->RaiseWidget(player + PRW_PLAYER_FIRST);
|
||||
player = (PlayerID)(widget - PRW_PLAYER_FIRST);
|
||||
this->LowerWidget(player + PRW_PLAYER_FIRST);
|
||||
this->RaiseWidget(company + PRW_COMPANY_FIRST);
|
||||
company = (CompanyID)(widget - PRW_COMPANY_FIRST);
|
||||
this->LowerWidget(company + PRW_COMPANY_FIRST);
|
||||
this->SetDirty();
|
||||
}
|
||||
}
|
||||
|
@ -1039,15 +1039,15 @@ public:
|
|||
{
|
||||
if (_pause_game != 0) return;
|
||||
|
||||
/* Update the player score every 5 days */
|
||||
/* Update the company score every 5 days */
|
||||
if (--this->timeout == 0) {
|
||||
this->UpdatePlayerStats();
|
||||
this->UpdateCompanyStats();
|
||||
this->SetDirty();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
PlayerID PerformanceRatingDetailWindow::player = INVALID_PLAYER;
|
||||
CompanyID PerformanceRatingDetailWindow::company = INVALID_COMPANY;
|
||||
|
||||
|
||||
static const Widget _performance_rating_detail_widgets[] = {
|
||||
|
|
12
src/group.h
12
src/group.h
|
@ -17,13 +17,13 @@ struct Group : PoolItem<Group, GroupID, &_Group_pool> {
|
|||
char *name; ///< Group Name
|
||||
|
||||
uint16 num_vehicle; ///< Number of vehicles wich belong to the group
|
||||
PlayerByte owner; ///< Group Owner
|
||||
OwnerByte owner; ///< Group Owner
|
||||
VehicleTypeByte vehicle_type; ///< Vehicle type of the group
|
||||
|
||||
bool replace_protection; ///< If set to true, the global autoreplace have no effect on the group
|
||||
uint16 *num_engines; ///< Caches the number of engines of each type the player owns (no need to save this)
|
||||
uint16 *num_engines; ///< Caches the number of engines of each type the company owns (no need to save this)
|
||||
|
||||
Group(PlayerID owner = INVALID_PLAYER);
|
||||
Group(CompanyID owner = INVALID_COMPANY);
|
||||
virtual ~Group();
|
||||
|
||||
bool IsValid() const;
|
||||
|
@ -41,7 +41,7 @@ static inline bool IsDefaultGroupID(GroupID index)
|
|||
}
|
||||
|
||||
/**
|
||||
* Checks if a GroupID stands for all vehicles of a player
|
||||
* Checks if a GroupID stands for all vehicles of a company
|
||||
* @param id_g The GroupID to check
|
||||
* @return true is id_g is identical to ALL_GROUP
|
||||
*/
|
||||
|
@ -73,7 +73,7 @@ static inline uint GetGroupArraySize(void)
|
|||
* @param id_e The EngineID of the engine to count
|
||||
* @return The number of engines with EngineID id_e in the group
|
||||
*/
|
||||
uint GetGroupNumEngines(PlayerID p, GroupID id_g, EngineID id_e);
|
||||
uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e);
|
||||
|
||||
static inline void IncreaseGroupNumVehicle(GroupID id_g)
|
||||
{
|
||||
|
@ -90,6 +90,6 @@ void InitializeGroup();
|
|||
void SetTrainGroupID(Vehicle *v, GroupID grp);
|
||||
void UpdateTrainGroupID(Vehicle *v);
|
||||
void RemoveVehicleFromGroup(const Vehicle *v);
|
||||
void RemoveAllGroupsForPlayer(const PlayerID p);
|
||||
void RemoveAllGroupsForCompany(const CompanyID company);
|
||||
|
||||
#endif /* GROUP_H */
|
||||
|
|
|
@ -48,7 +48,7 @@ static inline void UpdateNumEngineGroup(EngineID i, GroupID old_g, GroupID new_g
|
|||
DEFINE_OLD_POOL_GENERIC(Group, Group)
|
||||
|
||||
|
||||
Group::Group(PlayerID owner)
|
||||
Group::Group(Owner owner)
|
||||
{
|
||||
this->owner = owner;
|
||||
|
||||
|
@ -58,13 +58,13 @@ Group::Group(PlayerID owner)
|
|||
Group::~Group()
|
||||
{
|
||||
free(this->name);
|
||||
this->owner = INVALID_PLAYER;
|
||||
this->owner = INVALID_OWNER;
|
||||
free(this->num_engines);
|
||||
}
|
||||
|
||||
bool Group::IsValid() const
|
||||
{
|
||||
return this->owner != INVALID_PLAYER;
|
||||
return this->owner != INVALID_OWNER;
|
||||
}
|
||||
|
||||
void InitializeGroup(void)
|
||||
|
@ -83,16 +83,16 @@ void InitializeGroup(void)
|
|||
CommandCost CmdCreateGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
||||
{
|
||||
VehicleType vt = (VehicleType)p1;
|
||||
if (!IsPlayerBuildableVehicleType(vt)) return CMD_ERROR;
|
||||
if (!IsCompanyBuildableVehicleType(vt)) return CMD_ERROR;
|
||||
|
||||
if (!Group::CanAllocateItem()) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
Group *g = new Group(_current_player);
|
||||
Group *g = new Group(_current_company);
|
||||
g->replace_protection = false;
|
||||
g->vehicle_type = vt;
|
||||
|
||||
InvalidateWindowData(GetWindowClassForVehicleType(vt), (vt << 11) | VLW_GROUP_LIST | _current_player);
|
||||
InvalidateWindowData(GetWindowClassForVehicleType(vt), (vt << 11) | VLW_GROUP_LIST | _current_company);
|
||||
}
|
||||
|
||||
return CommandCost();
|
||||
|
@ -111,7 +111,7 @@ CommandCost CmdDeleteGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
if (!IsValidGroupID(p1)) return CMD_ERROR;
|
||||
|
||||
Group *g = GetGroup(p1);
|
||||
if (g->owner != _current_player) return CMD_ERROR;
|
||||
if (g->owner != _current_company) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
Vehicle *v;
|
||||
|
@ -125,13 +125,13 @@ CommandCost CmdDeleteGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
if (_backup_orders_data.group == g->index) _backup_orders_data.group = DEFAULT_GROUP;
|
||||
|
||||
/* If we set an autoreplace for the group we delete, remove it. */
|
||||
if (_current_player < MAX_PLAYERS) {
|
||||
Player *p;
|
||||
if (_current_company < MAX_COMPANIES) {
|
||||
Company *c;
|
||||
EngineRenew *er;
|
||||
|
||||
p = GetPlayer(_current_player);
|
||||
c = GetCompany(_current_company);
|
||||
FOR_ALL_ENGINE_RENEWS(er) {
|
||||
if (er->group_id == g->index) RemoveEngineReplacementForPlayer(p, er->from, g->index, flags);
|
||||
if (er->group_id == g->index) RemoveEngineReplacementForCompany(c, er->from, g->index, flags);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,7 @@ CommandCost CmdDeleteGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
DeleteWindowById(WC_REPLACE_VEHICLE, g->vehicle_type);
|
||||
delete g;
|
||||
|
||||
InvalidateWindowData(GetWindowClassForVehicleType(vt), (vt << 11) | VLW_GROUP_LIST | _current_player);
|
||||
InvalidateWindowData(GetWindowClassForVehicleType(vt), (vt << 11) | VLW_GROUP_LIST | _current_company);
|
||||
}
|
||||
|
||||
return CommandCost();
|
||||
|
@ -173,7 +173,7 @@ CommandCost CmdRenameGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
if (!IsValidGroupID(p1)) return CMD_ERROR;
|
||||
|
||||
Group *g = GetGroup(p1);
|
||||
if (g->owner != _current_player) return CMD_ERROR;
|
||||
if (g->owner != _current_company) return CMD_ERROR;
|
||||
|
||||
bool reset = StrEmpty(_cmd_text);
|
||||
|
||||
|
@ -188,7 +188,7 @@ CommandCost CmdRenameGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
/* Assign the new one */
|
||||
g->name = reset ? NULL : strdup(_cmd_text);
|
||||
|
||||
InvalidateWindowData(GetWindowClassForVehicleType(g->vehicle_type), (g->vehicle_type << 11) | VLW_GROUP_LIST | _current_player);
|
||||
InvalidateWindowData(GetWindowClassForVehicleType(g->vehicle_type), (g->vehicle_type << 11) | VLW_GROUP_LIST | _current_company);
|
||||
}
|
||||
|
||||
return CommandCost();
|
||||
|
@ -213,10 +213,10 @@ CommandCost CmdAddVehicleGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p
|
|||
|
||||
if (IsValidGroupID(new_g)) {
|
||||
Group *g = GetGroup(new_g);
|
||||
if (g->owner != _current_player || g->vehicle_type != v->type) return CMD_ERROR;
|
||||
if (g->owner != _current_company || g->vehicle_type != v->type) return CMD_ERROR;
|
||||
}
|
||||
|
||||
if (v->owner != _current_player || !v->IsPrimaryVehicle()) return CMD_ERROR;
|
||||
if (v->owner != _current_company || !v->IsPrimaryVehicle()) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
DecreaseGroupNumVehicle(v->group_id);
|
||||
|
@ -237,7 +237,7 @@ CommandCost CmdAddVehicleGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p
|
|||
|
||||
/* Update the Replace Vehicle Windows */
|
||||
InvalidateWindow(WC_REPLACE_VEHICLE, v->type);
|
||||
InvalidateWindowData(GetWindowClassForVehicleType(v->type), (v->type << 11) | VLW_GROUP_LIST | _current_player);
|
||||
InvalidateWindowData(GetWindowClassForVehicleType(v->type), (v->type << 11) | VLW_GROUP_LIST | _current_company);
|
||||
}
|
||||
|
||||
return CommandCost();
|
||||
|
@ -253,7 +253,7 @@ CommandCost CmdAddVehicleGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p
|
|||
CommandCost CmdAddSharedVehicleGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
||||
{
|
||||
VehicleType type = (VehicleType)p2;
|
||||
if (!IsValidGroupID(p1) || !IsPlayerBuildableVehicleType(type)) return CMD_ERROR;
|
||||
if (!IsValidGroupID(p1) || !IsCompanyBuildableVehicleType(type)) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
Vehicle *v;
|
||||
|
@ -273,7 +273,7 @@ CommandCost CmdAddSharedVehicleGroup(TileIndex tile, uint32 flags, uint32 p1, ui
|
|||
}
|
||||
}
|
||||
|
||||
InvalidateWindowData(GetWindowClassForVehicleType(type), (type << 11) | VLW_GROUP_LIST | _current_player);
|
||||
InvalidateWindowData(GetWindowClassForVehicleType(type), (type << 11) | VLW_GROUP_LIST | _current_company);
|
||||
}
|
||||
|
||||
return CommandCost();
|
||||
|
@ -290,10 +290,10 @@ CommandCost CmdAddSharedVehicleGroup(TileIndex tile, uint32 flags, uint32 p1, ui
|
|||
CommandCost CmdRemoveAllVehiclesGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
||||
{
|
||||
VehicleType type = (VehicleType)p2;
|
||||
if (!IsValidGroupID(p1) || !IsPlayerBuildableVehicleType(type)) return CMD_ERROR;
|
||||
if (!IsValidGroupID(p1) || !IsCompanyBuildableVehicleType(type)) return CMD_ERROR;
|
||||
|
||||
Group *g = GetGroup(p1);
|
||||
if (g->owner != _current_player) return CMD_ERROR;
|
||||
if (g->owner != _current_company) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
GroupID old_g = p1;
|
||||
|
@ -309,7 +309,7 @@ CommandCost CmdRemoveAllVehiclesGroup(TileIndex tile, uint32 flags, uint32 p1, u
|
|||
}
|
||||
}
|
||||
|
||||
InvalidateWindowData(GetWindowClassForVehicleType(type), (type << 11) | VLW_GROUP_LIST | _current_player);
|
||||
InvalidateWindowData(GetWindowClassForVehicleType(type), (type << 11) | VLW_GROUP_LIST | _current_company);
|
||||
}
|
||||
|
||||
return CommandCost();
|
||||
|
@ -329,12 +329,12 @@ CommandCost CmdSetGroupReplaceProtection(TileIndex tile, uint32 flags, uint32 p1
|
|||
if (!IsValidGroupID(p1)) return CMD_ERROR;
|
||||
|
||||
Group *g = GetGroup(p1);
|
||||
if (g->owner != _current_player) return CMD_ERROR;
|
||||
if (g->owner != _current_company) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
g->replace_protection = HasBit(p2, 0);
|
||||
|
||||
InvalidateWindowData(GetWindowClassForVehicleType(g->vehicle_type), (g->vehicle_type << 11) | VLW_GROUP_LIST | _current_player);
|
||||
InvalidateWindowData(GetWindowClassForVehicleType(g->vehicle_type), (g->vehicle_type << 11) | VLW_GROUP_LIST | _current_company);
|
||||
}
|
||||
|
||||
return CommandCost();
|
||||
|
@ -398,26 +398,26 @@ void UpdateTrainGroupID(Vehicle *v)
|
|||
InvalidateWindow(WC_REPLACE_VEHICLE, VEH_TRAIN);
|
||||
}
|
||||
|
||||
uint GetGroupNumEngines(PlayerID p, GroupID id_g, EngineID id_e)
|
||||
uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e)
|
||||
{
|
||||
if (IsValidGroupID(id_g)) return GetGroup(id_g)->num_engines[id_e];
|
||||
|
||||
uint num = GetPlayer(p)->num_engines[id_e];
|
||||
uint num = GetCompany(company)->num_engines[id_e];
|
||||
if (!IsDefaultGroupID(id_g)) return num;
|
||||
|
||||
const Group *g;
|
||||
FOR_ALL_GROUPS(g) {
|
||||
if (g->owner == p) num -= g->num_engines[id_e];
|
||||
if (g->owner == company) num -= g->num_engines[id_e];
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
void RemoveAllGroupsForPlayer(const PlayerID p)
|
||||
void RemoveAllGroupsForCompany(const CompanyID company)
|
||||
{
|
||||
Group *g;
|
||||
|
||||
FOR_ALL_GROUPS(g) {
|
||||
if (p == g->owner) delete g;
|
||||
if (company == g->owner) delete g;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ private:
|
|||
*
|
||||
* @param owner The owner of the window
|
||||
*/
|
||||
void BuildGroupList(PlayerID owner)
|
||||
void BuildGroupList(Owner owner)
|
||||
{
|
||||
if (!this->groups.NeedRebuild()) return;
|
||||
|
||||
|
@ -175,7 +175,7 @@ private:
|
|||
public:
|
||||
VehicleGroupWindow(const WindowDesc *desc, WindowNumber window_number) : BaseVehicleListWindow(desc, window_number)
|
||||
{
|
||||
const PlayerID owner = (PlayerID)GB(this->window_number, 0, 8);
|
||||
const Owner owner = (Owner)GB(this->window_number, 0, 8);
|
||||
this->vehicle_type = (VehicleType)GB(this->window_number, 11, 5);
|
||||
|
||||
this->caption_color = owner;
|
||||
|
@ -286,14 +286,14 @@ public:
|
|||
|
||||
virtual void OnPaint()
|
||||
{
|
||||
const PlayerID owner = (PlayerID)GB(this->window_number, 0, 8);
|
||||
const Owner owner = (Owner)GB(this->window_number, 0, 8);
|
||||
int x = this->widget[GRP_WIDGET_LIST_VEHICLE].left + 2;
|
||||
int y1 = PLY_WND_PRC__OFFSET_TOP_WIDGET + 2;
|
||||
int max;
|
||||
int i;
|
||||
|
||||
/* If we select the all vehicles, this->list will contain all vehicles of the player
|
||||
* else this->list will contain all vehicles which belong to the selected group */
|
||||
/* If we select the all vehicles, this->list will contain all vehicles of the owner
|
||||
* else this->list will contain all vehicles which belong to the selected group */
|
||||
this->BuildVehicleList(owner, this->group_sel, IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST);
|
||||
this->SortVehicleList();
|
||||
|
||||
|
@ -310,26 +310,26 @@ public:
|
|||
}
|
||||
|
||||
/* Disable all lists management button when the list is empty */
|
||||
this->SetWidgetsDisabledState(this->vehicles.Length() == 0 || _local_player != owner,
|
||||
this->SetWidgetsDisabledState(this->vehicles.Length() == 0 || _local_company != owner,
|
||||
GRP_WIDGET_STOP_ALL,
|
||||
GRP_WIDGET_START_ALL,
|
||||
GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN,
|
||||
WIDGET_LIST_END);
|
||||
|
||||
/* Disable the group specific function when we select the default group or all vehicles */
|
||||
this->SetWidgetsDisabledState(IsDefaultGroupID(this->group_sel) || IsAllGroupID(this->group_sel) || _local_player != owner,
|
||||
this->SetWidgetsDisabledState(IsDefaultGroupID(this->group_sel) || IsAllGroupID(this->group_sel) || _local_company != owner,
|
||||
GRP_WIDGET_DELETE_GROUP,
|
||||
GRP_WIDGET_RENAME_GROUP,
|
||||
GRP_WIDGET_REPLACE_PROTECTION,
|
||||
WIDGET_LIST_END);
|
||||
|
||||
/* Disable remaining buttons for non-local player
|
||||
* Needed while changing _local_player, eg. by cheats
|
||||
* All procedures (eg. move vehicle to another group)
|
||||
* verify, whether you are the owner of the vehicle,
|
||||
* so it doesn't have to be disabled
|
||||
*/
|
||||
this->SetWidgetsDisabledState(_local_player != owner,
|
||||
/* Disable remaining buttons for non-local companies
|
||||
* Needed while changing _local_company, eg. by cheats
|
||||
* All procedures (eg. move vehicle to another group)
|
||||
* verify, whether you are the owner of the vehicle,
|
||||
* so it doesn't have to be disabled
|
||||
*/
|
||||
this->SetWidgetsDisabledState(_local_company != owner,
|
||||
GRP_WIDGET_CREATE_GROUP,
|
||||
GRP_WIDGET_AVAILABLE_VEHICLES,
|
||||
WIDGET_LIST_END);
|
||||
|
@ -705,11 +705,11 @@ static WindowDesc _group_desc = {
|
|||
_group_widgets,
|
||||
};
|
||||
|
||||
void ShowPlayerGroup(PlayerID player, VehicleType vehicle_type)
|
||||
void ShowCompanyGroup(CompanyID company, VehicleType vehicle_type)
|
||||
{
|
||||
if (!IsValidPlayerID(player)) return;
|
||||
if (!IsValidCompanyID(company)) return;
|
||||
|
||||
_group_desc.cls = GetWindowClassForVehicleType(vehicle_type);
|
||||
WindowNumber num = (vehicle_type << 11) | VLW_GROUP_LIST | player;
|
||||
WindowNumber num = (vehicle_type << 11) | VLW_GROUP_LIST | company;
|
||||
AllocateWindowDescFront<VehicleGroupWindow>(&_group_desc, num);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,6 @@
|
|||
|
||||
#include "vehicle_type.h"
|
||||
|
||||
void ShowPlayerGroup(PlayerID player, VehicleType veh);
|
||||
void ShowCompanyGroup(CompanyID company, VehicleType veh);
|
||||
|
||||
#endif /* GROUP_GUI_H */
|
||||
|
|
|
@ -420,10 +420,10 @@ static CommandCost ClearTile_Industry(TileIndex tile, byte flags)
|
|||
* with magic_bulldozer cheat you can destroy industries
|
||||
* (area around OILRIG is water, so water shouldn't flood it
|
||||
*/
|
||||
if ((_current_player != OWNER_WATER && _game_mode != GM_EDITOR &&
|
||||
if ((_current_company != OWNER_WATER && _game_mode != GM_EDITOR &&
|
||||
!_cheats.magic_bulldozer.value) ||
|
||||
((flags & DC_AUTO) != 0) ||
|
||||
(_current_player == OWNER_WATER &&
|
||||
(_current_company == OWNER_WATER &&
|
||||
((indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER) ||
|
||||
HasBit(GetIndustryTileSpec(GetIndustryGfx(tile))->slopes_refused, 5)))) {
|
||||
SetDParam(0, indspec->name);
|
||||
|
@ -852,11 +852,11 @@ static void GetProducedCargo_Industry(TileIndex tile, CargoID *b)
|
|||
b[1] = i->produced_cargo[1];
|
||||
}
|
||||
|
||||
static void ChangeTileOwner_Industry(TileIndex tile, PlayerID old_player, PlayerID new_player)
|
||||
static void ChangeTileOwner_Industry(TileIndex tile, Owner old_owner, Owner new_owner)
|
||||
{
|
||||
/* If the founder merges, the industry was created by the merged company */
|
||||
Industry *i = GetIndustryByTile(tile);
|
||||
if (i->founder == old_player) i->founder = (new_player == PLAYER_SPECTATOR) ? OWNER_NONE : new_player;
|
||||
if (i->founder == old_owner) i->founder = (new_owner == INVALID_OWNER) ? OWNER_NONE : new_owner;
|
||||
}
|
||||
|
||||
static const byte _plantfarmfield_type[] = {1, 1, 1, 1, 1, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6};
|
||||
|
@ -976,17 +976,17 @@ void PlantRandomFarmField(const Industry *i)
|
|||
static bool SearchLumberMillTrees(TileIndex tile, void *user_data)
|
||||
{
|
||||
if (IsTileType(tile, MP_TREES) && GetTreeGrowth(tile) > 2) { ///< 3 and up means all fully grown trees
|
||||
PlayerID old_player = _current_player;
|
||||
CompanyID old_company = _current_company;
|
||||
/* found a tree */
|
||||
|
||||
_current_player = OWNER_NONE;
|
||||
_current_company = OWNER_NONE;
|
||||
_industry_sound_ctr = 1;
|
||||
_industry_sound_tile = tile;
|
||||
SndPlayTileFx(SND_38_CHAINSAW, tile);
|
||||
|
||||
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
||||
|
||||
_current_player = old_player;
|
||||
_current_company = old_company;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -1361,10 +1361,10 @@ static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, uint32 flags, const
|
|||
/* Check if we don't leave the map */
|
||||
if (TileX(cur_tile) == 0 || TileY(cur_tile) == 0 || TileX(cur_tile) + size_x >= MapMaxX() || TileY(cur_tile) + size_y >= MapMaxY()) return false;
|
||||
|
||||
/* _current_player is OWNER_NONE for randomly generated industries and in editor, or the player who funded or prospected the industry.
|
||||
/* _current_company is OWNER_NONE for randomly generated industries and in editor, or the company who funded or prospected the industry.
|
||||
* Perform terraforming as OWNER_TOWN to disable autoslope. */
|
||||
PlayerID old_player = _current_player;
|
||||
_current_player = OWNER_TOWN;
|
||||
CompanyID old_company = _current_company;
|
||||
_current_company = OWNER_TOWN;
|
||||
|
||||
BEGIN_TILE_LOOP(tile_walk, size_x, size_y, cur_tile) {
|
||||
curh = TileHeight(tile_walk);
|
||||
|
@ -1372,13 +1372,13 @@ static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, uint32 flags, const
|
|||
/* This tile needs terraforming. Check if we can do that without
|
||||
* damaging the surroundings too much. */
|
||||
if (!CheckCanTerraformSurroundingTiles(tile_walk, h, 0)) {
|
||||
_current_player = old_player;
|
||||
_current_company = old_company;
|
||||
return false;
|
||||
}
|
||||
/* This is not 100% correct check, but the best we can do without modifying the map.
|
||||
* What is missing, is if the difference in height is more than 1.. */
|
||||
if (CmdFailed(DoCommand(tile_walk, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND))) {
|
||||
_current_player = old_player;
|
||||
_current_company = old_company;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1398,7 +1398,7 @@ static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, uint32 flags, const
|
|||
} END_TILE_LOOP(tile_walk, size_x, size_y, cur_tile)
|
||||
}
|
||||
|
||||
_current_player = old_player;
|
||||
_current_company = old_company;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1502,7 +1502,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const Ind
|
|||
i->last_prod_year = _cur_year;
|
||||
i->last_month_production[0] = i->production_rate[0] * 8;
|
||||
i->last_month_production[1] = i->production_rate[1] * 8;
|
||||
i->founder = _current_player;
|
||||
i->founder = _current_company;
|
||||
|
||||
if (HasBit(indspec->callback_flags, CBM_IND_DECIDE_COLOUR)) {
|
||||
uint16 res = GetIndustryCallback(CBID_INDUSTRY_DECIDE_COLOUR, 0, 0, i, type, INVALID_TILE);
|
||||
|
@ -1734,8 +1734,8 @@ static void PlaceInitialIndustry(IndustryType type, int amount)
|
|||
num = (ind_spc->check_proc == CHECK_REFINERY || ind_spc->check_proc == CHECK_OIL_RIG) ? ScaleByMapSize1D(num) : ScaleByMapSize(num);
|
||||
|
||||
if (_settings_game.difficulty.number_industries != 0) {
|
||||
PlayerID old_player = _current_player;
|
||||
_current_player = OWNER_NONE;
|
||||
CompanyID old_company = _current_company;
|
||||
_current_company = OWNER_NONE;
|
||||
assert(num > 0);
|
||||
|
||||
do {
|
||||
|
@ -1748,7 +1748,7 @@ static void PlaceInitialIndustry(IndustryType type, int amount)
|
|||
}
|
||||
} while (--num);
|
||||
|
||||
_current_player = old_player;
|
||||
_current_company = old_company;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1959,7 +1959,7 @@ static void CanCargoServiceIndustry(CargoID cargo, Industry *ind, bool *c_accept
|
|||
*
|
||||
* @param ind: Industry being investigated.
|
||||
*
|
||||
* @return: 0 if nobody can service the industry, 2 if the local player can
|
||||
* @return: 0 if nobody can service the industry, 2 if the local company can
|
||||
* service the industry, and 1 otherwise (only competitors can service the
|
||||
* industry)
|
||||
*/
|
||||
|
@ -1974,7 +1974,7 @@ int WhoCanServiceIndustry(Industry* ind)
|
|||
int result = 0;
|
||||
FOR_ALL_VEHICLES(v) {
|
||||
/* Is it worthwhile to try this vehicle? */
|
||||
if (v->owner != _local_player && result != 0) continue;
|
||||
if (v->owner != _local_company && result != 0) continue;
|
||||
|
||||
/* Check whether it accepts the right kind of cargo */
|
||||
bool c_accepts = false;
|
||||
|
@ -2005,7 +2005,7 @@ int WhoCanServiceIndustry(Industry* ind)
|
|||
if ((o->GetUnloadType() & OUFB_UNLOAD) && !c_accepts) break;
|
||||
|
||||
if (stations.find(st) != stations.end()) {
|
||||
if (v->owner == _local_player) return 2; // Player services industry
|
||||
if (v->owner == _local_company) return 2; // Company services industry
|
||||
result = 1; // Competitor services industry
|
||||
}
|
||||
}
|
||||
|
@ -2026,9 +2026,9 @@ static void ReportNewsProductionChangeIndustry(Industry *ind, CargoID type, int
|
|||
NewsSubtype ns;
|
||||
|
||||
switch (WhoCanServiceIndustry(ind)) {
|
||||
case 0: ns = NS_INDUSTRY_NOBODY; break;
|
||||
case 1: ns = NS_INDUSTRY_OTHER; break;
|
||||
case 2: ns = NS_INDUSTRY_PLAYER; break;
|
||||
case 0: ns = NS_INDUSTRY_NOBODY; break;
|
||||
case 1: ns = NS_INDUSTRY_OTHER; break;
|
||||
case 2: ns = NS_INDUSTRY_COMPANY; break;
|
||||
default: NOT_REACHED(); break;
|
||||
}
|
||||
SetDParam(2, abs(percent));
|
||||
|
@ -2210,9 +2210,9 @@ static void ChangeIndustryProduction(Industry *i, bool monthly)
|
|||
ns = NS_INDUSTRY_CLOSE;
|
||||
} else {
|
||||
switch (WhoCanServiceIndustry(i)) {
|
||||
case 0: ns = NS_INDUSTRY_NOBODY; break;
|
||||
case 1: ns = NS_INDUSTRY_OTHER; break;
|
||||
case 2: ns = NS_INDUSTRY_PLAYER; break;
|
||||
case 0: ns = NS_INDUSTRY_NOBODY; break;
|
||||
case 1: ns = NS_INDUSTRY_OTHER; break;
|
||||
case 2: ns = NS_INDUSTRY_COMPANY; break;
|
||||
default: NOT_REACHED(); break;
|
||||
}
|
||||
}
|
||||
|
@ -2256,8 +2256,8 @@ void IndustryDailyLoop()
|
|||
return; // Nothing to do? get out
|
||||
}
|
||||
|
||||
PlayerID old_player = _current_player;
|
||||
_current_player = OWNER_NONE;
|
||||
CompanyID old_company = _current_company;
|
||||
_current_company = OWNER_NONE;
|
||||
|
||||
/* perform the required industry changes for the day */
|
||||
for (uint16 j = 0; j < change_loop; j++) {
|
||||
|
@ -2270,7 +2270,7 @@ void IndustryDailyLoop()
|
|||
}
|
||||
}
|
||||
|
||||
_current_player = old_player;
|
||||
_current_company = old_company;
|
||||
|
||||
/* production-change */
|
||||
InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 1);
|
||||
|
@ -2279,8 +2279,8 @@ void IndustryDailyLoop()
|
|||
void IndustryMonthlyLoop()
|
||||
{
|
||||
Industry *i;
|
||||
PlayerID old_player = _current_player;
|
||||
_current_player = OWNER_NONE;
|
||||
CompanyID old_company = _current_company;
|
||||
_current_company = OWNER_NONE;
|
||||
|
||||
FOR_ALL_INDUSTRIES(i) {
|
||||
UpdateIndustryStatistics(i);
|
||||
|
@ -2291,7 +2291,7 @@ void IndustryMonthlyLoop()
|
|||
}
|
||||
}
|
||||
|
||||
_current_player = old_player;
|
||||
_current_company = old_company;
|
||||
|
||||
/* production-change */
|
||||
InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 1);
|
||||
|
|
|
@ -359,7 +359,7 @@ public:
|
|||
return;
|
||||
}
|
||||
|
||||
_current_player = OWNER_NONE;
|
||||
_current_company = OWNER_NONE;
|
||||
_generating_world = true;
|
||||
_ignore_restrictions = true;
|
||||
success = DoCommandP(tile, (InteractiveRandomRange(indsp->num_table) << 16) | this->selected_type, seed, NULL, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY));
|
||||
|
@ -420,7 +420,7 @@ public:
|
|||
|
||||
void ShowBuildIndustryWindow()
|
||||
{
|
||||
if (_game_mode != GM_EDITOR && !IsValidPlayerID(_current_player)) return;
|
||||
if (_game_mode != GM_EDITOR && !IsValidCompanyID(_current_company)) return;
|
||||
if (BringWindowToFrontById(WC_BUILD_INDUSTRY, 0)) return;
|
||||
new BuildIndustryWindow();
|
||||
}
|
||||
|
|
|
@ -473,9 +473,9 @@ TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode
|
|||
return _tile_type_procs[GetTileType(tile)]->get_tile_track_status_proc(tile, mode, sub_mode, side);
|
||||
}
|
||||
|
||||
void ChangeTileOwner(TileIndex tile, PlayerID old_player, PlayerID new_player)
|
||||
void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner)
|
||||
{
|
||||
_tile_type_procs[GetTileType(tile)]->change_tile_owner_proc(tile, old_player, new_player);
|
||||
_tile_type_procs[GetTileType(tile)]->change_tile_owner_proc(tile, old_owner, new_owner);
|
||||
}
|
||||
|
||||
void GetAcceptedCargo(TileIndex tile, AcceptedCargo ac)
|
||||
|
@ -895,7 +895,7 @@ void OnTick_Trees();
|
|||
void OnTick_Station();
|
||||
void OnTick_Industry();
|
||||
|
||||
void OnTick_Players();
|
||||
void OnTick_Companies();
|
||||
void OnTick_Train();
|
||||
|
||||
void CallLandscapeTick()
|
||||
|
@ -905,7 +905,7 @@ void CallLandscapeTick()
|
|||
OnTick_Station();
|
||||
OnTick_Industry();
|
||||
|
||||
OnTick_Players();
|
||||
OnTick_Companies();
|
||||
OnTick_Train();
|
||||
}
|
||||
|
||||
|
|
|
@ -67,10 +67,10 @@ struct Livery {
|
|||
};
|
||||
|
||||
/**
|
||||
* Reset the livery schemes to the player's primary colour.
|
||||
* This is used on loading games without livery information and on new player start up.
|
||||
* @param p Player to reset.
|
||||
* Reset the livery schemes to the company's primary colour.
|
||||
* This is used on loading games without livery information and on new company start up.
|
||||
* @param c Company to reset.
|
||||
*/
|
||||
void ResetPlayerLivery(Player *p);
|
||||
void ResetCompanyLivery(Company *c);
|
||||
|
||||
#endif /* LIVERY_H */
|
||||
|
|
|
@ -49,7 +49,7 @@ void CcGiveMoney(bool success, TileIndex tile, uint32 p1, uint32 p2)
|
|||
if (!success || !_settings_game.economy.give_money) return;
|
||||
|
||||
char msg[20];
|
||||
/* Inform the player of this action */
|
||||
/* Inform the company of the action of one of it's clients (controllers). */
|
||||
snprintf(msg, sizeof(msg), "%d", p1);
|
||||
|
||||
if (!_network_server) {
|
||||
|
@ -67,8 +67,8 @@ void HandleOnEditText(const char *str)
|
|||
switch (_rename_what) {
|
||||
#ifdef ENABLE_NETWORK
|
||||
case 3: { // Give money, you can only give money in excess of loan
|
||||
const Player *p = GetPlayer(_current_player);
|
||||
Money money = min(p->player_money - p->current_loan, (Money)(atoi(str) / _currency->rate));
|
||||
const Company *c = GetCompany(_current_company);
|
||||
Money money = min(c->money - c->current_loan, (Money)(atoi(str) / _currency->rate));
|
||||
|
||||
uint32 money_c = Clamp(ClampToI32(money), 0, 20000000); // Clamp between 20 million and 0
|
||||
|
||||
|
@ -118,9 +118,9 @@ void CcPlaySound10(bool success, TileIndex tile, uint32 p1, uint32 p2)
|
|||
}
|
||||
|
||||
#ifdef ENABLE_NETWORK
|
||||
void ShowNetworkGiveMoneyWindow(PlayerID player)
|
||||
void ShowNetworkGiveMoneyWindow(CompanyID company)
|
||||
{
|
||||
_rename_id = player;
|
||||
_rename_id = company;
|
||||
_rename_what = 3;
|
||||
ShowQueryString(STR_EMPTY, STR_NETWORK_GIVE_MONEY_CAPTION, 30, 180, NULL, CS_NUMERAL, QSF_NONE);
|
||||
}
|
||||
|
@ -319,8 +319,8 @@ struct MainWindow : Window
|
|||
|
||||
if (cio == NULL) break;
|
||||
|
||||
/* Only players actually playing can speak to team. Eg spectators cannot */
|
||||
if (_settings_client.gui.prefer_teamchat && IsValidPlayerID(cio->client_playas)) {
|
||||
/* Only companies actually playing can speak to team. Eg spectators cannot */
|
||||
if (_settings_client.gui.prefer_teamchat && IsValidCompanyID(cio->client_playas)) {
|
||||
const NetworkClientInfo *ci;
|
||||
FOR_ALL_ACTIVE_CLIENT_INFOS(ci) {
|
||||
if (ci->client_playas == cio->client_playas && ci != cio) {
|
||||
|
@ -334,7 +334,7 @@ struct MainWindow : Window
|
|||
}
|
||||
break;
|
||||
|
||||
case WKC_SHIFT | WKC_RETURN: case WKC_SHIFT | 'T': // send text message to all players
|
||||
case WKC_SHIFT | WKC_RETURN: case WKC_SHIFT | 'T': // send text message to all clients
|
||||
if (_networking) ShowNetworkChatQueryWindow(DESTTYPE_BROADCAST, 0);
|
||||
break;
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ void InitializeTrees();
|
|||
void InitializeSigns();
|
||||
void InitializeStations();
|
||||
void InitializeCargoPackets();
|
||||
void InitializePlayers();
|
||||
void InitializeCompanies();
|
||||
void InitializeCheats();
|
||||
void InitializeNPF();
|
||||
void InitializeOldNames();
|
||||
|
@ -101,7 +101,7 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date)
|
|||
InitializeTrains();
|
||||
InitializeNPF();
|
||||
|
||||
InitializePlayers();
|
||||
InitializeCompanies();
|
||||
AI_Initialize();
|
||||
InitializeCheats();
|
||||
|
||||
|
@ -151,7 +151,7 @@ static const SaveLoadGlobVarList _date_desc[] = {
|
|||
SLEG_VAR(_random.state[1], SLE_UINT32),
|
||||
SLEG_CONDVAR(_cur_town_ctr, SLE_FILE_U8 | SLE_VAR_U32, 0, 9),
|
||||
SLEG_CONDVAR(_cur_town_ctr, SLE_UINT32, 10, SL_MAX_VERSION),
|
||||
SLEG_VAR(_cur_player_tick_index, SLE_FILE_U8 | SLE_VAR_U32),
|
||||
SLEG_VAR(_cur_company_tick_index, SLE_FILE_U8 | SLE_VAR_U32),
|
||||
SLEG_VAR(_next_competitor_start, SLE_FILE_U16 | SLE_VAR_U32),
|
||||
SLEG_VAR(_trees_tick_ctr, SLE_UINT8),
|
||||
SLEG_CONDVAR(_pause_game, SLE_UINT8, 4, SL_MAX_VERSION),
|
||||
|
|
126
src/misc_cmd.cpp
126
src/misc_cmd.cpp
|
@ -25,26 +25,26 @@
|
|||
|
||||
#include "table/strings.h"
|
||||
|
||||
/** Change the player's face.
|
||||
/** Change the company manager's face.
|
||||
* @param tile unused
|
||||
* @param flags operation to perform
|
||||
* @param p1 unused
|
||||
* @param p2 face bitmasked
|
||||
*/
|
||||
CommandCost CmdSetPlayerFace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
||||
CommandCost CmdSetCompanyManagerFace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
||||
{
|
||||
PlayerFace pf = (PlayerFace)p2;
|
||||
CompanyManagerFace cmf = (CompanyManagerFace)p2;
|
||||
|
||||
if (!IsValidPlayerIDFace(pf)) return CMD_ERROR;
|
||||
if (!IsValidCompanyManagerFace(cmf)) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
GetPlayer(_current_player)->face = pf;
|
||||
GetCompany(_current_company)->face = cmf;
|
||||
MarkWholeScreenDirty();
|
||||
}
|
||||
return CommandCost();
|
||||
}
|
||||
|
||||
/** Change the player's company-colour
|
||||
/** Change the company's company-colour
|
||||
* @param tile unused
|
||||
* @param flags operation to perform
|
||||
* @param p1 bitstuffed:
|
||||
|
@ -52,7 +52,7 @@ CommandCost CmdSetPlayerFace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
* p1 bits 8-9 set in use state or first/second colour
|
||||
* @param p2 new colour for vehicles, property, etc.
|
||||
*/
|
||||
CommandCost CmdSetPlayerColor(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
||||
CommandCost CmdSetCompanyColor(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
||||
{
|
||||
if (p2 >= 16) return CMD_ERROR; // max 16 colours
|
||||
|
||||
|
@ -63,35 +63,35 @@ CommandCost CmdSetPlayerColor(TileIndex tile, uint32 flags, uint32 p1, uint32 p2
|
|||
|
||||
if (scheme >= LS_END || state >= 3) return CMD_ERROR;
|
||||
|
||||
Player *p = GetPlayer(_current_player);
|
||||
Company *c = GetCompany(_current_company);
|
||||
|
||||
/* Ensure no two companies have the same primary colour */
|
||||
if (scheme == LS_DEFAULT && state == 0) {
|
||||
const Player *pp;
|
||||
FOR_ALL_PLAYERS(pp) {
|
||||
if (pp != p && pp->player_color == colour) return CMD_ERROR;
|
||||
const Company *cc;
|
||||
FOR_ALL_COMPANIES(cc) {
|
||||
if (cc != c && cc->colour == colour) return CMD_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
switch (state) {
|
||||
case 0:
|
||||
p->livery[scheme].colour1 = colour;
|
||||
c->livery[scheme].colour1 = colour;
|
||||
|
||||
/* If setting the first colour of the default scheme, adjust the
|
||||
* original and cached player colours too. */
|
||||
* original and cached company colours too. */
|
||||
if (scheme == LS_DEFAULT) {
|
||||
_player_colors[_current_player] = colour;
|
||||
p->player_color = colour;
|
||||
_company_colours[_current_company] = colour;
|
||||
c->colour = colour;
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
p->livery[scheme].colour2 = colour;
|
||||
c->livery[scheme].colour2 = colour;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
p->livery[scheme].in_use = colour != 0;
|
||||
c->livery[scheme].in_use = colour != 0;
|
||||
|
||||
/* Now handle setting the default scheme's in_use flag.
|
||||
* This is different to the other schemes, as it signifies if any
|
||||
|
@ -101,16 +101,16 @@ CommandCost CmdSetPlayerColor(TileIndex tile, uint32 flags, uint32 p1, uint32 p2
|
|||
|
||||
/* If enabling a scheme, set the default scheme to be in use too */
|
||||
if (colour != 0) {
|
||||
p->livery[LS_DEFAULT].in_use = true;
|
||||
c->livery[LS_DEFAULT].in_use = true;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Else loop through all schemes to see if any are left enabled.
|
||||
* If not, disable the default scheme too. */
|
||||
p->livery[LS_DEFAULT].in_use = false;
|
||||
c->livery[LS_DEFAULT].in_use = false;
|
||||
for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
|
||||
if (p->livery[scheme].in_use) {
|
||||
p->livery[LS_DEFAULT].in_use = true;
|
||||
if (c->livery[scheme].in_use) {
|
||||
c->livery[LS_DEFAULT].in_use = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -134,9 +134,9 @@ CommandCost CmdSetPlayerColor(TileIndex tile, uint32 flags, uint32 p1, uint32 p2
|
|||
*/
|
||||
CommandCost CmdIncreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
||||
{
|
||||
Player *p = GetPlayer(_current_player);
|
||||
Company *c = GetCompany(_current_company);
|
||||
|
||||
if (p->current_loan >= _economy.max_loan) {
|
||||
if (c->current_loan >= _economy.max_loan) {
|
||||
SetDParam(0, _economy.max_loan);
|
||||
return_cmd_error(STR_702B_MAXIMUM_PERMITTED_LOAN);
|
||||
}
|
||||
|
@ -145,20 +145,20 @@ CommandCost CmdIncreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
switch (p2) {
|
||||
default: return CMD_ERROR; // Invalid method
|
||||
case 0: // Take some extra loan
|
||||
loan = (IsHumanPlayer(_current_player) || _settings_game.ai.ainew_active) ? LOAN_INTERVAL : LOAN_INTERVAL_OLD_AI;
|
||||
loan = (IsHumanCompany(_current_company) || _settings_game.ai.ainew_active) ? LOAN_INTERVAL : LOAN_INTERVAL_OLD_AI;
|
||||
break;
|
||||
case 1: // Take a loan as big as possible
|
||||
loan = _economy.max_loan - p->current_loan;
|
||||
loan = _economy.max_loan - c->current_loan;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Overflow protection */
|
||||
if (p->player_money + p->current_loan + loan < p->player_money) return CMD_ERROR;
|
||||
if (c->money + c->current_loan + loan < c->money) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
p->player_money += loan;
|
||||
p->current_loan += loan;
|
||||
InvalidatePlayerWindows(p);
|
||||
c->money += loan;
|
||||
c->current_loan += loan;
|
||||
InvalidateCompanyWindows(c);
|
||||
}
|
||||
|
||||
return CommandCost(EXPENSES_OTHER);
|
||||
|
@ -173,42 +173,42 @@ CommandCost CmdIncreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
*/
|
||||
CommandCost CmdDecreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
||||
{
|
||||
Player *p = GetPlayer(_current_player);
|
||||
Company *c = GetCompany(_current_company);
|
||||
|
||||
if (p->current_loan == 0) return_cmd_error(STR_702D_LOAN_ALREADY_REPAYED);
|
||||
if (c->current_loan == 0) return_cmd_error(STR_702D_LOAN_ALREADY_REPAYED);
|
||||
|
||||
Money loan;
|
||||
switch (p2) {
|
||||
default: return CMD_ERROR; // Invalid method
|
||||
case 0: // Pay back one step
|
||||
loan = min(p->current_loan, (Money)(IsHumanPlayer(_current_player) || _settings_game.ai.ainew_active) ? LOAN_INTERVAL : LOAN_INTERVAL_OLD_AI);
|
||||
loan = min(c->current_loan, (Money)(IsHumanCompany(_current_company) || _settings_game.ai.ainew_active) ? LOAN_INTERVAL : LOAN_INTERVAL_OLD_AI);
|
||||
break;
|
||||
case 1: // Pay back as much as possible
|
||||
loan = max(min(p->current_loan, p->player_money), (Money)LOAN_INTERVAL);
|
||||
loan = max(min(c->current_loan, c->money), (Money)LOAN_INTERVAL);
|
||||
loan -= loan % LOAN_INTERVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (p->player_money < loan) {
|
||||
if (c->money < loan) {
|
||||
SetDParam(0, loan);
|
||||
return_cmd_error(STR_702E_REQUIRED);
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
p->player_money -= loan;
|
||||
p->current_loan -= loan;
|
||||
InvalidatePlayerWindows(p);
|
||||
c->money -= loan;
|
||||
c->current_loan -= loan;
|
||||
InvalidateCompanyWindows(c);
|
||||
}
|
||||
return CommandCost();
|
||||
}
|
||||
|
||||
static bool IsUniqueCompanyName(const char *name)
|
||||
{
|
||||
const Player *p;
|
||||
const Company *c;
|
||||
char buf[512];
|
||||
|
||||
FOR_ALL_PLAYERS(p) {
|
||||
SetDParam(0, p->index);
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
SetDParam(0, c->index);
|
||||
GetString(buf, STR_COMPANY_NAME, lastof(buf));
|
||||
if (strcmp(buf, name) == 0) return false;
|
||||
}
|
||||
|
@ -232,9 +232,9 @@ CommandCost CmdRenameCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
Player *p = GetPlayer(_current_player);
|
||||
free(p->name);
|
||||
p->name = reset ? NULL : strdup(_cmd_text);
|
||||
Company *c = GetCompany(_current_company);
|
||||
free(c->name);
|
||||
c->name = reset ? NULL : strdup(_cmd_text);
|
||||
MarkWholeScreenDirty();
|
||||
}
|
||||
|
||||
|
@ -243,11 +243,11 @@ CommandCost CmdRenameCompany(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
|
||||
static bool IsUniquePresidentName(const char *name)
|
||||
{
|
||||
const Player *p;
|
||||
const Company *c;
|
||||
char buf[512];
|
||||
|
||||
FOR_ALL_PLAYERS(p) {
|
||||
SetDParam(0, p->index);
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
SetDParam(0, c->index);
|
||||
GetString(buf, STR_PLAYER_NAME, lastof(buf));
|
||||
if (strcmp(buf, name) == 0) return false;
|
||||
}
|
||||
|
@ -271,15 +271,15 @@ CommandCost CmdRenamePresident(TileIndex tile, uint32 flags, uint32 p1, uint32 p
|
|||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
Player *p = GetPlayer(_current_player);
|
||||
free(p->president_name);
|
||||
Company *c = GetCompany(_current_company);
|
||||
free(c->president_name);
|
||||
|
||||
if (reset) {
|
||||
p->president_name = NULL;
|
||||
c->president_name = NULL;
|
||||
} else {
|
||||
p->president_name = strdup(_cmd_text);
|
||||
c->president_name = strdup(_cmd_text);
|
||||
|
||||
if (p->name_1 == STR_SV_UNNAMED && p->name == NULL) {
|
||||
if (c->name_1 == STR_SV_UNNAMED && c->name == NULL) {
|
||||
char buf[80];
|
||||
|
||||
snprintf(buf, lengthof(buf), "%s Transport", _cmd_text);
|
||||
|
@ -358,34 +358,34 @@ CommandCost CmdMoneyCheat(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
return CommandCost(EXPENSES_OTHER, -(int32)p1);
|
||||
}
|
||||
|
||||
/** Transfer funds (money) from one player to another.
|
||||
/** Transfer funds (money) from one company to another.
|
||||
* To prevent abuse in multiplayer games you can only send money to other
|
||||
* players if you have paid off your loan (either explicitely, or implicitely
|
||||
* companies if you have paid off your loan (either explicitely, or implicitely
|
||||
* given the fact that you have more money than loan).
|
||||
* @param tile unused
|
||||
* @param flags operation to perform
|
||||
* @param p1 the amount of money to transfer; max 20.000.000
|
||||
* @param p2 the player to transfer the money to
|
||||
* @param p2 the company to transfer the money to
|
||||
*/
|
||||
CommandCost CmdGiveMoney(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
||||
{
|
||||
if (!_settings_game.economy.give_money) return CMD_ERROR;
|
||||
|
||||
const Player *p = GetPlayer(_current_player);
|
||||
const Company *c = GetCompany(_current_company);
|
||||
CommandCost amount(EXPENSES_OTHER, min((Money)p1, (Money)20000000LL));
|
||||
|
||||
/* You can only transfer funds that is in excess of your loan */
|
||||
if (p->player_money - p->current_loan < amount.GetCost() || amount.GetCost() <= 0) return CMD_ERROR;
|
||||
if (!_networking || !IsValidPlayerID((PlayerID)p2)) return CMD_ERROR;
|
||||
if (c->money - c->current_loan < amount.GetCost() || amount.GetCost() <= 0) return CMD_ERROR;
|
||||
if (!_networking || !IsValidCompanyID((CompanyID)p2)) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
/* Add money to player */
|
||||
PlayerID old_cp = _current_player;
|
||||
_current_player = (PlayerID)p2;
|
||||
SubtractMoneyFromPlayer(CommandCost(EXPENSES_OTHER, -amount.GetCost()));
|
||||
_current_player = old_cp;
|
||||
/* Add money to company */
|
||||
CompanyID old_company = _current_company;
|
||||
_current_company = (CompanyID)p2;
|
||||
SubtractMoneyFromCompany(CommandCost(EXPENSES_OTHER, -amount.GetCost()));
|
||||
_current_company = old_company;
|
||||
}
|
||||
|
||||
/* Subtract money from local-player */
|
||||
/* Subtract money from local-company */
|
||||
return amount;
|
||||
}
|
||||
|
|
|
@ -104,13 +104,13 @@ public:
|
|||
}
|
||||
|
||||
LandInfoWindow(TileIndex tile) : Window(&_land_info_desc) {
|
||||
Player *p = GetPlayer(IsValidPlayerID(_local_player) ? _local_player : PLAYER_FIRST);
|
||||
Company *c = GetCompany(IsValidCompanyID(_local_company) ? _local_company : COMPANY_FIRST);
|
||||
Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
|
||||
|
||||
Money old_money = p->player_money;
|
||||
p->player_money = INT64_MAX;
|
||||
Money old_money = c->money;
|
||||
c->money = INT64_MAX;
|
||||
CommandCost costclear = DoCommand(tile, 0, 0, 0, CMD_LANDSCAPE_CLEAR);
|
||||
p->player_money = old_money;
|
||||
c->money = old_money;
|
||||
|
||||
/* Because build_date is not set yet in every TileDesc, we make sure it is empty */
|
||||
TileDesc td;
|
||||
|
@ -423,14 +423,14 @@ private:
|
|||
uint64 decode_params[20];
|
||||
StringID message_1;
|
||||
StringID message_2;
|
||||
bool show_player_face;
|
||||
bool show_company_manager_face;
|
||||
|
||||
int y[2];
|
||||
|
||||
public:
|
||||
ErrmsgWindow(Point pt, int width, int height, StringID msg1, StringID msg2, const Widget *widget, bool show_player_face) :
|
||||
ErrmsgWindow(Point pt, int width, int height, StringID msg1, StringID msg2, const Widget *widget, bool show_company_manager_face) :
|
||||
Window(pt.x, pt.y, width, height, WC_ERRMSG, widget),
|
||||
show_player_face(show_player_face)
|
||||
show_company_manager_face(show_company_manager_face)
|
||||
{
|
||||
this->duration = _settings_client.gui.errmsg_duration;
|
||||
CopyOutDParam(this->decode_params, 0, lengthof(this->decode_params));
|
||||
|
@ -476,9 +476,9 @@ public:
|
|||
SwitchToErrorRefStack();
|
||||
RewindTextRefStack();
|
||||
|
||||
if (this->show_player_face) {
|
||||
const Player *p = GetPlayer((PlayerID)GetDParamX(this->decode_params, 2));
|
||||
DrawPlayerFace(p->face, p->player_color, 2, 16);
|
||||
if (this->show_company_manager_face) {
|
||||
const Company *c = GetCompany((CompanyID)GetDParamX(this->decode_params, 2));
|
||||
DrawCompanyManagerFace(c->face, c->colour, 2, 16);
|
||||
}
|
||||
|
||||
DrawStringMultiCenter(this->width - 120, y[1], this->message_2, this->width - 2);
|
||||
|
@ -1419,10 +1419,10 @@ struct SaveLoadWindow : public QueryStringBaseWindow {
|
|||
void GenerateFileName()
|
||||
{
|
||||
/* Check if we are not a spectator who wants to generate a name..
|
||||
* Let's use the name of player #0 for now. */
|
||||
const Player *p = GetPlayer(IsValidPlayerID(_local_player) ? _local_player : PLAYER_FIRST);
|
||||
* Let's use the name of company #0 for now. */
|
||||
const Company *c = GetCompany(IsValidCompanyID(_local_company) ? _local_company : COMPANY_FIRST);
|
||||
|
||||
SetDParam(0, p->index);
|
||||
SetDParam(0, c->index);
|
||||
SetDParam(1, _date);
|
||||
GetString(this->edit_str_buf, STR_4004, &this->edit_str_buf[this->edit_str_size - 1]);
|
||||
SanitizeFilename(this->edit_str_buf);
|
||||
|
|
|
@ -29,8 +29,8 @@ enum {
|
|||
NETWORK_UNIQUE_ID_LENGTH = 33, ///< The maximum length of the unique id of the clients, in bytes including '\0'
|
||||
NETWORK_REVISION_LENGTH = 15, ///< The maximum length of the revision, in bytes including '\0'
|
||||
NETWORK_PASSWORD_LENGTH = 33, ///< The maximum length of the password, in bytes including '\0' (must be >= NETWORK_UNIQUE_ID_LENGTH)
|
||||
NETWORK_PLAYERS_LENGTH = 200, ///< The maximum length for the list of players that controls a company, in bytes including '\0'
|
||||
NETWORK_CLIENT_NAME_LENGTH = 25, ///< The maximum length of a player, in bytes including '\0'
|
||||
NETWORK_CLIENTS_LENGTH = 200, ///< The maximum length for the list of clients that controls a company, in bytes including '\0'
|
||||
NETWORK_CLIENT_NAME_LENGTH = 25, ///< The maximum length of a client's name, in bytes including '\0'
|
||||
NETWORK_RCONCOMMAND_LENGTH = 500, ///< The maximum length of a rconsole command, in bytes including '\0'
|
||||
NETWORK_CHAT_LENGTH = 900, ///< The maximum length of a chat message, in bytes including '\0'
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
/**
|
||||
* This is the struct used by both client and server
|
||||
* some fields will be empty on the client (like game_password) by default
|
||||
* and only filled with data a player enters.
|
||||
* and only filled with data a client enters.
|
||||
*/
|
||||
struct NetworkServerGameInfo {
|
||||
byte clients_on; ///< Current count of clients on server
|
||||
|
|
|
@ -61,7 +61,7 @@ enum {
|
|||
/** Packet that wraps a command */
|
||||
struct CommandPacket {
|
||||
CommandPacket *next; ///< the next command packet (if in queue)
|
||||
PlayerByte player; ///< player that is executing the command
|
||||
CompanyByte company; ///< company that is executing the command
|
||||
uint32 cmd; ///< command being executed
|
||||
uint32 p1; ///< parameter p1
|
||||
uint32 p2; ///< parameter p2
|
||||
|
@ -81,7 +81,7 @@ enum ClientStatus {
|
|||
STATUS_MAP, ///< The client is downloading the map
|
||||
STATUS_DONE_MAP, ///< The client has downloaded the map
|
||||
STATUS_PRE_ACTIVE, ///< The client is catching up the delayed frames
|
||||
STATUS_ACTIVE, ///< The client is an active player in the game
|
||||
STATUS_ACTIVE, ///< The client is active within in the game
|
||||
};
|
||||
|
||||
/** Base socket handler for all TCP sockets */
|
||||
|
|
|
@ -47,7 +47,7 @@ bool _network_available; ///< is network mode available?
|
|||
bool _network_dedicated; ///< are we a dedicated server?
|
||||
bool _is_network_server; ///< Does this client wants to be a network-server?
|
||||
NetworkServerGameInfo _network_game_info;
|
||||
NetworkPlayerInfo _network_player_info[MAX_PLAYERS];
|
||||
NetworkCompanyInfo _network_company_info[MAX_COMPANIES];
|
||||
NetworkClientInfo _network_client_info[MAX_CLIENT_INFO];
|
||||
uint16 _network_own_client_index;
|
||||
uint16 _redirect_console_to_client;
|
||||
|
@ -155,7 +155,7 @@ byte NetworkSpectatorCount()
|
|||
byte count = 0;
|
||||
|
||||
FOR_ALL_CLIENTS(cs) {
|
||||
if (DEREF_CLIENT_INFO(cs)->client_playas == PLAYER_SPECTATOR) count++;
|
||||
if (DEREF_CLIENT_INFO(cs)->client_playas == COMPANY_SPECTATOR) count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
|
@ -335,54 +335,54 @@ char* GetNetworkErrorMsg(char* buf, NetworkErrorCode err, const char* last)
|
|||
}
|
||||
|
||||
/* Count the number of active clients connected */
|
||||
static uint NetworkCountPlayers()
|
||||
static uint NetworkCountActiveClients()
|
||||
{
|
||||
NetworkTCPSocketHandler *cs;
|
||||
uint count = 0;
|
||||
|
||||
FOR_ALL_CLIENTS(cs) {
|
||||
const NetworkClientInfo *ci = DEREF_CLIENT_INFO(cs);
|
||||
if (IsValidPlayerID(ci->client_playas)) count++;
|
||||
if (IsValidCompanyID(ci->client_playas)) count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static bool _min_players_paused = false;
|
||||
static bool _min_active_clients_paused = false;
|
||||
|
||||
/* Check if the minimum number of players has been reached and pause or unpause the game as appropriate */
|
||||
void CheckMinPlayers()
|
||||
/* Check if the minimum number of active clients has been reached and pause or unpause the game as appropriate */
|
||||
void CheckMinActiveClients()
|
||||
{
|
||||
if (!_network_dedicated) return;
|
||||
|
||||
if (NetworkCountPlayers() < _settings_client.network.min_players) {
|
||||
if (_min_players_paused) return;
|
||||
if (NetworkCountActiveClients() < _settings_client.network.min_active_clients) {
|
||||
if (_min_active_clients_paused) return;
|
||||
|
||||
_min_players_paused = true;
|
||||
_min_active_clients_paused = true;
|
||||
DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
|
||||
NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game paused (not enough players)", NETWORK_SERVER_INDEX);
|
||||
} else {
|
||||
if (!_min_players_paused) return;
|
||||
if (!_min_active_clients_paused) return;
|
||||
|
||||
_min_players_paused = false;
|
||||
_min_active_clients_paused = false;
|
||||
DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
|
||||
NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game unpaused (enough players)", NETWORK_SERVER_INDEX);
|
||||
}
|
||||
}
|
||||
|
||||
/** Converts a string to ip/port/player
|
||||
* Format: IP#player:port
|
||||
/** Converts a string to ip/port/company
|
||||
* Format: IP#company:port
|
||||
*
|
||||
* connection_string will be re-terminated to seperate out the hostname, and player and port will
|
||||
* be set to the player and port strings given by the user, inside the memory area originally
|
||||
* connection_string will be re-terminated to seperate out the hostname, and company and port will
|
||||
* be set to the company and port strings given by the user, inside the memory area originally
|
||||
* occupied by connection_string. */
|
||||
void ParseConnectionString(const char **player, const char **port, char *connection_string)
|
||||
void ParseConnectionString(const char **company, const char **port, char *connection_string)
|
||||
{
|
||||
char *p;
|
||||
for (p = connection_string; *p != '\0'; p++) {
|
||||
switch (*p) {
|
||||
case '#':
|
||||
*player = p + 1;
|
||||
*company = p + 1;
|
||||
*p = '\0';
|
||||
break;
|
||||
case ':':
|
||||
|
@ -421,7 +421,7 @@ static NetworkTCPSocketHandler *NetworkAllocClient(SOCKET s)
|
|||
|
||||
cs->index = _network_client_index++;
|
||||
ci->client_index = cs->index;
|
||||
ci->client_playas = PLAYER_INACTIVE_CLIENT;
|
||||
ci->client_playas = COMPANY_INACTIVE_CLIENT;
|
||||
ci->join_date = _date;
|
||||
|
||||
InvalidateWindow(WC_CLIENT_LIST, 0);
|
||||
|
@ -495,7 +495,7 @@ void NetworkCloseClient(NetworkTCPSocketHandler *cs)
|
|||
cs->index = NETWORK_EMPTY_INDEX;
|
||||
ci->client_index = NETWORK_EMPTY_INDEX;
|
||||
|
||||
CheckMinPlayers();
|
||||
CheckMinActiveClients();
|
||||
}
|
||||
|
||||
// A client wants to connect to a server
|
||||
|
@ -688,7 +688,7 @@ static void NetworkInitialize()
|
|||
|
||||
// Clean the client_info memory
|
||||
memset(&_network_client_info, 0, sizeof(_network_client_info));
|
||||
memset(&_network_player_info, 0, sizeof(_network_player_info));
|
||||
memset(&_network_company_info, 0, sizeof(_network_company_info));
|
||||
|
||||
_sync_frame = 0;
|
||||
_network_first_time = true;
|
||||
|
@ -729,7 +729,7 @@ void NetworkAddServer(const char *b)
|
|||
{
|
||||
if (*b != '\0') {
|
||||
const char *port = NULL;
|
||||
const char *player = NULL;
|
||||
const char *company = NULL;
|
||||
char host[NETWORK_HOSTNAME_LENGTH];
|
||||
uint16 rport;
|
||||
|
||||
|
@ -738,7 +738,7 @@ void NetworkAddServer(const char *b)
|
|||
ttd_strlcpy(_settings_client.network.connect_to_ip, b, lengthof(_settings_client.network.connect_to_ip));
|
||||
rport = NETWORK_DEFAULT_PORT;
|
||||
|
||||
ParseConnectionString(&player, &port, host);
|
||||
ParseConnectionString(&company, &port, host);
|
||||
if (port != NULL) rport = atoi(port);
|
||||
|
||||
NetworkUDPQueryServer(host, rport, true);
|
||||
|
@ -812,9 +812,9 @@ static void NetworkInitGameInfo()
|
|||
memset(ci, 0, sizeof(*ci));
|
||||
|
||||
ci->client_index = NETWORK_SERVER_INDEX;
|
||||
ci->client_playas = _network_dedicated ? PLAYER_SPECTATOR : _local_player;
|
||||
ci->client_playas = _network_dedicated ? COMPANY_SPECTATOR : _local_company;
|
||||
|
||||
ttd_strlcpy(ci->client_name, _settings_client.network.player_name, sizeof(ci->client_name));
|
||||
ttd_strlcpy(ci->client_name, _settings_client.network.client_name, sizeof(ci->client_name));
|
||||
ttd_strlcpy(ci->unique_id, _settings_client.network.network_id, sizeof(ci->unique_id));
|
||||
}
|
||||
|
||||
|
@ -841,8 +841,8 @@ bool NetworkServerStart()
|
|||
_last_sync_frame = 0;
|
||||
_network_own_client_index = NETWORK_SERVER_INDEX;
|
||||
|
||||
/* Non-dedicated server will always be player #1 */
|
||||
if (!_network_dedicated) _network_playas = PLAYER_FIRST;
|
||||
/* Non-dedicated server will always be company #1 */
|
||||
if (!_network_dedicated) _network_playas = COMPANY_FIRST;
|
||||
|
||||
_network_clients_connected = 0;
|
||||
|
||||
|
@ -853,8 +853,8 @@ bool NetworkServerStart()
|
|||
// if the server is dedicated ... add some other script
|
||||
if (_network_dedicated) IConsoleCmdExec("exec scripts/on_dedicated.scr 0");
|
||||
|
||||
_min_players_paused = false;
|
||||
CheckMinPlayers();
|
||||
_min_active_clients_paused = false;
|
||||
CheckMinActiveClients();
|
||||
|
||||
/* Try to register us to the master server */
|
||||
_network_last_advertise_frame = 0;
|
||||
|
@ -1077,7 +1077,7 @@ void NetworkGameLoop()
|
|||
|
||||
while (f != NULL && !feof(f)) {
|
||||
if (cp != NULL && _date == next_date && _date_fract == next_date_fract) {
|
||||
_current_player = cp->player;
|
||||
_current_company = cp->company;
|
||||
_cmd_text = cp->text;
|
||||
DoCommandP(cp->tile, cp->p1, cp->p2, NULL, cp->cmd);
|
||||
free(cp);
|
||||
|
@ -1090,9 +1090,9 @@ void NetworkGameLoop()
|
|||
if (fgets(buff, lengthof(buff), f) == NULL) break;
|
||||
if (strncmp(buff, "ddc:cmd:", 8) != 0) continue;
|
||||
cp = MallocT<CommandPacket>(1);
|
||||
int player;
|
||||
sscanf(&buff[8], "%d;%d;%d;%d;%d;%d;%d;%s", &next_date, &next_date_fract, &player, &cp->tile, &cp->p1, &cp->p2, &cp->cmd, cp->text);
|
||||
cp->player = (Owner)player;
|
||||
int company;
|
||||
sscanf(&buff[8], "%d;%d;%d;%d;%d;%d;%d;%s", &next_date, &next_date_fract, &company, &cp->tile, &cp->p1, &cp->p2, &cp->cmd, cp->text);
|
||||
cp->company = (CompanyID)company;
|
||||
}
|
||||
#endif /* DEBUG_DUMP_COMMANDS */
|
||||
|
||||
|
@ -1238,4 +1238,4 @@ bool IsNetworkCompatibleVersion(const char *other)
|
|||
#endif /* ENABLE_NETWORK */
|
||||
|
||||
/* NOTE: this variable needs to be always available */
|
||||
PlayerID _network_playas;
|
||||
CompanyID _network_playas;
|
||||
|
|
|
@ -34,7 +34,7 @@ static inline void NetworkDrawChatMessage() {}
|
|||
|
||||
#endif /* ENABLE_NETWORK */
|
||||
|
||||
/** As which player do we play? */
|
||||
extern PlayerID _network_playas;
|
||||
/** As which company do we play? */
|
||||
extern CompanyID _network_playas;
|
||||
|
||||
#endif /* NETWORK_H */
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
#include "table/strings.h"
|
||||
|
||||
/* The draw buffer must be able to contain the chat message, player name and the "[All]" message,
|
||||
/* The draw buffer must be able to contain the chat message, client name and the "[All]" message,
|
||||
* some spaces and possible translations of [All] to other languages. */
|
||||
assert_compile((int)DRAW_STRING_BUFFER >= (int)NETWORK_CHAT_LENGTH + NETWORK_NAME_LENGTH + 40);
|
||||
|
||||
|
@ -99,7 +99,7 @@ void CDECL NetworkAddChatMessage(uint16 color, uint8 duration, const char *messa
|
|||
ChatMessage *cmsg = &_chatmsg_list[msg_count++];
|
||||
ttd_strlcpy(cmsg->message, bufp, sizeof(cmsg->message));
|
||||
|
||||
/* The default colour for a message is player colour. Replace this with
|
||||
/* The default colour for a message is company colour. Replace this with
|
||||
* white for any additional lines */
|
||||
cmsg->color = (bufp == buf && color & IS_PALETTE_COLOR) ? color : (0x1D - 15) | IS_PALETTE_COLOR;
|
||||
cmsg->end_date = _date + duration;
|
||||
|
|
|
@ -77,17 +77,17 @@ static const char *GenerateCompanyPasswordHash(const char *password)
|
|||
}
|
||||
|
||||
/**
|
||||
* Hash the current company password; used when the server 'player' sets his/her password.
|
||||
* Hash the current company password; used when the server 'company' sets his/her password.
|
||||
*/
|
||||
void HashCurrentCompanyPassword()
|
||||
{
|
||||
if (StrEmpty(_network_player_info[_local_player].password)) return;
|
||||
if (StrEmpty(_network_company_info[_local_company].password)) return;
|
||||
|
||||
_password_game_seed = _settings_game.game_creation.generation_seed;
|
||||
ttd_strlcpy(_password_server_unique_id, _settings_client.network.network_id, sizeof(_password_server_unique_id));
|
||||
|
||||
const char *new_pw = GenerateCompanyPasswordHash(_network_player_info[_local_player].password);
|
||||
ttd_strlcpy(_network_player_info[_local_player].password, new_pw, sizeof(_network_player_info[_local_player].password));
|
||||
const char *new_pw = GenerateCompanyPasswordHash(_network_company_info[_local_company].password);
|
||||
ttd_strlcpy(_network_company_info[_local_company].password, new_pw, sizeof(_network_company_info[_local_company].password));
|
||||
}
|
||||
|
||||
|
||||
|
@ -119,10 +119,10 @@ DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_JOIN)
|
|||
// Function: Try to join the server
|
||||
// Data:
|
||||
// String: OpenTTD Revision (norev000 if no revision)
|
||||
// String: Player Name (max NETWORK_NAME_LENGTH)
|
||||
// uint8: Play as Player id (1..MAX_PLAYERS)
|
||||
// String: Client Name (max NETWORK_NAME_LENGTH)
|
||||
// uint8: Play as Company id (1..MAX_COMPANIES)
|
||||
// uint8: Language ID
|
||||
// String: Unique id to find the player back in server-listing
|
||||
// String: Unique id to find the client back in server-listing
|
||||
//
|
||||
|
||||
Packet *p;
|
||||
|
@ -131,7 +131,7 @@ DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_JOIN)
|
|||
|
||||
p = NetworkSend_Init(PACKET_CLIENT_JOIN);
|
||||
p->Send_string(_openttd_revision);
|
||||
p->Send_string(_settings_client.network.player_name); // Player name
|
||||
p->Send_string(_settings_client.network.client_name); // Client name
|
||||
p->Send_uint8 (_network_playas); // PlayAs
|
||||
p->Send_uint8 (NETLANG_ANY); // Language
|
||||
p->Send_string(_settings_client.network.network_id);
|
||||
|
@ -213,7 +213,7 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_COMMAND)(CommandPacket *cp)
|
|||
// Packet: CLIENT_COMMAND
|
||||
// Function: Send a DoCommand to the Server
|
||||
// Data:
|
||||
// uint8: PlayerID (0..MAX_PLAYERS-1)
|
||||
// uint8: CompanyID (0..MAX_COMPANIES-1)
|
||||
// uint32: CommandID (see command.h)
|
||||
// uint32: P1 (free variables used in DoCommand)
|
||||
// uint32: P2
|
||||
|
@ -224,7 +224,7 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_COMMAND)(CommandPacket *cp)
|
|||
|
||||
Packet *p = NetworkSend_Init(PACKET_CLIENT_COMMAND);
|
||||
|
||||
p->Send_uint8 (cp->player);
|
||||
p->Send_uint8 (cp->company);
|
||||
p->Send_uint32(cp->cmd);
|
||||
p->Send_uint32(cp->p1);
|
||||
p->Send_uint32(cp->p2);
|
||||
|
@ -244,7 +244,7 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_CHAT)(NetworkAction action, DestType
|
|||
// Data:
|
||||
// uint8: ActionID (see network_data.h, NetworkAction)
|
||||
// uint8: Destination Type (see network_data.h, DestType);
|
||||
// uint16: Destination Player
|
||||
// uint16: Destination Company/Client
|
||||
// String: Message (max NETWORK_CHAT_LENGTH)
|
||||
//
|
||||
|
||||
|
@ -290,7 +290,7 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_SET_NAME)(const char *name)
|
|||
{
|
||||
//
|
||||
// Packet: PACKET_CLIENT_SET_NAME
|
||||
// Function: Gives the player a new name
|
||||
// Function: Gives the client a new name
|
||||
// Data:
|
||||
// String: Name
|
||||
//
|
||||
|
@ -359,7 +359,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_INFO)
|
|||
|
||||
if (!MY_CLIENT->has_quit && company_info_version == NETWORK_COMPANY_INFO_VERSION) {
|
||||
byte total;
|
||||
PlayerID current;
|
||||
CompanyID current;
|
||||
|
||||
total = p->Recv_uint8();
|
||||
|
||||
|
@ -367,21 +367,21 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_INFO)
|
|||
if (total == 0) return NETWORK_RECV_STATUS_CLOSE_QUERY;
|
||||
|
||||
current = (Owner)p->Recv_uint8();
|
||||
if (current >= MAX_PLAYERS) return NETWORK_RECV_STATUS_CLOSE_QUERY;
|
||||
if (current >= MAX_COMPANIES) return NETWORK_RECV_STATUS_CLOSE_QUERY;
|
||||
|
||||
p->Recv_string(_network_player_info[current].company_name, sizeof(_network_player_info[current].company_name));
|
||||
_network_player_info[current].inaugurated_year = p->Recv_uint32();
|
||||
_network_player_info[current].company_value = p->Recv_uint64();
|
||||
_network_player_info[current].money = p->Recv_uint64();
|
||||
_network_player_info[current].income = p->Recv_uint64();
|
||||
_network_player_info[current].performance = p->Recv_uint16();
|
||||
_network_player_info[current].use_password = p->Recv_bool();
|
||||
p->Recv_string(_network_company_info[current].company_name, sizeof(_network_company_info[current].company_name));
|
||||
_network_company_info[current].inaugurated_year = p->Recv_uint32();
|
||||
_network_company_info[current].company_value = p->Recv_uint64();
|
||||
_network_company_info[current].money = p->Recv_uint64();
|
||||
_network_company_info[current].income = p->Recv_uint64();
|
||||
_network_company_info[current].performance = p->Recv_uint16();
|
||||
_network_company_info[current].use_password = p->Recv_bool();
|
||||
for (i = 0; i < NETWORK_VEHICLE_TYPES; i++)
|
||||
_network_player_info[current].num_vehicle[i] = p->Recv_uint16();
|
||||
_network_company_info[current].num_vehicle[i] = p->Recv_uint16();
|
||||
for (i = 0; i < NETWORK_STATION_TYPES; i++)
|
||||
_network_player_info[current].num_station[i] = p->Recv_uint16();
|
||||
_network_company_info[current].num_station[i] = p->Recv_uint16();
|
||||
|
||||
p->Recv_string(_network_player_info[current].players, sizeof(_network_player_info[current].players));
|
||||
p->Recv_string(_network_company_info[current].clients, sizeof(_network_company_info[current].clients));
|
||||
|
||||
InvalidateWindow(WC_NETWORK_WINDOW, 0);
|
||||
|
||||
|
@ -398,7 +398,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CLIENT_INFO)
|
|||
{
|
||||
NetworkClientInfo *ci;
|
||||
uint16 index = p->Recv_uint16();
|
||||
PlayerID playas = (Owner)p->Recv_uint8();
|
||||
CompanyID playas = (CompanyID)p->Recv_uint8();
|
||||
char name[NETWORK_NAME_LENGTH];
|
||||
|
||||
p->Recv_string(name, sizeof(name));
|
||||
|
@ -414,7 +414,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CLIENT_INFO)
|
|||
// Client name changed, display the change
|
||||
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, "%s", name);
|
||||
} else if (playas != ci->client_playas) {
|
||||
// The player changed from client-player..
|
||||
// The client changed from client-player..
|
||||
// Do not display that for now
|
||||
}
|
||||
|
||||
|
@ -451,7 +451,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_ERROR)
|
|||
/* We made an error in the protocol, and our connection is closed.... */
|
||||
case NETWORK_ERROR_NOT_AUTHORIZED:
|
||||
case NETWORK_ERROR_NOT_EXPECTED:
|
||||
case NETWORK_ERROR_PLAYER_MISMATCH:
|
||||
case NETWORK_ERROR_COMPANY_MISMATCH:
|
||||
_switch_mode_errorstr = STR_NETWORK_ERR_SERVER_ERROR;
|
||||
break;
|
||||
case NETWORK_ERROR_FULL:
|
||||
|
@ -622,21 +622,21 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP)
|
|||
// Say we received the map and loaded it correctly!
|
||||
SEND_COMMAND(PACKET_CLIENT_MAP_OK)();
|
||||
|
||||
/* New company/spectator (invalid player) or company we want to join is not active
|
||||
* Switch local player to spectator and await the server's judgement */
|
||||
if (_network_playas == PLAYER_NEW_COMPANY || !IsValidPlayerID(_network_playas)) {
|
||||
SetLocalPlayer(PLAYER_SPECTATOR);
|
||||
/* New company/spectator (invalid company) or company we want to join is not active
|
||||
* Switch local company to spectator and await the server's judgement */
|
||||
if (_network_playas == COMPANY_NEW_COMPANY || !IsValidCompanyID(_network_playas)) {
|
||||
SetLocalCompany(COMPANY_SPECTATOR);
|
||||
|
||||
if (_network_playas != PLAYER_SPECTATOR) {
|
||||
/* We have arrived and ready to start playing; send a command to make a new player;
|
||||
if (_network_playas != COMPANY_SPECTATOR) {
|
||||
/* We have arrived and ready to start playing; send a command to make a new company;
|
||||
* the server will give us a client-id and let us in */
|
||||
_network_join_status = NETWORK_JOIN_STATUS_REGISTERING;
|
||||
ShowJoinStatusWindow();
|
||||
NetworkSend_Command(0, 0, 0, CMD_PLAYER_CTRL, NULL);
|
||||
NetworkSend_Command(0, 0, 0, CMD_COMPANY_CTRL, NULL);
|
||||
}
|
||||
} else {
|
||||
// take control over an existing company
|
||||
SetLocalPlayer(_network_playas);
|
||||
SetLocalCompany(_network_playas);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -685,7 +685,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_SYNC)
|
|||
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMMAND)
|
||||
{
|
||||
CommandPacket *cp = MallocT<CommandPacket>(1);
|
||||
cp->player = (PlayerID)p->Recv_uint8();
|
||||
cp->company = (CompanyID)p->Recv_uint8();
|
||||
cp->cmd = p->Recv_uint32();
|
||||
cp->p1 = p->Recv_uint32();
|
||||
cp->p2 = p->Recv_uint32();
|
||||
|
@ -733,12 +733,12 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CHAT)
|
|||
ci = NetworkFindClientInfoFromIndex(_network_own_client_index);
|
||||
break;
|
||||
|
||||
/* For speaking to company or giving money, we need the player-name */
|
||||
/* For speaking to company or giving money, we need the company-name */
|
||||
case NETWORK_ACTION_GIVE_MONEY:
|
||||
if (!IsValidPlayerID(ci_to->client_playas)) return NETWORK_RECV_STATUS_OKAY;
|
||||
if (!IsValidCompanyID(ci_to->client_playas)) return NETWORK_RECV_STATUS_OKAY;
|
||||
/* fallthrough */
|
||||
case NETWORK_ACTION_CHAT_COMPANY: {
|
||||
StringID str = IsValidPlayerID(ci_to->client_playas) ? STR_COMPANY_NAME : STR_NETWORK_SPECTATORS;
|
||||
StringID str = IsValidCompanyID(ci_to->client_playas) ? STR_COMPANY_NAME : STR_NETWORK_SPECTATORS;
|
||||
SetDParam(0, ci_to->client_playas);
|
||||
|
||||
GetString(name, str, lastof(name));
|
||||
|
@ -754,7 +754,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CHAT)
|
|||
}
|
||||
|
||||
if (ci != NULL)
|
||||
NetworkTextMessage(action, (ConsoleColour)GetDrawStringPlayerColor(ci->client_playas), self_send, name, "%s", msg);
|
||||
NetworkTextMessage(action, (ConsoleColour)GetDrawStringCompanyColor(ci->client_playas), self_send, name, "%s", msg);
|
||||
return NETWORK_RECV_STATUS_OKAY;
|
||||
}
|
||||
|
||||
|
@ -831,10 +831,10 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_SHUTDOWN)
|
|||
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_NEWGAME)
|
||||
{
|
||||
// To trottle the reconnects a bit, every clients waits
|
||||
// his _local_player value before reconnecting
|
||||
// PLAYER_SPECTATOR is currently 255, so to avoid long wait periods
|
||||
// his _local_company value before reconnecting
|
||||
// COMPANY_SPECTATOR is currently 255, so to avoid long wait periods
|
||||
// set the max to 10.
|
||||
_network_reconnect = min(_local_player + 1, 10);
|
||||
_network_reconnect = min(_local_company + 1, 10);
|
||||
_switch_mode_errorstr = STR_NETWORK_SERVER_REBOOT;
|
||||
|
||||
return NETWORK_RECV_STATUS_SERVER_ERROR;
|
||||
|
@ -938,20 +938,20 @@ void NetworkClientSendRcon(const char *password, const char *command)
|
|||
SEND_COMMAND(PACKET_CLIENT_RCON)(password, command);
|
||||
}
|
||||
|
||||
void NetworkUpdatePlayerName()
|
||||
void NetworkUpdateClientName()
|
||||
{
|
||||
NetworkClientInfo *ci = NetworkFindClientInfoFromIndex(_network_own_client_index);
|
||||
|
||||
if (ci == NULL) return;
|
||||
|
||||
/* Don't change the name if it is the same as the old name */
|
||||
if (strcmp(ci->client_name, _settings_client.network.player_name) != 0) {
|
||||
if (strcmp(ci->client_name, _settings_client.network.client_name) != 0) {
|
||||
if (!_network_server) {
|
||||
SEND_COMMAND(PACKET_CLIENT_SET_NAME)(_settings_client.network.player_name);
|
||||
SEND_COMMAND(PACKET_CLIENT_SET_NAME)(_settings_client.network.client_name);
|
||||
} else {
|
||||
if (NetworkFindName(_settings_client.network.player_name)) {
|
||||
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, "%s", _settings_client.network.player_name);
|
||||
ttd_strlcpy(ci->client_name, _settings_client.network.player_name, sizeof(ci->client_name));
|
||||
if (NetworkFindName(_settings_client.network.client_name)) {
|
||||
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, "%s", _settings_client.network.client_name);
|
||||
ttd_strlcpy(ci->client_name, _settings_client.network.client_name, sizeof(ci->client_name));
|
||||
NetworkUpdateClientInfo(NETWORK_SERVER_INDEX);
|
||||
}
|
||||
}
|
||||
|
@ -965,7 +965,7 @@ void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const
|
|||
|
||||
void NetworkClientSetPassword()
|
||||
{
|
||||
SEND_COMMAND(PACKET_CLIENT_SET_PASSWORD)(_network_player_info[_local_player].password);
|
||||
SEND_COMMAND(PACKET_CLIENT_SET_PASSWORD)(_network_company_info[_local_company].password);
|
||||
}
|
||||
|
||||
#endif /* ENABLE_NETWORK */
|
||||
|
|
|
@ -36,12 +36,12 @@ void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, Comma
|
|||
{
|
||||
CommandPacket c;
|
||||
|
||||
c.player = _local_player;
|
||||
c.next = NULL;
|
||||
c.tile = tile;
|
||||
c.p1 = p1;
|
||||
c.p2 = p2;
|
||||
c.cmd = cmd;
|
||||
c.company = _local_company;
|
||||
c.next = NULL;
|
||||
c.tile = tile;
|
||||
c.p1 = p1;
|
||||
c.p2 = p2;
|
||||
c.cmd = cmd;
|
||||
|
||||
c.callback = 0;
|
||||
while (c.callback < _callback_table_count && _callback_table[c.callback] != callback) {
|
||||
|
@ -95,7 +95,7 @@ void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, Comma
|
|||
// Execute a DoCommand we received from the network
|
||||
void NetworkExecuteCommand(CommandPacket *cp)
|
||||
{
|
||||
_current_player = cp->player;
|
||||
_current_company = cp->company;
|
||||
_cmd_text = cp->text;
|
||||
/* cp->callback is unsigned. so we don't need to do lower bounds checking. */
|
||||
if (cp->callback > _callback_table_count) {
|
||||
|
@ -103,7 +103,7 @@ void NetworkExecuteCommand(CommandPacket *cp)
|
|||
cp->callback = 0;
|
||||
}
|
||||
|
||||
DebugDumpCommands("ddc:cmd:%d;%d;%d;%d;%d;%d;%d;%s\n", _date, _date_fract, (int)cp->player, cp->tile, cp->p1, cp->p2, cp->cmd, cp->text);
|
||||
DebugDumpCommands("ddc:cmd:%d;%d;%d;%d;%d;%d;%d;%s\n", _date, _date_fract, (int)cp->company, cp->tile, cp->p1, cp->p2, cp->cmd, cp->text);
|
||||
|
||||
DoCommandP(cp->tile, cp->p1, cp->p2, _callback_table[cp->callback], cp->cmd | CMD_NETWORK_COMMAND, cp->my_cmd);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include "../console_type.h"
|
||||
|
||||
extern NetworkServerGameInfo _network_game_info;
|
||||
extern NetworkPlayerInfo _network_player_info[MAX_PLAYERS];
|
||||
extern NetworkCompanyInfo _network_company_info[MAX_COMPANIES];
|
||||
extern NetworkClientInfo _network_client_info[MAX_CLIENT_INFO];
|
||||
|
||||
extern uint16 _network_own_client_index;
|
||||
|
@ -23,16 +23,16 @@ extern char *_network_host_list[10];
|
|||
extern char *_network_ban_list[25];
|
||||
|
||||
byte NetworkSpectatorCount();
|
||||
void CheckMinPlayers();
|
||||
void NetworkUpdatePlayerName();
|
||||
bool NetworkCompanyHasPlayers(PlayerID company);
|
||||
void CheckMinActiveClients();
|
||||
void NetworkUpdateClientName();
|
||||
bool NetworkCompanyHasClients(CompanyID company);
|
||||
bool NetworkChangeCompanyPassword(byte argc, char *argv[]);
|
||||
void NetworkReboot();
|
||||
void NetworkDisconnect();
|
||||
void NetworkGameLoop();
|
||||
void NetworkUDPGameLoop();
|
||||
void NetworkUDPCloseAll();
|
||||
void ParseConnectionString(const char **player, const char **port, char *connection_string);
|
||||
void ParseConnectionString(const char **company, const char **port, char *connection_string);
|
||||
void NetworkStartDebugLog(const char *hostname, uint16 port);
|
||||
void NetworkPopulateCompanyInfo();
|
||||
|
||||
|
@ -45,13 +45,13 @@ void NetworkClientSetPassword();
|
|||
/*** Commands ran by the server ***/
|
||||
void NetworkServerMonthlyLoop();
|
||||
void NetworkServerYearlyLoop();
|
||||
void NetworkServerChangeOwner(PlayerID current_player, PlayerID new_player);
|
||||
void NetworkServerChangeOwner(Owner current_owner, Owner new_owner);
|
||||
void NetworkServerShowStatusToConsole();
|
||||
bool NetworkServerStart();
|
||||
|
||||
NetworkClientInfo *NetworkFindClientInfoFromIndex(uint16 client_index);
|
||||
NetworkClientInfo *NetworkFindClientInfoFromIP(const char *ip);
|
||||
const char* GetPlayerIP(const NetworkClientInfo *ci);
|
||||
const char* GetClientIP(const NetworkClientInfo *ci);
|
||||
|
||||
void NetworkServerSendRcon(uint16 client_index, ConsoleColour colour_code, const char *string);
|
||||
void NetworkServerSendError(uint16 client_index, NetworkErrorCode error);
|
||||
|
|
|
@ -87,7 +87,7 @@ enum NetworkGameWindowWidgets {
|
|||
|
||||
NGWW_CONNECTION, ///< Label in from of connection droplist
|
||||
NGWW_CONN_BTN, ///< 'Connection' droplist button
|
||||
NGWW_PLAYER, ///< Panel with editbox to set player name
|
||||
NGWW_CLIENT, ///< Panel with editbox to set client name
|
||||
|
||||
NGWW_NAME, ///< 'Name' button
|
||||
NGWW_CLIENTS, ///< 'Clients' button
|
||||
|
@ -286,7 +286,7 @@ protected:
|
|||
public:
|
||||
NetworkGameWindow(const WindowDesc *desc) : QueryStringBaseWindow(NETWORK_NAME_LENGTH, desc)
|
||||
{
|
||||
ttd_strlcpy(this->edit_str_buf, _settings_client.network.player_name, this->edit_str_size);
|
||||
ttd_strlcpy(this->edit_str_buf, _settings_client.network.client_name, this->edit_str_size);
|
||||
this->afilter = CS_ALPHANUMERAL;
|
||||
InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, 120);
|
||||
|
||||
|
@ -295,7 +295,7 @@ public:
|
|||
this->vscroll.cap = 11;
|
||||
this->resize.step_height = NET_PRC__SIZE_OF_ROW;
|
||||
|
||||
this->field = NGWW_PLAYER;
|
||||
this->field = NGWW_CLIENT;
|
||||
this->server = NULL;
|
||||
|
||||
this->servers.SetListing(this->last_sorting);
|
||||
|
@ -339,10 +339,10 @@ public:
|
|||
SetDParam(1, _lan_internet_types_dropdown[_settings_client.network.lan_internet]);
|
||||
this->DrawWidgets();
|
||||
|
||||
/* Edit box to set player name */
|
||||
this->DrawEditBox(NGWW_PLAYER);
|
||||
/* Edit box to set client name */
|
||||
this->DrawEditBox(NGWW_CLIENT);
|
||||
|
||||
DrawString(this->widget[NGWW_PLAYER].left - 100, 23, STR_NETWORK_PLAYER_NAME, TC_GOLD);
|
||||
DrawString(this->widget[NGWW_CLIENT].left - 100, 23, STR_NETWORK_PLAYER_NAME, TC_GOLD);
|
||||
|
||||
/* Sort based on widgets: name, clients, compatibility */
|
||||
switch (this->servers.SortType()) {
|
||||
|
@ -446,8 +446,8 @@ public:
|
|||
{
|
||||
this->field = widget;
|
||||
switch (widget) {
|
||||
case NGWW_PLAYER:
|
||||
ShowOnScreenKeyboard(this, NGWW_PLAYER, 0, 0);
|
||||
case NGWW_CLIENT:
|
||||
ShowOnScreenKeyboard(this, NGWW_CLIENT, 0, 0);
|
||||
break;
|
||||
|
||||
case NGWW_CANCEL: // Cancel button
|
||||
|
@ -554,7 +554,7 @@ public:
|
|||
|
||||
virtual void OnMouseLoop()
|
||||
{
|
||||
if (this->field == NGWW_PLAYER) this->HandleEditBox(NGWW_PLAYER);
|
||||
if (this->field == NGWW_CLIENT) this->HandleEditBox(NGWW_CLIENT);
|
||||
}
|
||||
|
||||
virtual void OnInvalidateData(int data)
|
||||
|
@ -567,7 +567,7 @@ public:
|
|||
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
||||
{
|
||||
EventState state = ES_NOT_HANDLED;
|
||||
if (this->field != NGWW_PLAYER) {
|
||||
if (this->field != NGWW_CLIENT) {
|
||||
if (this->server != NULL) {
|
||||
if (keycode == WKC_DELETE) { // Press 'delete' to remove servers
|
||||
NetworkGameListRemoveItem(this->server);
|
||||
|
@ -578,13 +578,13 @@ public:
|
|||
return state;
|
||||
}
|
||||
|
||||
if (this->HandleEditBoxKey(NGWW_PLAYER, key, keycode, state) == 1) return state; // enter pressed
|
||||
if (this->HandleEditBoxKey(NGWW_CLIENT, key, keycode, state) == 1) return state; // enter pressed
|
||||
|
||||
/* The name is only allowed when it starts with a letter! */
|
||||
if (!StrEmpty(this->edit_str_buf) && this->edit_str_buf[0] != ' ') {
|
||||
ttd_strlcpy(_settings_client.network.player_name, this->edit_str_buf, lengthof(_settings_client.network.player_name));
|
||||
ttd_strlcpy(_settings_client.network.client_name, this->edit_str_buf, lengthof(_settings_client.network.client_name));
|
||||
} else {
|
||||
ttd_strlcpy(_settings_client.network.player_name, "Player", lengthof(_settings_client.network.player_name));
|
||||
ttd_strlcpy(_settings_client.network.client_name, "Player", lengthof(_settings_client.network.client_name));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
@ -670,7 +670,7 @@ static const Widget _network_game_window_widgets[] = {
|
|||
{ WWT_TEXT, RESIZE_NONE, COLOUR_LIGHT_BLUE, 9, 85, 23, 35, STR_NETWORK_CONNECTION, STR_NULL}, // NGWW_CONNECTION
|
||||
{ WWT_DROPDOWNIN, RESIZE_NONE, COLOUR_LIGHT_BLUE, 90, 181, 22, 33, STR_NETWORK_LAN_INTERNET_COMBO, STR_NETWORK_CONNECTION_TIP}, // NGWW_CONN_BTN
|
||||
|
||||
{ WWT_EDITBOX, RESIZE_LR, COLOUR_LIGHT_BLUE, 290, 440, 22, 33, STR_NETWORK_PLAYER_NAME_OSKTITLE, STR_NETWORK_ENTER_NAME_TIP}, // NGWW_PLAYER
|
||||
{ WWT_EDITBOX, RESIZE_LR, COLOUR_LIGHT_BLUE, 290, 440, 22, 33, STR_NETWORK_PLAYER_NAME_OSKTITLE, STR_NETWORK_ENTER_NAME_TIP}, // NGWW_CLIENT
|
||||
|
||||
/* LEFT SIDE */
|
||||
{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_WHITE, 10, 70, 42, 53, STR_NETWORK_GAME_NAME, STR_NETWORK_GAME_NAME_TIP}, // NGWW_NAME
|
||||
|
@ -864,7 +864,7 @@ struct NetworkStartServerWindow : public QueryStringBaseWindow {
|
|||
_settings_client.network.max_clients = Clamp(_settings_client.network.max_clients + widget - NSSW_CLIENTS_TXT, 2, MAX_CLIENTS);
|
||||
break;
|
||||
case NSSW_COMPANIES_BTND: case NSSW_COMPANIES_BTNU:
|
||||
_settings_client.network.max_companies = Clamp(_settings_client.network.max_companies + widget - NSSW_COMPANIES_TXT, 1, MAX_PLAYERS);
|
||||
_settings_client.network.max_companies = Clamp(_settings_client.network.max_companies + widget - NSSW_COMPANIES_TXT, 1, MAX_COMPANIES);
|
||||
break;
|
||||
case NSSW_SPECTATORS_BTND: case NSSW_SPECTATORS_BTNU:
|
||||
_settings_client.network.max_spectators = Clamp(_settings_client.network.max_spectators + widget - NSSW_SPECTATORS_TXT, 0, MAX_CLIENTS);
|
||||
|
@ -874,7 +874,7 @@ struct NetworkStartServerWindow : public QueryStringBaseWindow {
|
|||
_left_button_clicked = false;
|
||||
break;
|
||||
|
||||
case NSSW_CLIENTS_TXT: // Click on number of players
|
||||
case NSSW_CLIENTS_TXT: // Click on number of clients
|
||||
this->widget_id = NSSW_CLIENTS_TXT;
|
||||
SetDParam(0, _settings_client.network.max_clients);
|
||||
ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_NETWORK_NUMBER_OF_CLIENTS, 3, 50, this, CS_NUMERAL, QSF_NONE);
|
||||
|
@ -977,7 +977,7 @@ struct NetworkStartServerWindow : public QueryStringBaseWindow {
|
|||
switch (this->widget_id) {
|
||||
default: NOT_REACHED();
|
||||
case NSSW_CLIENTS_TXT: _settings_client.network.max_clients = Clamp(value, 2, MAX_CLIENTS); break;
|
||||
case NSSW_COMPANIES_TXT: _settings_client.network.max_companies = Clamp(value, 1, MAX_PLAYERS); break;
|
||||
case NSSW_COMPANIES_TXT: _settings_client.network.max_companies = Clamp(value, 1, MAX_COMPANIES); break;
|
||||
case NSSW_SPECTATORS_TXT: _settings_client.network.max_spectators = Clamp(value, 0, MAX_CLIENTS); break;
|
||||
}
|
||||
}
|
||||
|
@ -1046,16 +1046,16 @@ static void ShowNetworkStartServerWindow()
|
|||
new NetworkStartServerWindow(&_network_start_server_window_desc);
|
||||
}
|
||||
|
||||
static PlayerID NetworkLobbyFindCompanyIndex(byte pos)
|
||||
static CompanyID NetworkLobbyFindCompanyIndex(byte pos)
|
||||
{
|
||||
/* Scroll through all _network_player_info and get the 'pos' item that is not empty */
|
||||
for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) {
|
||||
if (_network_player_info[i].company_name[0] != '\0') {
|
||||
/* Scroll through all _network_company_info and get the 'pos' item that is not empty */
|
||||
for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
|
||||
if (!StrEmpty(_network_company_info[i].company_name)) {
|
||||
if (pos-- == 0) return i;
|
||||
}
|
||||
}
|
||||
|
||||
return PLAYER_FIRST;
|
||||
return COMPANY_FIRST;
|
||||
}
|
||||
|
||||
/** Enum for NetworkLobbyWindow, referring to _network_lobby_window_widgets */
|
||||
|
@ -1071,11 +1071,11 @@ enum NetworkLobbyWindowWidgets {
|
|||
};
|
||||
|
||||
struct NetworkLobbyWindow : public Window {
|
||||
PlayerID company; ///< Select company
|
||||
CompanyID company; ///< Select company
|
||||
NetworkGameList *server; ///< Selected server
|
||||
|
||||
NetworkLobbyWindow(const WindowDesc *desc, NetworkGameList *ngl) :
|
||||
Window(desc), company(INVALID_PLAYER), server(ngl)
|
||||
Window(desc), company(INVALID_COMPANY), server(ngl)
|
||||
{
|
||||
this->vscroll.cap = 10;
|
||||
|
||||
|
@ -1088,7 +1088,7 @@ struct NetworkLobbyWindow : public Window {
|
|||
int y = NET_PRC__OFFSET_TOP_WIDGET_COMPANY, pos;
|
||||
|
||||
/* Join button is disabled when no company is selected */
|
||||
this->SetWidgetDisabledState(NLWW_JOIN, this->company == INVALID_PLAYER);
|
||||
this->SetWidgetDisabledState(NLWW_JOIN, this->company == INVALID_COMPANY);
|
||||
/* Cannot start new company if there are too many */
|
||||
this->SetWidgetDisabledState(NLWW_NEW, gi->companies_on >= gi->companies_max);
|
||||
/* Cannot spectate if there are too many spectators */
|
||||
|
@ -1107,11 +1107,11 @@ struct NetworkLobbyWindow : public Window {
|
|||
GfxFillRect(11, y - 1, 154, y + 10, 10); // show highlighted item with a different colour
|
||||
}
|
||||
|
||||
DoDrawStringTruncated(_network_player_info[company].company_name, 13, y, TC_BLACK, 135 - 13);
|
||||
if (_network_player_info[company].use_password != 0) DrawSprite(SPR_LOCK, PAL_NONE, 135, y);
|
||||
DoDrawStringTruncated(_network_company_info[company].company_name, 13, y, TC_BLACK, 135 - 13);
|
||||
if (_network_company_info[company].use_password != 0) DrawSprite(SPR_LOCK, PAL_NONE, 135, y);
|
||||
|
||||
/* If the company's income was positive puts a green dot else a red dot */
|
||||
if (_network_player_info[company].income >= 0) income = true;
|
||||
if (_network_company_info[company].income >= 0) income = true;
|
||||
DrawSprite(SPR_BLOT, income ? PALETTE_TO_GREEN : PALETTE_TO_RED, 145, y);
|
||||
|
||||
pos++;
|
||||
|
@ -1122,7 +1122,7 @@ struct NetworkLobbyWindow : public Window {
|
|||
/* Draw info about selected company when it is selected in the left window */
|
||||
GfxFillRect(174, 39, 403, 75, 157);
|
||||
DrawStringCentered(290, 50, STR_NETWORK_COMPANY_INFO, TC_FROMSTRING);
|
||||
if (this->company != INVALID_PLAYER) {
|
||||
if (this->company != INVALID_COMPANY) {
|
||||
const uint x = 183;
|
||||
const uint trunc_width = this->widget[NLWW_DETAILS].right - x;
|
||||
y = 80;
|
||||
|
@ -1134,47 +1134,47 @@ struct NetworkLobbyWindow : public Window {
|
|||
DrawString(x, y, STR_NETWORK_CLIENTS, TC_GOLD);
|
||||
y += 10;
|
||||
|
||||
SetDParamStr(0, _network_player_info[this->company].company_name);
|
||||
SetDParamStr(0, _network_company_info[this->company].company_name);
|
||||
DrawStringTruncated(x, y, STR_NETWORK_COMPANY_NAME, TC_GOLD, trunc_width);
|
||||
y += 10;
|
||||
|
||||
SetDParam(0, _network_player_info[this->company].inaugurated_year);
|
||||
SetDParam(0, _network_company_info[this->company].inaugurated_year);
|
||||
DrawString(x, y, STR_NETWORK_INAUGURATION_YEAR, TC_GOLD); // inauguration year
|
||||
y += 10;
|
||||
|
||||
SetDParam(0, _network_player_info[this->company].company_value);
|
||||
SetDParam(0, _network_company_info[this->company].company_value);
|
||||
DrawString(x, y, STR_NETWORK_VALUE, TC_GOLD); // company value
|
||||
y += 10;
|
||||
|
||||
SetDParam(0, _network_player_info[this->company].money);
|
||||
SetDParam(0, _network_company_info[this->company].money);
|
||||
DrawString(x, y, STR_NETWORK_CURRENT_BALANCE, TC_GOLD); // current balance
|
||||
y += 10;
|
||||
|
||||
SetDParam(0, _network_player_info[this->company].income);
|
||||
SetDParam(0, _network_company_info[this->company].income);
|
||||
DrawString(x, y, STR_NETWORK_LAST_YEARS_INCOME, TC_GOLD); // last year's income
|
||||
y += 10;
|
||||
|
||||
SetDParam(0, _network_player_info[this->company].performance);
|
||||
SetDParam(0, _network_company_info[this->company].performance);
|
||||
DrawString(x, y, STR_NETWORK_PERFORMANCE, TC_GOLD); // performance
|
||||
y += 10;
|
||||
|
||||
SetDParam(0, _network_player_info[this->company].num_vehicle[0]);
|
||||
SetDParam(1, _network_player_info[this->company].num_vehicle[1]);
|
||||
SetDParam(2, _network_player_info[this->company].num_vehicle[2]);
|
||||
SetDParam(3, _network_player_info[this->company].num_vehicle[3]);
|
||||
SetDParam(4, _network_player_info[this->company].num_vehicle[4]);
|
||||
SetDParam(0, _network_company_info[this->company].num_vehicle[0]);
|
||||
SetDParam(1, _network_company_info[this->company].num_vehicle[1]);
|
||||
SetDParam(2, _network_company_info[this->company].num_vehicle[2]);
|
||||
SetDParam(3, _network_company_info[this->company].num_vehicle[3]);
|
||||
SetDParam(4, _network_company_info[this->company].num_vehicle[4]);
|
||||
DrawString(x, y, STR_NETWORK_VEHICLES, TC_GOLD); // vehicles
|
||||
y += 10;
|
||||
|
||||
SetDParam(0, _network_player_info[this->company].num_station[0]);
|
||||
SetDParam(1, _network_player_info[this->company].num_station[1]);
|
||||
SetDParam(2, _network_player_info[this->company].num_station[2]);
|
||||
SetDParam(3, _network_player_info[this->company].num_station[3]);
|
||||
SetDParam(4, _network_player_info[this->company].num_station[4]);
|
||||
SetDParam(0, _network_company_info[this->company].num_station[0]);
|
||||
SetDParam(1, _network_company_info[this->company].num_station[1]);
|
||||
SetDParam(2, _network_company_info[this->company].num_station[2]);
|
||||
SetDParam(3, _network_company_info[this->company].num_station[3]);
|
||||
SetDParam(4, _network_company_info[this->company].num_station[4]);
|
||||
DrawString(x, y, STR_NETWORK_STATIONS, TC_GOLD); // stations
|
||||
y += 10;
|
||||
|
||||
SetDParamStr(0, _network_player_info[this->company].players);
|
||||
SetDParamStr(0, _network_company_info[this->company].clients);
|
||||
DrawStringTruncated(x, y, STR_NETWORK_PLAYERS, TC_GOLD, trunc_width); // players
|
||||
}
|
||||
}
|
||||
|
@ -1193,7 +1193,7 @@ struct NetworkLobbyWindow : public Window {
|
|||
if (id_v >= this->vscroll.cap) break;
|
||||
|
||||
id_v += this->vscroll.pos;
|
||||
this->company = (id_v >= this->server->info.companies_on) ? INVALID_PLAYER : NetworkLobbyFindCompanyIndex(id_v);
|
||||
this->company = (id_v >= this->server->info.companies_on) ? INVALID_COMPANY : NetworkLobbyFindCompanyIndex(id_v);
|
||||
this->SetDirty();
|
||||
} break;
|
||||
|
||||
|
@ -1204,12 +1204,12 @@ struct NetworkLobbyWindow : public Window {
|
|||
break;
|
||||
|
||||
case NLWW_NEW: // New company
|
||||
_network_playas = PLAYER_NEW_COMPANY;
|
||||
_network_playas = COMPANY_NEW_COMPANY;
|
||||
NetworkClientConnectGame(_settings_client.network.last_host, _settings_client.network.last_port);
|
||||
break;
|
||||
|
||||
case NLWW_SPECTATE: // Spectate game
|
||||
_network_playas = PLAYER_SPECTATOR;
|
||||
_network_playas = COMPANY_SPECTATOR;
|
||||
NetworkClientConnectGame(_settings_client.network.last_host, _settings_client.network.last_port);
|
||||
break;
|
||||
|
||||
|
@ -1240,7 +1240,7 @@ static const Widget _network_lobby_window_widgets[] = {
|
|||
{ WWT_MATRIX, RESIZE_NONE, COLOUR_LIGHT_BLUE, 10, 155, 50, 190, (10 << 8) + 1, STR_NETWORK_COMPANY_LIST_TIP}, // NLWW_MATRIX
|
||||
{ WWT_SCROLLBAR, RESIZE_NONE, COLOUR_LIGHT_BLUE, 156, 167, 38, 190, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
||||
|
||||
/* company/player info */
|
||||
/* company info */
|
||||
{ WWT_PANEL, RESIZE_NONE, COLOUR_LIGHT_BLUE, 173, 404, 38, 190, 0x0, STR_NULL}, // NLWW_DETAILS
|
||||
|
||||
/* buttons */
|
||||
|
@ -1276,7 +1276,7 @@ static void ShowNetworkLobbyWindow(NetworkGameList *ngl)
|
|||
// and also makes able to give money to them, kick them (if server)
|
||||
// and stuff like that.
|
||||
|
||||
extern void DrawPlayerIcon(PlayerID pid, int x, int y);
|
||||
extern void DrawCompanyIcon(CompanyID cid, int x, int y);
|
||||
|
||||
// Every action must be of this form
|
||||
typedef void ClientList_Action_Proc(byte client_no);
|
||||
|
@ -1326,7 +1326,7 @@ static const NetworkClientInfo *NetworkFindClientInfo(byte client_no)
|
|||
// Here we start to define the options out of the menu
|
||||
static void ClientList_Kick(byte client_no)
|
||||
{
|
||||
if (client_no < MAX_PLAYERS)
|
||||
if (client_no < MAX_COMPANIES)
|
||||
SEND_COMMAND(PACKET_SERVER_ERROR)(DEREF_CLIENT(client_no), NETWORK_ERROR_KICKED);
|
||||
}
|
||||
|
||||
|
@ -1341,7 +1341,7 @@ static void ClientList_Ban(byte client_no)
|
|||
}
|
||||
}
|
||||
|
||||
if (client_no < MAX_PLAYERS) {
|
||||
if (client_no < MAX_COMPANIES) {
|
||||
SEND_COMMAND(PACKET_SERVER_ERROR)(DEREF_CLIENT(client_no), NETWORK_ERROR_KICKED);
|
||||
}
|
||||
}
|
||||
|
@ -1402,7 +1402,7 @@ struct NetworkClientListPopupWindow : Window {
|
|||
this->proc[i++] = &ClientList_SpeakToClient;
|
||||
}
|
||||
|
||||
if (IsValidPlayerID(ci->client_playas) || ci->client_playas == PLAYER_SPECTATOR) {
|
||||
if (IsValidCompanyID(ci->client_playas) || ci->client_playas == COMPANY_SPECTATOR) {
|
||||
GetString(this->action[i], STR_NETWORK_CLIENTLIST_SPEAK_TO_COMPANY, lastof(this->action[i]));
|
||||
this->proc[i++] = &ClientList_SpeakToCompany;
|
||||
}
|
||||
|
@ -1410,8 +1410,8 @@ struct NetworkClientListPopupWindow : Window {
|
|||
this->proc[i++] = &ClientList_SpeakToAll;
|
||||
|
||||
if (_network_own_client_index != ci->client_index) {
|
||||
/* We are no spectator and the player we want to give money to is no spectator and money gifts are allowed */
|
||||
if (IsValidPlayerID(_network_playas) && IsValidPlayerID(ci->client_playas) && _settings_game.economy.give_money) {
|
||||
/* We are no spectator and the company we want to give money to is no spectator and money gifts are allowed */
|
||||
if (IsValidCompanyID(_network_playas) && IsValidCompanyID(ci->client_playas) && _settings_game.economy.give_money) {
|
||||
GetString(this->action[i], STR_NETWORK_CLIENTLIST_GIVE_MONEY, lastof(this->action[i]));
|
||||
this->proc[i++] = &ClientList_GiveMoney;
|
||||
}
|
||||
|
@ -1600,7 +1600,7 @@ struct NetworkClientListWindow : Window
|
|||
}
|
||||
|
||||
/* Filter out spectators */
|
||||
if (IsValidPlayerID(ci->client_playas)) DrawPlayerIcon(ci->client_playas, 64, y + 1);
|
||||
if (IsValidCompanyID(ci->client_playas)) DrawCompanyIcon(ci->client_playas, 64, y + 1);
|
||||
|
||||
DoDrawString(ci->client_name, 81, y, colour);
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include "network_type.h"
|
||||
|
||||
void ShowNetworkNeedPassword(NetworkPasswordType npt);
|
||||
void ShowNetworkGiveMoneyWindow(PlayerID player); // PlayerID
|
||||
void ShowNetworkGiveMoneyWindow(CompanyID company);
|
||||
void ShowNetworkChatQueryWindow(DestType type, int dest);
|
||||
void ShowJoinStatusWindow();
|
||||
void ShowNetworkGameWindow();
|
||||
|
|
|
@ -91,7 +91,7 @@ enum NetworkLanguage {
|
|||
NETLANG_COUNT
|
||||
};
|
||||
|
||||
extern NetworkPlayerInfo _network_player_info[MAX_PLAYERS];
|
||||
extern NetworkCompanyInfo _network_company_info[MAX_COMPANIES];
|
||||
|
||||
extern uint32 _frame_counter_server; // The frame_counter of the server, if in network-mode
|
||||
extern uint32 _frame_counter_max; // To where we may go with our clients
|
||||
|
|
|
@ -47,7 +47,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CLIENT_INFO)(NetworkTCPSocketHandler
|
|||
// Function: Sends info about a client
|
||||
// Data:
|
||||
// uint16: The index of the client (always unique on a server. 1 = server)
|
||||
// uint8: As which player the client is playing
|
||||
// uint8: As which company the client is playing
|
||||
// String: The name of the client
|
||||
//
|
||||
|
||||
|
@ -71,10 +71,10 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_COMPANY_INFO)
|
|||
|
||||
int i;
|
||||
|
||||
Player *player;
|
||||
Company *company;
|
||||
Packet *p;
|
||||
|
||||
byte active = ActivePlayerCount();
|
||||
byte active = ActiveCompanyCount();
|
||||
|
||||
if (active == 0) {
|
||||
p = NetworkSend_Init(PACKET_SERVER_COMPANY_INFO);
|
||||
|
@ -88,35 +88,35 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_COMPANY_INFO)
|
|||
|
||||
NetworkPopulateCompanyInfo();
|
||||
|
||||
FOR_ALL_PLAYERS(player) {
|
||||
FOR_ALL_COMPANIES(company) {
|
||||
p = NetworkSend_Init(PACKET_SERVER_COMPANY_INFO);
|
||||
|
||||
p->Send_uint8 (NETWORK_COMPANY_INFO_VERSION);
|
||||
p->Send_uint8 (active);
|
||||
p->Send_uint8 (player->index);
|
||||
p->Send_uint8 (company->index);
|
||||
|
||||
p->Send_string(_network_player_info[player->index].company_name);
|
||||
p->Send_uint32(_network_player_info[player->index].inaugurated_year);
|
||||
p->Send_uint64(_network_player_info[player->index].company_value);
|
||||
p->Send_uint64(_network_player_info[player->index].money);
|
||||
p->Send_uint64(_network_player_info[player->index].income);
|
||||
p->Send_uint16(_network_player_info[player->index].performance);
|
||||
p->Send_string(_network_company_info[company->index].company_name);
|
||||
p->Send_uint32(_network_company_info[company->index].inaugurated_year);
|
||||
p->Send_uint64(_network_company_info[company->index].company_value);
|
||||
p->Send_uint64(_network_company_info[company->index].money);
|
||||
p->Send_uint64(_network_company_info[company->index].income);
|
||||
p->Send_uint16(_network_company_info[company->index].performance);
|
||||
|
||||
/* Send 1 if there is a passord for the company else send 0 */
|
||||
p->Send_bool(!StrEmpty(_network_player_info[player->index].password));
|
||||
p->Send_bool(!StrEmpty(_network_company_info[company->index].password));
|
||||
|
||||
for (i = 0; i < NETWORK_VEHICLE_TYPES; i++) {
|
||||
p->Send_uint16(_network_player_info[player->index].num_vehicle[i]);
|
||||
p->Send_uint16(_network_company_info[company->index].num_vehicle[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < NETWORK_STATION_TYPES; i++) {
|
||||
p->Send_uint16(_network_player_info[player->index].num_station[i]);
|
||||
p->Send_uint16(_network_company_info[company->index].num_station[i]);
|
||||
}
|
||||
|
||||
if (_network_player_info[player->index].players[0] == '\0') {
|
||||
if (StrEmpty(_network_company_info[company->index].clients)) {
|
||||
p->Send_string("<none>");
|
||||
} else {
|
||||
p->Send_string(_network_player_info[player->index].players);
|
||||
p->Send_string(_network_company_info[company->index].clients);
|
||||
}
|
||||
|
||||
cs->Send_Packet(p);
|
||||
|
@ -276,7 +276,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_WAIT)
|
|||
NetworkTCPSocketHandler *new_cs;
|
||||
Packet *p;
|
||||
|
||||
// Count how many players are waiting in the queue
|
||||
// Count how many clients are waiting in the queue
|
||||
FOR_ALL_CLIENTS(new_cs) {
|
||||
if (new_cs->status == STATUS_MAP_WAIT) waiting++;
|
||||
}
|
||||
|
@ -300,9 +300,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MAP)
|
|||
// if MAP_PACKET_NORMAL:
|
||||
// piece of the map (till max-size of packet)
|
||||
// if MAP_PACKET_END:
|
||||
// uint32: seed0 of player
|
||||
// uint32: seed1 of player
|
||||
// last 2 are repeated MAX_PLAYERS time
|
||||
// nothing
|
||||
//
|
||||
|
||||
static FILE *file_pointer;
|
||||
|
@ -476,7 +474,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_COMMAND)(NetworkTCPSocketHandler *cs
|
|||
// Packet: SERVER_COMMAND
|
||||
// Function: Sends a DoCommand to the client
|
||||
// Data:
|
||||
// uint8: PlayerID (0..MAX_PLAYERS-1)
|
||||
// uint8: CompanyID (0..MAX_COMPANIES-1)
|
||||
// uint32: CommandID (see command.h)
|
||||
// uint32: P1 (free variables used in DoCommand)
|
||||
// uint32: P2
|
||||
|
@ -488,7 +486,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_COMMAND)(NetworkTCPSocketHandler *cs
|
|||
|
||||
Packet *p = NetworkSend_Init(PACKET_SERVER_COMMAND);
|
||||
|
||||
p->Send_uint8 (cp->player);
|
||||
p->Send_uint8 (cp->company);
|
||||
p->Send_uint32(cp->cmd);
|
||||
p->Send_uint32(cp->p1);
|
||||
p->Send_uint32(cp->p2);
|
||||
|
@ -619,7 +617,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_NEWGRFS_CHECKED)
|
|||
if (!StrEmpty(_settings_client.network.server_password)) {
|
||||
SEND_COMMAND(PACKET_SERVER_NEED_PASSWORD)(cs, NETWORK_GAME_PASSWORD);
|
||||
} else {
|
||||
if (IsValidPlayerID(ci->client_playas) && _network_player_info[ci->client_playas].password[0] != '\0') {
|
||||
if (IsValidCompanyID(ci->client_playas) && _network_company_info[ci->client_playas].password[0] != '\0') {
|
||||
SEND_COMMAND(PACKET_SERVER_NEED_PASSWORD)(cs, NETWORK_COMPANY_PASSWORD);
|
||||
} else {
|
||||
SEND_COMMAND(PACKET_SERVER_WELCOME)(cs);
|
||||
|
@ -638,7 +636,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN)
|
|||
char name[NETWORK_CLIENT_NAME_LENGTH];
|
||||
char unique_id[NETWORK_UNIQUE_ID_LENGTH];
|
||||
NetworkClientInfo *ci;
|
||||
PlayerID playas;
|
||||
CompanyID playas;
|
||||
NetworkLanguage client_lang;
|
||||
char client_revision[NETWORK_REVISION_LENGTH];
|
||||
|
||||
|
@ -660,31 +658,31 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN)
|
|||
|
||||
// join another company does not affect these values
|
||||
switch (playas) {
|
||||
case PLAYER_NEW_COMPANY: /* New company */
|
||||
if (ActivePlayerCount() >= _settings_client.network.max_companies) {
|
||||
case COMPANY_NEW_COMPANY: /* New company */
|
||||
if (ActiveCompanyCount() >= _settings_client.network.max_companies) {
|
||||
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_FULL);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case PLAYER_SPECTATOR: /* Spectator */
|
||||
case COMPANY_SPECTATOR: /* Spectator */
|
||||
if (NetworkSpectatorCount() >= _settings_client.network.max_spectators) {
|
||||
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_FULL);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default: /* Join another company (companies 1-8 (index 0-7)) */
|
||||
if (!IsValidPlayerID(playas)) {
|
||||
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_PLAYER_MISMATCH);
|
||||
if (!IsValidCompanyID(playas)) {
|
||||
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_COMPANY_MISMATCH);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// We need a valid name.. make it Player
|
||||
if (*name == '\0') ttd_strlcpy(name, "Player", sizeof(name));
|
||||
if (StrEmpty(name)) ttd_strlcpy(name, "Player", sizeof(name));
|
||||
|
||||
if (!NetworkFindName(name)) { // Change name if duplicate
|
||||
// We could not create a name for this player
|
||||
// We could not create a name for this client
|
||||
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NAME_IN_USE);
|
||||
return;
|
||||
}
|
||||
|
@ -697,7 +695,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN)
|
|||
ci->client_lang = client_lang;
|
||||
|
||||
/* Make sure companies to which people try to join are not autocleaned */
|
||||
if (IsValidPlayerID(playas)) _network_player_info[playas].months_empty = 0;
|
||||
if (IsValidCompanyID(playas)) _network_company_info[playas].months_empty = 0;
|
||||
|
||||
if (_grfconfig == NULL) {
|
||||
RECEIVE_COMMAND(PACKET_CLIENT_NEWGRFS_CHECKED)(cs, NULL);
|
||||
|
@ -725,7 +723,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_PASSWORD)
|
|||
|
||||
ci = DEREF_CLIENT_INFO(cs);
|
||||
|
||||
if (IsValidPlayerID(ci->client_playas) && _network_player_info[ci->client_playas].password[0] != '\0') {
|
||||
if (IsValidCompanyID(ci->client_playas) && _network_company_info[ci->client_playas].password[0] != '\0') {
|
||||
SEND_COMMAND(PACKET_SERVER_NEED_PASSWORD)(cs, NETWORK_COMPANY_PASSWORD);
|
||||
return;
|
||||
}
|
||||
|
@ -736,7 +734,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_PASSWORD)
|
|||
} else if (cs->status == STATUS_AUTHORIZING && type == NETWORK_COMPANY_PASSWORD) {
|
||||
ci = DEREF_CLIENT_INFO(cs);
|
||||
|
||||
if (strcmp(password, _network_player_info[ci->client_playas].password) != 0) {
|
||||
if (strcmp(password, _network_company_info[ci->client_playas].password) != 0) {
|
||||
// Password is invalid
|
||||
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_WRONG_PASSWORD);
|
||||
return;
|
||||
|
@ -828,17 +826,17 @@ static bool CheckCommandFlags(const CommandPacket *cp, const NetworkClientInfo *
|
|||
byte flags = GetCommandFlags(cp->cmd);
|
||||
|
||||
if (flags & CMD_SERVER && ci->client_index != NETWORK_SERVER_INDEX) {
|
||||
IConsolePrintF(CC_ERROR, "WARNING: server only command from client %d (IP: %s), kicking...", ci->client_index, GetPlayerIP(ci));
|
||||
IConsolePrintF(CC_ERROR, "WARNING: server only command from client %d (IP: %s), kicking...", ci->client_index, GetClientIP(ci));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (flags & CMD_OFFLINE) {
|
||||
IConsolePrintF(CC_ERROR, "WARNING: offline only command from client %d (IP: %s), kicking...", ci->client_index, GetPlayerIP(ci));
|
||||
IConsolePrintF(CC_ERROR, "WARNING: offline only command from client %d (IP: %s), kicking...", ci->client_index, GetClientIP(ci));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cp->cmd != CMD_PLAYER_CTRL && !IsValidPlayerID(cp->player) && ci->client_index != NETWORK_SERVER_INDEX) {
|
||||
IConsolePrintF(CC_ERROR, "WARNING: spectator issueing command from client %d (IP: %s), kicking...", ci->client_index, GetPlayerIP(ci));
|
||||
if (cp->cmd != CMD_COMPANY_CTRL && !IsValidCompanyID(cp->company) && ci->client_index != NETWORK_SERVER_INDEX) {
|
||||
IConsolePrintF(CC_ERROR, "WARNING: spectator issueing command from client %d (IP: %s), kicking...", ci->client_index, GetClientIP(ci));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -863,11 +861,11 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
|
|||
}
|
||||
|
||||
CommandPacket *cp = MallocT<CommandPacket>(1);
|
||||
cp->player = (Owner)p->Recv_uint8();
|
||||
cp->cmd = p->Recv_uint32();
|
||||
cp->p1 = p->Recv_uint32();
|
||||
cp->p2 = p->Recv_uint32();
|
||||
cp->tile = p->Recv_uint32();
|
||||
cp->company = (CompanyID)p->Recv_uint8();
|
||||
cp->cmd = p->Recv_uint32();
|
||||
cp->p1 = p->Recv_uint32();
|
||||
cp->p2 = p->Recv_uint32();
|
||||
cp->tile = p->Recv_uint32();
|
||||
p->Recv_string(cp->text, lengthof(cp->text));
|
||||
|
||||
callback = p->Recv_uint8();
|
||||
|
@ -881,7 +879,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
|
|||
|
||||
/* Check if cp->cmd is valid */
|
||||
if (!IsValidCommand(cp->cmd)) {
|
||||
IConsolePrintF(CC_ERROR, "WARNING: invalid command from client %d (IP: %s).", ci->client_index, GetPlayerIP(ci));
|
||||
IConsolePrintF(CC_ERROR, "WARNING: invalid command from client %d (IP: %s).", ci->client_index, GetClientIP(ci));
|
||||
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_EXPECTED);
|
||||
free(cp);
|
||||
return;
|
||||
|
@ -893,35 +891,35 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
|
|||
return;
|
||||
}
|
||||
|
||||
/** Only CMD_PLAYER_CTRL is always allowed, for the rest, playas needs
|
||||
* to match the player in the packet. If it doesn't, the client has done
|
||||
/** Only CMD_COMPANY_CTRL is always allowed, for the rest, playas needs
|
||||
* to match the company in the packet. If it doesn't, the client has done
|
||||
* something pretty naughty (or a bug), and will be kicked
|
||||
*/
|
||||
if (!(cp->cmd == CMD_PLAYER_CTRL && cp->p1 == 0 && ci->client_playas == PLAYER_NEW_COMPANY) && ci->client_playas != cp->player) {
|
||||
IConsolePrintF(CC_ERROR, "WARNING: player %d (IP: %s) tried to execute a command as player %d, kicking...",
|
||||
ci->client_playas + 1, GetPlayerIP(ci), cp->player + 1);
|
||||
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_PLAYER_MISMATCH);
|
||||
if (!(cp->cmd == CMD_COMPANY_CTRL && cp->p1 == 0 && ci->client_playas == COMPANY_NEW_COMPANY) && ci->client_playas != cp->company) {
|
||||
IConsolePrintF(CC_ERROR, "WARNING: client %d (IP: %s) tried to execute a command as company %d, kicking...",
|
||||
ci->client_playas + 1, GetClientIP(ci), cp->company + 1);
|
||||
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_COMPANY_MISMATCH);
|
||||
free(cp);
|
||||
return;
|
||||
}
|
||||
|
||||
/** @todo CMD_PLAYER_CTRL with p1 = 0 announces a new player to the server. To give the
|
||||
* player the correct ID, the server injects p2 and executes the command. Any other p1
|
||||
/** @todo CMD_COMPANY_CTRL with p1 = 0 announces a new company to the server. To give the
|
||||
* company the correct ID, the server injects p2 and executes the command. Any other p1
|
||||
* is prohibited. Pretty ugly and should be redone together with its function.
|
||||
* @see CmdPlayerCtrl() players.c:655
|
||||
* @see CmdCompanyCtrl()
|
||||
*/
|
||||
if (cp->cmd == CMD_PLAYER_CTRL) {
|
||||
if (cp->cmd == CMD_COMPANY_CTRL) {
|
||||
if (cp->p1 != 0) {
|
||||
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_CHEATER);
|
||||
free(cp);
|
||||
return;
|
||||
}
|
||||
|
||||
/* XXX - Execute the command as a valid player. Normally this would be done by a
|
||||
/* XXX - Execute the command as a valid company. Normally this would be done by a
|
||||
* spectator, but that is not allowed any commands. So do an impersonation. The drawback
|
||||
* of this is that the first company's last_built_tile is also updated... */
|
||||
cp->player = OWNER_BEGIN;
|
||||
cp->p2 = cs - _clients; // XXX - UGLY! p2 is mis-used to get the client-id in CmdPlayerCtrl
|
||||
cp->company = OWNER_BEGIN;
|
||||
cp->p2 = cs - _clients; // XXX - UGLY! p2 is mis-used to get the client-id in CmdCompanyCtrl
|
||||
}
|
||||
|
||||
// The frame can be executed in the same frame as the next frame-packet
|
||||
|
@ -1038,7 +1036,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_ACK)
|
|||
NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game unpaused (client connected)", NETWORK_SERVER_INDEX);
|
||||
}
|
||||
|
||||
CheckMinPlayers();
|
||||
CheckMinActiveClients();
|
||||
|
||||
/* Execute script for, e.g. MOTD */
|
||||
IConsoleCmdExec("exec scripts/on_server_connect.scr 0");
|
||||
|
@ -1064,7 +1062,7 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
|
|||
ci = NetworkFindClientInfoFromIndex(from_index);
|
||||
/* Display the text locally, and that is it */
|
||||
if (ci != NULL)
|
||||
NetworkTextMessage(action, (ConsoleColour)GetDrawStringPlayerColor(ci->client_playas), false, ci->client_name, "%s", msg);
|
||||
NetworkTextMessage(action, (ConsoleColour)GetDrawStringCompanyColor(ci->client_playas), false, ci->client_name, "%s", msg);
|
||||
} else {
|
||||
/* Else find the client to send the message to */
|
||||
FOR_ALL_CLIENTS(cs) {
|
||||
|
@ -1081,7 +1079,7 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
|
|||
ci = NetworkFindClientInfoFromIndex(from_index);
|
||||
ci_to = NetworkFindClientInfoFromIndex(dest);
|
||||
if (ci != NULL && ci_to != NULL)
|
||||
NetworkTextMessage(action, (ConsoleColour)GetDrawStringPlayerColor(ci->client_playas), true, ci_to->client_name, "%s", msg);
|
||||
NetworkTextMessage(action, (ConsoleColour)GetDrawStringCompanyColor(ci->client_playas), true, ci_to->client_name, "%s", msg);
|
||||
} else {
|
||||
FOR_ALL_CLIENTS(cs) {
|
||||
if (cs->index == from_index) {
|
||||
|
@ -1095,7 +1093,7 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
|
|||
case DESTTYPE_TEAM: {
|
||||
bool show_local = true; // If this is false, the message is already displayed
|
||||
// on the client who did sent it.
|
||||
/* Find all clients that belong to this player */
|
||||
/* Find all clients that belong to this company */
|
||||
ci_to = NULL;
|
||||
FOR_ALL_CLIENTS(cs) {
|
||||
ci = DEREF_CLIENT_INFO(cs);
|
||||
|
@ -1109,22 +1107,22 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
|
|||
ci = NetworkFindClientInfoFromIndex(from_index);
|
||||
ci_own = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
|
||||
if (ci != NULL && ci_own != NULL && ci_own->client_playas == dest) {
|
||||
NetworkTextMessage(action, (ConsoleColour)GetDrawStringPlayerColor(ci->client_playas), false, ci->client_name, "%s", msg);
|
||||
NetworkTextMessage(action, (ConsoleColour)GetDrawStringCompanyColor(ci->client_playas), false, ci->client_name, "%s", msg);
|
||||
if (from_index == NETWORK_SERVER_INDEX) show_local = false;
|
||||
ci_to = ci_own;
|
||||
}
|
||||
|
||||
/* There is no such player */
|
||||
/* There is no such client */
|
||||
if (ci_to == NULL) break;
|
||||
|
||||
// Display the message locally (so you know you have sent it)
|
||||
if (ci != NULL && show_local) {
|
||||
if (from_index == NETWORK_SERVER_INDEX) {
|
||||
char name[NETWORK_NAME_LENGTH];
|
||||
StringID str = IsValidPlayerID(ci_to->client_playas) ? STR_COMPANY_NAME : STR_NETWORK_SPECTATORS;
|
||||
StringID str = IsValidCompanyID(ci_to->client_playas) ? STR_COMPANY_NAME : STR_NETWORK_SPECTATORS;
|
||||
SetDParam(0, ci_to->client_playas);
|
||||
GetString(name, str, lastof(name));
|
||||
NetworkTextMessage(action, (ConsoleColour)GetDrawStringPlayerColor(ci_own->client_playas), true, name, "%s", msg);
|
||||
NetworkTextMessage(action, (ConsoleColour)GetDrawStringCompanyColor(ci_own->client_playas), true, name, "%s", msg);
|
||||
} else {
|
||||
FOR_ALL_CLIENTS(cs) {
|
||||
if (cs->index == from_index) {
|
||||
|
@ -1144,7 +1142,7 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
|
|||
}
|
||||
ci = NetworkFindClientInfoFromIndex(from_index);
|
||||
if (ci != NULL)
|
||||
NetworkTextMessage(action, (ConsoleColour)GetDrawStringPlayerColor(ci->client_playas), false, ci->client_name, "%s", msg);
|
||||
NetworkTextMessage(action, (ConsoleColour)GetDrawStringCompanyColor(ci->client_playas), false, ci->client_name, "%s", msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1167,7 +1165,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_CHAT)
|
|||
const NetworkClientInfo *ci = DEREF_CLIENT_INFO(cs);
|
||||
switch (action) {
|
||||
case NETWORK_ACTION_GIVE_MONEY:
|
||||
if (!IsValidPlayerID(ci->client_playas)) break;
|
||||
if (!IsValidCompanyID(ci->client_playas)) break;
|
||||
/* Fall-through */
|
||||
case NETWORK_ACTION_CHAT:
|
||||
case NETWORK_ACTION_CHAT_CLIENT:
|
||||
|
@ -1175,7 +1173,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_CHAT)
|
|||
NetworkServerSendChat(action, desttype, dest, msg, cs->index);
|
||||
break;
|
||||
default:
|
||||
IConsolePrintF(CC_ERROR, "WARNING: invalid chat action from client %d (IP: %s).", ci->client_index, GetPlayerIP(ci));
|
||||
IConsolePrintF(CC_ERROR, "WARNING: invalid chat action from client %d (IP: %s).", ci->client_index, GetClientIP(ci));
|
||||
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_EXPECTED);
|
||||
break;
|
||||
}
|
||||
|
@ -1195,8 +1193,8 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_SET_PASSWORD)
|
|||
p->Recv_string(password, sizeof(password));
|
||||
ci = DEREF_CLIENT_INFO(cs);
|
||||
|
||||
if (IsValidPlayerID(ci->client_playas)) {
|
||||
ttd_strlcpy(_network_player_info[ci->client_playas].password, password, sizeof(_network_player_info[0].password));
|
||||
if (IsValidCompanyID(ci->client_playas)) {
|
||||
ttd_strlcpy(_network_company_info[ci->client_playas].password, password, sizeof(_network_company_info[0].password));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1301,7 +1299,7 @@ assert_compile(lengthof(_network_server_packet) == PACKET_END);
|
|||
void NetworkPopulateCompanyInfo()
|
||||
{
|
||||
char password[NETWORK_PASSWORD_LENGTH];
|
||||
const Player *p;
|
||||
const Company *c;
|
||||
const Vehicle *v;
|
||||
const Station *s;
|
||||
NetworkTCPSocketHandler *cs;
|
||||
|
@ -1309,44 +1307,44 @@ void NetworkPopulateCompanyInfo()
|
|||
uint i;
|
||||
uint16 months_empty;
|
||||
|
||||
for (PlayerID pid = PLAYER_FIRST; pid < MAX_PLAYERS; pid++) {
|
||||
if (!IsValidPlayerID(pid)) memset(&_network_player_info[pid], 0, sizeof(NetworkPlayerInfo));
|
||||
for (CompanyID cid = COMPANY_FIRST; cid < MAX_COMPANIES; cid++) {
|
||||
if (!IsValidCompanyID(cid)) memset(&_network_company_info[cid], 0, sizeof(NetworkCompanyInfo));
|
||||
}
|
||||
|
||||
FOR_ALL_PLAYERS(p) {
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
// Clean the info but not the password
|
||||
ttd_strlcpy(password, _network_player_info[p->index].password, sizeof(password));
|
||||
months_empty = _network_player_info[p->index].months_empty;
|
||||
memset(&_network_player_info[p->index], 0, sizeof(NetworkPlayerInfo));
|
||||
_network_player_info[p->index].months_empty = months_empty;
|
||||
ttd_strlcpy(_network_player_info[p->index].password, password, sizeof(_network_player_info[p->index].password));
|
||||
ttd_strlcpy(password, _network_company_info[c->index].password, sizeof(password));
|
||||
months_empty = _network_company_info[c->index].months_empty;
|
||||
memset(&_network_company_info[c->index], 0, sizeof(NetworkCompanyInfo));
|
||||
_network_company_info[c->index].months_empty = months_empty;
|
||||
ttd_strlcpy(_network_company_info[c->index].password, password, sizeof(_network_company_info[c->index].password));
|
||||
|
||||
// Grap the company name
|
||||
SetDParam(0, p->index);
|
||||
GetString(_network_player_info[p->index].company_name, STR_COMPANY_NAME, lastof(_network_player_info[p->index].company_name));
|
||||
SetDParam(0, c->index);
|
||||
GetString(_network_company_info[c->index].company_name, STR_COMPANY_NAME, lastof(_network_company_info[c->index].company_name));
|
||||
|
||||
// Check the income
|
||||
if (_cur_year - 1 == p->inaugurated_year) {
|
||||
// The player is here just 1 year, so display [2], else display[1]
|
||||
for (i = 0; i < lengthof(p->yearly_expenses[2]); i++) {
|
||||
_network_player_info[p->index].income -= p->yearly_expenses[2][i];
|
||||
if (_cur_year - 1 == c->inaugurated_year) {
|
||||
// The company is here just 1 year, so display [2], else display[1]
|
||||
for (i = 0; i < lengthof(c->yearly_expenses[2]); i++) {
|
||||
_network_company_info[c->index].income -= c->yearly_expenses[2][i];
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < lengthof(p->yearly_expenses[1]); i++) {
|
||||
_network_player_info[p->index].income -= p->yearly_expenses[1][i];
|
||||
for (i = 0; i < lengthof(c->yearly_expenses[1]); i++) {
|
||||
_network_company_info[c->index].income -= c->yearly_expenses[1][i];
|
||||
}
|
||||
}
|
||||
|
||||
// Set some general stuff
|
||||
_network_player_info[p->index].inaugurated_year = p->inaugurated_year;
|
||||
_network_player_info[p->index].company_value = p->old_economy[0].company_value;
|
||||
_network_player_info[p->index].money = p->player_money;
|
||||
_network_player_info[p->index].performance = p->old_economy[0].performance_history;
|
||||
_network_company_info[c->index].inaugurated_year = c->inaugurated_year;
|
||||
_network_company_info[c->index].company_value = c->old_economy[0].company_value;
|
||||
_network_company_info[c->index].money = c->money;
|
||||
_network_company_info[c->index].performance = c->old_economy[0].performance_history;
|
||||
}
|
||||
|
||||
// Go through all vehicles and count the type of vehicles
|
||||
FOR_ALL_VEHICLES(v) {
|
||||
if (!IsValidPlayerID(v->owner) || !v->IsPrimaryVehicle()) continue;
|
||||
if (!IsValidCompanyID(v->owner) || !v->IsPrimaryVehicle()) continue;
|
||||
byte type = 0;
|
||||
switch (v->type) {
|
||||
case VEH_TRAIN: type = 0; break;
|
||||
|
@ -1355,13 +1353,13 @@ void NetworkPopulateCompanyInfo()
|
|||
case VEH_SHIP: type = 4; break;
|
||||
default: continue;
|
||||
}
|
||||
_network_player_info[v->owner].num_vehicle[type]++;
|
||||
_network_company_info[v->owner].num_vehicle[type]++;
|
||||
}
|
||||
|
||||
// Go through all stations and count the types of stations
|
||||
FOR_ALL_STATIONS(s) {
|
||||
if (IsValidPlayerID(s->owner)) {
|
||||
NetworkPlayerInfo *npi = &_network_player_info[s->owner];
|
||||
if (IsValidCompanyID(s->owner)) {
|
||||
NetworkCompanyInfo *npi = &_network_company_info[s->owner];
|
||||
|
||||
if (s->facilities & FACIL_TRAIN) npi->num_station[0]++;
|
||||
if (s->facilities & FACIL_TRUCK_STOP) npi->num_station[1]++;
|
||||
|
@ -1372,9 +1370,9 @@ void NetworkPopulateCompanyInfo()
|
|||
}
|
||||
|
||||
ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
|
||||
// Register local player (if not dedicated)
|
||||
if (ci != NULL && IsValidPlayerID(ci->client_playas))
|
||||
ttd_strlcpy(_network_player_info[ci->client_playas].players, ci->client_name, sizeof(_network_player_info[0].players));
|
||||
// Register local company (if not dedicated)
|
||||
if (ci != NULL && IsValidCompanyID(ci->client_playas))
|
||||
ttd_strlcpy(_network_company_info[ci->client_playas].clients, ci->client_name, sizeof(_network_company_info[0].clients));
|
||||
|
||||
FOR_ALL_CLIENTS(cs) {
|
||||
char client_name[NETWORK_CLIENT_NAME_LENGTH];
|
||||
|
@ -1382,12 +1380,12 @@ void NetworkPopulateCompanyInfo()
|
|||
NetworkGetClientName(client_name, sizeof(client_name), cs);
|
||||
|
||||
ci = DEREF_CLIENT_INFO(cs);
|
||||
if (ci != NULL && IsValidPlayerID(ci->client_playas)) {
|
||||
if (!StrEmpty(_network_player_info[ci->client_playas].players)) {
|
||||
ttd_strlcat(_network_player_info[ci->client_playas].players, ", ", lengthof(_network_player_info[0].players));
|
||||
if (ci != NULL && IsValidCompanyID(ci->client_playas)) {
|
||||
if (!StrEmpty(_network_company_info[ci->client_playas].clients)) {
|
||||
ttd_strlcat(_network_company_info[ci->client_playas].clients, ", ", lengthof(_network_company_info[0].clients));
|
||||
}
|
||||
|
||||
ttd_strlcat(_network_player_info[ci->client_playas].players, client_name, lengthof(_network_player_info[0].players));
|
||||
ttd_strlcat(_network_company_info[ci->client_playas].clients, client_name, lengthof(_network_company_info[0].clients));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1424,8 +1422,8 @@ static void NetworkAutoCleanCompanies()
|
|||
{
|
||||
NetworkTCPSocketHandler *cs;
|
||||
const NetworkClientInfo *ci;
|
||||
const Player *p;
|
||||
bool clients_in_company[MAX_PLAYERS];
|
||||
const Company *c;
|
||||
bool clients_in_company[MAX_COMPANIES];
|
||||
|
||||
if (!_settings_client.network.autoclean_companies) return;
|
||||
|
||||
|
@ -1434,39 +1432,39 @@ static void NetworkAutoCleanCompanies()
|
|||
/* Detect the active companies */
|
||||
FOR_ALL_CLIENTS(cs) {
|
||||
ci = DEREF_CLIENT_INFO(cs);
|
||||
if (IsValidPlayerID(ci->client_playas)) clients_in_company[ci->client_playas] = true;
|
||||
if (IsValidCompanyID(ci->client_playas)) clients_in_company[ci->client_playas] = true;
|
||||
}
|
||||
|
||||
if (!_network_dedicated) {
|
||||
ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
|
||||
if (IsValidPlayerID(ci->client_playas)) clients_in_company[ci->client_playas] = true;
|
||||
if (IsValidCompanyID(ci->client_playas)) clients_in_company[ci->client_playas] = true;
|
||||
}
|
||||
|
||||
/* Go through all the comapnies */
|
||||
FOR_ALL_PLAYERS(p) {
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
/* Skip the non-active once */
|
||||
if (p->is_ai) continue;
|
||||
if (c->is_ai) continue;
|
||||
|
||||
if (!clients_in_company[p->index]) {
|
||||
if (!clients_in_company[c->index]) {
|
||||
/* The company is empty for one month more */
|
||||
_network_player_info[p->index].months_empty++;
|
||||
_network_company_info[c->index].months_empty++;
|
||||
|
||||
/* Is the company empty for autoclean_unprotected-months, and is there no protection? */
|
||||
if (_settings_client.network.autoclean_unprotected != 0 && _network_player_info[p->index].months_empty > _settings_client.network.autoclean_unprotected && _network_player_info[p->index].password[0] == '\0') {
|
||||
if (_settings_client.network.autoclean_unprotected != 0 && _network_company_info[c->index].months_empty > _settings_client.network.autoclean_unprotected && StrEmpty(_network_company_info[c->index].password)) {
|
||||
/* Shut the company down */
|
||||
DoCommandP(0, 2, p->index, NULL, CMD_PLAYER_CTRL);
|
||||
IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d", p->index + 1);
|
||||
DoCommandP(0, 2, c->index, NULL, CMD_COMPANY_CTRL);
|
||||
IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d", c->index + 1);
|
||||
}
|
||||
/* Is the compnay empty for autoclean_protected-months, and there is a protection? */
|
||||
if (_settings_client.network.autoclean_protected != 0 && _network_player_info[p->index].months_empty > _settings_client.network.autoclean_protected && _network_player_info[p->index].password[0] != '\0') {
|
||||
/* Is the company empty for autoclean_protected-months, and there is a protection? */
|
||||
if (_settings_client.network.autoclean_protected != 0 && _network_company_info[c->index].months_empty > _settings_client.network.autoclean_protected && !StrEmpty(_network_company_info[c->index].password)) {
|
||||
/* Unprotect the company */
|
||||
_network_player_info[p->index].password[0] = '\0';
|
||||
IConsolePrintF(CC_DEFAULT, "Auto-removed protection from company #%d", p->index+1);
|
||||
_network_player_info[p->index].months_empty = 0;
|
||||
_network_company_info[c->index].password[0] = '\0';
|
||||
IConsolePrintF(CC_DEFAULT, "Auto-removed protection from company #%d", c->index + 1);
|
||||
_network_company_info[c->index].months_empty = 0;
|
||||
}
|
||||
} else {
|
||||
/* It is not empty, reset the date */
|
||||
_network_player_info[p->index].months_empty = 0;
|
||||
_network_company_info[c->index].months_empty = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1625,30 +1623,30 @@ void NetworkServerMonthlyLoop()
|
|||
NetworkAutoCleanCompanies();
|
||||
}
|
||||
|
||||
void NetworkServerChangeOwner(PlayerID current_player, PlayerID new_player)
|
||||
void NetworkServerChangeOwner(Owner current_owner, Owner new_owner)
|
||||
{
|
||||
/* The server has to handle all administrative issues, for example
|
||||
* updating and notifying all clients of what has happened */
|
||||
NetworkTCPSocketHandler *cs;
|
||||
NetworkClientInfo *ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
|
||||
|
||||
/* The server has just changed from player */
|
||||
if (current_player == ci->client_playas) {
|
||||
ci->client_playas = new_player;
|
||||
/* The server has just changed from owner */
|
||||
if (current_owner == ci->client_playas) {
|
||||
ci->client_playas = new_owner;
|
||||
NetworkUpdateClientInfo(NETWORK_SERVER_INDEX);
|
||||
}
|
||||
|
||||
/* Find all clients that were in control of this company, and mark them as new_player */
|
||||
/* Find all clients that were in control of this company, and mark them as new_owner */
|
||||
FOR_ALL_CLIENTS(cs) {
|
||||
ci = DEREF_CLIENT_INFO(cs);
|
||||
if (current_player == ci->client_playas) {
|
||||
ci->client_playas = new_player;
|
||||
if (current_owner == ci->client_playas) {
|
||||
ci->client_playas = new_owner;
|
||||
NetworkUpdateClientInfo(ci->client_index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const char* GetPlayerIP(const NetworkClientInfo* ci)
|
||||
const char* GetClientIP(const NetworkClientInfo* ci)
|
||||
{
|
||||
struct in_addr addr;
|
||||
|
||||
|
@ -1678,8 +1676,8 @@ void NetworkServerShowStatusToConsole()
|
|||
status = (cs->status < (ptrdiff_t)lengthof(stat_str) ? stat_str[cs->status] : "unknown");
|
||||
IConsolePrintF(CC_INFO, "Client #%1d name: '%s' status: '%s' frame-lag: %3d company: %1d IP: %s unique-id: '%s'",
|
||||
cs->index, ci->client_name, status, lag,
|
||||
ci->client_playas + (IsValidPlayerID(ci->client_playas) ? 1 : 0),
|
||||
GetPlayerIP(ci), ci->unique_id);
|
||||
ci->client_playas + (IsValidCompanyID(ci->client_playas) ? 1 : 0),
|
||||
GetClientIP(ci), ci->unique_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1693,7 +1691,7 @@ void NetworkServerSendError(uint16 client_index, NetworkErrorCode error)
|
|||
SEND_COMMAND(PACKET_SERVER_ERROR)(NetworkFindClientStateFromIndex(client_index), error);
|
||||
}
|
||||
|
||||
bool NetworkCompanyHasPlayers(PlayerID company)
|
||||
bool NetworkCompanyHasClients(CompanyID company)
|
||||
{
|
||||
const NetworkTCPSocketHandler *cs;
|
||||
const NetworkClientInfo *ci;
|
||||
|
|
|
@ -14,11 +14,11 @@
|
|||
|
||||
enum {
|
||||
/**
|
||||
* How many clients can we have? Like.. MAX_PLAYERS - 1 is the amount of
|
||||
* players that can really play.. so.. a max of 4 spectators.. gives us..
|
||||
* MAX_PLAYERS + 3
|
||||
* How many clients can we have? Like.. MAX_COMPANIES is the amount of
|
||||
* companies that can really play.. so.. a max of 3 spectators.. gives us..
|
||||
* MAX_COMPANIES + 3
|
||||
*/
|
||||
MAX_CLIENTS = MAX_PLAYERS + 3,
|
||||
MAX_CLIENTS = MAX_COMPANIES + 3,
|
||||
|
||||
/** Do not change this next line. It should _ALWAYS_ be MAX_CLIENTS + 1 */
|
||||
MAX_CLIENT_INFO = MAX_CLIENTS + 1,
|
||||
|
@ -34,9 +34,9 @@ enum {
|
|||
NETWORK_EMPTY_INDEX = 0,
|
||||
};
|
||||
|
||||
struct NetworkPlayerInfo {
|
||||
struct NetworkCompanyInfo {
|
||||
char company_name[NETWORK_COMPANY_NAME_LENGTH]; ///< Company name
|
||||
char password[NETWORK_PASSWORD_LENGTH]; ///< The password for the player
|
||||
char password[NETWORK_PASSWORD_LENGTH]; ///< The password for the company
|
||||
Year inaugurated_year; ///< What year the company started in
|
||||
Money company_value; ///< The company value
|
||||
Money money; ///< The amount of money the company has
|
||||
|
@ -45,7 +45,7 @@ struct NetworkPlayerInfo {
|
|||
bool use_password; ///< Is there a password
|
||||
uint16 num_vehicle[NETWORK_VEHICLE_TYPES]; ///< How many vehicles are there of this type?
|
||||
uint16 num_station[NETWORK_STATION_TYPES]; ///< How many stations are there of this type?
|
||||
char players[NETWORK_PLAYERS_LENGTH]; ///< The players that control this company (Name1, name2, ..)
|
||||
char clients[NETWORK_CLIENTS_LENGTH]; ///< The clients that control this company (Name1, name2, ..)
|
||||
uint16 months_empty; ///< How many months the company is empty
|
||||
};
|
||||
|
||||
|
@ -53,9 +53,9 @@ struct NetworkClientInfo {
|
|||
uint16 client_index; ///< Index of the client (same as ClientState->index)
|
||||
char client_name[NETWORK_CLIENT_NAME_LENGTH]; ///< Name of the client
|
||||
byte client_lang; ///< The language of the client
|
||||
PlayerID client_playas; ///< As which player is this client playing (PlayerID)
|
||||
CompanyID client_playas; ///< As which company is this client playing (CompanyID)
|
||||
uint32 client_ip; ///< IP-address of the client (so he can be banned)
|
||||
Date join_date; ///< Gamedate the player has joined
|
||||
Date join_date; ///< Gamedate the client has joined
|
||||
char unique_id[NETWORK_UNIQUE_ID_LENGTH]; ///< Every play sends an unique id so we can indentify him
|
||||
};
|
||||
|
||||
|
@ -65,9 +65,9 @@ enum NetworkPasswordType {
|
|||
};
|
||||
|
||||
enum DestType {
|
||||
DESTTYPE_BROADCAST, ///< Send message/notice to all players (All)
|
||||
DESTTYPE_BROADCAST, ///< Send message/notice to all clients (All)
|
||||
DESTTYPE_TEAM, ///< Send message/notice to everyone playing the same company (Team)
|
||||
DESTTYPE_CLIENT, ///< Send message/notice to only a certain player (Private)
|
||||
DESTTYPE_CLIENT, ///< Send message/notice to only a certain client (Private)
|
||||
};
|
||||
|
||||
/** Actions that can be used for NetworkTextMessage */
|
||||
|
@ -98,7 +98,7 @@ enum NetworkErrorCode {
|
|||
NETWORK_ERROR_WRONG_REVISION,
|
||||
NETWORK_ERROR_NAME_IN_USE,
|
||||
NETWORK_ERROR_WRONG_PASSWORD,
|
||||
NETWORK_ERROR_PLAYER_MISMATCH, // Happens in CLIENT_COMMAND
|
||||
NETWORK_ERROR_COMPANY_MISMATCH, // Happens in CLIENT_COMMAND
|
||||
NETWORK_ERROR_KICKED,
|
||||
NETWORK_ERROR_CHEATER,
|
||||
NETWORK_ERROR_FULL,
|
||||
|
|
|
@ -83,7 +83,7 @@ DEF_UDP_RECEIVE_COMMAND(Server, PACKET_UDP_CLIENT_FIND_SERVER)
|
|||
ngi.server_lang = _settings_client.network.server_lang;
|
||||
ngi.use_password = !StrEmpty(_settings_client.network.server_password);
|
||||
ngi.clients_max = _settings_client.network.max_clients;
|
||||
ngi.companies_on = ActivePlayerCount();
|
||||
ngi.companies_on = ActiveCompanyCount();
|
||||
ngi.companies_max = _settings_client.network.max_companies;
|
||||
ngi.spectators_on = NetworkSpectatorCount();
|
||||
ngi.spectators_max = _settings_client.network.max_spectators;
|
||||
|
@ -116,36 +116,36 @@ DEF_UDP_RECEIVE_COMMAND(Server, PACKET_UDP_CLIENT_DETAIL_INFO)
|
|||
|
||||
/* Send the amount of active companies */
|
||||
packet.Send_uint8 (NETWORK_COMPANY_INFO_VERSION);
|
||||
packet.Send_uint8 (ActivePlayerCount());
|
||||
packet.Send_uint8 (ActiveCompanyCount());
|
||||
|
||||
/* Fetch the latest version of everything */
|
||||
NetworkPopulateCompanyInfo();
|
||||
|
||||
Player *player;
|
||||
Company *company;
|
||||
byte current = 0;
|
||||
/* Go through all the players */
|
||||
FOR_ALL_PLAYERS(player) {
|
||||
/* Go through all the companies */
|
||||
FOR_ALL_COMPANIES(company) {
|
||||
current++;
|
||||
|
||||
/* Send the information */
|
||||
packet.Send_uint8 (current);
|
||||
|
||||
packet.Send_string(_network_player_info[player->index].company_name);
|
||||
packet.Send_uint32(_network_player_info[player->index].inaugurated_year);
|
||||
packet.Send_uint64(_network_player_info[player->index].company_value);
|
||||
packet.Send_uint64(_network_player_info[player->index].money);
|
||||
packet.Send_uint64(_network_player_info[player->index].income);
|
||||
packet.Send_uint16(_network_player_info[player->index].performance);
|
||||
packet.Send_string(_network_company_info[company->index].company_name);
|
||||
packet.Send_uint32(_network_company_info[company->index].inaugurated_year);
|
||||
packet.Send_uint64(_network_company_info[company->index].company_value);
|
||||
packet.Send_uint64(_network_company_info[company->index].money);
|
||||
packet.Send_uint64(_network_company_info[company->index].income);
|
||||
packet.Send_uint16(_network_company_info[company->index].performance);
|
||||
|
||||
/* Send 1 if there is a passord for the company else send 0 */
|
||||
packet.Send_bool (!StrEmpty(_network_player_info[player->index].password));
|
||||
packet.Send_bool (!StrEmpty(_network_company_info[company->index].password));
|
||||
|
||||
for (int i = 0; i < NETWORK_VEHICLE_TYPES; i++) {
|
||||
packet.Send_uint16(_network_player_info[player->index].num_vehicle[i]);
|
||||
packet.Send_uint16(_network_company_info[company->index].num_vehicle[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < NETWORK_STATION_TYPES; i++) {
|
||||
packet.Send_uint16(_network_player_info[player->index].num_station[i]);
|
||||
packet.Send_uint16(_network_company_info[company->index].num_station[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ enum CallbackID {
|
|||
/** Called to determine the type (if any) of foundation to draw for industry tile. */
|
||||
CBID_INDUSTRY_DRAW_FOUNDATIONS = 0x30, // 15 bit callback
|
||||
|
||||
/** Called when the player (or AI) tries to start or stop a vehicle. Mainly
|
||||
/** Called when the company (or AI) tries to start or stop a vehicle. Mainly
|
||||
* used for preventing a vehicle from leaving the depot. */
|
||||
CBID_VEHICLE_START_STOP_CHECK = 0x31, // 15 bit callback, but 0xFF test is done with 8 bit
|
||||
|
||||
|
|
|
@ -445,8 +445,8 @@ static uint8 LiveryHelper(EngineID engine, const Vehicle *v)
|
|||
const Livery *l;
|
||||
|
||||
if (v == NULL) {
|
||||
if (!IsValidPlayerID(_current_player)) return 0;
|
||||
l = GetEngineLivery(engine, _current_player, INVALID_ENGINE, NULL);
|
||||
if (!IsValidCompanyID(_current_company)) return 0;
|
||||
l = GetEngineLivery(engine, _current_company, INVALID_ENGINE, NULL);
|
||||
} else if (v->type == VEH_TRAIN) {
|
||||
l = GetEngineLivery((v->u.rail.first_engine != INVALID_ENGINE && (IsArticulatedPart(v) || UsesWagonOverride(v))) ? v->u.rail.first_engine : v->engine_type, v->owner, v->u.rail.first_engine, v);
|
||||
} else {
|
||||
|
@ -464,7 +464,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
|
|||
if (v == NULL) {
|
||||
/* Vehicle does not exist, so we're in a purchase list */
|
||||
switch (variable) {
|
||||
case 0x43: return _current_player | (LiveryHelper(object->u.vehicle.self_type, NULL) << 24); // Owner information
|
||||
case 0x43: return _current_company | (LiveryHelper(object->u.vehicle.self_type, NULL) << 24); // Owner information
|
||||
case 0x46: return 0; // Motion counter
|
||||
case 0x48: return GetEngine(object->u.vehicle.self_type)->flags; // Vehicle Type Info
|
||||
case 0x49: return _cur_year; // 'Long' format build year
|
||||
|
@ -542,8 +542,8 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
|
|||
return cargo_classes | (common_cargo_type << 8) | (common_subtype << 16) | (user_def_data << 24);
|
||||
}
|
||||
|
||||
case 0x43: // Player information
|
||||
return v->owner | (GetPlayer(v->owner)->is_ai ? 0x10000 : 0) | (LiveryHelper(v->engine_type, v) << 24);
|
||||
case 0x43: // Company information
|
||||
return v->owner | (GetCompany(v->owner)->is_ai ? 0x10000 : 0) | (LiveryHelper(v->engine_type, v) << 24);
|
||||
|
||||
case 0x44: // Aircraft information
|
||||
if (v->type != VEH_AIRCRAFT) return UINT_MAX;
|
||||
|
|
|
@ -579,10 +579,10 @@ bool CanDeleteHouse(TileIndex tile)
|
|||
{
|
||||
const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile));
|
||||
|
||||
/* Human players are always allowed to remove buildings, as is water and
|
||||
/* Humans are always allowed to remove buildings, as is water and
|
||||
* anyone using the scenario editor. */
|
||||
if ((IsValidPlayerID(_current_player) && IsHumanPlayer(_current_player))
|
||||
|| _current_player == OWNER_WATER || _current_player == OWNER_NONE) return true;
|
||||
if ((IsValidCompanyID(_current_company) && IsHumanCompany(_current_company))
|
||||
|| _current_company == OWNER_WATER || _current_company == OWNER_NONE) return true;
|
||||
|
||||
if (HasBit(hs->callback_mask, CBM_HOUSE_DENY_DESTRUCTION)) {
|
||||
uint16 callback_res = GetHouseCallback(CBID_HOUSE_DENY_DESTRUCTION, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile);
|
||||
|
|
|
@ -267,16 +267,16 @@ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte par
|
|||
/* Layout number */
|
||||
case 0x44: return industry->selected_layout;
|
||||
|
||||
/* player info */
|
||||
/* Company info */
|
||||
case 0x45: {
|
||||
byte colours;
|
||||
bool is_ai = false;
|
||||
|
||||
if (IsValidPlayerID(industry->founder)) {
|
||||
const Player *p = GetPlayer(industry->founder);
|
||||
const Livery *l = &p->livery[LS_DEFAULT];
|
||||
if (IsValidCompanyID(industry->founder)) {
|
||||
const Company *c = GetCompany(industry->founder);
|
||||
const Livery *l = &c->livery[LS_DEFAULT];
|
||||
|
||||
is_ai = p->is_ai;
|
||||
is_ai = c->is_ai;
|
||||
colours = l->colour1 + l->colour2 * 16;
|
||||
} else {
|
||||
colours = GB(Random(), 0, 8);
|
||||
|
|
|
@ -382,10 +382,10 @@ static uint32 StationGetVariable(const ResolverObject *object, byte variable, by
|
|||
case 0x41:
|
||||
case 0x46:
|
||||
case 0x47:
|
||||
case 0x49: return 0x2110000; // Platforms, tracks & position
|
||||
case 0x42: return 0; // Rail type (XXX Get current type from GUI?)
|
||||
case 0x43: return _current_player; // Station owner
|
||||
case 0x44: return 2; // PBS status
|
||||
case 0x49: return 0x2110000; // Platforms, tracks & position
|
||||
case 0x42: return 0; // Rail type (XXX Get current type from GUI?)
|
||||
case 0x43: return _current_company; // Station owner
|
||||
case 0x44: return 2; // PBS status
|
||||
case 0xFA: return Clamp(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Build date, clamped to a 16 bit value
|
||||
}
|
||||
|
||||
|
@ -782,7 +782,7 @@ bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID
|
|||
const RailtypeInfo *rti = GetRailTypeInfo(railtype);
|
||||
SpriteID relocation;
|
||||
SpriteID image;
|
||||
SpriteID palette = PLAYER_SPRITE_COLOR(_local_player);
|
||||
SpriteID palette = COMPANY_SPRITE_COLOR(_local_company);
|
||||
uint tile = 2;
|
||||
|
||||
statspec = GetCustomStationSpec(sclass, station);
|
||||
|
|
|
@ -51,7 +51,7 @@ static void DrawNewsBankrupcy(Window *w, const NewsItem *ni)
|
|||
{
|
||||
const CompanyNewsInformation *cni = (const CompanyNewsInformation*)ni->free_data;
|
||||
|
||||
DrawPlayerFace(cni->face, cni->colour, 2, 23);
|
||||
DrawCompanyManagerFace(cni->face, cni->colour, 2, 23);
|
||||
GfxFillRect(3, 23, 3 + 91, 23 + 118, PALETTE_TO_STRUCT_GREY, FILLRECT_RECOLOR);
|
||||
|
||||
SetDParamStr(0, cni->president_name);
|
||||
|
@ -123,26 +123,26 @@ struct NewsSubtypeData {
|
|||
* Data common to all news items of a given subtype (actual data)
|
||||
*/
|
||||
static const struct NewsSubtypeData _news_subtype_data[NS_END] = {
|
||||
/* type, display_mode, flags, callback */
|
||||
{ NT_ARRIVAL_PLAYER, NM_THIN, NF_VIEWPORT|NF_VEHICLE, NULL }, ///< NS_ARRIVAL_PLAYER
|
||||
{ NT_ARRIVAL_OTHER, NM_THIN, NF_VIEWPORT|NF_VEHICLE, NULL }, ///< NS_ARRIVAL_OTHER
|
||||
{ NT_ACCIDENT, NM_THIN, NF_VIEWPORT|NF_TILE, NULL }, ///< NS_ACCIDENT_TILE
|
||||
{ NT_ACCIDENT, NM_THIN, NF_VIEWPORT|NF_VEHICLE, NULL }, ///< NS_ACCIDENT_VEHICLE
|
||||
{ NT_COMPANY_INFO, NM_NORMAL, NF_NONE, DrawNewsBankrupcy }, ///< NS_COMPANY_TROUBLE
|
||||
{ NT_COMPANY_INFO, NM_NORMAL, NF_NONE, DrawNewsBankrupcy }, ///< NS_COMPANY_MERGER
|
||||
{ NT_COMPANY_INFO, NM_NORMAL, NF_NONE, DrawNewsBankrupcy }, ///< NS_COMPANY_BANKRUPT
|
||||
{ NT_COMPANY_INFO, NM_NORMAL, NF_TILE, DrawNewsBankrupcy }, ///< NS_COMPANY_NEW
|
||||
{ NT_INDUSTRY_OPEN, NM_THIN, NF_VIEWPORT|NF_TILE, NULL }, ///< NS_INDUSTRY_OPEN
|
||||
{ NT_INDUSTRY_CLOSE, NM_THIN, NF_VIEWPORT|NF_TILE, NULL }, ///< NS_INDUSTRY_CLOSE
|
||||
{ NT_ECONOMY, NM_NORMAL, NF_NONE, NULL }, ///< NS_ECONOMY
|
||||
{ NT_INDUSTRY_PLAYER, NM_THIN, NF_VIEWPORT|NF_TILE, NULL }, ///< NS_INDUSTRY_PLAYER
|
||||
{ NT_INDUSTRY_OTHER, NM_THIN, NF_VIEWPORT|NF_TILE, NULL }, ///< NS_INDUSTRY_OTHER
|
||||
{ NT_INDUSTRY_NOBODY, NM_THIN, NF_VIEWPORT|NF_TILE, NULL }, ///< NS_INDUSTRY_NOBODY
|
||||
{ NT_ADVICE, NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NULL }, ///< NS_ADVICE
|
||||
{ NT_NEW_VEHICLES, NM_NORMAL, NF_NONE, DrawNewsNewVehicleAvail }, ///< NS_NEW_VEHICLES
|
||||
{ NT_ACCEPTANCE, NM_SMALL, NF_VIEWPORT|NF_TILE, NULL }, ///< NS_ACCEPTANCE
|
||||
{ NT_SUBSIDIES, NM_NORMAL, NF_TILE|NF_TILE2, NULL }, ///< NS_SUBSIDIES
|
||||
{ NT_GENERAL, NM_NORMAL, NF_TILE, NULL }, ///< NS_GENERAL
|
||||
/* type, display_mode, flags, callback */
|
||||
{ NT_ARRIVAL_COMPANY, NM_THIN, NF_VIEWPORT|NF_VEHICLE, NULL }, ///< NS_ARRIVAL_COMPANY
|
||||
{ NT_ARRIVAL_OTHER, NM_THIN, NF_VIEWPORT|NF_VEHICLE, NULL }, ///< NS_ARRIVAL_OTHER
|
||||
{ NT_ACCIDENT, NM_THIN, NF_VIEWPORT|NF_TILE, NULL }, ///< NS_ACCIDENT_TILE
|
||||
{ NT_ACCIDENT, NM_THIN, NF_VIEWPORT|NF_VEHICLE, NULL }, ///< NS_ACCIDENT_VEHICLE
|
||||
{ NT_COMPANY_INFO, NM_NORMAL, NF_NONE, DrawNewsBankrupcy }, ///< NS_COMPANY_TROUBLE
|
||||
{ NT_COMPANY_INFO, NM_NORMAL, NF_NONE, DrawNewsBankrupcy }, ///< NS_COMPANY_MERGER
|
||||
{ NT_COMPANY_INFO, NM_NORMAL, NF_NONE, DrawNewsBankrupcy }, ///< NS_COMPANY_BANKRUPT
|
||||
{ NT_COMPANY_INFO, NM_NORMAL, NF_TILE, DrawNewsBankrupcy }, ///< NS_COMPANY_NEW
|
||||
{ NT_INDUSTRY_OPEN, NM_THIN, NF_VIEWPORT|NF_TILE, NULL }, ///< NS_INDUSTRY_OPEN
|
||||
{ NT_INDUSTRY_CLOSE, NM_THIN, NF_VIEWPORT|NF_TILE, NULL }, ///< NS_INDUSTRY_CLOSE
|
||||
{ NT_ECONOMY, NM_NORMAL, NF_NONE, NULL }, ///< NS_ECONOMY
|
||||
{ NT_INDUSTRY_COMPANY, NM_THIN, NF_VIEWPORT|NF_TILE, NULL }, ///< NS_INDUSTRY_COMPANY
|
||||
{ NT_INDUSTRY_OTHER, NM_THIN, NF_VIEWPORT|NF_TILE, NULL }, ///< NS_INDUSTRY_OTHER
|
||||
{ NT_INDUSTRY_NOBODY, NM_THIN, NF_VIEWPORT|NF_TILE, NULL }, ///< NS_INDUSTRY_NOBODY
|
||||
{ NT_ADVICE, NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NULL }, ///< NS_ADVICE
|
||||
{ NT_NEW_VEHICLES, NM_NORMAL, NF_NONE, DrawNewsNewVehicleAvail }, ///< NS_NEW_VEHICLES
|
||||
{ NT_ACCEPTANCE, NM_SMALL, NF_VIEWPORT|NF_TILE, NULL }, ///< NS_ACCEPTANCE
|
||||
{ NT_SUBSIDIES, NM_NORMAL, NF_TILE|NF_TILE2, NULL }, ///< NS_SUBSIDIES
|
||||
{ NT_GENERAL, NM_NORMAL, NF_TILE, NULL }, ///< NS_GENERAL
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -150,14 +150,14 @@ static const struct NewsSubtypeData _news_subtype_data[NS_END] = {
|
|||
*/
|
||||
NewsTypeData _news_type_data[NT_END] = {
|
||||
/* name, age, sound, display */
|
||||
{ "arrival_player", 60, SND_1D_APPLAUSE, ND_FULL }, ///< NT_ARRIVAL_PLAYER
|
||||
{ "arrival_player", 60, SND_1D_APPLAUSE, ND_FULL }, ///< NT_ARRIVAL_COMPANY
|
||||
{ "arrival_other", 60, SND_1D_APPLAUSE, ND_FULL }, ///< NT_ARRIVAL_OTHER
|
||||
{ "accident", 90, SND_BEGIN, ND_FULL }, ///< NT_ACCIDENT
|
||||
{ "company_info", 60, SND_BEGIN, ND_FULL }, ///< NT_COMPANY_INFO
|
||||
{ "open", 90, SND_BEGIN, ND_FULL }, ///< NT_INDUSTRY_OPEN
|
||||
{ "close", 90, SND_BEGIN, ND_FULL }, ///< NT_INDUSTRY_CLOSE
|
||||
{ "economy", 30, SND_BEGIN, ND_FULL }, ///< NT_ECONOMY
|
||||
{ "production_player", 30, SND_BEGIN, ND_FULL }, ///< NT_INDUSTRY_PLAYER
|
||||
{ "production_player", 30, SND_BEGIN, ND_FULL }, ///< NT_INDUSTRY_COMPANY
|
||||
{ "production_other", 30, SND_BEGIN, ND_FULL }, ///< NT_INDUSTRY_OTHER
|
||||
{ "production_nobody", 30, SND_BEGIN, ND_FULL }, ///< NT_INDUSTRY_NOBODY
|
||||
{ "advice", 150, SND_BEGIN, ND_FULL }, ///< NT_ADVICE
|
||||
|
@ -590,7 +590,7 @@ void DeleteStationNews(StationID sid)
|
|||
while (ni != NULL) {
|
||||
NewsItem *next = ni->next;
|
||||
switch (ni->subtype) {
|
||||
case NS_ARRIVAL_PLAYER:
|
||||
case NS_ARRIVAL_COMPANY:
|
||||
case NS_ARRIVAL_OTHER:
|
||||
case NS_ACCEPTANCE:
|
||||
if (ni->data_b == sid) DeleteNewsItem(ni);
|
||||
|
@ -968,21 +968,21 @@ static const Widget _message_options_widgets[] = {
|
|||
/* List of news-setting lines (4 widgets for each line).
|
||||
* First widget must be number WIDGET_NEWSOPT_START_OPTION
|
||||
*/
|
||||
NEWS_SETTINGS_LINE(26, NT_ARRIVAL_PLAYER, STR_0206_ARRIVAL_OF_FIRST_VEHICLE),
|
||||
NEWS_SETTINGS_LINE(26, NT_ARRIVAL_OTHER, STR_0207_ARRIVAL_OF_FIRST_VEHICLE),
|
||||
NEWS_SETTINGS_LINE(26, NT_ACCIDENT, STR_0208_ACCIDENTS_DISASTERS),
|
||||
NEWS_SETTINGS_LINE(26, NT_COMPANY_INFO, STR_0209_COMPANY_INFORMATION),
|
||||
NEWS_SETTINGS_LINE(26, NT_INDUSTRY_OPEN, STR_NEWS_INDUSTRY_OPEN),
|
||||
NEWS_SETTINGS_LINE(26, NT_INDUSTRY_CLOSE, STR_NEWS_INDUSTRY_CLOSE),
|
||||
NEWS_SETTINGS_LINE(26, NT_ECONOMY, STR_020A_ECONOMY_CHANGES),
|
||||
NEWS_SETTINGS_LINE(26, NT_INDUSTRY_PLAYER, STR_INDUSTRY_CHANGES_SERVED_BY_PLAYER),
|
||||
NEWS_SETTINGS_LINE(26, NT_INDUSTRY_OTHER, STR_INDUSTRY_CHANGES_SERVED_BY_OTHER),
|
||||
NEWS_SETTINGS_LINE(26, NT_INDUSTRY_NOBODY, STR_OTHER_INDUSTRY_PRODUCTION_CHANGES),
|
||||
NEWS_SETTINGS_LINE(26, NT_ADVICE, STR_020B_ADVICE_INFORMATION_ON_PLAYER),
|
||||
NEWS_SETTINGS_LINE(26, NT_NEW_VEHICLES, STR_020C_NEW_VEHICLES),
|
||||
NEWS_SETTINGS_LINE(26, NT_ACCEPTANCE, STR_020D_CHANGES_OF_CARGO_ACCEPTANCE),
|
||||
NEWS_SETTINGS_LINE(26, NT_SUBSIDIES, STR_020E_SUBSIDIES),
|
||||
NEWS_SETTINGS_LINE(26, NT_GENERAL, STR_020F_GENERAL_INFORMATION),
|
||||
NEWS_SETTINGS_LINE(26, NT_ARRIVAL_COMPANY, STR_0206_ARRIVAL_OF_FIRST_VEHICLE),
|
||||
NEWS_SETTINGS_LINE(26, NT_ARRIVAL_OTHER, STR_0207_ARRIVAL_OF_FIRST_VEHICLE),
|
||||
NEWS_SETTINGS_LINE(26, NT_ACCIDENT, STR_0208_ACCIDENTS_DISASTERS),
|
||||
NEWS_SETTINGS_LINE(26, NT_COMPANY_INFO, STR_0209_COMPANY_INFORMATION),
|
||||
NEWS_SETTINGS_LINE(26, NT_INDUSTRY_OPEN, STR_NEWS_INDUSTRY_OPEN),
|
||||
NEWS_SETTINGS_LINE(26, NT_INDUSTRY_CLOSE, STR_NEWS_INDUSTRY_CLOSE),
|
||||
NEWS_SETTINGS_LINE(26, NT_ECONOMY, STR_020A_ECONOMY_CHANGES),
|
||||
NEWS_SETTINGS_LINE(26, NT_INDUSTRY_COMPANY, STR_INDUSTRY_CHANGES_SERVED_BY_PLAYER),
|
||||
NEWS_SETTINGS_LINE(26, NT_INDUSTRY_OTHER, STR_INDUSTRY_CHANGES_SERVED_BY_OTHER),
|
||||
NEWS_SETTINGS_LINE(26, NT_INDUSTRY_NOBODY, STR_OTHER_INDUSTRY_PRODUCTION_CHANGES),
|
||||
NEWS_SETTINGS_LINE(26, NT_ADVICE, STR_020B_ADVICE_INFORMATION_ON_PLAYER),
|
||||
NEWS_SETTINGS_LINE(26, NT_NEW_VEHICLES, STR_020C_NEW_VEHICLES),
|
||||
NEWS_SETTINGS_LINE(26, NT_ACCEPTANCE, STR_020D_CHANGES_OF_CARGO_ACCEPTANCE),
|
||||
NEWS_SETTINGS_LINE(26, NT_SUBSIDIES, STR_020E_SUBSIDIES),
|
||||
NEWS_SETTINGS_LINE(26, NT_GENERAL, STR_020F_GENERAL_INFORMATION),
|
||||
|
||||
{ WIDGETS_END},
|
||||
};
|
||||
|
|
|
@ -13,17 +13,17 @@
|
|||
* Type of news.
|
||||
*/
|
||||
enum NewsType {
|
||||
NT_ARRIVAL_PLAYER, ///< Cargo arrived for player
|
||||
NT_ARRIVAL_COMPANY, ///< Cargo arrived for company
|
||||
NT_ARRIVAL_OTHER, ///< Cargo arrived for competitor
|
||||
NT_ACCIDENT, ///< An accident or disaster has occurred
|
||||
NT_COMPANY_INFO, ///< Company info (new companies, bankrupcy messages)
|
||||
NT_INDUSTRY_OPEN, ///< Opening of industries
|
||||
NT_INDUSTRY_CLOSE, ///< Closing of industries
|
||||
NT_ECONOMY, ///< Economic changes (recession, industry up/dowm)
|
||||
NT_INDUSTRY_PLAYER, ///< Production changes of industry serviced by local player
|
||||
NT_INDUSTRY_COMPANY,///< Production changes of industry serviced by local company
|
||||
NT_INDUSTRY_OTHER, ///< Production changes of industry serviced by competitor(s)
|
||||
NT_INDUSTRY_NOBODY, ///< Other industry production changes
|
||||
NT_ADVICE, ///< Bits of news about vehicles of the player
|
||||
NT_ADVICE, ///< Bits of news about vehicles of the company
|
||||
NT_NEW_VEHICLES, ///< New vehicle has become available
|
||||
NT_ACCEPTANCE, ///< A type of cargo is (no longer) accepted
|
||||
NT_SUBSIDIES, ///< News about subsidies (announcements, expirations, acceptance)
|
||||
|
@ -35,7 +35,7 @@ enum NewsType {
|
|||
* News subtypes.
|
||||
*/
|
||||
enum NewsSubtype {
|
||||
NS_ARRIVAL_PLAYER, ///< NT_ARRIVAL_PLAYER
|
||||
NS_ARRIVAL_COMPANY, ///< NT_ARRIVAL_COMPANY
|
||||
NS_ARRIVAL_OTHER, ///< NT_ARRIVAL_OTHER
|
||||
NS_ACCIDENT_TILE, ///< NT_ACCIDENT (tile)
|
||||
NS_ACCIDENT_VEHICLE, ///< NT_ACCIDENT (vehicle)
|
||||
|
@ -46,7 +46,7 @@ enum NewsSubtype {
|
|||
NS_INDUSTRY_OPEN, ///< NT_INDUSTRY_OPEN
|
||||
NS_INDUSTRY_CLOSE, ///< NT_INDUSTRY_CLOSE
|
||||
NS_ECONOMY, ///< NT_ECONOMY
|
||||
NS_INDUSTRY_PLAYER, ///< NT_INDUSTRY_PLAYER
|
||||
NS_INDUSTRY_COMPANY, ///< NT_INDUSTRY_COMPANY
|
||||
NS_INDUSTRY_OTHER, ///< NT_INDUSTRY_OTHER
|
||||
NS_INDUSTRY_NOBODY, ///< NT_INDUSTRY_NOBODY
|
||||
NS_ADVICE, ///< NT_ADVICE
|
||||
|
@ -130,7 +130,7 @@ struct CompanyNewsInformation {
|
|||
uint32 face; ///< The face of the president
|
||||
byte colour; ///< The colour related to the company
|
||||
|
||||
void FillData(const struct Player *p, const struct Player *other = NULL);
|
||||
void FillData(const struct Company *c, const struct Company *other = NULL);
|
||||
};
|
||||
|
||||
#endif /* NEWS_TYPE_H */
|
||||
|
|
|
@ -573,7 +573,7 @@ static void NPFSaveTargetData(AyStar* as, OpenListNode* current)
|
|||
}
|
||||
|
||||
/**
|
||||
* Finds out if a given player's vehicles are allowed to enter a given tile.
|
||||
* Finds out if a given company's vehicles are allowed to enter a given tile.
|
||||
* @param owner The owner of the vehicle.
|
||||
* @param tile The tile that is about to be entered.
|
||||
* @param enterdir The direction in which the vehicle wants to enter the tile.
|
||||
|
|
|
@ -363,7 +363,7 @@ static void FixOldVehicles()
|
|||
* or vehicles that could not have an order would still have a
|
||||
* (loading) order which causes assertions and the like later on.
|
||||
*/
|
||||
if (!IsPlayerBuildableVehicleType(v) ||
|
||||
if (!IsCompanyBuildableVehicleType(v) ||
|
||||
(v->IsPrimaryVehicle() && v->current_order.IsType(OT_NOTHING))) {
|
||||
v->current_order.MakeDummy();
|
||||
}
|
||||
|
@ -770,60 +770,60 @@ static bool LoadOldIndustry(LoadgameState *ls, int num)
|
|||
return true;
|
||||
}
|
||||
|
||||
static PlayerID _current_player_id;
|
||||
static CompanyID _current_company_id;
|
||||
static int32 _old_yearly;
|
||||
|
||||
static const OldChunks player_yearly_chunk[] = {
|
||||
static const OldChunks _company_yearly_chunk[] = {
|
||||
OCL_VAR( OC_INT32, 1, &_old_yearly ),
|
||||
OCL_END()
|
||||
};
|
||||
|
||||
static bool OldPlayerYearly(LoadgameState *ls, int num)
|
||||
static bool OldCompanyYearly(LoadgameState *ls, int num)
|
||||
{
|
||||
int i;
|
||||
Player *p = GetPlayer(_current_player_id);
|
||||
Company *c = GetCompany(_current_company_id);
|
||||
|
||||
for (i = 0; i < 13; i++) {
|
||||
if (!LoadChunk(ls, NULL, player_yearly_chunk)) return false;
|
||||
if (!LoadChunk(ls, NULL, _company_yearly_chunk)) return false;
|
||||
|
||||
p->yearly_expenses[num][i] = _old_yearly;
|
||||
c->yearly_expenses[num][i] = _old_yearly;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static const OldChunks player_economy_chunk[] = {
|
||||
OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, PlayerEconomyEntry, income ),
|
||||
OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, PlayerEconomyEntry, expenses ),
|
||||
OCL_SVAR( OC_INT32, PlayerEconomyEntry, delivered_cargo ),
|
||||
OCL_SVAR( OC_INT32, PlayerEconomyEntry, performance_history ),
|
||||
OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, PlayerEconomyEntry, company_value ),
|
||||
static const OldChunks _company_economy_chunk[] = {
|
||||
OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, CompanyEconomyEntry, income ),
|
||||
OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, CompanyEconomyEntry, expenses ),
|
||||
OCL_SVAR( OC_INT32, CompanyEconomyEntry, delivered_cargo ),
|
||||
OCL_SVAR( OC_INT32, CompanyEconomyEntry, performance_history ),
|
||||
OCL_SVAR( OC_FILE_I32 | OC_VAR_I64, CompanyEconomyEntry, company_value ),
|
||||
|
||||
OCL_END()
|
||||
};
|
||||
|
||||
static bool OldPlayerEconomy(LoadgameState *ls, int num)
|
||||
static bool OldCompanyEconomy(LoadgameState *ls, int num)
|
||||
{
|
||||
int i;
|
||||
Player *p = GetPlayer(_current_player_id);
|
||||
Company *c = GetCompany(_current_company_id);
|
||||
|
||||
if (!LoadChunk(ls, &p->cur_economy, player_economy_chunk)) return false;
|
||||
if (!LoadChunk(ls, &c->cur_economy, _company_economy_chunk)) return false;
|
||||
|
||||
/* Don't ask, but the number in TTD(Patch) are inversed to OpenTTD */
|
||||
p->cur_economy.income = -p->cur_economy.income;
|
||||
p->cur_economy.expenses = -p->cur_economy.expenses;
|
||||
c->cur_economy.income = -c->cur_economy.income;
|
||||
c->cur_economy.expenses = -c->cur_economy.expenses;
|
||||
|
||||
for (i = 0; i < 24; i++) {
|
||||
if (!LoadChunk(ls, &p->old_economy[i], player_economy_chunk)) return false;
|
||||
if (!LoadChunk(ls, &c->old_economy[i], _company_economy_chunk)) return false;
|
||||
|
||||
p->old_economy[i].income = -p->old_economy[i].income;
|
||||
p->old_economy[i].expenses = -p->old_economy[i].expenses;
|
||||
c->old_economy[i].income = -c->old_economy[i].income;
|
||||
c->old_economy[i].expenses = -c->old_economy[i].expenses;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static const OldChunks player_ai_build_rec_chunk[] = {
|
||||
static const OldChunks _company_ai_build_rec_chunk[] = {
|
||||
OCL_SVAR( OC_TILE, AiBuildRec, spec_tile ),
|
||||
OCL_SVAR( OC_TILE, AiBuildRec, use_tile ),
|
||||
OCL_SVAR( OC_UINT8, AiBuildRec, rand_rng ),
|
||||
|
@ -842,216 +842,215 @@ static const OldChunks player_ai_build_rec_chunk[] = {
|
|||
|
||||
static bool OldLoadAIBuildRec(LoadgameState *ls, int num)
|
||||
{
|
||||
Player *p = GetPlayer(_current_player_id);
|
||||
Company *c = GetCompany(_current_company_id);
|
||||
|
||||
switch (num) {
|
||||
case 0: return LoadChunk(ls, &_players_ai[p->index].src, player_ai_build_rec_chunk);
|
||||
case 1: return LoadChunk(ls, &_players_ai[p->index].dst, player_ai_build_rec_chunk);
|
||||
case 2: return LoadChunk(ls, &_players_ai[p->index].mid1, player_ai_build_rec_chunk);
|
||||
case 3: return LoadChunk(ls, &_players_ai[p->index].mid2, player_ai_build_rec_chunk);
|
||||
case 0: return LoadChunk(ls, &_companies_ai[c->index].src, _company_ai_build_rec_chunk);
|
||||
case 1: return LoadChunk(ls, &_companies_ai[c->index].dst, _company_ai_build_rec_chunk);
|
||||
case 2: return LoadChunk(ls, &_companies_ai[c->index].mid1, _company_ai_build_rec_chunk);
|
||||
case 3: return LoadChunk(ls, &_companies_ai[c->index].mid2, _company_ai_build_rec_chunk);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
static const OldChunks player_ai_chunk[] = {
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, state ),
|
||||
static const OldChunks _company_ai_chunk[] = {
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, state ),
|
||||
OCL_NULL( 1 ), ///< Junk
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, state_mode ),
|
||||
OCL_SVAR( OC_UINT16, PlayerAI, state_counter ),
|
||||
OCL_SVAR( OC_UINT16, PlayerAI, timeout_counter ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, state_mode ),
|
||||
OCL_SVAR( OC_UINT16, CompanyAI, state_counter ),
|
||||
OCL_SVAR( OC_UINT16, CompanyAI, timeout_counter ),
|
||||
|
||||
OCL_CHUNK( 4, OldLoadAIBuildRec ),
|
||||
|
||||
OCL_NULL( 20 ), ///< More junk
|
||||
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, cargo_type ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, num_wagons ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, build_kind ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, num_build_rec ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, num_loco_to_build ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, num_want_fullload ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, cargo_type ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, num_wagons ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, build_kind ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, num_build_rec ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, num_loco_to_build ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, num_want_fullload ),
|
||||
|
||||
OCL_NULL( 14 ), ///< Oh no more junk :|
|
||||
|
||||
OCL_NULL( 2 ), ///< Loco-id, not used
|
||||
|
||||
OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[0] ),
|
||||
OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[1] ),
|
||||
OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[2] ),
|
||||
OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[3] ),
|
||||
OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[4] ),
|
||||
OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[5] ),
|
||||
OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[6] ),
|
||||
OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[7] ),
|
||||
OCL_SVAR( OC_UINT16, PlayerAI, wagon_list[8] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, order_list_blocks[0] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, order_list_blocks[1] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, order_list_blocks[2] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, order_list_blocks[3] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, order_list_blocks[4] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, order_list_blocks[5] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, order_list_blocks[6] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, order_list_blocks[7] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, order_list_blocks[8] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, order_list_blocks[9] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, order_list_blocks[10] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, order_list_blocks[11] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, order_list_blocks[12] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, order_list_blocks[13] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, order_list_blocks[14] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, order_list_blocks[15] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, order_list_blocks[16] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, order_list_blocks[17] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, order_list_blocks[18] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, order_list_blocks[19] ),
|
||||
OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[0] ),
|
||||
OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[1] ),
|
||||
OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[2] ),
|
||||
OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[3] ),
|
||||
OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[4] ),
|
||||
OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[5] ),
|
||||
OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[6] ),
|
||||
OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[7] ),
|
||||
OCL_SVAR( OC_UINT16, CompanyAI, wagon_list[8] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[0] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[1] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[2] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[3] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[4] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[5] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[6] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[7] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[8] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[9] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[10] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[11] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[12] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[13] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[14] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[15] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[16] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[17] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[18] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, order_list_blocks[19] ),
|
||||
|
||||
OCL_SVAR( OC_UINT16, PlayerAI, start_tile_a ),
|
||||
OCL_SVAR( OC_UINT16, PlayerAI, start_tile_b ),
|
||||
OCL_SVAR( OC_UINT16, PlayerAI, cur_tile_a ),
|
||||
OCL_SVAR( OC_UINT16, PlayerAI, cur_tile_b ),
|
||||
OCL_SVAR( OC_UINT16, CompanyAI, start_tile_a ),
|
||||
OCL_SVAR( OC_UINT16, CompanyAI, start_tile_b ),
|
||||
OCL_SVAR( OC_UINT16, CompanyAI, cur_tile_a ),
|
||||
OCL_SVAR( OC_UINT16, CompanyAI, cur_tile_b ),
|
||||
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, start_dir_a ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, start_dir_b ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, cur_dir_a ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, cur_dir_b ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, start_dir_a ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, start_dir_b ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, cur_dir_a ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, cur_dir_b ),
|
||||
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, banned_tile_count ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, banned_tile_count ),
|
||||
|
||||
OCL_SVAR( OC_TILE, PlayerAI, banned_tiles[0] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, banned_val[0] ),
|
||||
OCL_SVAR( OC_TILE, PlayerAI, banned_tiles[1] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, banned_val[1] ),
|
||||
OCL_SVAR( OC_TILE, PlayerAI, banned_tiles[2] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, banned_val[2] ),
|
||||
OCL_SVAR( OC_TILE, PlayerAI, banned_tiles[3] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, banned_val[3] ),
|
||||
OCL_SVAR( OC_TILE, PlayerAI, banned_tiles[4] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, banned_val[4] ),
|
||||
OCL_SVAR( OC_TILE, PlayerAI, banned_tiles[5] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, banned_val[5] ),
|
||||
OCL_SVAR( OC_TILE, PlayerAI, banned_tiles[6] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, banned_val[6] ),
|
||||
OCL_SVAR( OC_TILE, PlayerAI, banned_tiles[7] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, banned_val[7] ),
|
||||
OCL_SVAR( OC_TILE, PlayerAI, banned_tiles[8] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, banned_val[8] ),
|
||||
OCL_SVAR( OC_TILE, PlayerAI, banned_tiles[9] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, banned_val[9] ),
|
||||
OCL_SVAR( OC_TILE, PlayerAI, banned_tiles[10] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, banned_val[10] ),
|
||||
OCL_SVAR( OC_TILE, PlayerAI, banned_tiles[11] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, banned_val[11] ),
|
||||
OCL_SVAR( OC_TILE, PlayerAI, banned_tiles[12] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, banned_val[12] ),
|
||||
OCL_SVAR( OC_TILE, PlayerAI, banned_tiles[13] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, banned_val[13] ),
|
||||
OCL_SVAR( OC_TILE, PlayerAI, banned_tiles[14] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, banned_val[14] ),
|
||||
OCL_SVAR( OC_TILE, PlayerAI, banned_tiles[15] ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, banned_val[15] ),
|
||||
OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[0] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, banned_val[0] ),
|
||||
OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[1] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, banned_val[1] ),
|
||||
OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[2] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, banned_val[2] ),
|
||||
OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[3] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, banned_val[3] ),
|
||||
OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[4] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, banned_val[4] ),
|
||||
OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[5] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, banned_val[5] ),
|
||||
OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[6] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, banned_val[6] ),
|
||||
OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[7] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, banned_val[7] ),
|
||||
OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[8] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, banned_val[8] ),
|
||||
OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[9] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, banned_val[9] ),
|
||||
OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[10] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, banned_val[10] ),
|
||||
OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[11] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, banned_val[11] ),
|
||||
OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[12] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, banned_val[12] ),
|
||||
OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[13] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, banned_val[13] ),
|
||||
OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[14] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, banned_val[14] ),
|
||||
OCL_SVAR( OC_TILE, CompanyAI, banned_tiles[15] ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, banned_val[15] ),
|
||||
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, railtype_to_use ),
|
||||
OCL_SVAR( OC_UINT8, PlayerAI, route_type_mask ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, railtype_to_use ),
|
||||
OCL_SVAR( OC_UINT8, CompanyAI, route_type_mask ),
|
||||
|
||||
OCL_END()
|
||||
};
|
||||
|
||||
static bool OldPlayerAI(LoadgameState *ls, int num)
|
||||
static bool OldCompanyAI(LoadgameState *ls, int num)
|
||||
{
|
||||
return LoadChunk(ls, &_players_ai[_current_player_id], player_ai_chunk);
|
||||
return LoadChunk(ls, &_companies_ai[_current_company_id], _company_ai_chunk);
|
||||
}
|
||||
|
||||
uint8 ai_tick;
|
||||
static const OldChunks player_chunk[] = {
|
||||
static const OldChunks _company_chunk[] = {
|
||||
OCL_VAR ( OC_UINT16, 1, &_old_string_id ),
|
||||
OCL_SVAR( OC_UINT32, Player, name_2 ),
|
||||
OCL_SVAR( OC_UINT32, Player, face ),
|
||||
OCL_SVAR( OC_UINT32, Company, name_2 ),
|
||||
OCL_SVAR( OC_UINT32, Company, face ),
|
||||
OCL_VAR ( OC_UINT16, 1, &_old_string_id_2 ),
|
||||
OCL_SVAR( OC_UINT32, Player, president_name_2 ),
|
||||
OCL_SVAR( OC_UINT32, Company, president_name_2 ),
|
||||
|
||||
OCL_SVAR( OC_INT32, Player, player_money ),
|
||||
OCL_SVAR( OC_INT32, Player, current_loan ),
|
||||
OCL_SVAR( OC_INT32, Company, money ),
|
||||
OCL_SVAR( OC_INT32, Company, current_loan ),
|
||||
|
||||
OCL_SVAR( OC_UINT8, Player, player_color ),
|
||||
OCL_SVAR( OC_UINT8, Player, player_money_fraction ),
|
||||
OCL_SVAR( OC_UINT8, Player, quarters_of_bankrupcy ),
|
||||
OCL_SVAR( OC_UINT8, Player, bankrupt_asked ),
|
||||
OCL_SVAR( OC_FILE_U32 | OC_VAR_I64, Player, bankrupt_value ),
|
||||
OCL_SVAR( OC_UINT16, Player, bankrupt_timeout ),
|
||||
OCL_SVAR( OC_UINT8, Company, colour ),
|
||||
OCL_SVAR( OC_UINT8, Company, money_fraction ),
|
||||
OCL_SVAR( OC_UINT8, Company, quarters_of_bankrupcy ),
|
||||
OCL_SVAR( OC_UINT8, Company, bankrupt_asked ),
|
||||
OCL_SVAR( OC_FILE_U32 | OC_VAR_I64, Company, bankrupt_value ),
|
||||
OCL_SVAR( OC_UINT16, Company, bankrupt_timeout ),
|
||||
|
||||
OCL_SVAR( OC_UINT32, Player, cargo_types ),
|
||||
OCL_SVAR( OC_UINT32, Company, cargo_types ),
|
||||
|
||||
OCL_CHUNK( 3, OldPlayerYearly ),
|
||||
OCL_CHUNK( 1, OldPlayerEconomy ),
|
||||
OCL_CHUNK( 3, OldCompanyYearly ),
|
||||
OCL_CHUNK( 1, OldCompanyEconomy ),
|
||||
|
||||
OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Player, inaugurated_year),
|
||||
OCL_SVAR( OC_TILE, Player, last_build_coordinate ),
|
||||
OCL_SVAR( OC_UINT8, Player, num_valid_stat_ent ),
|
||||
OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Company, inaugurated_year),
|
||||
OCL_SVAR( OC_TILE, Company, last_build_coordinate ),
|
||||
OCL_SVAR( OC_UINT8, Company, num_valid_stat_ent ),
|
||||
|
||||
OCL_CHUNK( 1, OldPlayerAI ),
|
||||
OCL_CHUNK( 1, OldCompanyAI ),
|
||||
|
||||
OCL_SVAR( OC_UINT8, Player, block_preview ),
|
||||
OCL_SVAR( OC_UINT8, Company, block_preview ),
|
||||
OCL_VAR( OC_UINT8, 1, &ai_tick ),
|
||||
OCL_SVAR( OC_UINT8, Player, avail_railtypes ),
|
||||
OCL_SVAR( OC_TILE, Player, location_of_HQ ),
|
||||
OCL_SVAR( OC_UINT8, Player, share_owners[0] ),
|
||||
OCL_SVAR( OC_UINT8, Player, share_owners[1] ),
|
||||
OCL_SVAR( OC_UINT8, Player, share_owners[2] ),
|
||||
OCL_SVAR( OC_UINT8, Player, share_owners[3] ),
|
||||
OCL_SVAR( OC_UINT8, Company, avail_railtypes ),
|
||||
OCL_SVAR( OC_TILE, Company, location_of_HQ ),
|
||||
OCL_SVAR( OC_UINT8, Company, share_owners[0] ),
|
||||
OCL_SVAR( OC_UINT8, Company, share_owners[1] ),
|
||||
OCL_SVAR( OC_UINT8, Company, share_owners[2] ),
|
||||
OCL_SVAR( OC_UINT8, Company, share_owners[3] ),
|
||||
|
||||
OCL_NULL( 8 ), ///< junk at end of chunk
|
||||
|
||||
OCL_END()
|
||||
};
|
||||
|
||||
static bool LoadOldPlayer(LoadgameState *ls, int num)
|
||||
static bool LoadOldCompany(LoadgameState *ls, int num)
|
||||
{
|
||||
Player *p = new (num) Player();
|
||||
Company *c = new (num) Company();
|
||||
|
||||
_current_player_id = (PlayerID)num;
|
||||
_current_company_id = (CompanyID)num;
|
||||
|
||||
if (!LoadChunk(ls, p, player_chunk)) return false;
|
||||
if (!LoadChunk(ls, c, _company_chunk)) return false;
|
||||
|
||||
if (_old_string_id == 0) {
|
||||
delete p;
|
||||
delete c;
|
||||
return true;
|
||||
}
|
||||
|
||||
p->name_1 = RemapOldStringID(_old_string_id);
|
||||
p->president_name_1 = RemapOldStringID(_old_string_id_2);
|
||||
_players_ai[_current_player_id].tick = ai_tick;
|
||||
c->name_1 = RemapOldStringID(_old_string_id);
|
||||
c->president_name_1 = RemapOldStringID(_old_string_id_2);
|
||||
_companies_ai[_current_company_id].tick = ai_tick;
|
||||
|
||||
if (num == 0) {
|
||||
/* If the first player has no name, make sure we call it UNNAMED */
|
||||
if (p->name_1 == 0)
|
||||
p->name_1 = STR_SV_UNNAMED;
|
||||
/* If the first company has no name, make sure we call it UNNAMED */
|
||||
if (c->name_1 == 0)
|
||||
c->name_1 = STR_SV_UNNAMED;
|
||||
} else {
|
||||
/* Beside some multiplayer maps (1 on 1), which we don't official support,
|
||||
all other players are an AI.. mark them as such */
|
||||
p->is_ai = true;
|
||||
* all other companys are an AI.. mark them as such */
|
||||
c->is_ai = true;
|
||||
}
|
||||
|
||||
/* Sometimes it is better to not ask.. in old scenarios, the money
|
||||
was always 893288 pounds. In the newer versions this is correct,
|
||||
but correct for those oldies
|
||||
Ps: this also means that if you had exact 893288 pounds, you will go back
|
||||
to 10000.. this is a very VERY small chance ;) */
|
||||
if (p->player_money == 893288)
|
||||
p->player_money = p->current_loan = 100000;
|
||||
* was always 893288 pounds. In the newer versions this is correct,
|
||||
* but correct for those oldies
|
||||
* Ps: this also means that if you had exact 893288 pounds, you will go back
|
||||
* to 10000.. this is a very VERY small chance ;) */
|
||||
if (c->money == 893288) c->money = c->current_loan = 100000;
|
||||
|
||||
_player_colors[num] = p->player_color;
|
||||
p->inaugurated_year -= ORIGINAL_BASE_YEAR;
|
||||
if (p->location_of_HQ == 0xFFFF)
|
||||
p->location_of_HQ = 0;
|
||||
_company_colours[num] = c->colour;
|
||||
c->inaugurated_year -= ORIGINAL_BASE_YEAR;
|
||||
if (c->location_of_HQ == 0xFFFF)
|
||||
c->location_of_HQ = 0;
|
||||
|
||||
/* State 20 for AI players is sell vehicle. Since the AI struct is not
|
||||
* really figured out as of now, _players_ai[p->index].cur_veh; needed for 'sell vehicle'
|
||||
/* State 20 for AI companies is sell vehicle. Since the AI struct is not
|
||||
* really figured out as of now, _companies_ai[c->index].cur_veh; needed for 'sell vehicle'
|
||||
* is NULL and the function will crash. To fix this, just change the state
|
||||
* to some harmless state, like 'loop vehicle'; 1 */
|
||||
if (!IsHumanPlayer((PlayerID)num) && _players_ai[p->index].state == 20) _players_ai[p->index].state = 1;
|
||||
if (!IsHumanCompany((CompanyID)num) && _companies_ai[c->index].state == 20) _companies_ai[c->index].state = 1;
|
||||
|
||||
if (p->is_ai && (!_networking || _network_server) && _ai.enabled)
|
||||
AI_StartNewAI(p->index);
|
||||
if (c->is_ai && (!_networking || _network_server) && _ai.enabled)
|
||||
AI_StartNewAI(c->index);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1323,7 +1322,7 @@ static bool LoadOldSign(LoadgameState *ls, int num)
|
|||
}
|
||||
|
||||
static const OldChunks engine_chunk[] = {
|
||||
OCL_SVAR( OC_UINT16, Engine, player_avail ),
|
||||
OCL_SVAR( OC_UINT16, Engine, company_avail ),
|
||||
OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Engine, intro_date ),
|
||||
OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Engine, age ),
|
||||
OCL_SVAR( OC_UINT16, Engine, reliability ),
|
||||
|
@ -1337,7 +1336,7 @@ static const OldChunks engine_chunk[] = {
|
|||
|
||||
OCL_SVAR( OC_UINT8, Engine, lifelength ),
|
||||
OCL_SVAR( OC_UINT8, Engine, flags ),
|
||||
OCL_SVAR( OC_UINT8, Engine, preview_player_rank ),
|
||||
OCL_SVAR( OC_UINT8, Engine, preview_company_rank ),
|
||||
OCL_SVAR( OC_UINT8, Engine, preview_wait ),
|
||||
|
||||
OCL_NULL( 2 ), ///< Junk
|
||||
|
@ -1542,7 +1541,7 @@ static const OldChunks main_chunk[] = {
|
|||
|
||||
OCL_CHUNK(250, LoadOldStation ),
|
||||
OCL_CHUNK( 90, LoadOldIndustry ),
|
||||
OCL_CHUNK( 8, LoadOldPlayer ),
|
||||
OCL_CHUNK( 8, LoadOldCompany ),
|
||||
|
||||
OCL_ASSERT( 0x547F2 ),
|
||||
|
||||
|
@ -1577,16 +1576,16 @@ static const OldChunks main_chunk[] = {
|
|||
OCL_CHUNK(256, LoadOldEngineName ),
|
||||
|
||||
OCL_NULL( 144 ), ///< AI cargo-stuff, calculated in InitializeLandscapeVariables
|
||||
OCL_NULL( 2 ), ///< Company indexes of players, no longer in use
|
||||
OCL_NULL( 2 ), ///< Company indexes of companies, no longer in use
|
||||
|
||||
OCL_VAR ( OC_FILE_U8 | OC_VAR_U16, 1, &_station_tick_ctr ),
|
||||
|
||||
OCL_VAR ( OC_UINT8, 1, &_settings_game.locale.currency ),
|
||||
OCL_VAR ( OC_UINT8, 1, &_settings_game.locale.units ),
|
||||
OCL_VAR ( OC_FILE_U8 | OC_VAR_U32, 1, &_cur_player_tick_index ),
|
||||
OCL_VAR ( OC_FILE_U8 | OC_VAR_U32, 1, &_cur_company_tick_index ),
|
||||
|
||||
OCL_NULL( 2 ), ///< Date stuff, calculated automatically
|
||||
OCL_NULL( 8 ), ///< Player colors, calculated automatically
|
||||
OCL_NULL( 8 ), ///< Company colors, calculated automatically
|
||||
|
||||
OCL_VAR ( OC_UINT8, 1, &_economy.infl_amount ),
|
||||
OCL_VAR ( OC_UINT8, 1, &_economy.infl_amount_pr ),
|
||||
|
@ -1693,7 +1692,7 @@ static bool LoadOldMain(LoadgameState *ls)
|
|||
FOR_ALL_ENGINES(e) {
|
||||
if (_date >= (e->intro_date + 365)) {
|
||||
e->flags = (e->flags & ~ENGINE_EXCLUSIVE_PREVIEW) | ENGINE_AVAILABLE;
|
||||
e->player_avail = (byte)-1;
|
||||
e->company_avail = (CompanyMask)-1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
217
src/openttd.cpp
217
src/openttd.cpp
|
@ -98,7 +98,7 @@ void ProcessAsyncSaveFinish();
|
|||
void CallWindowTickEvent();
|
||||
|
||||
extern void SetDifficultyLevel(int mode, DifficultySettings *gm_opt);
|
||||
extern Player* DoStartupNewPlayer(bool is_ai);
|
||||
extern Company *DoStartupNewCompany(bool is_ai);
|
||||
extern void ShowOSErrorBox(const char *buf, bool system);
|
||||
extern void InitializeRailGUI();
|
||||
|
||||
|
@ -182,7 +182,7 @@ static void ShowHelp()
|
|||
" -g [savegame] = Start new/save game immediately\n"
|
||||
" -G seed = Set random seed\n"
|
||||
#if defined(ENABLE_NETWORK)
|
||||
" -n [ip:port#player] = Start networkgame\n"
|
||||
" -n [ip:port#company]= Start networkgame\n"
|
||||
" -D [ip][:port] = Start dedicated server\n"
|
||||
" -l ip[:port] = Redirect DEBUG()\n"
|
||||
#if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32)
|
||||
|
@ -307,7 +307,7 @@ static void InitializeDynamicVariables()
|
|||
/* Dynamic stuff needs to be initialized somewhere... */
|
||||
_industry_mngr.ResetMapping();
|
||||
_industile_mngr.ResetMapping();
|
||||
_Player_pool.AddBlockToPool();
|
||||
_Company_pool.AddBlockToPool();
|
||||
}
|
||||
|
||||
|
||||
|
@ -341,7 +341,7 @@ static void ShutdownGame()
|
|||
_Group_pool.CleanPool();
|
||||
_CargoPacket_pool.CleanPool();
|
||||
_Engine_pool.CleanPool();
|
||||
_Player_pool.CleanPool();
|
||||
_Company_pool.CleanPool();
|
||||
|
||||
free(_config_file);
|
||||
|
||||
|
@ -363,9 +363,9 @@ static void LoadIntroGame()
|
|||
if (SaveOrLoad("opntitle.dat", SL_LOAD, DATA_DIR) != SL_OK) {
|
||||
GenerateWorld(GW_EMPTY, 64, 64); // if failed loading, make empty world.
|
||||
WaitTillGeneratedWorld();
|
||||
SetLocalPlayer(PLAYER_SPECTATOR);
|
||||
SetLocalCompany(COMPANY_SPECTATOR);
|
||||
} else {
|
||||
SetLocalPlayer(PLAYER_FIRST);
|
||||
SetLocalCompany(COMPANY_FIRST);
|
||||
}
|
||||
|
||||
_pause_game = 0;
|
||||
|
@ -437,7 +437,7 @@ int ttd_main(int argc, char *argv[])
|
|||
dedicated = true;
|
||||
if (mgo.opt != NULL) {
|
||||
/* Use the existing method for parsing (openttd -n).
|
||||
* However, we do ignore the #player part. */
|
||||
* However, we do ignore the #company part. */
|
||||
const char *temp = NULL;
|
||||
const char *port = NULL;
|
||||
ParseConnectionString(&temp, &port, mgo.opt);
|
||||
|
@ -649,20 +649,20 @@ int ttd_main(int argc, char *argv[])
|
|||
if (network && _network_available) {
|
||||
if (network_conn != NULL) {
|
||||
const char *port = NULL;
|
||||
const char *player = NULL;
|
||||
const char *company = NULL;
|
||||
uint16 rport;
|
||||
|
||||
rport = NETWORK_DEFAULT_PORT;
|
||||
_network_playas = PLAYER_NEW_COMPANY;
|
||||
_network_playas = COMPANY_NEW_COMPANY;
|
||||
|
||||
ParseConnectionString(&player, &port, network_conn);
|
||||
ParseConnectionString(&company, &port, network_conn);
|
||||
|
||||
if (player != NULL) {
|
||||
_network_playas = (PlayerID)atoi(player);
|
||||
if (company != NULL) {
|
||||
_network_playas = (CompanyID)atoi(company);
|
||||
|
||||
if (_network_playas != PLAYER_SPECTATOR) {
|
||||
if (_network_playas != COMPANY_SPECTATOR) {
|
||||
_network_playas--;
|
||||
if (_network_playas >= MAX_PLAYERS) return false;
|
||||
if (_network_playas >= MAX_COMPANIES) return false;
|
||||
}
|
||||
}
|
||||
if (port != NULL) rport = atoi(port);
|
||||
|
@ -719,21 +719,21 @@ static void MakeNewGameDone()
|
|||
|
||||
/* In a dedicated server, the server does not play */
|
||||
if (_network_dedicated) {
|
||||
SetLocalPlayer(PLAYER_SPECTATOR);
|
||||
SetLocalCompany(COMPANY_SPECTATOR);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Create a single player */
|
||||
DoStartupNewPlayer(false);
|
||||
/* Create a single company */
|
||||
DoStartupNewCompany(false);
|
||||
|
||||
SetLocalPlayer(PLAYER_FIRST);
|
||||
_current_player = _local_player;
|
||||
SetLocalCompany(COMPANY_FIRST);
|
||||
_current_company = _local_company;
|
||||
DoCommandP(0, (_settings_client.gui.autorenew << 15 ) | (_settings_client.gui.autorenew_months << 16) | 4, _settings_client.gui.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
|
||||
|
||||
InitializeRailGUI();
|
||||
|
||||
#ifdef ENABLE_NETWORK
|
||||
/* We are the server, we start a new player (not dedicated),
|
||||
/* We are the server, we start a new company (not dedicated),
|
||||
* so set the default password *if* needed. */
|
||||
if (_network_server && !StrEmpty(_settings_client.network.default_company_pass)) {
|
||||
char *password = _settings_client.network.default_company_pass;
|
||||
|
@ -759,7 +759,7 @@ static void MakeNewGame(bool from_heightmap)
|
|||
|
||||
static void MakeNewEditorWorldDone()
|
||||
{
|
||||
SetLocalPlayer(OWNER_NONE);
|
||||
SetLocalCompany(OWNER_NONE);
|
||||
|
||||
MarkWholeScreenDirty();
|
||||
}
|
||||
|
@ -774,7 +774,7 @@ static void MakeNewEditorWorld()
|
|||
GenerateWorld(GW_EMPTY, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
|
||||
}
|
||||
|
||||
void StartupPlayers();
|
||||
void StartupCompanies();
|
||||
void StartupDisasters();
|
||||
extern void StartupEconomy();
|
||||
|
||||
|
@ -816,12 +816,12 @@ static void StartScenario()
|
|||
|
||||
/* Inititalize data */
|
||||
StartupEconomy();
|
||||
StartupPlayers();
|
||||
StartupCompanies();
|
||||
StartupEngines();
|
||||
StartupDisasters();
|
||||
|
||||
SetLocalPlayer(PLAYER_FIRST);
|
||||
_current_player = _local_player;
|
||||
SetLocalCompany(COMPANY_FIRST);
|
||||
_current_company = _local_company;
|
||||
DoCommandP(0, (_settings_client.gui.autorenew << 15 ) | (_settings_client.gui.autorenew_months << 16) | 4, _settings_client.gui.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
|
||||
|
||||
MarkWholeScreenDirty();
|
||||
|
@ -927,9 +927,9 @@ void SwitchMode(int new_mode)
|
|||
if (_saveload_mode == SLD_LOAD_SCENARIO) {
|
||||
StartupEngines();
|
||||
}
|
||||
/* Update the local player for a loaded game. It is either always
|
||||
* player #1 (eg 0) or in the case of a dedicated server a spectator */
|
||||
SetLocalPlayer(_network_dedicated ? PLAYER_SPECTATOR : PLAYER_FIRST);
|
||||
/* Update the local company for a loaded game. It is either always
|
||||
* company #1 (eg 0) or in the case of a dedicated server a spectator */
|
||||
SetLocalCompany(_network_dedicated ? COMPANY_SPECTATOR : COMPANY_FIRST);
|
||||
/* Decrease pause counter (was increased from opening load dialog) */
|
||||
DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
|
||||
#ifdef ENABLE_NETWORK
|
||||
|
@ -951,7 +951,7 @@ void SwitchMode(int new_mode)
|
|||
break;
|
||||
|
||||
case SM_LOAD_HEIGHTMAP: /* Load heightmap from scenario editor */
|
||||
SetLocalPlayer(OWNER_NONE);
|
||||
SetLocalCompany(OWNER_NONE);
|
||||
|
||||
GenerateWorld(GW_HEIGHTMAP, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
|
||||
MarkWholeScreenDirty();
|
||||
|
@ -959,7 +959,7 @@ void SwitchMode(int new_mode)
|
|||
|
||||
case SM_LOAD_SCENARIO: { /* Load scenario from scenario editor */
|
||||
if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR, NO_DIRECTORY)) {
|
||||
SetLocalPlayer(OWNER_NONE);
|
||||
SetLocalCompany(OWNER_NONE);
|
||||
_settings_newgame.game_creation.starting_year = _cur_year;
|
||||
} else {
|
||||
SetDParam(0, STR_JUST_RAW_STRING);
|
||||
|
@ -987,7 +987,7 @@ void SwitchMode(int new_mode)
|
|||
break;
|
||||
|
||||
case SM_GENRANDLAND: /* Generate random land within scenario editor */
|
||||
SetLocalPlayer(OWNER_NONE);
|
||||
SetLocalCompany(OWNER_NONE);
|
||||
GenerateWorld(GW_RANDOM, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
|
||||
/* XXX: set date */
|
||||
MarkWholeScreenDirty();
|
||||
|
@ -1034,7 +1034,7 @@ void StateGameLoop()
|
|||
case VEH_ROAD: {
|
||||
extern byte GetRoadVehLength(const Vehicle *v);
|
||||
if (GetRoadVehLength(v) != v->u.road.cached_veh_length) {
|
||||
printf("cache mismatch: vehicle %i, player %i, unit number %i\n", v->index, (int)v->owner, v->unitnumber);
|
||||
printf("cache mismatch: vehicle %i, company %i, unit number %i\n", v->index, (int)v->owner, v->unitnumber);
|
||||
}
|
||||
} break;
|
||||
|
||||
|
@ -1051,7 +1051,7 @@ void StateGameLoop()
|
|||
length = 0;
|
||||
for (Vehicle *u = v; u != NULL; u = u->Next()) {
|
||||
if (memcmp(&wagons[length], &u->u.rail, sizeof(VehicleRail)) != 0) {
|
||||
printf("cache mismatch: vehicle %i, player %i, unit number %i, wagon %i\n", v->index, (int)v->owner, v->unitnumber, length);
|
||||
printf("cache mismatch: vehicle %i, company %i, unit number %i, wagon %i\n", v->index, (int)v->owner, v->unitnumber, length);
|
||||
}
|
||||
length++;
|
||||
}
|
||||
|
@ -1063,7 +1063,7 @@ void StateGameLoop()
|
|||
uint speed = v->u.air.cached_max_speed;
|
||||
UpdateAircraftCache(v);
|
||||
if (speed != v->u.air.cached_max_speed) {
|
||||
printf("cache mismatch: vehicle %i, player %i, unit number %i\n", v->index, (int)v->owner, v->unitnumber);
|
||||
printf("cache mismatch: vehicle %i, company %i, unit number %i\n", v->index, (int)v->owner, v->unitnumber);
|
||||
}
|
||||
} break;
|
||||
|
||||
|
@ -1075,8 +1075,8 @@ void StateGameLoop()
|
|||
|
||||
/* All these actions has to be done from OWNER_NONE
|
||||
* for multiplayer compatibility */
|
||||
PlayerID p = _current_player;
|
||||
_current_player = OWNER_NONE;
|
||||
CompanyID old_company = _current_company;
|
||||
_current_company = OWNER_NONE;
|
||||
|
||||
AnimateAnimatedTiles();
|
||||
IncreaseDate();
|
||||
|
@ -1089,7 +1089,7 @@ void StateGameLoop()
|
|||
|
||||
CallWindowTickEvent();
|
||||
NewsLoop();
|
||||
_current_player = p;
|
||||
_current_company = old_company;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1104,8 +1104,8 @@ static void DoAutosave()
|
|||
if (_networking) return;
|
||||
#endif /* PSP */
|
||||
|
||||
if (_settings_client.gui.keep_all_autosave && _local_player != PLAYER_SPECTATOR) {
|
||||
SetDParam(0, _local_player);
|
||||
if (_settings_client.gui.keep_all_autosave && _local_company != COMPANY_SPECTATOR) {
|
||||
SetDParam(0, _local_company);
|
||||
SetDParam(1, _date);
|
||||
GetString(buf, STR_4004, lastof(buf));
|
||||
ttd_strlcat(buf, ".sav", lengthof(buf));
|
||||
|
@ -1203,16 +1203,16 @@ static void UpdateExclusiveRights()
|
|||
Town *t;
|
||||
|
||||
FOR_ALL_TOWNS(t) {
|
||||
t->exclusivity = INVALID_PLAYER;
|
||||
t->exclusivity = INVALID_COMPANY;
|
||||
}
|
||||
|
||||
/* FIXME old exclusive rights status is not being imported (stored in s->blocked_months_obsolete)
|
||||
* could be implemented this way:
|
||||
* 1.) Go through all stations
|
||||
* Build an array town_blocked[ town_id ][ player_id ]
|
||||
* that stores if at least one station in that town is blocked for a player
|
||||
* Build an array town_blocked[ town_id ][ company_id ]
|
||||
* that stores if at least one station in that town is blocked for a company
|
||||
* 2.) Go through that array, if you find a town that is not blocked for
|
||||
* one player, but for all others, then give him exclusivity.
|
||||
* one company, but for all others, then give him exclusivity.
|
||||
*/
|
||||
}
|
||||
|
||||
|
@ -1282,13 +1282,13 @@ static bool InitializeWindowsAndCaches()
|
|||
UpdateAllTownVirtCoords();
|
||||
UpdateAllWaypointSigns();
|
||||
|
||||
Player *p;
|
||||
FOR_ALL_PLAYERS(p) {
|
||||
/* For each player, verify (while loading a scenario) that the inauguration date is the current year and set it
|
||||
* accordingly if it is not the case. No need to set it on players that are not been used already,
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
/* For each company, verify (while loading a scenario) that the inauguration date is the current year and set it
|
||||
* accordingly if it is not the case. No need to set it on companies that are not been used already,
|
||||
* thus the MIN_YEAR (which is really nothing more than Zero, initialized value) test */
|
||||
if (_file_to_saveload.filetype == FT_SCENARIO && p->inaugurated_year != MIN_YEAR) {
|
||||
p->inaugurated_year = _cur_year;
|
||||
if (_file_to_saveload.filetype == FT_SCENARIO && c->inaugurated_year != MIN_YEAR) {
|
||||
c->inaugurated_year = _cur_year;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1307,7 +1307,7 @@ static bool InitializeWindowsAndCaches()
|
|||
bool AfterLoadGame()
|
||||
{
|
||||
TileIndex map_size = MapSize();
|
||||
Player *p;
|
||||
Company *c;
|
||||
|
||||
if (CheckSavegameVersion(98)) GamelogOldver();
|
||||
|
||||
|
@ -1334,19 +1334,18 @@ bool AfterLoadGame()
|
|||
* walk through the whole map.. */
|
||||
if (CheckSavegameVersionOldStyle(4, 3)) {
|
||||
for (TileIndex t = 0; t < map_size; t++) {
|
||||
if (IsTileType(t, MP_WATER) && GetTileOwner(t) >= MAX_PLAYERS) {
|
||||
if (IsTileType(t, MP_WATER) && GetTileOwner(t) >= MAX_COMPANIES) {
|
||||
SetTileOwner(t, OWNER_WATER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (CheckSavegameVersion(84)) {
|
||||
Player *p;
|
||||
FOR_ALL_PLAYERS(p) {
|
||||
p->name = CopyFromOldName(p->name_1);
|
||||
if (p->name != NULL) p->name_1 = STR_SV_UNNAMED;
|
||||
p->president_name = CopyFromOldName(p->president_name_1);
|
||||
if (p->president_name != NULL) p->president_name_1 = SPECSTR_PRESIDENT_NAME;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
c->name = CopyFromOldName(c->name_1);
|
||||
if (c->name != NULL) c->name_1 = STR_SV_UNNAMED;
|
||||
c->president_name = CopyFromOldName(c->president_name_1);
|
||||
if (c->president_name != NULL) c->president_name_1 = SPECSTR_PRESIDENT_NAME;
|
||||
}
|
||||
|
||||
Station *st;
|
||||
|
@ -1369,7 +1368,7 @@ bool AfterLoadGame()
|
|||
}
|
||||
|
||||
for (uint i = 0; i < GetSignPoolSize(); i++) {
|
||||
/* invalid signs are determined by si->ower == INVALID_PLAYER now */
|
||||
/* invalid signs are determined by si->ower == INVALID_COMPANY now */
|
||||
Sign *si = GetSign(i);
|
||||
if (!si->IsValid() && si->name != NULL) {
|
||||
si->owner = OWNER_NONE;
|
||||
|
@ -1444,11 +1443,11 @@ bool AfterLoadGame()
|
|||
if (CheckSavegameVersion(87)) UpdateVoidTiles();
|
||||
|
||||
/* If Load Scenario / New (Scenario) Game is used,
|
||||
* a player does not exist yet. So create one here.
|
||||
* 1 exeption: network-games. Those can have 0 players
|
||||
* a company does not exist yet. So create one here.
|
||||
* 1 exeption: network-games. Those can have 0 companies
|
||||
* But this exeption is not true for non dedicated network_servers! */
|
||||
if (!IsValidPlayerID(PLAYER_FIRST) && (!_networking || (_networking && _network_server && !_network_dedicated)))
|
||||
DoStartupNewPlayer(false);
|
||||
if (!IsValidCompanyID(COMPANY_FIRST) && (!_networking || (_networking && _network_server && !_network_dedicated)))
|
||||
DoStartupNewCompany(false);
|
||||
|
||||
if (CheckSavegameVersion(72)) {
|
||||
/* Locks/shiplifts in very old savegames had OWNER_WATER as owner */
|
||||
|
@ -1589,24 +1588,24 @@ bool AfterLoadGame()
|
|||
/* From version 16.0, we included autorenew on engines, which are now saved, but
|
||||
* of course, we do need to initialize them for older savegames. */
|
||||
if (CheckSavegameVersion(16)) {
|
||||
FOR_ALL_PLAYERS(p) {
|
||||
p->engine_renew_list = NULL;
|
||||
p->engine_renew = false;
|
||||
p->engine_renew_months = -6;
|
||||
p->engine_renew_money = 100000;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
c->engine_renew_list = NULL;
|
||||
c->engine_renew = false;
|
||||
c->engine_renew_months = -6;
|
||||
c->engine_renew_money = 100000;
|
||||
}
|
||||
|
||||
/* When loading a game, _local_player is not yet set to the correct value.
|
||||
/* When loading a game, _local_company is not yet set to the correct value.
|
||||
* However, in a dedicated server we are a spectator, so nothing needs to
|
||||
* happen. In case we are not a dedicated server, the local player always
|
||||
* becomes player 0, unless we are in the scenario editor where all the
|
||||
* players are 'invalid'.
|
||||
* happen. In case we are not a dedicated server, the local company always
|
||||
* becomes company 0, unless we are in the scenario editor where all the
|
||||
* companies are 'invalid'.
|
||||
*/
|
||||
if (!_network_dedicated && IsValidPlayerID(PLAYER_FIRST)) {
|
||||
p = GetPlayer(PLAYER_FIRST);
|
||||
p->engine_renew = _settings_client.gui.autorenew;
|
||||
p->engine_renew_months = _settings_client.gui.autorenew_months;
|
||||
p->engine_renew_money = _settings_client.gui.autorenew_money;
|
||||
if (!_network_dedicated && IsValidCompanyID(COMPANY_FIRST)) {
|
||||
c = GetCompany(COMPANY_FIRST);
|
||||
c->engine_renew = _settings_client.gui.autorenew;
|
||||
c->engine_renew_months = _settings_client.gui.autorenew_months;
|
||||
c->engine_renew_money = _settings_client.gui.autorenew_money;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1808,11 +1807,11 @@ bool AfterLoadGame()
|
|||
|
||||
}
|
||||
|
||||
/* In version 16.1 of the savegame a player can decide if trains, which get
|
||||
/* In version 16.1 of the savegame a company can decide if trains, which get
|
||||
* replaced, shall keep their old length. In all prior versions, just default
|
||||
* to false */
|
||||
if (CheckSavegameVersionOldStyle(16, 1)) {
|
||||
FOR_ALL_PLAYERS(p) p->renew_keep_length = false;
|
||||
FOR_ALL_COMPANIES(c) c->renew_keep_length = false;
|
||||
}
|
||||
|
||||
/* In version 17, ground type is moved from m2 to m4 for depots and
|
||||
|
@ -1913,11 +1912,11 @@ bool AfterLoadGame()
|
|||
|
||||
YapfNotifyTrackLayoutChange(INVALID_TILE, INVALID_TRACK);
|
||||
|
||||
if (CheckSavegameVersion(34)) FOR_ALL_PLAYERS(p) ResetPlayerLivery(p);
|
||||
if (CheckSavegameVersion(34)) FOR_ALL_COMPANIES(c) ResetCompanyLivery(c);
|
||||
|
||||
FOR_ALL_PLAYERS(p) {
|
||||
p->avail_railtypes = GetPlayerRailtypes(p->index);
|
||||
p->avail_roadtypes = GetPlayerRoadtypes(p->index);
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
c->avail_railtypes = GetCompanyRailtypes(c->index);
|
||||
c->avail_roadtypes = GetCompanyRoadtypes(c->index);
|
||||
}
|
||||
|
||||
if (!CheckSavegameVersion(27)) AfterLoadStations();
|
||||
|
@ -1928,18 +1927,17 @@ bool AfterLoadGame()
|
|||
Station *st;
|
||||
Waypoint *wp;
|
||||
Engine *e;
|
||||
Player *player;
|
||||
Industry *i;
|
||||
Vehicle *v;
|
||||
|
||||
_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
|
||||
_cur_year += ORIGINAL_BASE_YEAR;
|
||||
|
||||
FOR_ALL_STATIONS(st) st->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
|
||||
FOR_ALL_WAYPOINTS(wp) wp->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
|
||||
FOR_ALL_ENGINES(e) e->intro_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
|
||||
FOR_ALL_PLAYERS(player) player->inaugurated_year += ORIGINAL_BASE_YEAR;
|
||||
FOR_ALL_INDUSTRIES(i) i->last_prod_year += ORIGINAL_BASE_YEAR;
|
||||
FOR_ALL_STATIONS(st) st->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
|
||||
FOR_ALL_WAYPOINTS(wp) wp->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
|
||||
FOR_ALL_ENGINES(e) e->intro_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
|
||||
FOR_ALL_COMPANIES(c) c->inaugurated_year += ORIGINAL_BASE_YEAR;
|
||||
FOR_ALL_INDUSTRIES(i) i->last_prod_year += ORIGINAL_BASE_YEAR;
|
||||
|
||||
FOR_ALL_VEHICLES(v) {
|
||||
v->date_of_last_service += DAYS_TILL_ORIGINAL_BASE_YEAR;
|
||||
|
@ -2139,7 +2137,7 @@ bool AfterLoadGame()
|
|||
}
|
||||
}
|
||||
|
||||
if (CheckSavegameVersion(49)) FOR_ALL_PLAYERS(p) p->face = ConvertFromOldPlayerFace(p->face);
|
||||
if (CheckSavegameVersion(49)) FOR_ALL_COMPANIES(c) c->face = ConvertFromOldCompanyManagerFace(c->face);
|
||||
|
||||
if (CheckSavegameVersion(52)) {
|
||||
for (TileIndex t = 0; t < map_size; t++) {
|
||||
|
@ -2337,18 +2335,17 @@ bool AfterLoadGame()
|
|||
}
|
||||
}
|
||||
|
||||
/* Set all share owners to PLAYER_SPECTATOR for
|
||||
* 1) all inactive players
|
||||
* (when inactive players were stored in the savegame - TTD, TTDP and some
|
||||
* *really* old revisions of OTTD; else it is already set in InitializePlayers())
|
||||
* 2) shares that are owned by inactive players or self
|
||||
* (caused by cheating players in earlier revisions) */
|
||||
Player *p;
|
||||
FOR_ALL_PLAYERS(p) {
|
||||
/* Set all share owners to INVALID_COMPANY for
|
||||
* 1) all inactive companies
|
||||
* (when inactive companies were stored in the savegame - TTD, TTDP and some
|
||||
* *really* old revisions of OTTD; else it is already set in InitializeCompanies())
|
||||
* 2) shares that are owned by inactive companies or self
|
||||
* (caused by cheating clients in earlier revisions) */
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
for (uint i = 0; i < 4; i++) {
|
||||
PlayerID o = p->share_owners[i];
|
||||
if (o == PLAYER_SPECTATOR) continue;
|
||||
if (!IsValidPlayerID(o) || o == p->index) p->share_owners[i] = PLAYER_SPECTATOR;
|
||||
CompanyID company = c->share_owners[i];
|
||||
if (company == INVALID_COMPANY) continue;
|
||||
if (!IsValidCompanyID(company) || company == c->index) c->share_owners[i] = INVALID_COMPANY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2396,13 +2393,13 @@ bool AfterLoadGame()
|
|||
|
||||
if (IsBuoyTile(t) || IsDriveThroughStopTile(t) || IsTileType(t, MP_WATER)) {
|
||||
Owner o = GetTileOwner(t);
|
||||
if (o < MAX_PLAYERS && !IsValidPlayerID(o)) {
|
||||
_current_player = o;
|
||||
ChangeTileOwner(t, o, PLAYER_SPECTATOR);
|
||||
if (o < MAX_COMPANIES && !IsValidCompanyID(o)) {
|
||||
_current_company = o;
|
||||
ChangeTileOwner(t, o, INVALID_OWNER);
|
||||
}
|
||||
if (IsBuoyTile(t)) {
|
||||
/* reset buoy owner to OWNER_NONE in the station struct
|
||||
* (even if it is owned by active player) */
|
||||
* (even if it is owned by active company) */
|
||||
GetStationByTile(t)->owner = OWNER_NONE;
|
||||
}
|
||||
} else if (IsTileType(t, MP_ROAD)) {
|
||||
|
@ -2410,13 +2407,13 @@ bool AfterLoadGame()
|
|||
for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
|
||||
/* update even non-existing road types to update tile owner too */
|
||||
Owner o = GetRoadOwner(t, rt);
|
||||
if (o < MAX_PLAYERS && !IsValidPlayerID(o)) SetRoadOwner(t, rt, OWNER_NONE);
|
||||
if (o < MAX_COMPANIES && !IsValidCompanyID(o)) SetRoadOwner(t, rt, OWNER_NONE);
|
||||
}
|
||||
if (IsLevelCrossing(t)) {
|
||||
Owner o = GetTileOwner(t);
|
||||
if (!IsValidPlayerID(o)) {
|
||||
if (!IsValidCompanyID(o)) {
|
||||
/* remove leftover rail piece from crossing (from very old savegames) */
|
||||
_current_player = o;
|
||||
_current_company = o;
|
||||
DoCommand(t, 0, GetCrossingRailTrack(t), DC_EXEC | DC_BANKRUPT, CMD_REMOVE_SINGLE_RAIL);
|
||||
}
|
||||
}
|
||||
|
@ -2551,7 +2548,7 @@ bool AfterLoadGame()
|
|||
Waypoint *wp;
|
||||
FOR_ALL_WAYPOINTS(wp) {
|
||||
Owner owner = (IsRailWaypointTile(wp->xy) ? GetTileOwner(wp->xy) : OWNER_NONE);
|
||||
wp->owner = IsValidPlayerID(owner) ? owner : OWNER_NONE;
|
||||
wp->owner = IsValidCompanyID(owner) ? owner : OWNER_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2566,7 +2563,7 @@ bool AfterLoadGame()
|
|||
/* signs with invalid owner left from older savegames */
|
||||
Sign *si;
|
||||
FOR_ALL_SIGNS(si) {
|
||||
if (si->owner != OWNER_NONE && !IsValidPlayerID(si->owner)) si->owner = OWNER_NONE;
|
||||
if (si->owner != OWNER_NONE && !IsValidCompanyID(si->owner)) si->owner = OWNER_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2598,7 +2595,7 @@ void ReloadNewGRFData()
|
|||
/* Check and update house and town values */
|
||||
UpdateHousesAndTowns();
|
||||
/* Update livery selection windows */
|
||||
for (PlayerID i = PLAYER_FIRST; i < MAX_PLAYERS; i++) InvalidateWindowData(WC_PLAYER_COLOR, i, _loaded_newgrf_features.has_2CC);
|
||||
for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) InvalidateWindowData(WC_COMPANY_COLOR, i, _loaded_newgrf_features.has_2CC);
|
||||
/* redraw the whole screen */
|
||||
MarkWholeScreenDirty();
|
||||
CheckTrainsLengths();
|
||||
|
|
|
@ -285,7 +285,7 @@ void Order::AssignOrder(const Order &other)
|
|||
/**
|
||||
* Delete all news items regarding defective orders about a vehicle
|
||||
* This could kill still valid warnings (for example about void order when just
|
||||
* another order gets added), but assume the player will notice the problems,
|
||||
* another order gets added), but assume the company will notice the problems,
|
||||
* when (s)he's changing the orders.
|
||||
*/
|
||||
static void DeleteOrderWarnings(const Vehicle* v)
|
||||
|
@ -437,7 +437,7 @@ CommandCost CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if (!IsPlayerBuildableVehicleType(v)) return CMD_ERROR;
|
||||
if (!IsCompanyBuildableVehicleType(v)) return CMD_ERROR;
|
||||
}
|
||||
|
||||
if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN && v->type != VEH_ROAD) return CMD_ERROR;
|
||||
|
@ -495,7 +495,7 @@ CommandCost CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
|
||||
if (!HasOrderPoolFree(1)) return_cmd_error(STR_8831_NO_MORE_SPACE_FOR_ORDERS);
|
||||
|
||||
if (v->type == VEH_SHIP && IsHumanPlayer(v->owner) && _settings_game.pf.pathfinder_for_ships != VPF_NPF) {
|
||||
if (v->type == VEH_SHIP && IsHumanCompany(v->owner) && _settings_game.pf.pathfinder_for_ships != VPF_NPF) {
|
||||
/* Make sure the new destination is not too far away from the previous */
|
||||
const Order *prev = NULL;
|
||||
uint n = 0;
|
||||
|
@ -1390,7 +1390,7 @@ void CheckOrders(const Vehicle* v)
|
|||
if (v->FirstShared() != v) return;
|
||||
|
||||
/* Only check every 20 days, so that we don't flood the message log */
|
||||
if (v->owner == _local_player && v->day_counter % 20 == 0) {
|
||||
if (v->owner == _local_company && v->day_counter % 20 == 0) {
|
||||
int n_st, problem_type = -1;
|
||||
const Order *order;
|
||||
int message = 0;
|
||||
|
|
|
@ -279,7 +279,7 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
|
|||
if (_settings_game.order.gotodepot) {
|
||||
switch (GetTileType(tile)) {
|
||||
case MP_RAILWAY:
|
||||
if (v->type == VEH_TRAIN && IsTileOwner(tile, _local_player)) {
|
||||
if (v->type == VEH_TRAIN && IsTileOwner(tile, _local_company)) {
|
||||
if (IsRailDepot(tile)) {
|
||||
order.MakeGoToDepot(GetDepotByTile(tile)->index, ODTFB_PART_OF_ORDERS);
|
||||
if (_settings_client.gui.new_nonstop) order.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
|
||||
|
@ -289,7 +289,7 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
|
|||
break;
|
||||
|
||||
case MP_ROAD:
|
||||
if (IsRoadDepot(tile) && v->type == VEH_ROAD && IsTileOwner(tile, _local_player)) {
|
||||
if (IsRoadDepot(tile) && v->type == VEH_ROAD && IsTileOwner(tile, _local_company)) {
|
||||
order.MakeGoToDepot(GetDepotByTile(tile)->index, ODTFB_PART_OF_ORDERS);
|
||||
if (_settings_client.gui.new_nonstop) order.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
|
||||
return order;
|
||||
|
@ -298,7 +298,7 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
|
|||
|
||||
case MP_STATION:
|
||||
if (v->type != VEH_AIRCRAFT) break;
|
||||
if (IsHangar(tile) && IsTileOwner(tile, _local_player)) {
|
||||
if (IsHangar(tile) && IsTileOwner(tile, _local_company)) {
|
||||
order.MakeGoToDepot(GetStationIndex(tile), ODTFB_PART_OF_ORDERS);
|
||||
return order;
|
||||
}
|
||||
|
@ -306,7 +306,7 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
|
|||
|
||||
case MP_WATER:
|
||||
if (v->type != VEH_SHIP) break;
|
||||
if (IsShipDepot(tile) && IsTileOwner(tile, _local_player)) {
|
||||
if (IsShipDepot(tile) && IsTileOwner(tile, _local_company)) {
|
||||
TileIndex tile2 = GetOtherShipDepotTile(tile);
|
||||
|
||||
order.MakeGoToDepot(GetDepotByTile(tile < tile2 ? tile : tile2)->index, ODTFB_PART_OF_ORDERS);
|
||||
|
@ -321,7 +321,7 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
|
|||
/* check waypoint */
|
||||
if (IsRailWaypointTile(tile) &&
|
||||
v->type == VEH_TRAIN &&
|
||||
IsTileOwner(tile, _local_player)) {
|
||||
IsTileOwner(tile, _local_company)) {
|
||||
order.MakeGoToWaypoint(GetWaypointByTile(tile)->index);
|
||||
if (_settings_client.gui.new_nonstop) order.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
|
||||
return order;
|
||||
|
@ -331,7 +331,7 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
|
|||
StationID st_index = GetStationIndex(tile);
|
||||
const Station *st = GetStation(st_index);
|
||||
|
||||
if (st->owner == _current_player || st->owner == OWNER_NONE) {
|
||||
if (st->owner == _current_company || st->owner == OWNER_NONE) {
|
||||
byte facil;
|
||||
(facil = FACIL_DOCK, v->type == VEH_SHIP) ||
|
||||
(facil = FACIL_TRAIN, v->type == VEH_TRAIN) ||
|
||||
|
@ -668,7 +668,7 @@ public:
|
|||
int sel = OrderGetSel();
|
||||
const Order *order = GetVehicleOrder(this->vehicle, sel);
|
||||
|
||||
if (this->vehicle->owner == _local_player) {
|
||||
if (this->vehicle->owner == _local_company) {
|
||||
/* Set the strings for the dropdown boxes. */
|
||||
this->widget[ORDER_WIDGET_COND_VARIABLE].data = _order_conditional_variable[order == NULL ? 0 : order->GetConditionVariable()];
|
||||
this->widget[ORDER_WIDGET_COND_COMPARATOR].data = _order_conditional_condition[order == NULL ? 0 : order->GetConditionComparator()];
|
||||
|
@ -833,7 +833,7 @@ public:
|
|||
/* Select clicked order */
|
||||
this->selected_order = sel;
|
||||
|
||||
if (this->vehicle->owner == _local_player) {
|
||||
if (this->vehicle->owner == _local_company) {
|
||||
/* Activate drag and drop */
|
||||
SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, VHM_DRAG, this);
|
||||
}
|
||||
|
@ -1007,7 +1007,7 @@ public:
|
|||
//('?', OrderClick_Service},
|
||||
};
|
||||
|
||||
if (this->vehicle->owner != _local_player) return ES_NOT_HANDLED;
|
||||
if (this->vehicle->owner != _local_company) return ES_NOT_HANDLED;
|
||||
|
||||
for (uint i = 0; i < lengthof(keytoevent); i++) {
|
||||
if (keycode == keytoevent[i].keycode) {
|
||||
|
@ -1093,7 +1093,7 @@ public:
|
|||
};
|
||||
|
||||
/**
|
||||
* Widget definition for player train orders
|
||||
* Widget definition for "your" train orders
|
||||
*/
|
||||
static const Widget _orders_train_widgets[] = {
|
||||
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_GREY, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // ORDER_WIDGET_CLOSEBOX
|
||||
|
@ -1136,7 +1136,7 @@ static const WindowDesc _orders_train_desc = {
|
|||
};
|
||||
|
||||
/**
|
||||
* Widget definition for player orders (!train)
|
||||
* Widget definition for "your" orders (!train)
|
||||
*/
|
||||
static const Widget _orders_widgets[] = {
|
||||
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_GREY, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // ORDER_WIDGET_CLOSEBOX
|
||||
|
@ -1228,7 +1228,7 @@ void ShowOrdersWindow(const Vehicle *v)
|
|||
DeleteWindowById(WC_VEHICLE_ORDERS, veh);
|
||||
DeleteWindowById(WC_VEHICLE_DETAILS, veh);
|
||||
|
||||
if (v->owner != _local_player) {
|
||||
if (v->owner != _local_company) {
|
||||
new OrdersWindow(&_other_orders_desc, v);
|
||||
} else {
|
||||
new OrdersWindow((v->type == VEH_TRAIN || v->type == VEH_ROAD) ? &_orders_train_desc : &_orders_desc, v);
|
||||
|
|
|
@ -72,7 +72,7 @@ enum OrderNonStopFlags {
|
|||
* Reasons that could cause us to go to the depot.
|
||||
*/
|
||||
enum OrderDepotTypeFlags {
|
||||
ODTF_MANUAL = 0, ///< The player initiated this order manually.
|
||||
ODTF_MANUAL = 0, ///< Manually initiated order.
|
||||
ODTFB_SERVICE = 1 << 0, ///< This depot order is because of the servicing limit.
|
||||
ODTFB_PART_OF_ORDERS = 1 << 1, ///< This depot order is because of a regular order.
|
||||
};
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
/* $Id$ */
|
||||
|
||||
/** @file player_base.h Definition of stuff that is very close to a player, like the player struct itself. */
|
||||
/** @file company_base.h Definition of stuff that is very close to a company, like the company struct itself. */
|
||||
|
||||
#ifndef PLAYER_BASE_H
|
||||
#define PLAYER_BASE_H
|
||||
#ifndef COMPANY_BASE_H
|
||||
#define COMPANY_BASE_H
|
||||
|
||||
#include "player_type.h"
|
||||
#include "oldpool.h"
|
||||
|
@ -16,23 +16,23 @@
|
|||
#include "economy_type.h"
|
||||
#include "tile_type.h"
|
||||
|
||||
struct PlayerEconomyEntry {
|
||||
struct CompanyEconomyEntry {
|
||||
Money income;
|
||||
Money expenses;
|
||||
int32 delivered_cargo;
|
||||
int32 performance_history; ///< player score (scale 0-1000)
|
||||
int32 performance_history; ///< company score (scale 0-1000)
|
||||
Money company_value;
|
||||
};
|
||||
|
||||
/* The third parameter and the number after >> MUST be the same,
|
||||
* otherwise more (or less) players will be allowed to be
|
||||
* created than what MAX_PLAYER specifies!
|
||||
* otherwise more (or less) companies will be allowed to be
|
||||
* created than what MAX_COMPANIES specifies!
|
||||
*/
|
||||
DECLARE_OLD_POOL(Player, Player, 1, MAX_PLAYERS >> 1)
|
||||
DECLARE_OLD_POOL(Company, Company, 1, MAX_COMPANIES >> 1)
|
||||
|
||||
struct Player : PoolItem<Player, PlayerByte, &_Player_pool> {
|
||||
Player(uint16 name_1 = 0, bool is_ai = false);
|
||||
~Player();
|
||||
struct Company : PoolItem<Company, CompanyByte, &_Company_pool> {
|
||||
Company(uint16 name_1 = 0, bool is_ai = false);
|
||||
~Company();
|
||||
|
||||
uint32 name_2;
|
||||
uint16 name_1;
|
||||
|
@ -42,14 +42,14 @@ struct Player : PoolItem<Player, PlayerByte, &_Player_pool> {
|
|||
uint32 president_name_2;
|
||||
char *president_name;
|
||||
|
||||
PlayerFace face;
|
||||
CompanyManagerFace face;
|
||||
|
||||
Money player_money;
|
||||
Money money;
|
||||
byte money_fraction;
|
||||
Money current_loan;
|
||||
|
||||
byte player_color;
|
||||
byte colour;
|
||||
Livery livery[LS_END];
|
||||
byte player_money_fraction;
|
||||
RailTypes avail_railtypes;
|
||||
RoadTypes avail_roadtypes;
|
||||
byte block_preview;
|
||||
|
@ -59,49 +59,49 @@ struct Player : PoolItem<Player, PlayerByte, &_Player_pool> {
|
|||
TileIndex location_of_HQ;
|
||||
TileIndex last_build_coordinate;
|
||||
|
||||
PlayerByte share_owners[4];
|
||||
OwnerByte share_owners[4];
|
||||
|
||||
Year inaugurated_year;
|
||||
byte num_valid_stat_ent;
|
||||
|
||||
byte quarters_of_bankrupcy;
|
||||
byte bankrupt_asked; ///< which players were asked about buying it?
|
||||
byte bankrupt_asked; ///< which companies were asked about buying it?
|
||||
int16 bankrupt_timeout;
|
||||
Money bankrupt_value;
|
||||
|
||||
bool is_ai;
|
||||
|
||||
Money yearly_expenses[3][EXPENSES_END];
|
||||
PlayerEconomyEntry cur_economy;
|
||||
PlayerEconomyEntry old_economy[24];
|
||||
CompanyEconomyEntry cur_economy;
|
||||
CompanyEconomyEntry old_economy[24];
|
||||
EngineRenewList engine_renew_list; ///< Defined later
|
||||
bool engine_renew;
|
||||
bool renew_keep_length;
|
||||
int16 engine_renew_months;
|
||||
uint32 engine_renew_money;
|
||||
uint16 *num_engines; ///< caches the number of engines of each type the player owns (no need to save this)
|
||||
uint16 *num_engines; ///< caches the number of engines of each type the company owns (no need to save this)
|
||||
|
||||
inline bool IsValid() const { return this->name_1 != 0; }
|
||||
};
|
||||
|
||||
static inline bool IsValidPlayerID(PlayerID index)
|
||||
static inline bool IsValidCompanyID(CompanyID company)
|
||||
{
|
||||
return (uint)index < GetPlayerPoolSize() && GetPlayer(index)->IsValid();
|
||||
return (uint)company < GetCompanyPoolSize() && GetCompany(company)->IsValid();
|
||||
}
|
||||
|
||||
#define FOR_ALL_PLAYERS_FROM(d, start) for (d = GetPlayer(start); d != NULL; d = (d->index + 1U < GetPlayerPoolSize()) ? GetPlayer(d->index + 1U) : NULL) if (d->IsValid())
|
||||
#define FOR_ALL_PLAYERS(d) FOR_ALL_PLAYERS_FROM(d, 0)
|
||||
#define FOR_ALL_COMPANIES_FROM(d, start) for (d = GetCompany(start); d != NULL; d = (d->index + 1U < GetCompanyPoolSize()) ? GetCompany(d->index + 1U) : NULL) if (d->IsValid())
|
||||
#define FOR_ALL_COMPANIES(d) FOR_ALL_COMPANIES_FROM(d, 0)
|
||||
|
||||
static inline byte ActivePlayerCount()
|
||||
static inline byte ActiveCompanyCount()
|
||||
{
|
||||
const Player *p;
|
||||
const Company *c;
|
||||
byte count = 0;
|
||||
|
||||
FOR_ALL_PLAYERS(p) count++;
|
||||
FOR_ALL_COMPANIES(c) count++;
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
Money CalculateCompanyValue(const Player *p);
|
||||
Money CalculateCompanyValue(const Company *c);
|
||||
|
||||
#endif /* PLAYER_BASE_H */
|
||||
#endif /* COMPANY_BASE_H */
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
/* $Id$ */
|
||||
|
||||
/** @file player_face.h Functionality related to the player's face */
|
||||
/** @file company_manager_face.h Functionality related to the company manager's face */
|
||||
|
||||
#ifndef PLAYER_FACE_H
|
||||
#define PLAYER_FACE_H
|
||||
#ifndef COMPANY_MANAGER_FACE_H
|
||||
#define COMPANY_MANAGER_FACE_H
|
||||
|
||||
#include "core/random_func.hpp"
|
||||
#include "core/bitmath_func.hpp"
|
||||
|
@ -21,214 +21,214 @@ enum GenderEthnicity {
|
|||
};
|
||||
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity); ///< See GenderRace as a bitset
|
||||
|
||||
/** Bitgroups of the PlayerFace variable */
|
||||
enum PlayerFaceVariable {
|
||||
PFV_GENDER,
|
||||
PFV_ETHNICITY,
|
||||
PFV_GEN_ETHN,
|
||||
PFV_HAS_MOUSTACHE,
|
||||
PFV_HAS_TIE_EARRING,
|
||||
PFV_HAS_GLASSES,
|
||||
PFV_EYE_COLOUR,
|
||||
PFV_CHEEKS,
|
||||
PFV_CHIN,
|
||||
PFV_EYEBROWS,
|
||||
PFV_MOUSTACHE,
|
||||
PFV_LIPS,
|
||||
PFV_NOSE,
|
||||
PFV_HAIR,
|
||||
PFV_JACKET,
|
||||
PFV_COLLAR,
|
||||
PFV_TIE_EARRING,
|
||||
PFV_GLASSES,
|
||||
PFV_END
|
||||
/** Bitgroups of the CompanyManagerFace variable */
|
||||
enum CompanyManagerFaceVariable {
|
||||
CMFV_GENDER,
|
||||
CMFV_ETHNICITY,
|
||||
CMFV_GEN_ETHN,
|
||||
CMFV_HAS_MOUSTACHE,
|
||||
CMFV_HAS_TIE_EARRING,
|
||||
CMFV_HAS_GLASSES,
|
||||
CMFV_EYE_COLOUR,
|
||||
CMFV_CHEEKS,
|
||||
CMFV_CHIN,
|
||||
CMFV_EYEBROWS,
|
||||
CMFV_MOUSTACHE,
|
||||
CMFV_LIPS,
|
||||
CMFV_NOSE,
|
||||
CMFV_HAIR,
|
||||
CMFV_JACKET,
|
||||
CMFV_COLLAR,
|
||||
CMFV_TIE_EARRING,
|
||||
CMFV_GLASSES,
|
||||
CMFV_END
|
||||
};
|
||||
DECLARE_POSTFIX_INCREMENT(PlayerFaceVariable);
|
||||
DECLARE_POSTFIX_INCREMENT(CompanyManagerFaceVariable);
|
||||
|
||||
/** Information about the valid values of PlayerFace bitgroups as well as the sprites to draw */
|
||||
struct PlayerFaceBitsInfo {
|
||||
byte offset; ///< Offset in bits into the PlayerFace
|
||||
byte length; ///< Number of bits used in the PlayerFace
|
||||
/** Information about the valid values of CompanyManagerFace bitgroups as well as the sprites to draw */
|
||||
struct CompanyManagerFaceBitsInfo {
|
||||
byte offset; ///< Offset in bits into the CompanyManagerFace
|
||||
byte length; ///< Number of bits used in the CompanyManagerFace
|
||||
byte valid_values[GE_END]; ///< The number of valid values per gender/ethnicity
|
||||
SpriteID first_sprite[GE_END]; ///< The first sprite per gender/ethnicity
|
||||
};
|
||||
|
||||
/** Lookup table for indices into the PlayerFace, valid ranges and sprites */
|
||||
static const PlayerFaceBitsInfo _pf_info[] = {
|
||||
/** Lookup table for indices into the CompanyManagerFace, valid ranges and sprites */
|
||||
static const CompanyManagerFaceBitsInfo _cmf_info[] = {
|
||||
/* Index off len WM WF BM BF WM WF BM BF */
|
||||
/* PFV_GENDER */ { 0, 1, { 2, 2, 2, 2 }, { 0, 0, 0, 0 } }, ///< 0 = male, 1 = female
|
||||
/* PFV_ETHNICITY */ { 1, 2, { 2, 2, 2, 2 }, { 0, 0, 0, 0 } }, ///< 0 = (Western-)Caucasian, 1 = African(-American)/Black
|
||||
/* PFV_GEN_ETHN */ { 0, 3, { 4, 4, 4, 4 }, { 0, 0, 0, 0 } }, ///< Shortcut to get/set gender _and_ ethnicity
|
||||
/* PFV_HAS_MOUSTACHE */ { 3, 1, { 2, 0, 2, 0 }, { 0, 0, 0, 0 } }, ///< Females do not have a moustache
|
||||
/* PFV_HAS_TIE_EARRING */ { 3, 1, { 0, 2, 0, 2 }, { 0, 0, 0, 0 } }, ///< Draw the earring for females or not. For males the tie is always drawn.
|
||||
/* PFV_HAS_GLASSES */ { 4, 1, { 2, 2, 2, 2 }, { 0, 0, 0, 0 } }, ///< Whether to draw glasses or not
|
||||
/* PFV_EYE_COLOUR */ { 5, 2, { 3, 3, 1, 1 }, { 0, 0, 0, 0 } }, ///< Palette modification
|
||||
/* PFV_CHEEKS */ { 0, 0, { 1, 1, 1, 1 }, { 0x325, 0x326, 0x390, 0x3B0 } }, ///< Cheeks are only indexed by their gender/ethnicity
|
||||
/* PFV_CHIN */ { 7, 2, { 4, 1, 2, 2 }, { 0x327, 0x327, 0x391, 0x3B1 } },
|
||||
/* PFV_EYEBROWS */ { 9, 4, { 12, 16, 11, 16 }, { 0x32B, 0x337, 0x39A, 0x3B8 } },
|
||||
/* PFV_MOUSTACHE */ { 13, 2, { 3, 0, 3, 0 }, { 0x367, 0, 0x397, 0 } }, ///< Depends on PFV_HAS_MOUSTACHE
|
||||
/* PFV_LIPS */ { 13, 4, { 12, 10, 9, 9 }, { 0x35B, 0x351, 0x3A5, 0x3C8 } }, ///< Depends on !PFV_HAS_MOUSTACHE
|
||||
/* PFV_NOSE */ { 17, 3, { 8, 4, 4, 5 }, { 0x349, 0x34C, 0x393, 0x3B3 } }, ///< Depends on !PFV_HAS_MOUSTACHE
|
||||
/* PFV_HAIR */ { 20, 4, { 9, 5, 5, 4 }, { 0x382, 0x38B, 0x3D4, 0x3D9 } },
|
||||
/* PFV_JACKET */ { 24, 2, { 3, 3, 3, 3 }, { 0x36B, 0x378, 0x36B, 0x378 } },
|
||||
/* PFV_COLLAR */ { 26, 2, { 4, 4, 4, 4 }, { 0x36E, 0x37B, 0x36E, 0x37B } },
|
||||
/* PFV_TIE_EARRING */ { 28, 3, { 6, 3, 6, 3 }, { 0x372, 0x37F, 0x372, 0x3D1 } }, ///< Depends on PFV_HAS_TIE_EARRING
|
||||
/* PFV_GLASSES */ { 31, 1, { 2, 2, 2, 2 }, { 0x347, 0x347, 0x3AE, 0x3AE } } ///< Depends on PFV_HAS_GLASSES
|
||||
/* CMFV_GENDER */ { 0, 1, { 2, 2, 2, 2 }, { 0, 0, 0, 0 } }, ///< 0 = male, 1 = female
|
||||
/* CMFV_ETHNICITY */ { 1, 2, { 2, 2, 2, 2 }, { 0, 0, 0, 0 } }, ///< 0 = (Western-)Caucasian, 1 = African(-American)/Black
|
||||
/* CMFV_GEN_ETHN */ { 0, 3, { 4, 4, 4, 4 }, { 0, 0, 0, 0 } }, ///< Shortcut to get/set gender _and_ ethnicity
|
||||
/* CMFV_HAS_MOUSTACHE */ { 3, 1, { 2, 0, 2, 0 }, { 0, 0, 0, 0 } }, ///< Females do not have a moustache
|
||||
/* CMFV_HAS_TIE_EARRING */ { 3, 1, { 0, 2, 0, 2 }, { 0, 0, 0, 0 } }, ///< Draw the earring for females or not. For males the tie is always drawn.
|
||||
/* CMFV_HAS_GLASSES */ { 4, 1, { 2, 2, 2, 2 }, { 0, 0, 0, 0 } }, ///< Whether to draw glasses or not
|
||||
/* CMFV_EYE_COLOUR */ { 5, 2, { 3, 3, 1, 1 }, { 0, 0, 0, 0 } }, ///< Palette modification
|
||||
/* CMFV_CHEEKS */ { 0, 0, { 1, 1, 1, 1 }, { 0x325, 0x326, 0x390, 0x3B0 } }, ///< Cheeks are only indexed by their gender/ethnicity
|
||||
/* CMFV_CHIN */ { 7, 2, { 4, 1, 2, 2 }, { 0x327, 0x327, 0x391, 0x3B1 } },
|
||||
/* CMFV_EYEBROWS */ { 9, 4, { 12, 16, 11, 16 }, { 0x32B, 0x337, 0x39A, 0x3B8 } },
|
||||
/* CMFV_MOUSTACHE */ { 13, 2, { 3, 0, 3, 0 }, { 0x367, 0, 0x397, 0 } }, ///< Depends on CMFV_HAS_MOUSTACHE
|
||||
/* CMFV_LIPS */ { 13, 4, { 12, 10, 9, 9 }, { 0x35B, 0x351, 0x3A5, 0x3C8 } }, ///< Depends on !CMFV_HAS_MOUSTACHE
|
||||
/* CMFV_NOSE */ { 17, 3, { 8, 4, 4, 5 }, { 0x349, 0x34C, 0x393, 0x3B3 } }, ///< Depends on !CMFV_HAS_MOUSTACHE
|
||||
/* CMFV_HAIR */ { 20, 4, { 9, 5, 5, 4 }, { 0x382, 0x38B, 0x3D4, 0x3D9 } },
|
||||
/* CMFV_JACKET */ { 24, 2, { 3, 3, 3, 3 }, { 0x36B, 0x378, 0x36B, 0x378 } },
|
||||
/* CMFV_COLLAR */ { 26, 2, { 4, 4, 4, 4 }, { 0x36E, 0x37B, 0x36E, 0x37B } },
|
||||
/* CMFV_TIE_EARRING */ { 28, 3, { 6, 3, 6, 3 }, { 0x372, 0x37F, 0x372, 0x3D1 } }, ///< Depends on CMFV_HAS_TIE_EARRING
|
||||
/* CMFV_GLASSES */ { 31, 1, { 2, 2, 2, 2 }, { 0x347, 0x347, 0x3AE, 0x3AE } } ///< Depends on CMFV_HAS_GLASSES
|
||||
};
|
||||
assert_compile(lengthof(_pf_info) == PFV_END);
|
||||
assert_compile(lengthof(_cmf_info) == CMFV_END);
|
||||
|
||||
/**
|
||||
* Gets the player's face bits for the given player face variable
|
||||
* @param pf the face to extract the bits from
|
||||
* @param pfv the face variable to get the data of
|
||||
* @param ge the gender and ethnicity of the face
|
||||
* @pre _pf_info[pfv].valid_values[ge] != 0
|
||||
* Gets the company manager's face bits for the given company manager's face variable
|
||||
* @param cmf the face to extract the bits from
|
||||
* @param cmfv the face variable to get the data of
|
||||
* @param ge the gender and ethnicity of the face
|
||||
* @pre _cmf_info[cmfv].valid_values[ge] != 0
|
||||
* @return the requested bits
|
||||
*/
|
||||
static inline uint GetPlayerFaceBits(PlayerFace pf, PlayerFaceVariable pfv, GenderEthnicity ge)
|
||||
static inline uint GetCompanyManagerFaceBits(CompanyManagerFace cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge)
|
||||
{
|
||||
assert(_pf_info[pfv].valid_values[ge] != 0);
|
||||
assert(_cmf_info[cmfv].valid_values[ge] != 0);
|
||||
|
||||
return GB(pf, _pf_info[pfv].offset, _pf_info[pfv].length);
|
||||
return GB(cmf, _cmf_info[cmfv].offset, _cmf_info[cmfv].length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the player's face bits for the given player face variable
|
||||
* @param pf the face to write the bits to
|
||||
* @param pfv the face variable to write the data of
|
||||
* @param ge the gender and ethnicity of the face
|
||||
* @param val the new value
|
||||
* @pre val < _pf_info[pfv].valid_values[ge]
|
||||
* Sets the company manager's face bits for the given company manager's face variable
|
||||
* @param cmf the face to write the bits to
|
||||
* @param cmfv the face variable to write the data of
|
||||
* @param ge the gender and ethnicity of the face
|
||||
* @param val the new value
|
||||
* @pre val < _cmf_info[cmfv].valid_values[ge]
|
||||
*/
|
||||
static inline void SetPlayerFaceBits(PlayerFace &pf, PlayerFaceVariable pfv, GenderEthnicity ge, uint val)
|
||||
static inline void SetCompanyManagerFaceBits(CompanyManagerFace &cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge, uint val)
|
||||
{
|
||||
assert(val < _pf_info[pfv].valid_values[ge]);
|
||||
assert(val < _cmf_info[cmfv].valid_values[ge]);
|
||||
|
||||
SB(pf, _pf_info[pfv].offset, _pf_info[pfv].length, val);
|
||||
SB(cmf, _cmf_info[cmfv].offset, _cmf_info[cmfv].length, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase/Decrease the player face variable by the given amount.
|
||||
* Increase/Decrease the company manager's face variable by the given amount.
|
||||
* If the new value greater than the max value for this variable it will be set to 0.
|
||||
* Or is it negativ (< 0) it will be set to max value.
|
||||
*
|
||||
* @param pf the player face to write the bits to
|
||||
* @param pfv the player face variable to write the data of
|
||||
* @param ge the gender and ethnicity of the player face
|
||||
* @param cmf the company manager face to write the bits to
|
||||
* @param cmfv the company manager face variable to write the data of
|
||||
* @param ge the gender and ethnicity of the company manager's face
|
||||
* @param amount the amount which change the value
|
||||
*
|
||||
* @pre 0 <= val < _pf_info[pfv].valid_values[ge]
|
||||
* @pre 0 <= val < _cmf_info[cmfv].valid_values[ge]
|
||||
*/
|
||||
static inline void IncreasePlayerFaceBits(PlayerFace &pf, PlayerFaceVariable pfv, GenderEthnicity ge, int8 amount)
|
||||
static inline void IncreaseCompanyManagerFaceBits(CompanyManagerFace &cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge, int8 amount)
|
||||
{
|
||||
int8 val = GetPlayerFaceBits(pf, pfv, ge) + amount; // the new value for the pfv
|
||||
int8 val = GetCompanyManagerFaceBits(cmf, cmfv, ge) + amount; // the new value for the cmfv
|
||||
|
||||
/* scales the new value to the correct scope */
|
||||
if (val >= _pf_info[pfv].valid_values[ge]) {
|
||||
if (val >= _cmf_info[cmfv].valid_values[ge]) {
|
||||
val = 0;
|
||||
} else if (val < 0) {
|
||||
val = _pf_info[pfv].valid_values[ge] - 1;
|
||||
val = _cmf_info[cmfv].valid_values[ge] - 1;
|
||||
}
|
||||
|
||||
SetPlayerFaceBits(pf, pfv, ge, val); // save the new value
|
||||
SetCompanyManagerFaceBits(cmf, cmfv, ge, val); // save the new value
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the player bits have a valid range
|
||||
* @param pf the face to extract the bits from
|
||||
* @param pfv the face variable to get the data of
|
||||
* @param ge the gender and ethnicity of the face
|
||||
* Checks whether the company manager's face bits have a valid range
|
||||
* @param cmf the face to extract the bits from
|
||||
* @param cmfv the face variable to get the data of
|
||||
* @param ge the gender and ethnicity of the face
|
||||
* @return true if and only if the bits are valid
|
||||
*/
|
||||
static inline bool ArePlayerFaceBitsValid(PlayerFace pf, PlayerFaceVariable pfv, GenderEthnicity ge)
|
||||
static inline bool AreCompanyManagerFaceBitsValid(CompanyManagerFace cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge)
|
||||
{
|
||||
return GB(pf, _pf_info[pfv].offset, _pf_info[pfv].length) < _pf_info[pfv].valid_values[ge];
|
||||
return GB(cmf, _cmf_info[cmfv].offset, _cmf_info[cmfv].length) < _cmf_info[cmfv].valid_values[ge];
|
||||
}
|
||||
|
||||
/**
|
||||
* Scales a player face bits variable to the correct scope
|
||||
* @param pfv the face variable to write the data of
|
||||
* Scales a company manager's face bits variable to the correct scope
|
||||
* @param cmfv the face variable to write the data of
|
||||
* @param ge the gender and ethnicity of the face
|
||||
* @param val the to value to scale
|
||||
* @pre val < (1U << _pf_info[pfv].length), i.e. val has a value of 0..2^(bits used for this variable)-1
|
||||
* @pre val < (1U << _cmf_info[cmfv].length), i.e. val has a value of 0..2^(bits used for this variable)-1
|
||||
* @return the scaled value
|
||||
*/
|
||||
static inline uint ScalePlayerFaceValue(PlayerFaceVariable pfv, GenderEthnicity ge, uint val)
|
||||
static inline uint ScaleCompanyManagerFaceValue(CompanyManagerFaceVariable cmfv, GenderEthnicity ge, uint val)
|
||||
{
|
||||
assert(val < (1U << _pf_info[pfv].length));
|
||||
assert(val < (1U << _cmf_info[cmfv].length));
|
||||
|
||||
return (val * _pf_info[pfv].valid_values[ge]) >> _pf_info[pfv].length;
|
||||
return (val * _cmf_info[cmfv].valid_values[ge]) >> _cmf_info[cmfv].length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scales all player face bits to the correct scope
|
||||
* Scales all company manager's face bits to the correct scope
|
||||
*
|
||||
* @param pf the player face to write the bits to
|
||||
* @param cmf the company manager's face to write the bits to
|
||||
*/
|
||||
static inline void ScaleAllPlayerFaceBits(PlayerFace &pf)
|
||||
static inline void ScaleAllCompanyManagerFaceBits(CompanyManagerFace &cmf)
|
||||
{
|
||||
IncreasePlayerFaceBits(pf, PFV_ETHNICITY, GE_WM, 0); // scales the ethnicity
|
||||
IncreaseCompanyManagerFaceBits(cmf, CMFV_ETHNICITY, GE_WM, 0); // scales the ethnicity
|
||||
|
||||
GenderEthnicity ge = (GenderEthnicity)GB(pf, _pf_info[PFV_GEN_ETHN].offset, _pf_info[PFV_GEN_ETHN].length); // gender & ethnicity of the face
|
||||
GenderEthnicity ge = (GenderEthnicity)GB(cmf, _cmf_info[CMFV_GEN_ETHN].offset, _cmf_info[CMFV_GEN_ETHN].length); // gender & ethnicity of the face
|
||||
|
||||
/* Is a male face with moustache. Need to reduce CPU load in the loop. */
|
||||
bool is_moust_male = !HasBit(ge, GENDER_FEMALE) && GetPlayerFaceBits(pf, PFV_HAS_MOUSTACHE, ge) != 0;
|
||||
bool is_moust_male = !HasBit(ge, GENDER_FEMALE) && GetCompanyManagerFaceBits(cmf, CMFV_HAS_MOUSTACHE, ge) != 0;
|
||||
|
||||
for (PlayerFaceVariable pfv = PFV_EYE_COLOUR; pfv < PFV_END; pfv++) { // scales all other variables
|
||||
for (CompanyManagerFaceVariable cmfv = CMFV_EYE_COLOUR; cmfv < CMFV_END; cmfv++) { // scales all other variables
|
||||
|
||||
/* The moustache variable will be scaled only if it is a male face with has a moustache */
|
||||
if (pfv != PFV_MOUSTACHE || is_moust_male) {
|
||||
IncreasePlayerFaceBits(pf, pfv, ge, 0);
|
||||
if (cmfv != CMFV_MOUSTACHE || is_moust_male) {
|
||||
IncreaseCompanyManagerFaceBits(cmf, cmfv, ge, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a random new face.
|
||||
* If it is for the advanced player face window then the new face have the same gender
|
||||
* If it is for the advanced company manager's face window then the new face have the same gender
|
||||
* and ethnicity as the old one, else the gender is equal and the ethnicity is random.
|
||||
*
|
||||
* @param pf the player face to write the bits to
|
||||
* @param ge the gender and ethnicity of the old player face
|
||||
* @param adv if it for the advanced player face window
|
||||
* @param cmf the company manager's face to write the bits to
|
||||
* @param ge the gender and ethnicity of the old company manager's face
|
||||
* @param adv if it for the advanced company manager's face window
|
||||
*
|
||||
* @pre scale 'ge' to a valid gender/ethnicity combination
|
||||
*/
|
||||
static inline void RandomPlayerFaceBits(PlayerFace &pf, GenderEthnicity ge, bool adv)
|
||||
static inline void RandomCompanyManagerFaceBits(CompanyManagerFace &cmf, GenderEthnicity ge, bool adv)
|
||||
{
|
||||
pf = InteractiveRandom(); // random all player face bits
|
||||
cmf = InteractiveRandom(); // random all company manager's face bits
|
||||
|
||||
/* scale ge: 0 == GE_WM, 1 == GE_WF, 2 == GE_BM, 3 == GE_BF (and maybe in future: ...) */
|
||||
ge = (GenderEthnicity)((uint)ge % GE_END);
|
||||
|
||||
/* set the gender (and ethnicity) for the new player face */
|
||||
/* set the gender (and ethnicity) for the new company manager's face */
|
||||
if (adv) {
|
||||
SetPlayerFaceBits(pf, PFV_GEN_ETHN, ge, ge);
|
||||
SetCompanyManagerFaceBits(cmf, CMFV_GEN_ETHN, ge, ge);
|
||||
} else {
|
||||
SetPlayerFaceBits(pf, PFV_GENDER, ge, HasBit(ge, GENDER_FEMALE));
|
||||
SetCompanyManagerFaceBits(cmf, CMFV_GENDER, ge, HasBit(ge, GENDER_FEMALE));
|
||||
}
|
||||
|
||||
/* scales all player face bits to the correct scope */
|
||||
ScaleAllPlayerFaceBits(pf);
|
||||
/* scales all company manager's face bits to the correct scope */
|
||||
ScaleAllCompanyManagerFaceBits(cmf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the sprite to draw for the given player face variable
|
||||
* @param pf the face to extract the data from
|
||||
* @param pfv the face variable to get the sprite of
|
||||
* @param ge the gender and ethnicity of the face
|
||||
* @pre _pf_info[pfv].valid_values[ge] != 0
|
||||
* Gets the sprite to draw for the given company manager's face variable
|
||||
* @param cmf the face to extract the data from
|
||||
* @param cmfv the face variable to get the sprite of
|
||||
* @param ge the gender and ethnicity of the face
|
||||
* @pre _cmf_info[cmfv].valid_values[ge] != 0
|
||||
* @return sprite to draw
|
||||
*/
|
||||
static inline SpriteID GetPlayerFaceSprite(PlayerFace pf, PlayerFaceVariable pfv, GenderEthnicity ge)
|
||||
static inline SpriteID GetCompanyManagerFaceSprite(CompanyManagerFace cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge)
|
||||
{
|
||||
assert(_pf_info[pfv].valid_values[ge] != 0);
|
||||
assert(_cmf_info[cmfv].valid_values[ge] != 0);
|
||||
|
||||
return _pf_info[pfv].first_sprite[ge] + GB(pf, _pf_info[pfv].offset, _pf_info[pfv].length);
|
||||
return _cmf_info[cmfv].first_sprite[ge] + GB(cmf, _cmf_info[cmfv].offset, _cmf_info[cmfv].length);
|
||||
}
|
||||
|
||||
void DrawPlayerFace(PlayerFace face, int color, int x, int y);
|
||||
PlayerFace ConvertFromOldPlayerFace(uint32 face);
|
||||
bool IsValidPlayerIDFace(PlayerFace pf);
|
||||
void DrawCompanyManagerFace(CompanyManagerFace face, int color, int x, int y);
|
||||
CompanyManagerFace ConvertFromOldCompanyManagerFace(uint32 face);
|
||||
bool IsValidCompanyManagerFace(CompanyManagerFace cmf);
|
||||
|
||||
#endif /* PLAYER_FACE_H */
|
||||
#endif /* COMPANY_MANAGER_FACE_H */
|
||||
|
|
|
@ -1,49 +1,49 @@
|
|||
/* $Id$ */
|
||||
|
||||
/** @file player_func.h Functions related to players. */
|
||||
/** @file company_func.h Functions related to companies. */
|
||||
|
||||
#ifndef PLAYER_FUNC_H
|
||||
#define PLAYER_FUNC_H
|
||||
#ifndef COMPANY_FUNC_H
|
||||
#define COMPANY_FUNC_H
|
||||
|
||||
#include "core/math_func.hpp"
|
||||
#include "player_type.h"
|
||||
#include "tile_type.h"
|
||||
#include "strings_type.h"
|
||||
|
||||
void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player);
|
||||
void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner);
|
||||
void GetNameOfOwner(Owner owner, TileIndex tile);
|
||||
void SetLocalPlayer(PlayerID new_player);
|
||||
void SetLocalCompany(CompanyID new_company);
|
||||
|
||||
extern PlayerByte _local_player;
|
||||
extern PlayerByte _current_player;
|
||||
/* NOSAVE: can be determined from player structs */
|
||||
extern byte _player_colors[MAX_PLAYERS];
|
||||
extern PlayerFace _player_face; ///< for player face storage in openttd.cfg
|
||||
extern CompanyByte _local_company;
|
||||
extern CompanyByte _current_company;
|
||||
|
||||
bool IsHumanPlayer(PlayerID pi);
|
||||
extern byte _company_colours[MAX_COMPANIES]; ///< NOSAVE: can be determined from company structs
|
||||
extern CompanyManagerFace _company_manager_face; ///< for company manager face storage in openttd.cfg
|
||||
|
||||
static inline bool IsLocalPlayer()
|
||||
bool IsHumanCompany(CompanyID company);
|
||||
|
||||
static inline bool IsLocalCompany()
|
||||
{
|
||||
return _local_player == _current_player;
|
||||
return _local_company == _current_company;
|
||||
}
|
||||
|
||||
static inline bool IsInteractivePlayer(PlayerID pi)
|
||||
static inline bool IsInteractiveCompany(CompanyID company)
|
||||
{
|
||||
return pi == _local_player;
|
||||
return company == _local_company;
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct HighScore {
|
||||
char company[100];
|
||||
StringID title; ///< NO_SAVE, has troubles with changing string-numbers.
|
||||
StringID title; ///< NOSAVE, has troubles with changing string-numbers.
|
||||
uint16 score; ///< do NOT change type, will break hs.dat
|
||||
};
|
||||
|
||||
extern HighScore _highscore_table[5][5]; // 4 difficulty-settings (+ network); top 5
|
||||
void SaveToHighScore();
|
||||
void LoadFromHighScore();
|
||||
int8 SaveHighScoreValue(const Player *p);
|
||||
int8 SaveHighScoreValue(const Company *p);
|
||||
int8 SaveHighScoreValueNetwork();
|
||||
|
||||
#endif /* PLAYER_FUNC_H */
|
||||
#endif /* COMPANY_FUNC_H */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,20 +1,20 @@
|
|||
/* $Id$ */
|
||||
|
||||
/** @file player_gui.h GUI Functions related to players. */
|
||||
/** @file company_gui.h GUI Functions related to companies. */
|
||||
|
||||
#ifndef PLAYER_GUI_H
|
||||
#define PLAYER_GUI_H
|
||||
#ifndef COMPANY_GUI_H
|
||||
#define COMPANY_GUI_H
|
||||
|
||||
#include "player_type.h"
|
||||
|
||||
uint16 GetDrawStringPlayerColor(PlayerID player);
|
||||
void DrawPlayerIcon(PlayerID p, int x, int y);
|
||||
uint16 GetDrawStringCompanyColor(CompanyID company);
|
||||
void DrawCompanyIcon(CompanyID p, int x, int y);
|
||||
|
||||
void ShowPlayerStations(PlayerID player);
|
||||
void ShowPlayerFinances(PlayerID player);
|
||||
void ShowPlayerCompany(PlayerID player);
|
||||
void ShowCompanyStations(CompanyID company);
|
||||
void ShowCompanyFinances(CompanyID company);
|
||||
void ShowCompany(CompanyID company);
|
||||
|
||||
void InvalidatePlayerWindows(const Player *p);
|
||||
void DeletePlayerWindows(PlayerID pi);
|
||||
void InvalidateCompanyWindows(const Company *c);
|
||||
void DeleteCompanyWindows(CompanyID company);
|
||||
|
||||
#endif /* PLAYER_GUI_H */
|
||||
#endif /* COMPANY_GUI_H */
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
/* $Id$ */
|
||||
|
||||
/** @file player_type.h Types related to players. */
|
||||
/** @file company_type.h Types related to companies. */
|
||||
|
||||
#ifndef PLAYER_TYPE_H
|
||||
#define PLAYER_TYPE_H
|
||||
#ifndef COMPANY_TYPE_H
|
||||
#define COMPANY_TYPE_H
|
||||
|
||||
#include "core/enum_type.hpp"
|
||||
|
||||
/**
|
||||
* Enum for all players/owners.
|
||||
* Enum for all companies/owners.
|
||||
*/
|
||||
enum Owner {
|
||||
/* Player identifiers All players below MAX_PLAYERS are playable
|
||||
* players, above, they are special, computer controlled players */
|
||||
OWNER_BEGIN = 0x00, ///< First Owner
|
||||
PLAYER_FIRST = 0x00, ///< First Player, same as owner
|
||||
MAX_PLAYERS = 0x08, ///< Maximum numbe rof players
|
||||
/* All companies below MAX_COMPANIES are playable
|
||||
* companies, above, they are special, computer controlled 'companies' */
|
||||
OWNER_BEGIN = 0x00, ///< First owner
|
||||
COMPANY_FIRST = 0x00, ///< First company, same as owner
|
||||
MAX_COMPANIES = 0x08, ///< Maximum number of companies
|
||||
OWNER_TOWN = 0x0F, ///< A town owns the tile, or a town is expanding
|
||||
OWNER_NONE = 0x10, ///< The tile has no ownership
|
||||
OWNER_WATER = 0x11, ///< The tile/execution is done by "water"
|
||||
OWNER_END, ///< Last + 1 owner
|
||||
INVALID_OWNER = 0xFF, ///< An invalid owner
|
||||
INVALID_PLAYER = 0xFF, ///< And a valid owner
|
||||
INVALID_COMPANY = 0xFF, ///< An invalid company
|
||||
|
||||
/* 'Fake' Players used for networks */
|
||||
PLAYER_INACTIVE_CLIENT = 253, ///< The client is joining
|
||||
PLAYER_NEW_COMPANY = 254, ///< The client wants a new company
|
||||
PLAYER_SPECTATOR = 255, ///< The client is spectating
|
||||
/* 'Fake' companies used for networks */
|
||||
COMPANY_INACTIVE_CLIENT = 253, ///< The client is joining
|
||||
COMPANY_NEW_COMPANY = 254, ///< The client wants a new company
|
||||
COMPANY_SPECTATOR = 255, ///< The client is spectating
|
||||
};
|
||||
DECLARE_POSTFIX_INCREMENT(Owner);
|
||||
|
||||
|
@ -41,12 +41,12 @@ enum {
|
|||
template <> struct EnumPropsT<Owner> : MakeEnumPropsT<Owner, byte, OWNER_BEGIN, OWNER_END, INVALID_OWNER> {};
|
||||
typedef TinyEnumT<Owner> OwnerByte;
|
||||
|
||||
typedef Owner PlayerID;
|
||||
typedef OwnerByte PlayerByte;
|
||||
typedef Owner CompanyID;
|
||||
typedef OwnerByte CompanyByte;
|
||||
|
||||
typedef uint8 PlayerMask;
|
||||
typedef uint8 CompanyMask;
|
||||
|
||||
struct Player;
|
||||
typedef uint32 PlayerFace; ///< player face bits, info see in player_face.h
|
||||
struct Company;
|
||||
typedef uint32 CompanyManagerFace; ///< Company manager face bits, info see in company_manager_face.h
|
||||
|
||||
#endif /* PLAYER_TYPE_H */
|
||||
#endif /* COMPANY_TYPE_H */
|
||||
|
|
868
src/players.cpp
868
src/players.cpp
File diff suppressed because it is too large
Load Diff
18
src/rail.cpp
18
src/rail.cpp
|
@ -174,25 +174,25 @@ RailType GetTileRailType(TileIndex tile)
|
|||
return INVALID_RAILTYPE;
|
||||
}
|
||||
|
||||
bool HasRailtypeAvail(const PlayerID p, const RailType railtype)
|
||||
bool HasRailtypeAvail(const CompanyID company, const RailType railtype)
|
||||
{
|
||||
return HasBit(GetPlayer(p)->avail_railtypes, railtype);
|
||||
return HasBit(GetCompany(company)->avail_railtypes, railtype);
|
||||
}
|
||||
|
||||
bool ValParamRailtype(const RailType rail)
|
||||
{
|
||||
return HasRailtypeAvail(_current_player, rail);
|
||||
return HasRailtypeAvail(_current_company, rail);
|
||||
}
|
||||
|
||||
RailType GetBestRailtype(const PlayerID p)
|
||||
RailType GetBestRailtype(const CompanyID company)
|
||||
{
|
||||
if (HasRailtypeAvail(p, RAILTYPE_MAGLEV)) return RAILTYPE_MAGLEV;
|
||||
if (HasRailtypeAvail(p, RAILTYPE_MONO)) return RAILTYPE_MONO;
|
||||
if (HasRailtypeAvail(p, RAILTYPE_ELECTRIC)) return RAILTYPE_ELECTRIC;
|
||||
if (HasRailtypeAvail(company, RAILTYPE_MAGLEV)) return RAILTYPE_MAGLEV;
|
||||
if (HasRailtypeAvail(company, RAILTYPE_MONO)) return RAILTYPE_MONO;
|
||||
if (HasRailtypeAvail(company, RAILTYPE_ELECTRIC)) return RAILTYPE_ELECTRIC;
|
||||
return RAILTYPE_RAIL;
|
||||
}
|
||||
|
||||
RailTypes GetPlayerRailtypes(PlayerID p)
|
||||
RailTypes GetCompanyRailtypes(CompanyID company)
|
||||
{
|
||||
RailTypes rt = RAILTYPES_NONE;
|
||||
|
||||
|
@ -201,7 +201,7 @@ RailTypes GetPlayerRailtypes(PlayerID p)
|
|||
const EngineInfo *ei = &e->info;
|
||||
|
||||
if (HasBit(ei->climates, _settings_game.game_creation.landscape) &&
|
||||
(HasBit(e->player_avail, p) || _date >= e->intro_date + 365)) {
|
||||
(HasBit(e->company_avail, company) || _date >= e->intro_date + 365)) {
|
||||
const RailVehicleInfo *rvi = &e->u.rail;
|
||||
|
||||
if (rvi->railveh_type != RAILVEH_WAGON) {
|
||||
|
|
24
src/rail.h
24
src/rail.h
|
@ -210,35 +210,35 @@ Foundation GetRailFoundation(Slope tileh, TrackBits bits);
|
|||
|
||||
|
||||
/**
|
||||
* Finds out if a Player has a certain railtype available
|
||||
* @param p Player in question
|
||||
* Finds out if a company has a certain railtype available
|
||||
* @param company the company in question
|
||||
* @param railtype requested RailType
|
||||
* @return true if player has requested RailType available
|
||||
* @return true if company has requested RailType available
|
||||
*/
|
||||
bool HasRailtypeAvail(const PlayerID p, const RailType railtype);
|
||||
bool HasRailtypeAvail(const CompanyID company, const RailType railtype);
|
||||
|
||||
/**
|
||||
* Validate functions for rail building.
|
||||
* @param rail the railtype to check.
|
||||
* @return true if the current player may build the rail.
|
||||
* @return true if the current company may build the rail.
|
||||
*/
|
||||
bool ValParamRailtype(const RailType rail);
|
||||
|
||||
/**
|
||||
* Returns the "best" railtype a player can build.
|
||||
* Returns the "best" railtype a company can build.
|
||||
* As the AI doesn't know what the BEST one is, we have our own priority list
|
||||
* here. When adding new railtypes, modify this function
|
||||
* @param p the player "in action"
|
||||
* @return The "best" railtype a player has available
|
||||
* @param company the company "in action"
|
||||
* @return The "best" railtype a company has available
|
||||
*/
|
||||
RailType GetBestRailtype(const PlayerID p);
|
||||
RailType GetBestRailtype(const CompanyID company);
|
||||
|
||||
/**
|
||||
* Get the rail types the given player can build.
|
||||
* @param p the player to get the rail types for.
|
||||
* Get the rail types the given company can build.
|
||||
* @param company the company to get the rail types for.
|
||||
* @return the rail types.
|
||||
*/
|
||||
RailTypes GetPlayerRailtypes(const PlayerID p);
|
||||
RailTypes GetCompanyRailtypes(const CompanyID p);
|
||||
|
||||
/**
|
||||
* Reset all rail type information to its default values.
|
||||
|
|
|
@ -155,7 +155,7 @@ static bool CheckTrackCombination(TileIndex tile, TrackBits to_build, uint flags
|
|||
|
||||
/* Let's see if we may build this */
|
||||
if (flags & DC_NO_RAIL_OVERLAP || HasSignals(tile)) {
|
||||
/* If we are not allowed to overlap (flag is on for ai players or we have
|
||||
/* If we are not allowed to overlap (flag is on for ai companies or we have
|
||||
* signals on the tile), check that */
|
||||
return future == TRACK_BIT_HORZ || future == TRACK_BIT_VERT;
|
||||
} else {
|
||||
|
@ -307,7 +307,7 @@ static CommandCost CheckRailSlope(Slope tileh, TrackBits rail_bits, TrackBits ex
|
|||
|
||||
/* check track/slope combination */
|
||||
if ((f_new == FOUNDATION_INVALID) ||
|
||||
((f_new != FOUNDATION_NONE) && (!_settings_game.construction.build_on_slopes || _is_old_ai_player))) {
|
||||
((f_new != FOUNDATION_NONE) && (!_settings_game.construction.build_on_slopes || _is_old_ai_company))) {
|
||||
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
|
||||
}
|
||||
|
||||
|
@ -344,7 +344,7 @@ CommandCost CmdBuildSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p
|
|||
!EnsureNoTrainOnTrack(tile, track)) {
|
||||
return CMD_ERROR;
|
||||
}
|
||||
if (!IsTileOwner(tile, _current_player) ||
|
||||
if (!IsTileOwner(tile, _current_company) ||
|
||||
!IsCompatibleRail(GetRailType(tile), railtype)) {
|
||||
/* Get detailed error message */
|
||||
return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
||||
|
@ -395,7 +395,7 @@ CommandCost CmdBuildSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p
|
|||
default: break;
|
||||
case ROADTYPES_TRAM:
|
||||
/* Tram crossings must always have road. */
|
||||
if (flags & DC_EXEC) SetRoadOwner(tile, ROADTYPE_ROAD, _current_player);
|
||||
if (flags & DC_EXEC) SetRoadOwner(tile, ROADTYPE_ROAD, _current_company);
|
||||
roadtypes |= ROADTYPES_ROAD;
|
||||
break;
|
||||
|
||||
|
@ -412,7 +412,7 @@ CommandCost CmdBuildSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p
|
|||
if ((track == TRACK_X && road == ROAD_Y) ||
|
||||
(track == TRACK_Y && road == ROAD_X)) {
|
||||
if (flags & DC_EXEC) {
|
||||
MakeRoadCrossing(tile, GetRoadOwner(tile, ROADTYPE_ROAD), GetRoadOwner(tile, ROADTYPE_TRAM), GetRoadOwner(tile, ROADTYPE_HWAY), _current_player, (track == TRACK_X ? AXIS_Y : AXIS_X), railtype, roadtypes, GetTownIndex(tile));
|
||||
MakeRoadCrossing(tile, GetRoadOwner(tile, ROADTYPE_ROAD), GetRoadOwner(tile, ROADTYPE_TRAM), GetRoadOwner(tile, ROADTYPE_HWAY), _current_company, (track == TRACK_X ? AXIS_Y : AXIS_X), railtype, roadtypes, GetTownIndex(tile));
|
||||
UpdateLevelCrossing(tile, false);
|
||||
}
|
||||
break;
|
||||
|
@ -442,7 +442,7 @@ CommandCost CmdBuildSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p
|
|||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
MakeRailNormal(tile, _current_player, trackbit, railtype);
|
||||
MakeRailNormal(tile, _current_company, trackbit, railtype);
|
||||
if (water_ground) SetRailGroundType(tile, RAIL_GROUND_WATER);
|
||||
}
|
||||
break;
|
||||
|
@ -450,7 +450,7 @@ CommandCost CmdBuildSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p
|
|||
|
||||
if (flags & DC_EXEC) {
|
||||
MarkTileDirtyByTile(tile);
|
||||
AddTrackToSignalBuffer(tile, track, _current_player);
|
||||
AddTrackToSignalBuffer(tile, track, _current_company);
|
||||
YapfNotifyTrackLayoutChange(tile, track);
|
||||
}
|
||||
|
||||
|
@ -474,7 +474,7 @@ CommandCost CmdRemoveSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32
|
|||
trackbit = TrackToTrackBits(track);
|
||||
|
||||
/* Need to read tile owner now because it may change when the rail is removed
|
||||
* Also, in case of floods, _current_player != owner
|
||||
* Also, in case of floods, _current_company != owner
|
||||
* There may be invalid tiletype even in exec run (when removing long track),
|
||||
* so do not call GetTileOwner(tile) in any case here */
|
||||
Owner owner = INVALID_OWNER;
|
||||
|
@ -485,7 +485,7 @@ CommandCost CmdRemoveSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32
|
|||
case MP_ROAD: {
|
||||
if (!IsLevelCrossing(tile) ||
|
||||
GetCrossingRailBits(tile) != trackbit ||
|
||||
(_current_player != OWNER_WATER && !CheckTileOwnership(tile)) ||
|
||||
(_current_company != OWNER_WATER && !CheckTileOwnership(tile)) ||
|
||||
(!(flags & DC_BANKRUPT) && !EnsureNoVehicleOnGround(tile))) {
|
||||
return CMD_ERROR;
|
||||
}
|
||||
|
@ -505,7 +505,7 @@ CommandCost CmdRemoveSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32
|
|||
TrackBits present;
|
||||
|
||||
if (!IsPlainRailTile(tile) ||
|
||||
(_current_player != OWNER_WATER && !CheckTileOwnership(tile)) ||
|
||||
(_current_company != OWNER_WATER && !CheckTileOwnership(tile)) ||
|
||||
!EnsureNoTrainOnTrack(tile, track)) {
|
||||
return CMD_ERROR;
|
||||
}
|
||||
|
@ -546,7 +546,7 @@ CommandCost CmdRemoveSingleRail(TileIndex tile, uint32 flags, uint32 p1, uint32
|
|||
|
||||
if (flags & DC_EXEC) {
|
||||
/* if we got that far, 'owner' variable is set correctly */
|
||||
assert(IsValidPlayerID(owner));
|
||||
assert(IsValidCompanyID(owner));
|
||||
|
||||
MarkTileDirtyByTile(tile);
|
||||
if (crossing) {
|
||||
|
@ -590,7 +590,7 @@ bool FloodHalftile(TileIndex t)
|
|||
|
||||
TrackBits to_remove = lower_track & rail_bits;
|
||||
if (to_remove != 0) {
|
||||
_current_player = OWNER_WATER;
|
||||
_current_company = OWNER_WATER;
|
||||
if (CmdFailed(DoCommand(t, 0, FIND_FIRST_BIT(to_remove), DC_EXEC, CMD_REMOVE_SINGLE_RAIL))) return flooded; // not yet floodable
|
||||
flooded = true;
|
||||
rail_bits = rail_bits & ~to_remove;
|
||||
|
@ -789,7 +789,7 @@ CommandCost CmdBuildTrainDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p
|
|||
*/
|
||||
|
||||
if (tileh != SLOPE_FLAT && (
|
||||
_is_old_ai_player ||
|
||||
_is_old_ai_company ||
|
||||
!_settings_game.construction.build_on_slopes ||
|
||||
IsSteepSlope(tileh) ||
|
||||
!CanBuildDepotByTileh(dir, tileh)
|
||||
|
@ -806,12 +806,12 @@ CommandCost CmdBuildTrainDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p
|
|||
|
||||
if (flags & DC_EXEC) {
|
||||
Depot *d = new Depot(tile);
|
||||
MakeRailDepot(tile, _current_player, dir, (RailType)p1);
|
||||
MakeRailDepot(tile, _current_company, dir, (RailType)p1);
|
||||
MarkTileDirtyByTile(tile);
|
||||
|
||||
d->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
|
||||
|
||||
AddSideToSignalBuffer(tile, INVALID_DIAGDIR, _current_player);
|
||||
AddSideToSignalBuffer(tile, INVALID_DIAGDIR, _current_company);
|
||||
YapfNotifyTrackLayoutChange(tile, DiagDirToDiagTrack(dir));
|
||||
}
|
||||
|
||||
|
@ -971,7 +971,7 @@ CommandCost CmdBuildSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint32
|
|||
SetSignalStates(tile, (GetSignalStates(tile) & ~mask) | ((HasBit(GetTrackReservation(tile), track) ? (uint)-1 : 0) & mask));
|
||||
}
|
||||
MarkTileDirtyByTile(tile);
|
||||
AddTrackToSignalBuffer(tile, track, _current_player);
|
||||
AddTrackToSignalBuffer(tile, track, _current_company);
|
||||
YapfNotifyTrackLayoutChange(tile, track);
|
||||
if (v != NULL) TryPathReserve(v, true);
|
||||
}
|
||||
|
@ -1200,7 +1200,7 @@ CommandCost CmdRemoveSingleSignal(TileIndex tile, uint32 flags, uint32 p1, uint3
|
|||
}
|
||||
|
||||
/* Only water can remove signals from anyone */
|
||||
if (_current_player != OWNER_WATER && !CheckTileOwnership(tile)) return CMD_ERROR;
|
||||
if (_current_company != OWNER_WATER && !CheckTileOwnership(tile)) return CMD_ERROR;
|
||||
|
||||
/* Do it? */
|
||||
if (flags & DC_EXEC) {
|
||||
|
@ -1441,7 +1441,7 @@ CommandCost CmdConvertRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
|
||||
static CommandCost RemoveTrainDepot(TileIndex tile, uint32 flags)
|
||||
{
|
||||
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER)
|
||||
if (!CheckTileOwnership(tile) && _current_company != OWNER_WATER)
|
||||
return CMD_ERROR;
|
||||
|
||||
if (!EnsureNoVehicleOnGround(tile))
|
||||
|
@ -1474,7 +1474,7 @@ static CommandCost ClearTile_Track(TileIndex tile, byte flags)
|
|||
CommandCost ret;
|
||||
|
||||
if (flags & DC_AUTO) {
|
||||
if (!IsTileOwner(tile, _current_player))
|
||||
if (!IsTileOwner(tile, _current_company))
|
||||
return_cmd_error(STR_1024_AREA_IS_OWNED_BY_ANOTHER);
|
||||
|
||||
if (IsPlainRailTile(tile)) {
|
||||
|
@ -1902,7 +1902,7 @@ static void DrawTile_Track(TileInfo *ti)
|
|||
const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
|
||||
SpriteID image;
|
||||
|
||||
_drawtile_track_palette = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile));
|
||||
_drawtile_track_palette = COMPANY_SPRITE_COLOR(GetTileOwner(ti->tile));
|
||||
|
||||
if (IsPlainRailTile(ti->tile)) {
|
||||
TrackBits rails = GetTrackBits(ti->tile);
|
||||
|
@ -2039,7 +2039,7 @@ default_waypoint:
|
|||
|
||||
static void DrawTileSequence(int x, int y, SpriteID ground, const DrawTileSeqStruct* dtss, uint32 offset)
|
||||
{
|
||||
SpriteID palette = PLAYER_SPRITE_COLOR(_local_player);
|
||||
SpriteID palette = COMPANY_SPRITE_COLOR(_local_company);
|
||||
|
||||
DrawSprite(ground, PAL_NONE, x, y);
|
||||
for (; dtss->image.sprite != 0; dtss++) {
|
||||
|
@ -2188,7 +2188,7 @@ static void TileLoop_Track(TileIndex tile)
|
|||
case TRACK_BIT_RIGHT: new_ground = RAIL_GROUND_FENCE_VERT2; break;
|
||||
|
||||
default: {
|
||||
PlayerID owner = GetTileOwner(tile);
|
||||
Owner owner = GetTileOwner(tile);
|
||||
|
||||
if (rail == (TRACK_BIT_LOWER | TRACK_BIT_RIGHT) || (
|
||||
(rail & TRACK_BIT_3WAY_NW) == 0 &&
|
||||
|
@ -2414,12 +2414,12 @@ static void GetTileDesc_Track(TileIndex tile, TileDesc *td)
|
|||
}
|
||||
}
|
||||
|
||||
static void ChangeTileOwner_Track(TileIndex tile, PlayerID old_player, PlayerID new_player)
|
||||
static void ChangeTileOwner_Track(TileIndex tile, Owner old_owner, Owner new_owner)
|
||||
{
|
||||
if (!IsTileOwner(tile, old_player)) return;
|
||||
if (!IsTileOwner(tile, old_owner)) return;
|
||||
|
||||
if (new_player != PLAYER_SPECTATOR) {
|
||||
SetTileOwner(tile, new_player);
|
||||
if (new_owner != INVALID_OWNER) {
|
||||
SetTileOwner(tile, new_owner);
|
||||
} else {
|
||||
DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
|
||||
}
|
||||
|
|
|
@ -843,7 +843,7 @@ void ShowBuildRailToolbar(RailType railtype, int button)
|
|||
{
|
||||
BuildRailToolbarWindow *w;
|
||||
|
||||
if (!IsValidPlayerID(_current_player)) return;
|
||||
if (!IsValidCompanyID(_current_company)) return;
|
||||
if (!ValParamRailtype(railtype)) return;
|
||||
|
||||
// don't recreate the window if we're clicking on a button and the window exists.
|
||||
|
@ -1718,7 +1718,7 @@ void ReinitGuiAfterToggleElrail(bool disable)
|
|||
/** Set the initial (default) railtype to use */
|
||||
static void SetDefaultRailGui()
|
||||
{
|
||||
if (_local_player == PLAYER_SPECTATOR || !IsValidPlayerID(_local_player)) return;
|
||||
if (_local_company == COMPANY_SPECTATOR || !IsValidCompanyID(_local_company)) return;
|
||||
|
||||
extern RailType _last_built_railtype;
|
||||
RailType rt = (RailType)_settings_client.gui.default_rail_type;
|
||||
|
@ -1745,11 +1745,11 @@ static void SetDefaultRailGui()
|
|||
switch (rt) {
|
||||
case RAILTYPE_END + 0:
|
||||
rt = RAILTYPE_RAIL;
|
||||
while (rt < RAILTYPE_END && !HasRailtypeAvail(_local_player, rt)) rt++;
|
||||
while (rt < RAILTYPE_END && !HasRailtypeAvail(_local_company, rt)) rt++;
|
||||
break;
|
||||
|
||||
case RAILTYPE_END + 1:
|
||||
rt = GetBestRailtype(_local_player);
|
||||
rt = GetBestRailtype(_local_company);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
14
src/road.cpp
14
src/road.cpp
|
@ -77,25 +77,25 @@ RoadBits CleanUpRoadBits(const TileIndex tile, RoadBits org_rb)
|
|||
return org_rb;
|
||||
}
|
||||
|
||||
bool HasRoadTypesAvail(const PlayerID p, const RoadTypes rts)
|
||||
bool HasRoadTypesAvail(const CompanyID company, const RoadTypes rts)
|
||||
{
|
||||
RoadTypes avail_roadtypes;
|
||||
|
||||
if (p == OWNER_TOWN || _game_mode == GM_EDITOR || IsGeneratingWorld()) {
|
||||
if (company == OWNER_TOWN || _game_mode == GM_EDITOR || IsGeneratingWorld()) {
|
||||
avail_roadtypes = ROADTYPES_ROAD;
|
||||
} else {
|
||||
if (!IsValidPlayerID(p)) return false;
|
||||
avail_roadtypes = (RoadTypes)GetPlayer(p)->avail_roadtypes | ROADTYPES_ROAD; // road is available for always for everybody
|
||||
if (!IsValidCompanyID(company)) return false;
|
||||
avail_roadtypes = (RoadTypes)GetCompany(company)->avail_roadtypes | ROADTYPES_ROAD; // road is available for always for everybody
|
||||
}
|
||||
return (rts & ~avail_roadtypes) == 0;
|
||||
}
|
||||
|
||||
bool ValParamRoadType(const RoadType rt)
|
||||
{
|
||||
return HasRoadTypesAvail(_current_player, RoadTypeToRoadTypes(rt));
|
||||
return HasRoadTypesAvail(_current_company, RoadTypeToRoadTypes(rt));
|
||||
}
|
||||
|
||||
RoadTypes GetPlayerRoadtypes(PlayerID p)
|
||||
RoadTypes GetCompanyRoadtypes(CompanyID company)
|
||||
{
|
||||
RoadTypes rt = ROADTYPES_NONE;
|
||||
|
||||
|
@ -104,7 +104,7 @@ RoadTypes GetPlayerRoadtypes(PlayerID p)
|
|||
const EngineInfo *ei = &e->info;
|
||||
|
||||
if (HasBit(ei->climates, _settings_game.game_creation.landscape) &&
|
||||
(HasBit(e->player_avail, p) || _date >= e->intro_date + 365)) {
|
||||
(HasBit(e->company_avail, company) || _date >= e->intro_date + 365)) {
|
||||
SetBit(rt, HasBit(ei->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -151,8 +151,8 @@ bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, RoadType
|
|||
/* Water can always flood and towns can always remove "normal" road pieces.
|
||||
* Towns are not be allowed to remove non "normal" road pieces, like tram
|
||||
* tracks as that would result in trams that cannot turn. */
|
||||
if (_current_player == OWNER_WATER ||
|
||||
(rt == ROADTYPE_ROAD && !IsValidPlayerID(_current_player))) return true;
|
||||
if (_current_company == OWNER_WATER ||
|
||||
(rt == ROADTYPE_ROAD && !IsValidCompanyID(_current_company))) return true;
|
||||
|
||||
/* Only do the special processing if the road is owned
|
||||
* by a town */
|
||||
|
@ -272,7 +272,7 @@ static CommandCost RemoveRoad(TileIndex tile, uint32 flags, RoadBits pieces, Roa
|
|||
const RoadBits other = GetOtherRoadBits(tile, rt);
|
||||
const Foundation f = GetRoadFoundation(tileh, present);
|
||||
|
||||
if (HasRoadWorks(tile) && _current_player != OWNER_WATER) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS);
|
||||
if (HasRoadWorks(tile) && _current_company != OWNER_WATER) return_cmd_error(STR_ROAD_WORKS_IN_PROGRESS);
|
||||
|
||||
/* Autocomplete to a straight road
|
||||
* @li on steep slopes
|
||||
|
@ -300,7 +300,7 @@ static CommandCost RemoveRoad(TileIndex tile, uint32 flags, RoadBits pieces, Roa
|
|||
if (flags & DC_EXEC) {
|
||||
if (HasRoadWorks(tile)) {
|
||||
/* flooding tile with road works, don't forget to remove the effect vehicle too */
|
||||
assert(_current_player == OWNER_WATER);
|
||||
assert(_current_company == OWNER_WATER);
|
||||
Vehicle *v;
|
||||
FOR_ALL_VEHICLES(v) {
|
||||
if (v->type == VEH_EFFECT && TileVirtXY(v->x_pos, v->y_pos) == tile) {
|
||||
|
@ -474,8 +474,8 @@ CommandCost CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
RoadBits other_bits = ROAD_NONE;
|
||||
|
||||
/* Road pieces are max 4 bitset values (NE, NW, SE, SW) and town can only be non-zero
|
||||
* if a non-player is building the road */
|
||||
if ((IsValidPlayerID(_current_player) && p2 != 0) || (_current_player == OWNER_TOWN && !IsValidTownID(p2))) return CMD_ERROR;
|
||||
* if a non-company is building the road */
|
||||
if ((IsValidCompanyID(_current_company) && p2 != 0) || (_current_company == OWNER_TOWN && !IsValidTownID(p2))) return CMD_ERROR;
|
||||
|
||||
RoadBits pieces = Extract<RoadBits, 0>(p1);
|
||||
|
||||
|
@ -506,7 +506,7 @@ CommandCost CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
}
|
||||
if ((existing & pieces) == pieces) {
|
||||
/* We only want to set the (dis)allowed road directions */
|
||||
if (toggle_drd != DRD_NONE && rt != ROADTYPE_TRAM && IsRoadOwner(tile, ROADTYPE_ROAD, _current_player)) {
|
||||
if (toggle_drd != DRD_NONE && rt != ROADTYPE_TRAM && IsRoadOwner(tile, ROADTYPE_ROAD, _current_company)) {
|
||||
if (crossing) return_cmd_error(STR_ERR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION);
|
||||
|
||||
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
|
||||
|
@ -569,7 +569,7 @@ CommandCost CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetTrackBits(tile)));
|
||||
/* Always add road to the roadtypes (can't draw without it) */
|
||||
bool reserved = HasBit(GetTrackReservation(tile), AxisToTrack(OtherAxis(roaddir)));
|
||||
MakeRoadCrossing(tile, _current_player, _current_player, _current_player, GetTileOwner(tile), roaddir, GetRailType(tile), RoadTypeToRoadTypes(rt) | ROADTYPES_ROAD, p2);
|
||||
MakeRoadCrossing(tile, _current_company, _current_company, _current_company, GetTileOwner(tile), roaddir, GetRailType(tile), RoadTypeToRoadTypes(rt) | ROADTYPES_ROAD, p2);
|
||||
SetCrossingReservation(tile, reserved);
|
||||
UpdateLevelCrossing(tile, false);
|
||||
MarkTileDirtyByTile(tile);
|
||||
|
@ -650,8 +650,8 @@ do_clear:;
|
|||
RoadTileType rtt = GetRoadTileType(tile);
|
||||
if (existing == ROAD_NONE || rtt == ROAD_TILE_CROSSING) {
|
||||
SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt));
|
||||
SetRoadOwner(tile, rt, _current_player);
|
||||
if (_current_player == OWNER_TOWN && rt == ROADTYPE_ROAD) SetTownIndex(tile, p2);
|
||||
SetRoadOwner(tile, rt, _current_company);
|
||||
if (_current_company == OWNER_TOWN && rt == ROADTYPE_ROAD) SetTownIndex(tile, p2);
|
||||
}
|
||||
if (rtt != ROAD_TILE_CROSSING) SetRoadBits(tile, existing | pieces, rt);
|
||||
} break;
|
||||
|
@ -679,7 +679,7 @@ do_clear:;
|
|||
break;
|
||||
|
||||
default:
|
||||
MakeRoadNormal(tile, pieces, RoadTypeToRoadTypes(rt), p2, _current_player, _current_player, _current_player);
|
||||
MakeRoadNormal(tile, pieces, RoadTypeToRoadTypes(rt), p2, _current_company, _current_company, _current_company);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -883,7 +883,7 @@ CommandCost CmdBuildRoadDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2
|
|||
Depot *dep = new Depot(tile);
|
||||
dep->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
|
||||
|
||||
MakeRoadDepot(tile, _current_player, dir, rt);
|
||||
MakeRoadDepot(tile, _current_company, dir, rt);
|
||||
MarkTileDirtyByTile(tile);
|
||||
}
|
||||
return cost.AddCost(_price.build_road_depot);
|
||||
|
@ -891,7 +891,7 @@ CommandCost CmdBuildRoadDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2
|
|||
|
||||
static CommandCost RemoveRoadDepot(TileIndex tile, uint32 flags)
|
||||
{
|
||||
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR;
|
||||
if (!CheckTileOwnership(tile) && _current_company != OWNER_WATER) return CMD_ERROR;
|
||||
|
||||
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
|
||||
|
||||
|
@ -1203,7 +1203,7 @@ static void DrawTile_Road(TileInfo *ti)
|
|||
case ROAD_TILE_DEPOT: {
|
||||
if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED);
|
||||
|
||||
SpriteID palette = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile));
|
||||
SpriteID palette = COMPANY_SPRITE_COLOR(GetTileOwner(ti->tile));
|
||||
|
||||
const DrawTileSprites *dts;
|
||||
if (HasTileRoadType(ti->tile, ROADTYPE_TRAM)) {
|
||||
|
@ -1243,7 +1243,7 @@ static void DrawTile_Road(TileInfo *ti)
|
|||
|
||||
void DrawRoadDepotSprite(int x, int y, DiagDirection dir, RoadType rt)
|
||||
{
|
||||
SpriteID palette = PLAYER_SPRITE_COLOR(_local_player);
|
||||
SpriteID palette = COMPANY_SPRITE_COLOR(_local_company);
|
||||
const DrawTileSprites *dts = (rt == ROADTYPE_TRAM) ? &_tram_depot[dir] : &_road_depot[dir];
|
||||
|
||||
x += 33;
|
||||
|
@ -1559,14 +1559,14 @@ static VehicleEnterTileStatus VehicleEnter_Road(Vehicle *v, TileIndex tile, int
|
|||
}
|
||||
|
||||
|
||||
static void ChangeTileOwner_Road(TileIndex tile, PlayerID old_player, PlayerID new_player)
|
||||
static void ChangeTileOwner_Road(TileIndex tile, Owner old_owner, Owner new_owner)
|
||||
{
|
||||
if (IsRoadDepot(tile)) {
|
||||
if (GetTileOwner(tile) == old_player) {
|
||||
if (new_player == PLAYER_SPECTATOR) {
|
||||
if (GetTileOwner(tile) == old_owner) {
|
||||
if (new_owner == INVALID_OWNER) {
|
||||
DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
|
||||
} else {
|
||||
SetTileOwner(tile, new_player);
|
||||
SetTileOwner(tile, new_owner);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
@ -1574,17 +1574,17 @@ static void ChangeTileOwner_Road(TileIndex tile, PlayerID old_player, PlayerID n
|
|||
|
||||
for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
|
||||
/* Update all roadtypes, no matter if they are present */
|
||||
if (GetRoadOwner(tile, rt) == old_player) {
|
||||
SetRoadOwner(tile, rt, new_player == PLAYER_SPECTATOR ? OWNER_NONE : new_player);
|
||||
if (GetRoadOwner(tile, rt) == old_owner) {
|
||||
SetRoadOwner(tile, rt, new_owner == INVALID_OWNER ? OWNER_NONE : new_owner);
|
||||
}
|
||||
}
|
||||
|
||||
if (IsLevelCrossing(tile)) {
|
||||
if (GetTileOwner(tile) == old_player) {
|
||||
if (new_player == PLAYER_SPECTATOR) {
|
||||
if (GetTileOwner(tile) == old_owner) {
|
||||
if (new_owner == INVALID_OWNER) {
|
||||
DoCommand(tile, 0, GetCrossingRailTrack(tile), DC_EXEC | DC_BANKRUPT, CMD_REMOVE_SINGLE_RAIL);
|
||||
} else {
|
||||
SetTileOwner(tile, new_player);
|
||||
SetTileOwner(tile, new_owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -140,26 +140,26 @@ static inline RoadBits AxisToRoadBits(Axis a)
|
|||
}
|
||||
|
||||
/**
|
||||
* Finds out, whether given player has all given RoadTypes available
|
||||
* @param PlayerID ID of player
|
||||
* Finds out, whether given company has all given RoadTypes available
|
||||
* @param company ID of company
|
||||
* @param rts RoadTypes to test
|
||||
* @return true if player has all requested RoadTypes available
|
||||
* @return true if company has all requested RoadTypes available
|
||||
*/
|
||||
bool HasRoadTypesAvail(const PlayerID p, const RoadTypes rts);
|
||||
bool HasRoadTypesAvail(const CompanyID company, const RoadTypes rts);
|
||||
|
||||
/**
|
||||
* Validate functions for rail building.
|
||||
* @param rt road type to check.
|
||||
* @return true if the current player may build the road.
|
||||
* @return true if the current company may build the road.
|
||||
*/
|
||||
bool ValParamRoadType(const RoadType rt);
|
||||
|
||||
/**
|
||||
* Get the road types the given player can build.
|
||||
* @param p the player to get the roadtypes for.
|
||||
* Get the road types the given company can build.
|
||||
* @param company the company to get the roadtypes for.
|
||||
* @return the road types.
|
||||
*/
|
||||
RoadTypes GetPlayerRoadtypes(const PlayerID p);
|
||||
RoadTypes GetCompanyRoadtypes(const CompanyID company);
|
||||
|
||||
void UpdateLevelCrossing(TileIndex tile, bool sound = true);
|
||||
|
||||
|
|
|
@ -421,7 +421,7 @@ struct BuildRoadToolbarWindow : Window {
|
|||
/**
|
||||
* Update the remove button lowered state of the road toolbar
|
||||
*
|
||||
* @param clicked_widget The widget which the player clicked just now
|
||||
* @param clicked_widget The widget which the client clicked just now
|
||||
*/
|
||||
void UpdateOptionWidgetStatus(RoadToolbarWidgets clicked_widget)
|
||||
{
|
||||
|
@ -676,7 +676,7 @@ static const WindowDesc _build_tramway_desc = {
|
|||
|
||||
void ShowBuildRoadToolbar(RoadType roadtype)
|
||||
{
|
||||
if (!IsValidPlayerID(_current_player)) return;
|
||||
if (!IsValidCompanyID(_current_company)) return;
|
||||
_cur_roadtype = roadtype;
|
||||
|
||||
DeleteWindowByClass(WC_BUILD_TOOLBAR);
|
||||
|
|
|
@ -180,7 +180,7 @@ CommandCost CmdBuildRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
UnitID unit_num;
|
||||
Engine *e;
|
||||
|
||||
if (!IsEngineBuildable(p1, VEH_ROAD, _current_player)) return_cmd_error(STR_ROAD_VEHICLE_NOT_AVAILABLE);
|
||||
if (!IsEngineBuildable(p1, VEH_ROAD, _current_company)) return_cmd_error(STR_ROAD_VEHICLE_NOT_AVAILABLE);
|
||||
|
||||
cost = EstimateRoadVehCost(p1);
|
||||
if (flags & DC_QUERY_COST) return cost;
|
||||
|
@ -188,7 +188,7 @@ CommandCost CmdBuildRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
/* The ai_new queries the vehicle cost before building the route,
|
||||
* so we must check against cheaters no sooner than now. --pasky */
|
||||
if (!IsRoadDepotTile(tile)) return CMD_ERROR;
|
||||
if (!IsTileOwner(tile, _current_player)) return CMD_ERROR;
|
||||
if (!IsTileOwner(tile, _current_company)) return CMD_ERROR;
|
||||
|
||||
if (HasTileRoadType(tile, ROADTYPE_TRAM) != HasBit(EngInfo(p1)->misc_flags, EF_ROAD_TRAM)) return_cmd_error(STR_DEPOT_WRONG_DEPOT_TYPE);
|
||||
|
||||
|
@ -218,7 +218,7 @@ CommandCost CmdBuildRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
v = new (v) RoadVehicle();
|
||||
v->unitnumber = unit_num;
|
||||
v->direction = DiagDirToDir(GetRoadDepotDirection(tile));
|
||||
v->owner = _current_player;
|
||||
v->owner = _current_company;
|
||||
|
||||
v->tile = tile;
|
||||
x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2;
|
||||
|
@ -283,10 +283,10 @@ CommandCost CmdBuildRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
|
||||
InvalidateWindowClassesData(WC_ROADVEH_LIST, 0);
|
||||
InvalidateWindow(WC_COMPANY, v->owner);
|
||||
if (IsLocalPlayer())
|
||||
if (IsLocalCompany())
|
||||
InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the replace Road window
|
||||
|
||||
GetPlayer(_current_player)->num_engines[p1]++;
|
||||
GetCompany(_current_company)->num_engines[p1]++;
|
||||
}
|
||||
|
||||
return cost;
|
||||
|
@ -441,7 +441,7 @@ CommandCost CmdSendRoadVehToDepot(TileIndex tile, uint32 flags, uint32 p1, uint3
|
|||
if (p2 & DEPOT_MASS_SEND) {
|
||||
/* Mass goto depot requested */
|
||||
if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR;
|
||||
return SendAllVehiclesToDepot(VEH_ROAD, flags, p2 & DEPOT_SERVICE, _current_player, (p2 & VLW_MASK), p1);
|
||||
return SendAllVehiclesToDepot(VEH_ROAD, flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1);
|
||||
}
|
||||
|
||||
if (!IsValidVehicleID(p1)) return CMD_ERROR;
|
||||
|
@ -805,7 +805,7 @@ static void RoadVehArrivesAt(const Vehicle* v, Station* st)
|
|||
SetDParam(0, st->index);
|
||||
AddNewsItem(
|
||||
v->u.road.roadtype == ROADTYPE_ROAD ? STR_902F_CITIZENS_CELEBRATE_FIRST : STR_CITIZENS_CELEBRATE_FIRST_PASSENGER_TRAM,
|
||||
(v->owner == _local_player) ? NS_ARRIVAL_PLAYER : NS_ARRIVAL_OTHER,
|
||||
(v->owner == _local_company) ? NS_ARRIVAL_COMPANY : NS_ARRIVAL_OTHER,
|
||||
v->index,
|
||||
st->index
|
||||
);
|
||||
|
@ -817,7 +817,7 @@ static void RoadVehArrivesAt(const Vehicle* v, Station* st)
|
|||
SetDParam(0, st->index);
|
||||
AddNewsItem(
|
||||
v->u.road.roadtype == ROADTYPE_ROAD ? STR_9030_CITIZENS_CELEBRATE_FIRST : STR_CITIZENS_CELEBRATE_FIRST_CARGO_TRAM,
|
||||
(v->owner == _local_player) ? NS_ARRIVAL_PLAYER : NS_ARRIVAL_OTHER,
|
||||
(v->owner == _local_company) ? NS_ARRIVAL_COMPANY : NS_ARRIVAL_OTHER,
|
||||
v->index,
|
||||
st->index
|
||||
);
|
||||
|
@ -1043,7 +1043,7 @@ static Trackdir RoadFindPathToDest(Vehicle* v, TileIndex tile, DiagDirection ent
|
|||
|
||||
if (IsTileType(tile, MP_ROAD)) {
|
||||
if (IsRoadDepot(tile) && (!IsTileOwner(tile, v->owner) || GetRoadDepotDirection(tile) == enterdir || (GetRoadTypes(tile) & v->u.road.compatible_roadtypes) == 0)) {
|
||||
/* Road depot owned by another player or with the wrong orientation */
|
||||
/* Road depot owned by another company or with the wrong orientation */
|
||||
trackdirs = TRACKDIR_BIT_NONE;
|
||||
}
|
||||
} else if (IsTileType(tile, MP_STATION) && IsStandardRoadStopTile(tile)) {
|
||||
|
@ -1358,20 +1358,20 @@ static Trackdir FollowPreviousRoadVehicle(const Vehicle *v, const Vehicle *prev,
|
|||
|
||||
/**
|
||||
* Can a tram track build without destruction on the given tile?
|
||||
* @param p the player that would be building the tram tracks
|
||||
* @param c the company that would be building the tram tracks
|
||||
* @param t the tile to build on.
|
||||
* @param r the road bits needed.
|
||||
* @return true when a track track can be build on 't'
|
||||
*/
|
||||
static bool CanBuildTramTrackOnTile(PlayerID p, TileIndex t, RoadBits r)
|
||||
static bool CanBuildTramTrackOnTile(CompanyID c, TileIndex t, RoadBits r)
|
||||
{
|
||||
/* The 'current' player is not necessarily the owner of the vehicle. */
|
||||
PlayerID original_player = _current_player;
|
||||
_current_player = p;
|
||||
/* The 'current' company is not necessarily the owner of the vehicle. */
|
||||
CompanyID original_company = _current_company;
|
||||
_current_company = c;
|
||||
|
||||
CommandCost ret = DoCommand(t, ROADTYPE_TRAM << 4 | r, 0, 0, CMD_BUILD_ROAD);
|
||||
|
||||
_current_player = original_player;
|
||||
_current_company = original_company;
|
||||
return CmdSucceeded(ret);
|
||||
}
|
||||
|
||||
|
@ -1491,7 +1491,7 @@ again:
|
|||
/*
|
||||
* Taking the 'small' corner for trams only happens when:
|
||||
* - We are not the from vehicle of an articulated tram.
|
||||
* - Or when the player cannot build on the next tile.
|
||||
* - Or when the company cannot build on the next tile.
|
||||
*
|
||||
* The 'small' corner means that the vehicle is on the end of a
|
||||
* tram track and needs to start turning there. To do this properly
|
||||
|
@ -1502,7 +1502,7 @@ again:
|
|||
tile = v->tile;
|
||||
start_frame = RVC_TURN_AROUND_START_FRAME_SHORT_TRAM;
|
||||
} else {
|
||||
/* The player can build on the next tile, so wait till (s)he does. */
|
||||
/* The company can build on the next tile, so wait till (s)he does. */
|
||||
v->cur_speed = 0;
|
||||
return false;
|
||||
}
|
||||
|
@ -1985,7 +1985,7 @@ void RoadVehicle::OnNewDay()
|
|||
this->profit_this_year -= cost.GetCost();
|
||||
this->running_ticks = 0;
|
||||
|
||||
SubtractMoneyFromPlayerFract(this->owner, cost);
|
||||
SubtractMoneyFromCompanyFract(this->owner, cost);
|
||||
|
||||
InvalidateWindow(WC_VEHICLE_DETAILS, this->index);
|
||||
InvalidateWindowClasses(WC_ROADVEH_LIST);
|
||||
|
@ -2086,7 +2086,7 @@ CommandCost CmdRefitRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
|
||||
total_capacity += capacity;
|
||||
|
||||
if (IsHumanPlayer(v->owner) && new_cid != v->cargo_type) {
|
||||
if (IsHumanCompany(v->owner) && new_cid != v->cargo_type) {
|
||||
cost.AddCost(GetRefitCost(v->engine_type));
|
||||
}
|
||||
|
||||
|
|
|
@ -1300,7 +1300,7 @@ extern const ChunkHandler _misc_chunk_handlers[];
|
|||
extern const ChunkHandler _name_chunk_handlers[];
|
||||
extern const ChunkHandler _cheat_chunk_handlers[] ;
|
||||
extern const ChunkHandler _setting_chunk_handlers[];
|
||||
extern const ChunkHandler _player_chunk_handlers[];
|
||||
extern const ChunkHandler _company_chunk_handlers[];
|
||||
extern const ChunkHandler _engine_chunk_handlers[];
|
||||
extern const ChunkHandler _veh_chunk_handlers[];
|
||||
extern const ChunkHandler _waypoint_chunk_handlers[];
|
||||
|
@ -1333,7 +1333,7 @@ static const ChunkHandler * const _chunk_handlers[] = {
|
|||
_town_chunk_handlers,
|
||||
_sign_chunk_handlers,
|
||||
_station_chunk_handlers,
|
||||
_player_chunk_handlers,
|
||||
_company_chunk_handlers,
|
||||
_animated_tile_chunk_handlers,
|
||||
_newgrf_chunk_handlers,
|
||||
_group_chunk_handlers,
|
||||
|
|
|
@ -160,7 +160,7 @@ enum VarTypes {
|
|||
|
||||
/* 8 bytes allocated for a maximum of 8 flags
|
||||
* Flags directing saving/loading of a variable */
|
||||
SLF_SAVE_NO = 1 << 8, ///< do not save with savegame, basically player-based
|
||||
SLF_SAVE_NO = 1 << 8, ///< do not save with savegame, basically client-based
|
||||
SLF_CONFIG_NO = 1 << 9, ///< do not save to config file
|
||||
SLF_NETWORK_NO = 1 << 10, ///< do not synchronize over network (but it is saved if SSF_SAVE_NO is not set)
|
||||
/* 5 more possible flags */
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue