OpenTTD Source 20260208-master-g43af8e94d0
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
9
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
24SignPool _sign_pool("Sign");
26
27
28Sign::~Sign()
29{
30 if (CleaningPool()) return;
31
33}
34
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
51{
52 for (Sign *si : Sign::Iterate()) {
53 si->UpdateVirtCoord();
54 }
55}
56
62bool 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}
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
static constexpr Owner OWNER_DEITY
The object is owned by a superuser / goal script.
Functions related to OTTD's landscape.
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
#define Point
Macro that prevents name conflicts between included headers.
Some methods of Pool are placed here in order to reduce compilation time and binary size.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
A number of safeguards to prevent using unsafe methods.
bool CompanyCanEditSign(const Sign *si)
Check if the current company can rename or move a given sign.
Definition signs.cpp:62
SignPool _sign_pool("Sign")
Initialize the sign-pool.
void UpdateAllSignVirtCoords()
Update the coordinates of all signs.
Definition signs.cpp:50
Base class for signs.
Functions related to signs.
void DeleteRenameSignWindow(SignID sign)
Close the sign window associated with the given sign.
Definition of base types and functions in a cross-platform compatible way.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
Functions related to OTTD's strings.
T y
Y coordinate.
T x
X coordinate.
static Pool::IterateWrapper< Sign > Iterate(size_t from=0)
void UpdateVirtCoord()
Update the coordinate of one sign.
Definition signs.cpp:38
Declarations for accessing the k-d tree of viewports.