misc_cmd.c
changeset 1878 980fabc7d8a5
parent 1877 ab6a315fa930
child 1881 435d39bd6ee0
equal deleted inserted replaced
1877:ab6a315fa930 1878:980fabc7d8a5
    31  * @param p2 new colour for vehicles, property, etc.
    31  * @param p2 new colour for vehicles, property, etc.
    32  */
    32  */
    33 int32 CmdSetPlayerColor(int x, int y, uint32 flags, uint32 p1, uint32 p2)
    33 int32 CmdSetPlayerColor(int x, int y, uint32 flags, uint32 p1, uint32 p2)
    34 {
    34 {
    35 	Player *p, *pp;
    35 	Player *p, *pp;
       
    36 	byte colour = (byte)p2;
       
    37 
       
    38 	if (p2 >= 16) return CMD_ERROR; // max 16 colours
    36 
    39 
    37 	p = GetPlayer(_current_player);
    40 	p = GetPlayer(_current_player);
    38 
    41 
    39 	/* Ensure no two companies have the same colour */
    42 	/* Ensure no two companies have the same colour */
    40 	FOR_ALL_PLAYERS(pp) {
    43 	FOR_ALL_PLAYERS(pp) {
    41 		if (pp->is_active && pp != p && pp->player_color == (byte)p2)
    44 		if (pp->is_active && pp != p && pp->player_color == colour)
    42 			return CMD_ERROR;
    45 			return CMD_ERROR;
    43 	}
    46 	}
    44 
    47 
    45 	if (flags & DC_EXEC) {
    48 	if (flags & DC_EXEC) {
    46 		_player_colors[_current_player] = (byte)p2;
    49 		_player_colors[_current_player] = colour;
    47 		p->player_color = (byte)p2;
    50 		p->player_color = colour;
    48 		MarkWholeScreenDirty();
    51 		MarkWholeScreenDirty();
    49 	}
    52 	}
    50 	return 0;
    53 	return 0;
    51 }
    54 }
    52 
    55