src/misc_cmd.cpp
branchnoai
changeset 9631 8a2d1c2ceb88
parent 9629 66dde6412125
child 9704 197cb8c6ae17
equal deleted inserted replaced
9630:550db5cefcc2 9631:8a2d1c2ceb88
    15 #include "economy.h"
    15 #include "economy.h"
    16 #include "network/network.h"
    16 #include "network/network.h"
    17 #include "variables.h"
    17 #include "variables.h"
    18 #include "livery.h"
    18 #include "livery.h"
    19 #include "player_face.h"
    19 #include "player_face.h"
       
    20 #include "strings.h"
    20 
    21 
    21 /** Change the player's face.
    22 /** Change the player's face.
    22  * @param tile unused
    23  * @param tile unused
    23  * @param flags operation to perform
    24  * @param flags operation to perform
    24  * @param p1 unused
    25  * @param p1 unused
   202 		InvalidatePlayerWindows(p);
   203 		InvalidatePlayerWindows(p);
   203 	}
   204 	}
   204 	return CommandCost();
   205 	return CommandCost();
   205 }
   206 }
   206 
   207 
       
   208 static bool IsUniqueCompanyName(const char *name)
       
   209 {
       
   210 	const Player *p;
       
   211 	char buf[512];
       
   212 
       
   213 	FOR_ALL_PLAYERS(p) {
       
   214 		if (!p->is_active) continue;
       
   215 		SetDParam(0, p->index);
       
   216 		GetString(buf, STR_COMPANY_NAME, lastof(buf));
       
   217 		if (strcmp(buf, name) == 0) return false;
       
   218 	}
       
   219 
       
   220 	return true;
       
   221 }
       
   222 
   207 /** Change the name of the company.
   223 /** Change the name of the company.
   208  * @param tile unused
   224  * @param tile unused
   209  * @param flags operation to perform
   225  * @param flags operation to perform
   210  * @param p1 unused
   226  * @param p1 unused
   211  * @param p2 unused
   227  * @param p2 unused
   213 CommandCost CmdChangeCompanyName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   229 CommandCost CmdChangeCompanyName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   214 {
   230 {
   215 	StringID str;
   231 	StringID str;
   216 	Player *p;
   232 	Player *p;
   217 
   233 
   218 	if (_cmd_text[0] == '\0') return CMD_ERROR;
   234 	if (StrEmpty(_cmd_text)) return CMD_ERROR;
   219 
   235 
   220 	str = AllocateNameUnique(_cmd_text, 4);
   236 	if (!IsUniqueCompanyName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
       
   237 
       
   238 	str = AllocateName(_cmd_text, 4);
   221 	if (str == 0) return CMD_ERROR;
   239 	if (str == 0) return CMD_ERROR;
   222 
   240 
   223 	if (flags & DC_EXEC) {
   241 	if (flags & DC_EXEC) {
   224 		p = GetPlayer(_current_player);
   242 		p = GetPlayer(_current_player);
   225 		DeleteName(p->name_1);
   243 		DeleteName(p->name_1);
   230 	}
   248 	}
   231 
   249 
   232 	return CommandCost();
   250 	return CommandCost();
   233 }
   251 }
   234 
   252 
       
   253 static bool IsUniquePresidentName(const char *name)
       
   254 {
       
   255 	const Player *p;
       
   256 	char buf[512];
       
   257 
       
   258 	FOR_ALL_PLAYERS(p) {
       
   259 		if (!p->is_active) continue;
       
   260 		SetDParam(0, p->index);
       
   261 		GetString(buf, STR_PLAYER_NAME, lastof(buf));
       
   262 		if (strcmp(buf, name) == 0) return false;
       
   263 	}
       
   264 
       
   265 	return true;
       
   266 }
       
   267 
   235 /** Change the name of the president.
   268 /** Change the name of the president.
   236  * @param tile unused
   269  * @param tile unused
   237  * @param flags operation to perform
   270  * @param flags operation to perform
   238  * @param p1 unused
   271  * @param p1 unused
   239  * @param p2 unused
   272  * @param p2 unused
   241 CommandCost CmdChangePresidentName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   274 CommandCost CmdChangePresidentName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   242 {
   275 {
   243 	StringID str;
   276 	StringID str;
   244 	Player *p;
   277 	Player *p;
   245 
   278 
   246 	if (_cmd_text[0] == '\0') return CMD_ERROR;
   279 	if (StrEmpty(_cmd_text)) return CMD_ERROR;
   247 
   280 
   248 	str = AllocateNameUnique(_cmd_text, 4);
   281 	if (!IsUniquePresidentName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
       
   282 
       
   283 	str = AllocateName(_cmd_text, 4);
   249 	if (str == 0) return CMD_ERROR;
   284 	if (str == 0) return CMD_ERROR;
   250 
   285 
   251 	if (flags & DC_EXEC) {
   286 	if (flags & DC_EXEC) {
   252 		p = GetPlayer(_current_player);
   287 		p = GetPlayer(_current_player);
   253 		DeleteName(p->president_name_1);
   288 		DeleteName(p->president_name_1);