author | rubidium |
Mon, 07 Jan 2008 14:23:25 +0000 | |
changeset 8710 | 52015340050c |
parent 8640 | 1e93b81e96d2 |
child 8726 | 5ae45b46506b |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6527
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6516
diff
changeset
|
3 |
/** @file misc_cmd.cpp */ |
f584ab6d87f8
(svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents:
6516
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1881
diff
changeset
|
6 |
#include "openttd.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
193
diff
changeset
|
7 |
#include "table/strings.h" |
8612
6414fc21c2f3
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8610
diff
changeset
|
8 |
#include "command_func.h" |
6414fc21c2f3
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8610
diff
changeset
|
9 |
#include "economy_func.h" |
0 | 10 |
#include "player.h" |
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1328
diff
changeset
|
11 |
#include "gui.h" |
8603
88c5ce6a5215
(svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents:
8602
diff
changeset
|
12 |
#include "window_func.h" |
88c5ce6a5215
(svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents:
8602
diff
changeset
|
13 |
#include "textbuf_gui.h" |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
4850
diff
changeset
|
14 |
#include "network/network.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2150
diff
changeset
|
15 |
#include "variables.h" |
4603
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
16 |
#include "livery.h" |
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
5838
diff
changeset
|
17 |
#include "player_face.h" |
8610
17cc343a23dd
(svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
8603
diff
changeset
|
18 |
#include "strings_func.h" |
8619
c2434269c3eb
(svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents:
8617
diff
changeset
|
19 |
#include "gfx_func.h" |
8627
448ebf3a8291
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8619
diff
changeset
|
20 |
#include "functions.h" |
8640
1e93b81e96d2
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8627
diff
changeset
|
21 |
#include "vehicle_func.h" |
8710
52015340050c
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
8640
diff
changeset
|
22 |
#include "string_func.h" |
0 | 23 |
|
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
24 |
/** Change the player's face. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
2767
diff
changeset
|
25 |
* @param tile unused |
6984
045168d13eef
(svn r9669) -Documentation: some more doxygen fixes
belugas
parents:
6977
diff
changeset
|
26 |
* @param flags operation to perform |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
27 |
* @param p1 unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
28 |
* @param p2 face bitmasked |
0 | 29 |
*/ |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7405
diff
changeset
|
30 |
CommandCost CmdSetPlayerFace(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 31 |
{ |
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
5838
diff
changeset
|
32 |
PlayerFace pf = (PlayerFace)p2; |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
5838
diff
changeset
|
33 |
|
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
5838
diff
changeset
|
34 |
if (!IsValidPlayerFace(pf)) return CMD_ERROR; |
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
5838
diff
changeset
|
35 |
|
0 | 36 |
if (flags & DC_EXEC) { |
6516
ee6d057b9850
(svn r8969) -Codechange: rework of the player face bits.
rubidium
parents:
5838
diff
changeset
|
37 |
GetPlayer(_current_player)->face = pf; |
0 | 38 |
MarkWholeScreenDirty(); |
39 |
} |
|
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
40 |
return CommandCost(); |
0 | 41 |
} |
42 |
||
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
43 |
/** Change the player's company-colour |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
2767
diff
changeset
|
44 |
* @param tile unused |
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6557
diff
changeset
|
45 |
* @param flags operation to perform |
4603
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
46 |
* @param p1 bitstuffed: |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
47 |
* p1 bits 0-7 scheme to set |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
48 |
* p1 bits 8-9 set in use state or first/second colour |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
49 |
* @param p2 new colour for vehicles, property, etc. |
0 | 50 |
*/ |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7405
diff
changeset
|
51 |
CommandCost CmdSetPlayerColor(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 52 |
{ |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
53 |
Player *p, *pp; |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
1962
diff
changeset
|
54 |
byte colour; |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
55 |
LiveryScheme scheme = (LiveryScheme)GB(p1, 0, 8); |
4603
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
56 |
byte state = GB(p1, 8, 2); |
1878
622765748231
(svn r2384) - Fix: Check selling land and setting player colour. Also an extra map-bounds check for terraforming; inspired by the monkey (and Tron :) )
Darkvater
parents:
1877
diff
changeset
|
57 |
|
622765748231
(svn r2384) - Fix: Check selling land and setting player colour. Also an extra map-bounds check for terraforming; inspired by the monkey (and Tron :) )
Darkvater
parents:
1877
diff
changeset
|
58 |
if (p2 >= 16) return CMD_ERROR; // max 16 colours |
2150
010d923a81a9
(svn r2660) Get rid of some more shifting/anding/casting
tron
parents:
1962
diff
changeset
|
59 |
colour = p2; |
0 | 60 |
|
4603
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
61 |
if (scheme >= LS_END || state >= 3) return CMD_ERROR; |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
62 |
|
1767
394867897b0a
(svn r2271) CMD_SET_PLAYER_FACE, CMD_SET_PLAYER_COLOR, CMD_INCREASE_LOAN, CMD_DECREASE_LOAN only make sense for the current player, so don't explicitly pass a player number
tron
parents:
1728
diff
changeset
|
63 |
p = GetPlayer(_current_player); |
0 | 64 |
|
4603
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
65 |
/* Ensure no two companies have the same primary colour */ |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
66 |
if (scheme == LS_DEFAULT && state == 0) { |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
67 |
FOR_ALL_PLAYERS(pp) { |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
68 |
if (pp->is_active && pp != p && pp->player_color == colour) return CMD_ERROR; |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
69 |
} |
0 | 70 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
84
diff
changeset
|
71 |
|
0 | 72 |
if (flags & DC_EXEC) { |
4603
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
73 |
switch (state) { |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
74 |
case 0: |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
75 |
p->livery[scheme].colour1 = colour; |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
76 |
|
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
77 |
/* If setting the first colour of the default scheme, adjust the |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
78 |
* original and cached player colours too. */ |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
79 |
if (scheme == LS_DEFAULT) { |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
80 |
_player_colors[_current_player] = colour; |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
81 |
p->player_color = colour; |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
82 |
} |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
83 |
break; |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
84 |
|
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
85 |
case 1: |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
86 |
p->livery[scheme].colour2 = colour; |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
87 |
break; |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
88 |
|
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
89 |
case 2: |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
90 |
p->livery[scheme].in_use = colour != 0; |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
91 |
|
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
92 |
/* Now handle setting the default scheme's in_use flag. |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
93 |
* This is different to the other schemes, as it signifies if any |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
94 |
* scheme is active at all. If this flag is not set, then no |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
95 |
* processing of vehicle types occurs at all, and only the default |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
96 |
* colours will be used. */ |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
97 |
|
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
98 |
/* If enabling a scheme, set the default scheme to be in use too */ |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
99 |
if (colour != 0) { |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
100 |
p->livery[LS_DEFAULT].in_use = true; |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
101 |
break; |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
102 |
} |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
103 |
|
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
104 |
/* Else loop through all schemes to see if any are left enabled. |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
105 |
* If not, disable the default scheme too. */ |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
106 |
p->livery[LS_DEFAULT].in_use = false; |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
107 |
for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) { |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
108 |
if (p->livery[scheme].in_use) { |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
109 |
p->livery[LS_DEFAULT].in_use = true; |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
110 |
break; |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
111 |
} |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
112 |
} |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
113 |
break; |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
114 |
|
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
115 |
default: |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
116 |
break; |
3ccd4ee0a2e2
(svn r6455) - Feature: Add 2cc (two company colours) livery schemes. This replaces the original colour selection window and bumps the saveload version. Liveries are supported for all vehicles, not just those with 2cc support. Thanks to lakie for GUI inspiration.
peter1138
parents:
4434
diff
changeset
|
117 |
} |
8298
b8f2b501e23a
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx
parents:
8238
diff
changeset
|
118 |
ResetVehicleColorMap(); |
0 | 119 |
MarkWholeScreenDirty(); |
120 |
} |
|
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
121 |
return CommandCost(); |
0 | 122 |
} |
123 |
||
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
124 |
/** Increase the loan of your company. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
2767
diff
changeset
|
125 |
* @param tile unused |
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6557
diff
changeset
|
126 |
* @param flags operation to perform |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
127 |
* @param p1 unused |
7405
480f118e5551
(svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents:
6984
diff
changeset
|
128 |
* @param p2 when 0: loans LOAN_INTERVAL |
480f118e5551
(svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents:
6984
diff
changeset
|
129 |
* when 1: loans the maximum loan permitting money (press CTRL), |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
130 |
*/ |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7405
diff
changeset
|
131 |
CommandCost CmdIncreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 132 |
{ |
7405
480f118e5551
(svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents:
6984
diff
changeset
|
133 |
Player *p = GetPlayer(_current_player); |
0 | 134 |
|
135 |
if (p->current_loan >= _economy.max_loan) { |
|
7498
ce6588257e8d
(svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents:
7487
diff
changeset
|
136 |
SetDParam(0, _economy.max_loan); |
0 | 137 |
return_cmd_error(STR_702B_MAXIMUM_PERMITTED_LOAN); |
138 |
} |
|
139 |
||
7449
5cedaf2c861c
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium
parents:
7448
diff
changeset
|
140 |
Money loan; |
7405
480f118e5551
(svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents:
6984
diff
changeset
|
141 |
switch (p2) { |
480f118e5551
(svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents:
6984
diff
changeset
|
142 |
default: return CMD_ERROR; // Invalid method |
480f118e5551
(svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents:
6984
diff
changeset
|
143 |
case 0: // Take some extra loan |
480f118e5551
(svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents:
6984
diff
changeset
|
144 |
loan = (IsHumanPlayer(_current_player) || _patches.ainew_active) ? LOAN_INTERVAL : LOAN_INTERVAL_OLD_AI; |
480f118e5551
(svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents:
6984
diff
changeset
|
145 |
break; |
480f118e5551
(svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents:
6984
diff
changeset
|
146 |
case 1: // Take a loan as big as possible |
480f118e5551
(svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents:
6984
diff
changeset
|
147 |
loan = _economy.max_loan - p->current_loan; |
480f118e5551
(svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents:
6984
diff
changeset
|
148 |
break; |
480f118e5551
(svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents:
6984
diff
changeset
|
149 |
} |
480f118e5551
(svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents:
6984
diff
changeset
|
150 |
|
7453
67ba4a6fc014
(svn r10212) -Fix [FS#723]: money overflow bugs in many locations.
rubidium
parents:
7449
diff
changeset
|
151 |
/* Overflow protection */ |
67ba4a6fc014
(svn r10212) -Fix [FS#723]: money overflow bugs in many locations.
rubidium
parents:
7449
diff
changeset
|
152 |
if (p->player_money + p->current_loan + loan < p->player_money) return CMD_ERROR; |
67ba4a6fc014
(svn r10212) -Fix [FS#723]: money overflow bugs in many locations.
rubidium
parents:
7449
diff
changeset
|
153 |
|
0 | 154 |
if (flags & DC_EXEC) { |
7448
424ab8df8adb
(svn r10207) -Codechange: remove the redundant player_money in favour of the money64, which is now renamed to player_money.
rubidium
parents:
7446
diff
changeset
|
155 |
p->player_money += loan; |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
156 |
p->current_loan += loan; |
0 | 157 |
InvalidatePlayerWindows(p); |
158 |
} |
|
159 |
||
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
160 |
return CommandCost(); |
0 | 161 |
} |
162 |
||
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
163 |
/** Decrease the loan of your company. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
2767
diff
changeset
|
164 |
* @param tile unused |
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6557
diff
changeset
|
165 |
* @param flags operation to perform |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
166 |
* @param p1 unused |
7405
480f118e5551
(svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents:
6984
diff
changeset
|
167 |
* @param p2 when 0: pays back LOAN_INTERVAL |
480f118e5551
(svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents:
6984
diff
changeset
|
168 |
* when 1: pays back the maximum loan permitting money (press CTRL), |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
169 |
*/ |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7405
diff
changeset
|
170 |
CommandCost CmdDecreaseLoan(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 171 |
{ |
7405
480f118e5551
(svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents:
6984
diff
changeset
|
172 |
Player *p = GetPlayer(_current_player); |
0 | 173 |
|
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
174 |
if (p->current_loan == 0) return_cmd_error(STR_702D_LOAN_ALREADY_REPAYED); |
0 | 175 |
|
7453
67ba4a6fc014
(svn r10212) -Fix [FS#723]: money overflow bugs in many locations.
rubidium
parents:
7449
diff
changeset
|
176 |
Money loan; |
7405
480f118e5551
(svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents:
6984
diff
changeset
|
177 |
switch (p2) { |
480f118e5551
(svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents:
6984
diff
changeset
|
178 |
default: return CMD_ERROR; // Invalid method |
480f118e5551
(svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents:
6984
diff
changeset
|
179 |
case 0: // Pay back one step |
7487
9ef3bd32c2eb
(svn r10247) -Fix (r10210): *always* call SetDParamMoney when you want to place money in some string.
rubidium
parents:
7453
diff
changeset
|
180 |
loan = min(p->current_loan, (Money)(IsHumanPlayer(_current_player) || _patches.ainew_active) ? LOAN_INTERVAL : LOAN_INTERVAL_OLD_AI); |
7405
480f118e5551
(svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents:
6984
diff
changeset
|
181 |
break; |
480f118e5551
(svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents:
6984
diff
changeset
|
182 |
case 1: // Pay back as much as possible |
7453
67ba4a6fc014
(svn r10212) -Fix [FS#723]: money overflow bugs in many locations.
rubidium
parents:
7449
diff
changeset
|
183 |
loan = max(min(p->current_loan, p->player_money), (Money)LOAN_INTERVAL); |
7405
480f118e5551
(svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents:
6984
diff
changeset
|
184 |
loan -= loan % LOAN_INTERVAL; |
480f118e5551
(svn r10158) -Codechange: port some changes from NoAI and FS#872 to make the loan commands a little better readable.
rubidium
parents:
6984
diff
changeset
|
185 |
break; |
0 | 186 |
} |
187 |
||
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
188 |
if (p->player_money < loan) { |
7498
ce6588257e8d
(svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents:
7487
diff
changeset
|
189 |
SetDParam(0, loan); |
0 | 190 |
return_cmd_error(STR_702E_REQUIRED); |
191 |
} |
|
192 |
||
193 |
if (flags & DC_EXEC) { |
|
7448
424ab8df8adb
(svn r10207) -Codechange: remove the redundant player_money in favour of the money64, which is now renamed to player_money.
rubidium
parents:
7446
diff
changeset
|
194 |
p->player_money -= loan; |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
195 |
p->current_loan -= loan; |
0 | 196 |
InvalidatePlayerWindows(p); |
197 |
} |
|
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
198 |
return CommandCost(); |
0 | 199 |
} |
200 |
||
7593
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
201 |
static bool IsUniqueCompanyName(const char *name) |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
202 |
{ |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
203 |
const Player *p; |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
204 |
char buf[512]; |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
205 |
|
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
206 |
FOR_ALL_PLAYERS(p) { |
7604
bdf34754bb16
(svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents:
7593
diff
changeset
|
207 |
if (!p->is_active) continue; |
7593
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
208 |
SetDParam(0, p->index); |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
209 |
GetString(buf, STR_COMPANY_NAME, lastof(buf)); |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
210 |
if (strcmp(buf, name) == 0) return false; |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
211 |
} |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
212 |
|
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
213 |
return true; |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
214 |
} |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
215 |
|
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
216 |
/** Change the name of the company. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
2767
diff
changeset
|
217 |
* @param tile unused |
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6557
diff
changeset
|
218 |
* @param flags operation to perform |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
219 |
* @param p1 unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
220 |
* @param p2 unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
221 |
*/ |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7405
diff
changeset
|
222 |
CommandCost CmdChangeCompanyName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 223 |
{ |
1787
79730785d7e7
(svn r2291) - Fix (regression): When a client joined it changed the server-player's name. Funny effect; but not desired. Thanks for pointing it out Tron. It needed a bit of hacking, but is not less of a hack than the one used before :)
Darkvater
parents:
1786
diff
changeset
|
224 |
StringID str; |
0 | 225 |
Player *p; |
226 |
||
7593
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
227 |
if (StrEmpty(_cmd_text)) return CMD_ERROR; |
1840
c181d5cb4ffe
(svn r2345) - Fix: Don't allow stuff to be renamed to nothing if we don't support it. Only valid ones are signs (delete) and waypoints (rename to default).
Darkvater
parents:
1820
diff
changeset
|
228 |
|
7593
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
229 |
if (!IsUniqueCompanyName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
230 |
|
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
231 |
str = AllocateName(_cmd_text, 4); |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
232 |
if (str == 0) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
84
diff
changeset
|
233 |
|
0 | 234 |
if (flags & DC_EXEC) { |
1962
51ee4f459268
(svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents:
1891
diff
changeset
|
235 |
p = GetPlayer(_current_player); |
1787
79730785d7e7
(svn r2291) - Fix (regression): When a client joined it changed the server-player's name. Funny effect; but not desired. Thanks for pointing it out Tron. It needed a bit of hacking, but is not less of a hack than the one used before :)
Darkvater
parents:
1786
diff
changeset
|
236 |
DeleteName(p->name_1); |
0 | 237 |
p->name_1 = str; |
238 |
MarkWholeScreenDirty(); |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3491
diff
changeset
|
239 |
} else { |
0 | 240 |
DeleteName(str); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3491
diff
changeset
|
241 |
} |
0 | 242 |
|
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
243 |
return CommandCost(); |
0 | 244 |
} |
245 |
||
7593
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
246 |
static bool IsUniquePresidentName(const char *name) |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
247 |
{ |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
248 |
const Player *p; |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
249 |
char buf[512]; |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
250 |
|
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
251 |
FOR_ALL_PLAYERS(p) { |
7604
bdf34754bb16
(svn r10380) -Fix (r10364): when checking for unique names, only check vehicles that can have names, and skip inactive players.
peter1138
parents:
7593
diff
changeset
|
252 |
if (!p->is_active) continue; |
7593
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
253 |
SetDParam(0, p->index); |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
254 |
GetString(buf, STR_PLAYER_NAME, lastof(buf)); |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
255 |
if (strcmp(buf, name) == 0) return false; |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
256 |
} |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
257 |
|
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
258 |
return true; |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
259 |
} |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
260 |
|
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
261 |
/** Change the name of the president. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
2767
diff
changeset
|
262 |
* @param tile unused |
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6557
diff
changeset
|
263 |
* @param flags operation to perform |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
264 |
* @param p1 unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
265 |
* @param p2 unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
266 |
*/ |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7405
diff
changeset
|
267 |
CommandCost CmdChangePresidentName(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 268 |
{ |
1787
79730785d7e7
(svn r2291) - Fix (regression): When a client joined it changed the server-player's name. Funny effect; but not desired. Thanks for pointing it out Tron. It needed a bit of hacking, but is not less of a hack than the one used before :)
Darkvater
parents:
1786
diff
changeset
|
269 |
StringID str; |
0 | 270 |
Player *p; |
271 |
||
7593
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
272 |
if (StrEmpty(_cmd_text)) return CMD_ERROR; |
1840
c181d5cb4ffe
(svn r2345) - Fix: Don't allow stuff to be renamed to nothing if we don't support it. Only valid ones are signs (delete) and waypoints (rename to default).
Darkvater
parents:
1820
diff
changeset
|
273 |
|
7593
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
274 |
if (!IsUniquePresidentName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); |
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
275 |
|
cfce84f8995c
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents:
7498
diff
changeset
|
276 |
str = AllocateName(_cmd_text, 4); |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1767
diff
changeset
|
277 |
if (str == 0) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
84
diff
changeset
|
278 |
|
0 | 279 |
if (flags & DC_EXEC) { |
1962
51ee4f459268
(svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents:
1891
diff
changeset
|
280 |
p = GetPlayer(_current_player); |
1787
79730785d7e7
(svn r2291) - Fix (regression): When a client joined it changed the server-player's name. Funny effect; but not desired. Thanks for pointing it out Tron. It needed a bit of hacking, but is not less of a hack than the one used before :)
Darkvater
parents:
1786
diff
changeset
|
281 |
DeleteName(p->president_name_1); |
0 | 282 |
p->president_name_1 = str; |
283 |
||
284 |
if (p->name_1 == STR_SV_UNNAMED) { |
|
1820
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1799
diff
changeset
|
285 |
char buf[80]; |
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1799
diff
changeset
|
286 |
|
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1799
diff
changeset
|
287 |
snprintf(buf, lengthof(buf), "%s Transport", _cmd_text); |
9b6458526480
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1799
diff
changeset
|
288 |
_cmd_text = buf; |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
2767
diff
changeset
|
289 |
DoCommand(0, 0, 0, DC_EXEC, CMD_CHANGE_COMPANY_NAME); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
84
diff
changeset
|
290 |
} |
0 | 291 |
MarkWholeScreenDirty(); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3491
diff
changeset
|
292 |
} else { |
0 | 293 |
DeleteName(str); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3491
diff
changeset
|
294 |
} |
0 | 295 |
|
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
296 |
return CommandCost(); |
0 | 297 |
} |
298 |
||
8509
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
299 |
/** |
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
300 |
* In case of an unsafe unpause, we want the |
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
301 |
* user to confirm that it might crash. |
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
302 |
* @param w unused |
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
303 |
* @param confirmed whether the user confirms his/her action |
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
304 |
*/ |
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
305 |
static void AskUnsafeUnpauseCallback(Window *w, bool confirmed) |
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
306 |
{ |
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
307 |
DoCommandP(0, confirmed ? 0 : 1, 0, NULL, CMD_PAUSE); |
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
308 |
} |
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
309 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
310 |
/** Pause/Unpause the game (server-only). |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
311 |
* Increase or decrease the pause counter. If the counter is zero, |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
312 |
* the game is unpaused. A counter is used instead of a boolean value |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
313 |
* to have more control over the game when saving/loading, etc. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
2767
diff
changeset
|
314 |
* @param tile unused |
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6557
diff
changeset
|
315 |
* @param flags operation to perform |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
316 |
* @param p1 0 = decrease pause counter; 1 = increase pause counter |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
317 |
* @param p2 unused |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
318 |
*/ |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7405
diff
changeset
|
319 |
CommandCost CmdPause(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 320 |
{ |
321 |
if (flags & DC_EXEC) { |
|
8561
e97b716fabee
(svn r11626) -Fix [FS#1529]: Pause state wasn't set correctly in multiplayer saves
skidd13
parents:
8509
diff
changeset
|
322 |
_pause_game += (p1 == 0) ? -1 : 1; |
8509
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
323 |
|
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
324 |
switch (_pause_game) { |
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
325 |
case (byte)-4: |
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
326 |
case (byte)-1: |
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
327 |
_pause_game = 0; |
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
328 |
break; |
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
329 |
case (byte)-3: |
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
330 |
ShowQuery( |
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
331 |
STR_NEWGRF_UNPAUSE_WARNING_TITLE, |
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
332 |
STR_NEWGRF_UNPAUSE_WARNING, |
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
333 |
NULL, |
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
334 |
AskUnsafeUnpauseCallback |
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
335 |
); |
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
336 |
break; |
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
337 |
|
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
338 |
default: break; |
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
339 |
} |
f7f6bccde48f
(svn r11573) -Codechange: pause games that miss GRFs by default and throw some warnings and disclaimers when you want to unpause it.
rubidium
parents:
8298
diff
changeset
|
340 |
|
0 | 341 |
InvalidateWindow(WC_STATUS_BAR, 0); |
342 |
InvalidateWindow(WC_MAIN_TOOLBAR, 0); |
|
343 |
} |
|
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
344 |
return CommandCost(); |
0 | 345 |
} |
346 |
||
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
347 |
/** Change the financial flow of your company. |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
348 |
* This is normally only enabled in offline mode, but if there is a debug |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
349 |
* build, you can cheat (to test). |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
2767
diff
changeset
|
350 |
* @param tile unused |
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6557
diff
changeset
|
351 |
* @param flags operation to perform |
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
352 |
* @param p1 the amount of money to receive (if negative), or spend (if positive) |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
353 |
* @param p2 unused |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
354 |
*/ |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7405
diff
changeset
|
355 |
CommandCost CmdMoneyCheat(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 356 |
{ |
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
357 |
#ifndef _DEBUG |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
358 |
if (_networking) return CMD_ERROR; |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
359 |
#endif |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
84
diff
changeset
|
360 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
7449
5cedaf2c861c
(svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium
parents:
7448
diff
changeset
|
361 |
return CommandCost(-(Money)p1); |
0 | 362 |
} |
363 |
||
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
364 |
/** Transfer funds (money) from one player to another. |
4434
4175805666a5
(svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents:
4077
diff
changeset
|
365 |
* To prevent abuse in multiplayer games you can only send money to other |
1799
05d56d2d0fea
(svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents:
1796
diff
changeset
|
366 |
* players if you have paid off your loan (either explicitely, or implicitely |
05d56d2d0fea
(svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents:
1796
diff
changeset
|
367 |
* given the fact that you have more money than loan). |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
2767
diff
changeset
|
368 |
* @param tile unused |
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6557
diff
changeset
|
369 |
* @param flags operation to perform |
1799
05d56d2d0fea
(svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents:
1796
diff
changeset
|
370 |
* @param p1 the amount of money to transfer; max 20.000.000 |
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
371 |
* @param p2 the player to transfer the money to |
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
372 |
*/ |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7405
diff
changeset
|
373 |
CommandCost CmdGiveMoney(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
374 |
{ |
8153
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7604
diff
changeset
|
375 |
if (!_patches.give_money) return CMD_ERROR; |
32f871f7e7f7
(svn r11188) -Codechange: rewrite of the town action related code (remove some of the magic).
rubidium
parents:
7604
diff
changeset
|
376 |
|
1962
51ee4f459268
(svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents:
1891
diff
changeset
|
377 |
const Player *p = GetPlayer(_current_player); |
7487
9ef3bd32c2eb
(svn r10247) -Fix (r10210): *always* call SetDParamMoney when you want to place money in some string.
rubidium
parents:
7453
diff
changeset
|
378 |
CommandCost amount(min((Money)p1, (Money)20000000LL)); |
1799
05d56d2d0fea
(svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents:
1796
diff
changeset
|
379 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
380 |
SET_EXPENSES_TYPE(EXPENSES_OTHER); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
381 |
|
1799
05d56d2d0fea
(svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents:
1796
diff
changeset
|
382 |
/* You can only transfer funds that is in excess of your loan */ |
7448
424ab8df8adb
(svn r10207) -Codechange: remove the redundant player_money in favour of the money64, which is now renamed to player_money.
rubidium
parents:
7446
diff
changeset
|
383 |
if (p->player_money - p->current_loan < amount.GetCost() || amount.GetCost() <= 0) return CMD_ERROR; |
4850
b4e9be22945f
(svn r6776) -Codechange: Use IsValidPlayer() function to determine of a PlayerID is an
Darkvater
parents:
4845
diff
changeset
|
384 |
if (!_networking || !IsValidPlayer((PlayerID)p2)) return CMD_ERROR; |
813
90d6adb8d4ad
(svn r1284) -Fix: Fixed 'money-cheat' (read: bug which could give people a lot of money)
truelight
parents:
543
diff
changeset
|
385 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
386 |
if (flags & DC_EXEC) { |
1799
05d56d2d0fea
(svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents:
1796
diff
changeset
|
387 |
/* Add money to player */ |
1796
cae31916ae54
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
388 |
PlayerID old_cp = _current_player; |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
389 |
_current_player = (PlayerID)p2; |
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
390 |
SubtractMoneyFromPlayer(CommandCost(-amount.GetCost())); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
391 |
_current_player = old_cp; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
392 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
393 |
|
1799
05d56d2d0fea
(svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents:
1796
diff
changeset
|
394 |
/* Subtract money from local-player */ |
05d56d2d0fea
(svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
Darkvater
parents:
1796
diff
changeset
|
395 |
return amount; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
396 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
397 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
398 |
/** Change difficulty level/settings (server-only). |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
399 |
* We cannot really check for valid values of p2 (too much work mostly); stored |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
400 |
* in file 'settings_gui.c' _game_setting_info[]; we'll just trust the server it knows |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
401 |
* what to do and does this correctly |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
2767
diff
changeset
|
402 |
* @param tile unused |
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6557
diff
changeset
|
403 |
* @param flags operation to perform |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
404 |
* @param p1 the difficulty setting being changed. If it is -1, the difficulty level |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
405 |
* itself is changed. The new value is inside p2 |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
406 |
* @param p2 new value for a difficulty setting or difficulty level |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
407 |
*/ |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7405
diff
changeset
|
408 |
CommandCost CmdChangeDifficultyLevel(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 409 |
{ |
1877
e7318705dd04
(svn r2383) - Fix: Monkey-testing turned up some command crashes.
Darkvater
parents:
1858
diff
changeset
|
410 |
if (p1 != (uint32)-1L && ((int32)p1 >= GAME_DIFFICULTY_NUM || (int32)p1 < 0)) return CMD_ERROR; |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
411 |
|
0 | 412 |
if (flags & DC_EXEC) { |
413 |
if (p1 != (uint32)-1L) { |
|
8238
29844a206bbe
(svn r11279) -Codechange: use a typedeffed type for all magic with GameDifficulty instead on relying ints to always be 32 bits, which they are not.
rubidium
parents:
8153
diff
changeset
|
414 |
((GDType*)&_opt_ptr->diff)[p1] = p2; |
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
415 |
_opt_ptr->diff_level = 3; // custom difficulty level |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3491
diff
changeset
|
416 |
} else { |
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1328
diff
changeset
|
417 |
_opt_ptr->diff_level = p2; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3491
diff
changeset
|
418 |
} |
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1328
diff
changeset
|
419 |
|
1793
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
420 |
/* If we are a network-client, update the difficult setting (if it is open). |
8ac8a8c9ec0f
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1787
diff
changeset
|
421 |
* Use this instead of just dirtying the window because we need to load in |
1877
e7318705dd04
(svn r2383) - Fix: Monkey-testing turned up some command crashes.
Darkvater
parents:
1858
diff
changeset
|
422 |
* the new difficulty settings */ |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
423 |
if (_networking && !_network_server && FindWindowById(WC_GAME_OPTIONS, 0) != NULL) |
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1328
diff
changeset
|
424 |
ShowGameDifficulty(); |
0 | 425 |
} |
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
426 |
return CommandCost(); |
0 | 427 |
} |