2009-08-21 22:21:05 +02:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 17:11:33 +02:00
|
|
|
/** @file signs.cpp Handling of signs. */
|
2007-04-04 03:35:16 +02:00
|
|
|
|
2005-01-12 12:21:28 +01:00
|
|
|
#include "stdafx.h"
|
2007-04-12 15:07:15 +02:00
|
|
|
#include "landscape.h"
|
2021-11-28 15:16:42 +01:00
|
|
|
#include "company_func.h"
|
2008-03-31 09:25:49 +02:00
|
|
|
#include "signs_base.h"
|
|
|
|
#include "signs_func.h"
|
2007-12-21 20:49:27 +01:00
|
|
|
#include "strings_func.h"
|
2009-05-22 17:13:50 +02:00
|
|
|
#include "core/pool_func.hpp"
|
2019-12-01 23:17:33 +01:00
|
|
|
#include "viewport_kdtree.h"
|
2005-01-12 12:21:28 +01:00
|
|
|
|
2008-01-13 02:21:35 +01:00
|
|
|
#include "table/strings.h"
|
|
|
|
|
2014-04-23 22:13:33 +02:00
|
|
|
#include "safeguards.h"
|
|
|
|
|
2011-05-01 21:51:52 +02:00
|
|
|
/** Initialize the sign-pool */
|
2009-05-22 17:13:50 +02:00
|
|
|
SignPool _sign_pool("Sign");
|
|
|
|
INSTANTIATE_POOL_METHODS(Sign)
|
2007-08-02 15:27:45 +02:00
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/**
|
|
|
|
* Creates a new sign
|
|
|
|
*/
|
2008-09-30 22:39:50 +02:00
|
|
|
Sign::Sign(Owner owner)
|
2005-02-04 15:45:32 +01:00
|
|
|
{
|
2008-01-12 20:58:06 +01:00
|
|
|
this->owner = owner;
|
2007-08-02 15:27:45 +02:00
|
|
|
}
|
2005-02-04 15:45:32 +01:00
|
|
|
|
2011-01-19 00:09:43 +01:00
|
|
|
/** Destroy the sign */
|
2007-08-02 15:27:45 +02:00
|
|
|
Sign::~Sign()
|
|
|
|
{
|
2008-09-16 21:05:38 +02:00
|
|
|
if (CleaningPool()) return;
|
|
|
|
|
|
|
|
DeleteRenameSignWindow(this->index);
|
2007-08-02 15:27:45 +02:00
|
|
|
}
|
2005-02-04 15:45:32 +01:00
|
|
|
|
2005-01-12 12:21:28 +01:00
|
|
|
/**
|
|
|
|
* Update the coordinate of one sign
|
|
|
|
*/
|
2009-07-14 00:33:25 +02:00
|
|
|
void Sign::UpdateVirtCoord()
|
2005-01-12 12:21:28 +01:00
|
|
|
{
|
2009-07-14 00:33:25 +02:00
|
|
|
Point pt = RemapCoords(this->x, this->y, this->z);
|
2019-12-01 23:17:33 +01:00
|
|
|
|
|
|
|
if (this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeSign(this->index));
|
|
|
|
|
2009-07-14 00:33:25 +02:00
|
|
|
SetDParam(0, this->index);
|
2024-04-04 19:27:34 +02:00
|
|
|
this->sign.UpdatePosition(pt.x, pt.y - 6 * ZOOM_BASE, STR_WHITE_SIGN);
|
2019-12-01 23:17:33 +01:00
|
|
|
|
|
|
|
_viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeSign(this->index));
|
2005-01-12 12:21:28 +01:00
|
|
|
}
|
|
|
|
|
2009-01-04 16:32:25 +01:00
|
|
|
/** Update the coordinates of all signs */
|
2007-03-07 12:47:46 +01:00
|
|
|
void UpdateAllSignVirtCoords()
|
2005-01-12 12:21:28 +01:00
|
|
|
{
|
2019-12-17 19:14:42 +01:00
|
|
|
for (Sign *si : Sign::Iterate()) {
|
2009-07-14 00:33:25 +02:00
|
|
|
si->UpdateVirtCoord();
|
|
|
|
}
|
2005-01-12 12:21:28 +01:00
|
|
|
}
|
2021-11-28 15:16:42 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the current company can rename a given sign.
|
|
|
|
* @param *si The sign in question.
|
|
|
|
* @return true if the sign can be renamed, else false.
|
|
|
|
*/
|
|
|
|
bool CompanyCanRenameSign(const Sign *si)
|
|
|
|
{
|
|
|
|
if (si->owner == OWNER_DEITY && _current_company != OWNER_DEITY && _game_mode != GM_EDITOR) return false;
|
|
|
|
return true;
|
|
|
|
}
|