OpenTTD Source: src/signs.cpp Source File

OpenTTD Source 15.0-RC2

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#include "stdafx.h"
11#include "landscape.h"
12#include "company_func.h"
13#include "signs_base.h"
14#include "signs_func.h"
15#include "strings_func.h"
16#include "core/pool_func.hpp"
17#include "viewport_kdtree.h"
18
19#include "table/strings.h"
20
21#include "safeguards.h"
22
24 SignPool _sign_pool("Sign");
25 INSTANTIATE_POOL_METHODS(Sign)
26
27
28 Sign::~Sign()
29{
30 if (CleaningPool()) return;
31
32 DeleteRenameSignWindow(this->index);
33}
34
38 void Sign::UpdateVirtCoord()
39{
40 Point pt = RemapCoords(this->x, this->y, this->z);
41
42 if (this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeSign(this->index));
43
44 this->sign.UpdatePosition(pt.x, pt.y - 6 * ZOOM_BASE, GetString(STR_WHITE_SIGN, this->index));
45
46 _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeSign(this->index));
47}
48
50 void UpdateAllSignVirtCoords()
51{
52 for (Sign *si : Sign::Iterate()) {
53 si->UpdateVirtCoord();
54 }
55}
56
62 bool CompanyCanEditSign(const Sign *si)
63{
64 if (si->owner == OWNER_DEITY && _current_company != OWNER_DEITY && _game_mode != GM_EDITOR) return false;
65 return true;
66}
Kdtree::Insert
void Insert(const T &element)
Insert a single element in the tree.
Definition kdtree.hpp:396
Kdtree::Remove
void Remove(const T &element)
Remove a single element from the tree, if it exists.
Definition kdtree.hpp:415
_current_company
CompanyID _current_company
Company currently doing an action.
Definition company_cmd.cpp:56
company_func.h
Functions related to companies.
OWNER_DEITY
static constexpr Owner OWNER_DEITY
The object is owned by a superuser / goal script.
Definition company_type.h:28
landscape.h
Functions related to OTTD's landscape.
RemapCoords
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:81
pool_func.hpp
Some methods of Pool are placed here in order to reduce compilation time and binary size.
INSTANTIATE_POOL_METHODS
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
Definition pool_func.hpp:210
safeguards.h
A number of safeguards to prevent using unsafe methods.
CompanyCanEditSign
bool CompanyCanEditSign(const Sign *si)
Check if the current company can rename or move a given sign.
Definition signs.cpp:62
_sign_pool
SignPool _sign_pool("Sign")
Initialize the sign-pool.
UpdateAllSignVirtCoords
void UpdateAllSignVirtCoords()
Update the coordinates of all signs.
Definition signs.cpp:50
signs_base.h
Base class for signs.
signs_func.h
Functions related to signs.
DeleteRenameSignWindow
void DeleteRenameSignWindow(SignID sign)
Close the sign window associated with the given sign.
Definition signs_gui.cpp:601
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
strings_func.h
Functions related to OTTD's strings.
Coord2D< int >
Coord2D::y
T y
Y coordinate.
Definition geometry_type.hpp:35
Coord2D::x
T x
X coordinate.
Definition geometry_type.hpp:34
Pool::PoolItem<&_sign_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition pool_type.hpp:436
Pool::PoolItem<&_sign_pool >::index
Tindex index
Index of this pool item.
Definition pool_type.hpp:286
Pool
Base class for all pools.
Definition pool_type.hpp:133
Sign
Definition signs_base.h:21
Sign::UpdateVirtCoord
void UpdateVirtCoord()
Update the coordinate of one sign.
Definition signs.cpp:38
TrackedViewportSign::UpdatePosition
void UpdatePosition(int center, int top, std::string_view str, std::string_view str_small={})
Update the position of the viewport sign.
Definition viewport_type.h:69
TrackedViewportSign::kdtree_valid
bool kdtree_valid
Are the sign data valid for use with the _viewport_sign_kdtree?
Definition viewport_type.h:61