OpenTTD Source: src/signs.cpp Source File

OpenTTD Source 15.0-beta1

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 "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
30 Sign::Sign(Owner owner)
31{
32 this->owner = owner;
33}
34
36Sign::~Sign()
37{
38 if (CleaningPool()) return;
39
40 DeleteRenameSignWindow(this->index);
41}
42
46 void Sign::UpdateVirtCoord()
47{
48 Point pt = RemapCoords(this->x, this->y, this->z);
49
50 if (this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeSign(this->index));
51
52 SetDParam(0, this->index);
53 this->sign.UpdatePosition(pt.x, pt.y - 6 * ZOOM_BASE, STR_WHITE_SIGN);
54
55 _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeSign(this->index));
56}
57
59 void UpdateAllSignVirtCoords()
60{
61 for (Sign *si : Sign::Iterate()) {
62 si->UpdateVirtCoord();
63 }
64}
65
71 bool CompanyCanRenameSign(const Sign *si)
72{
73 if (si->owner == OWNER_DEITY && _current_company != OWNER_DEITY && _game_mode != GM_EDITOR) return false;
74 return true;
75}
Kdtree::Insert
void Insert(const T &element)
Insert a single element in the tree.
Definition kdtree.hpp:398
Kdtree::Remove
void Remove(const T &element)
Remove a single element from the tree, if it exists.
Definition kdtree.hpp:417
_current_company
CompanyID _current_company
Company currently doing an action.
Definition company_cmd.cpp:53
company_func.h
Functions related to companies.
Owner
Owner
Enum for all companies/owners.
Definition company_type.h:18
OWNER_DEITY
@ OWNER_DEITY
The object is owned by a superuser / goal script.
Definition company_type.h:27
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:79
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:237
safeguards.h
A number of safeguards to prevent using unsafe methods.
_sign_pool
SignPool _sign_pool("Sign")
Initialize the sign-pool.
CompanyCanRenameSign
bool CompanyCanRenameSign(const Sign *si)
Check if the current company can rename a given sign.
Definition signs.cpp:71
UpdateAllSignVirtCoords
void UpdateAllSignVirtCoords()
Update the coordinates of all signs.
Definition signs.cpp:59
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:585
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition strings.cpp:104
strings_func.h
Functions related to OTTD's strings.
Point
Coordinates of a point in 2D.
Definition geometry_type.hpp:21
Pool::PoolItem<&_sign_pool >::index
Tindex index
Index of this pool item.
Definition pool_type.hpp:238
Pool::PoolItem<&_sign_pool >::CleaningPool
static bool CleaningPool()
Returns current state of pool cleaning - yes or no.
Definition pool_type.hpp:318
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:388
Pool
Base class for all pools.
Definition pool_type.hpp:80
Sign
Definition signs_base.h:21
Sign::UpdateVirtCoord
void UpdateVirtCoord()
Update the coordinate of one sign.
Definition signs.cpp:46
Sign::~Sign
~Sign()
Destroy the sign.
Definition signs.cpp:36
TrackedViewportSign::UpdatePosition
void UpdatePosition(int center, int top, StringID str, StringID str_small=STR_NULL)
Update the position of the viewport sign.
Definition viewport_type.h:60
TrackedViewportSign::kdtree_valid
bool kdtree_valid
Are the sign data valid for use with the _viewport_sign_kdtree?
Definition viewport_type.h:52