src/signs.cpp
author terom@frrb.lan
Fri, 19 Dec 2008 01:32:07 +0200
changeset 10438 51bff16a04c9
parent 10208 72c00af5c95d
permissions -rw-r--r--
initial mini-map stuff
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 9036
diff changeset
     3
/** @file signs.cpp Handling of signs. */
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6247
diff changeset
     4
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1881
diff changeset
     6
#include "openttd.h"
6453
226bcddeba32 (svn r9609) -Codechange: Move some function prototypes out of functions.h and into landscape.h, and add a few where they didn't exist.
maedhros
parents: 6420
diff changeset
     7
#include "landscape.h"
10208
72c00af5c95d (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents: 10207
diff changeset
     8
#include "company_func.h"
8790
4a7a796b3976 (svn r12501) -Codechange: split signs.h.
rubidium
parents: 8268
diff changeset
     9
#include "signs_base.h"
4a7a796b3976 (svn r12501) -Codechange: split signs.h.
rubidium
parents: 8268
diff changeset
    10
#include "signs_func.h"
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    11
#include "saveload.h"
8116
8da76dcb3287 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8114
diff changeset
    12
#include "command_func.h"
2153
ecfc674410b4 (svn r2663) Include variables.h only in these files which need it, not globally via openttd.h
tron
parents: 1977
diff changeset
    13
#include "variables.h"
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 7545
diff changeset
    14
#include "strings_func.h"
8225
cd84a95b6630 (svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium
parents: 8214
diff changeset
    15
#include "viewport_func.h"
9148
ba0f18cfc795 (svn r13010) -Codechange: move the tree building GUI out of misc_gui.cpp.
rubidium
parents: 9111
diff changeset
    16
#include "tilehighlight_func.h"
8123
ce31d2843a95 (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8121
diff changeset
    17
#include "zoom_func.h"
8131
160939e24ed3 (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: 8123
diff changeset
    18
#include "functions.h"
160939e24ed3 (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: 8123
diff changeset
    19
#include "window_func.h"
8139
4e91c448c409 (svn r11701) -Codechange: removal unnecessary inclusions of map.h (and split map.h).
rubidium
parents: 8131
diff changeset
    20
#include "map_func.h"
8214
971f861d5543 (svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents: 8139
diff changeset
    21
#include "string_func.h"
8847
426dd2d582e7 (svn r12599) -Codechange: force AllocateSafeRaw() to be linked to simplify compiler's decisions about inlining
smatz
parents: 8790
diff changeset
    22
#include "oldpool_func.h"
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    23
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8258
diff changeset
    24
#include "table/strings.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8258
diff changeset
    25
7295
ad5c855e13b1 (svn r10643) -Merge (from NoAI): properly counting the amount of signs instead of using the size of the sign pool.
rubidium
parents: 7266
diff changeset
    26
SignID _new_sign_id;
2789
12a6b123f12c (svn r3337) Remove an unused variable and add 2 times static
tron
parents: 2783
diff changeset
    27
7384
353183a5cd3a (svn r10753) -Codechange: make the sign struct use the pool item class as super class.
rubidium
parents: 7295
diff changeset
    28
/* Initialize the sign-pool */
353183a5cd3a (svn r10753) -Codechange: make the sign struct use the pool item class as super class.
rubidium
parents: 7295
diff changeset
    29
DEFINE_OLD_POOL_GENERIC(Sign, Sign)
353183a5cd3a (svn r10753) -Codechange: make the sign struct use the pool item class as super class.
rubidium
parents: 7295
diff changeset
    30
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10156
diff changeset
    31
Sign::Sign(Owner owner)
1283
85b520ad7266 (svn r1787) -Add: Dynamic signs (euh.. yeah, this means you can built 64k signs)
truelight
parents: 1201
diff changeset
    32
{
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
    33
	this->owner = owner;
1283
85b520ad7266 (svn r1787) -Add: Dynamic signs (euh.. yeah, this means you can built 64k signs)
truelight
parents: 1201
diff changeset
    34
}
85b520ad7266 (svn r1787) -Add: Dynamic signs (euh.. yeah, this means you can built 64k signs)
truelight
parents: 1201
diff changeset
    35
7384
353183a5cd3a (svn r10753) -Codechange: make the sign struct use the pool item class as super class.
rubidium
parents: 7295
diff changeset
    36
Sign::~Sign()
353183a5cd3a (svn r10753) -Codechange: make the sign struct use the pool item class as super class.
rubidium
parents: 7295
diff changeset
    37
{
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
    38
	free(this->name);
10156
5f8b021e74d6 (svn r14345) -Fix: delete the RenameSignWindow when 'its' sign is deleted
smatz
parents: 9959
diff changeset
    39
5f8b021e74d6 (svn r14345) -Fix: delete the RenameSignWindow when 'its' sign is deleted
smatz
parents: 9959
diff changeset
    40
	if (CleaningPool()) return;
5f8b021e74d6 (svn r14345) -Fix: delete the RenameSignWindow when 'its' sign is deleted
smatz
parents: 9959
diff changeset
    41
5f8b021e74d6 (svn r14345) -Fix: delete the RenameSignWindow when 'its' sign is deleted
smatz
parents: 9959
diff changeset
    42
	DeleteRenameSignWindow(this->index);
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10156
diff changeset
    43
	this->owner = INVALID_OWNER;
7384
353183a5cd3a (svn r10753) -Codechange: make the sign struct use the pool item class as super class.
rubidium
parents: 7295
diff changeset
    44
}
353183a5cd3a (svn r10753) -Codechange: make the sign struct use the pool item class as super class.
rubidium
parents: 7295
diff changeset
    45
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    46
/**
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    47
 *
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    48
 * Update the coordinate of one sign
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6247
diff changeset
    49
 * @param si Pointer to the Sign
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    50
 *
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    51
 */
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
    52
static void UpdateSignVirtCoords(Sign *si)
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    53
{
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
    54
	Point pt = RemapCoords(si->x, si->y, si->z);
7056
6daddeaa79df (svn r10321) -Codechange: refer to sign text by index
peter1138
parents: 6950
diff changeset
    55
	SetDParam(0, si->index);
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
    56
	UpdateViewportSignPos(&si->sign, pt.x, pt.y - 6, STR_2806);
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    57
}
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    58
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    59
/**
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    60
 *
990
d2872f4948c1 (svn r1488) -Fix: fixed some spelling mistakes (tnx to Tron)
truelight
parents: 988
diff changeset
    61
 * Update the coordinates of all signs
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    62
 *
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    63
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5587
diff changeset
    64
void UpdateAllSignVirtCoords()
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    65
{
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
    66
	Sign *si;
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    67
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
    68
	FOR_ALL_SIGNS(si) UpdateSignVirtCoords(si);
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    69
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    70
}
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    71
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    72
/**
7545
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7511
diff changeset
    73
 * Marks the region of a sign as dirty.
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    74
 *
7545
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7511
diff changeset
    75
 * This function marks the sign in all viewports as dirty for repaint.
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    76
 *
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
    77
 * @param si Pointer to the Sign
7545
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7511
diff changeset
    78
 * @ingroup dirty
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    79
 */
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
    80
static void MarkSignDirty(Sign *si)
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    81
{
6700
3c214e54cd1f (svn r9932) -Fix: can't assume a zoom-level with MarkAllViewportsDirty, causing segfaults when trying to load savegames in dedicated server via -g (reported by peter1138)
truelight
parents: 6653
diff changeset
    82
	/* We use ZOOM_LVL_MAX here, as every viewport can have an other zoom,
3c214e54cd1f (svn r9932) -Fix: can't assume a zoom-level with MarkAllViewportsDirty, causing segfaults when trying to load savegames in dedicated server via -g (reported by peter1138)
truelight
parents: 6653
diff changeset
    83
		*  and there is no way for us to know which is the biggest. So make the
3c214e54cd1f (svn r9932) -Fix: can't assume a zoom-level with MarkAllViewportsDirty, causing segfaults when trying to load savegames in dedicated server via -g (reported by peter1138)
truelight
parents: 6653
diff changeset
    84
		*  biggest area dirty, and we are safe for sure. */
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    85
	MarkAllViewportsDirty(
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
    86
		si->sign.left - 6,
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
    87
		si->sign.top  - 3,
6700
3c214e54cd1f (svn r9932) -Fix: can't assume a zoom-level with MarkAllViewportsDirty, causing segfaults when trying to load savegames in dedicated server via -g (reported by peter1138)
truelight
parents: 6653
diff changeset
    88
		si->sign.left + ScaleByZoom(si->sign.width_1 + 12, ZOOM_LVL_MAX),
3c214e54cd1f (svn r9932) -Fix: can't assume a zoom-level with MarkAllViewportsDirty, causing segfaults when trying to load savegames in dedicated server via -g (reported by peter1138)
truelight
parents: 6653
diff changeset
    89
		si->sign.top  + ScaleByZoom(12, ZOOM_LVL_MAX));
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    90
}
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    91
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
    92
/**
4400
82e6cecb71ec (svn r6153) -Codechange: DeleteSign removes a sign from the pool
truelight
parents: 4384
diff changeset
    93
 * Place a sign at the given coordinates. Ownership of sign has
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1575
diff changeset
    94
 * no effect whatsoever except for the colour the sign gets for easy recognition,
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1575
diff changeset
    95
 * but everybody is able to rename/remove it.
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3047
diff changeset
    96
 * @param tile tile to place sign at
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6247
diff changeset
    97
 * @param flags type of operation
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1575
diff changeset
    98
 * @param p1 unused
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1575
diff changeset
    99
 * @param p2 unused
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   100
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6700
diff changeset
   101
CommandCost CmdPlaceSign(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   102
{
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   103
	/* Try to locate a new sign */
9036
6368fe55fd6d (svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents: 8847
diff changeset
   104
	if (!Sign::CanAllocateItem()) return_cmd_error(STR_2808_TOO_MANY_SIGNS);
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   105
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   106
	/* When we execute, really make the sign */
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   107
	if (flags & DC_EXEC) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10156
diff changeset
   108
		Sign *si = new Sign(_current_company);
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3047
diff changeset
   109
		int x = TileX(tile) * TILE_SIZE;
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3047
diff changeset
   110
		int y = TileY(tile) * TILE_SIZE;
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3047
diff changeset
   111
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   112
		si->x = x;
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   113
		si->y = y;
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6453
diff changeset
   114
		si->z = GetSlopeZ(x, y);
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   115
		UpdateSignVirtCoords(si);
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   116
		MarkSignDirty(si);
9734
eb7fab767c8e (svn r13866) -Codechange: Use sortlist for sign windows
peter1138
parents: 9388
diff changeset
   117
		InvalidateWindowData(WC_SIGN_LIST, 0, 0);
7295
ad5c855e13b1 (svn r10643) -Merge (from NoAI): properly counting the amount of signs instead of using the size of the sign pool.
rubidium
parents: 7266
diff changeset
   118
		_new_sign_id = si->index;
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   119
	}
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   120
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   121
	return CommandCost();
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   122
}
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   123
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1575
diff changeset
   124
/** Rename a sign. If the new name of the sign is empty, we assume
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1575
diff changeset
   125
 * the user wanted to delete it. So delete it. Ownership of signs
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1575
diff changeset
   126
 * has no meaning/effect whatsoever except for eyecandy
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3047
diff changeset
   127
 * @param tile unused
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6247
diff changeset
   128
 * @param flags type of operation
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1575
diff changeset
   129
 * @param p1 index of the sign to be renamed/removed
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1575
diff changeset
   130
 * @param p2 unused
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6247
diff changeset
   131
 * @return 0 if succesfull, otherwise CMD_ERROR
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   132
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6700
diff changeset
   133
CommandCost CmdRenameSign(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   134
{
4352
6703cd8d39e0 (svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents: 4349
diff changeset
   135
	if (!IsValidSignID(p1)) return CMD_ERROR;
1837
549f054afcbc (svn r2342) - Fix (Regression): _cmd_text is always valid, so test the first character for '\0'. Also for some reason I forgot to validate the p1 param so that might lead to crashes with invalid signes. Fixed as well.
Darkvater
parents: 1835
diff changeset
   136
549f054afcbc (svn r2342) - Fix (Regression): _cmd_text is always valid, so test the first character for '\0'. Also for some reason I forgot to validate the p1 param so that might lead to crashes with invalid signes. Fixed as well.
Darkvater
parents: 1835
diff changeset
   137
	/* If _cmd_text 0 means the new text for the sign is non-empty.
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1575
diff changeset
   138
	 * So rename the sign. If it is empty, it has no name, so delete it */
7511
3b5200bf7342 (svn r11026) -Fix: the name of a sign could sometimes be NULL causing crashes.
rubidium
parents: 7413
diff changeset
   139
	if (!StrEmpty(_cmd_text)) {
9914
c07d0352d8d5 (svn r14064) -Fix [FS#1752]: check for the length of strings (in bytes) in the command. Checking for the length in pixels is impossible because that differs per client.
rubidium
parents: 9734
diff changeset
   140
		if (strlen(_cmd_text) >= MAX_LENGTH_SIGN_NAME_BYTES) return CMD_ERROR;
c07d0352d8d5 (svn r14064) -Fix [FS#1752]: check for the length of strings (in bytes) in the command. Checking for the length in pixels is impossible because that differs per client.
rubidium
parents: 9734
diff changeset
   141
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   142
		if (flags & DC_EXEC) {
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   143
			Sign *si = GetSign(p1);
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   144
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   145
			/* Delete the old name */
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   146
			free(si->name);
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   147
			/* Assign the new one */
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   148
			si->name = strdup(_cmd_text);
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10156
diff changeset
   149
			si->owner = _current_company;
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   150
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1575
diff changeset
   151
			/* Update; mark sign dirty twice, because it can either becom longer, or shorter */
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   152
			MarkSignDirty(si);
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   153
			UpdateSignVirtCoords(si);
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   154
			MarkSignDirty(si);
9734
eb7fab767c8e (svn r13866) -Codechange: Use sortlist for sign windows
peter1138
parents: 9388
diff changeset
   155
			InvalidateWindowData(WC_SIGN_LIST, 0, 1);
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   156
		}
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6247
diff changeset
   157
	} else { // Delete sign
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   158
		if (flags & DC_EXEC) {
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   159
			Sign *si = GetSign(p1);
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   160
4384
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 4352
diff changeset
   161
			MarkSignDirty(si);
7384
353183a5cd3a (svn r10753) -Codechange: make the sign struct use the pool item class as super class.
rubidium
parents: 7295
diff changeset
   162
			delete si;
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   163
9959
e2a9b616962a (svn r14114) -Fix [FS#2242]: Sign list was not properly updated on removal of signs.
frosch
parents: 9914
diff changeset
   164
			InvalidateWindowData(WC_SIGN_LIST, 0, 0);
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   165
		}
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   166
	}
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   167
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   168
	return CommandCost();
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   169
}
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   170
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   171
/**
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   172
 * Callback function that is called after a sign is placed
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6247
diff changeset
   173
 * @param success of the operation
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6247
diff changeset
   174
 * @param tile unused
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6247
diff changeset
   175
 * @param p1 unused
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6247
diff changeset
   176
 * @param p2 unused
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   177
 */
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   178
void CcPlaceSign(bool success, TileIndex tile, uint32 p1, uint32 p2)
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   179
{
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   180
	if (success) {
7295
ad5c855e13b1 (svn r10643) -Merge (from NoAI): properly counting the amount of signs instead of using the size of the sign pool.
rubidium
parents: 7266
diff changeset
   181
		ShowRenameSignWindow(GetSign(_new_sign_id));
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   182
		ResetObjectToPlace();
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   183
	}
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   184
}
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   185
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   186
/**
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   187
 *
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   188
 * PlaceProc function, called when someone pressed the button if the
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   189
 *  sign-tool is selected
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6247
diff changeset
   190
 * @param tile on which to place the sign
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   191
 */
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   192
void PlaceProc_Sign(TileIndex tile)
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   193
{
2783
0dac7c830584 (svn r3331) CMD_PLACE_SIGN doesn't use p1, so don't pass anything seemingly meaningful
tron
parents: 2239
diff changeset
   194
	DoCommandP(tile, 0, 0, CcPlaceSign, CMD_PLACE_SIGN | CMD_MSG(STR_2809_CAN_T_PLACE_SIGN_HERE));
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   195
}
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   196
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   197
/**
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   198
 *
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   199
 * Initialize the signs
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   200
 *
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   201
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5587
diff changeset
   202
void InitializeSigns()
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   203
{
7384
353183a5cd3a (svn r10753) -Codechange: make the sign struct use the pool item class as super class.
rubidium
parents: 7295
diff changeset
   204
	_Sign_pool.CleanPool();
353183a5cd3a (svn r10753) -Codechange: make the sign struct use the pool item class as super class.
rubidium
parents: 7295
diff changeset
   205
	_Sign_pool.AddBlockToPool();
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   206
}
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   207
1881
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1837
diff changeset
   208
static const SaveLoad _sign_desc[] = {
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   209
  SLE_CONDVAR(Sign, name,  SLE_NAME,                   0, 83),
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   210
  SLE_CONDSTR(Sign, name,  SLE_STR, 0,                84, SL_MAX_VERSION),
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   211
  SLE_CONDVAR(Sign, x,     SLE_FILE_I16 | SLE_VAR_I32, 0, 4),
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   212
  SLE_CONDVAR(Sign, y,     SLE_FILE_I16 | SLE_VAR_I32, 0, 4),
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   213
  SLE_CONDVAR(Sign, x,     SLE_INT32,                  5, SL_MAX_VERSION),
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   214
  SLE_CONDVAR(Sign, y,     SLE_INT32,                  5, SL_MAX_VERSION),
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   215
  SLE_CONDVAR(Sign, owner, SLE_UINT8,                  6, SL_MAX_VERSION),
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   216
      SLE_VAR(Sign, z,     SLE_UINT8),
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   217
	SLE_END()
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   218
};
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   219
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   220
/**
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   221
 *
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   222
 * Save all signs
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   223
 *
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   224
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5587
diff changeset
   225
static void Save_SIGN()
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   226
{
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   227
	Sign *si;
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   228
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   229
	FOR_ALL_SIGNS(si) {
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   230
		SlSetArrayIndex(si->index);
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   231
		SlObject(si, _sign_desc);
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   232
	}
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   233
}
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   234
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   235
/**
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   236
 *
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   237
 * Load all signs
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   238
 *
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   239
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5587
diff changeset
   240
static void Load_SIGN()
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   241
{
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   242
	int index;
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   243
	while ((index = SlIterateArray()) != -1) {
7384
353183a5cd3a (svn r10753) -Codechange: make the sign struct use the pool item class as super class.
rubidium
parents: 7295
diff changeset
   244
		Sign *si = new (index) Sign();
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   245
		SlObject(si, _sign_desc);
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   246
	}
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   247
}
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   248
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   249
extern const ChunkHandler _sign_chunk_handlers[] = {
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   250
	{ 'SIGN', Save_SIGN, Load_SIGN, CH_ARRAY | CH_LAST},
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
diff changeset
   251
};