OpenTTD
signs.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #include "stdafx.h"
11 #include "landscape.h"
12 #include "signs_base.h"
13 #include "signs_func.h"
14 #include "strings_func.h"
15 #include "core/pool_func.hpp"
16 #include "viewport_kdtree.h"
17 
18 #include "table/strings.h"
19 
20 #include "safeguards.h"
21 
23 SignPool _sign_pool("Sign");
25 
26 
29 Sign::Sign(Owner owner)
30 {
31  this->owner = owner;
32 }
33 
36 {
37  free(this->name);
38 
39  if (CleaningPool()) return;
40 
42 }
43 
48 {
49  Point pt = RemapCoords(this->x, this->y, this->z);
50 
51  if (this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeSign(this->index));
52 
53  SetDParam(0, this->index);
54  this->sign.UpdatePosition(pt.x, pt.y - 6 * ZOOM_LVL_BASE, STR_WHITE_SIGN);
55 
56  _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeSign(this->index));
57 }
58 
61 {
62  for (Sign *si : Sign::Iterate()) {
63  si->UpdateVirtCoord();
64  }
65 }
Functions related to OTTD&#39;s strings.
Owner
Enum for all companies/owners.
Definition: company_type.h:18
void DeleteRenameSignWindow(SignID sign)
Close the sign window associated with the given sign.
Definition: signs_gui.cpp:581
static Point RemapCoords(int x, int y, int z)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap...
Definition: landscape.h:82
Tindex index
Index of this pool item.
Definition: pool_type.hpp:189
void UpdatePosition(int center, int top, StringID str, StringID str_small=STR_NULL)
Update the position of the viewport sign.
Definition: viewport_type.h:64
Functions related to signs.
Some methods of Pool are placed here in order to reduce compilation time and binary size...
Definition of base types and functions in a cross-platform compatible way.
SignPool _sign_pool("Sign")
Initialize the sign-pool.
A number of safeguards to prevent using unsafe methods.
void UpdateAllSignVirtCoords()
Update the coordinates of all signs.
Definition: signs.cpp:60
void UpdateVirtCoord()
Update the coordinate of one sign.
Definition: signs.cpp:47
Base class for all pools.
Definition: pool_type.hpp:82
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don&#39;t get linker errors.
Definition: pool_func.hpp:224
static bool CleaningPool()
Returns current state of pool cleaning - yes or no.
Definition: pool_type.hpp:270
~Sign()
Destroy the sign.
Definition: signs.cpp:35
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:340
void Remove(const T &element)
Remove a single element from the tree, if it exists.
Definition: kdtree.hpp:420
Functions related to OTTD&#39;s landscape.
Coordinates of a point in 2D.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:129
bool kdtree_valid
Are the sign data valid for use with the _viewport_sign_kdtree?
Definition: viewport_type.h:58
void Insert(const T &element)
Insert a single element in the tree.
Definition: kdtree.hpp:401
Base class for signs.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:199