2012-06-29 16:44:26 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
// This file is part of Remere's Map Editor
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
2020-07-30 11:42:28 -03:00
|
|
|
// Remere's Map Editor 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, either version 3 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// Remere's Map Editor 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
2012-06-29 16:44:26 +02:00
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
|
|
2021-05-25 00:29:12 -03:00
|
|
|
#include "npc_brush.h"
|
2012-06-29 16:44:26 +02:00
|
|
|
#include "settings.h"
|
|
|
|
|
#include "tile.h"
|
2021-05-25 00:29:12 -03:00
|
|
|
#include "npc.h"
|
2012-06-29 16:44:26 +02:00
|
|
|
#include "basemap.h"
|
2021-05-25 00:29:12 -03:00
|
|
|
#include "spawn_npc.h"
|
2012-06-29 16:44:26 +02:00
|
|
|
|
|
|
|
|
//=============================================================================
|
2021-05-25 00:29:12 -03:00
|
|
|
// Npc brush
|
2012-06-29 16:44:26 +02:00
|
|
|
|
2021-05-25 00:29:12 -03:00
|
|
|
NpcBrush::NpcBrush(NpcType* type) :
|
2012-06-29 16:44:26 +02:00
|
|
|
Brush(),
|
2021-05-25 00:29:12 -03:00
|
|
|
npc_type(type)
|
2012-06-29 16:44:26 +02:00
|
|
|
{
|
2014-01-22 20:16:17 +01:00
|
|
|
ASSERT(type->brush == nullptr);
|
2021-05-25 00:29:12 -03:00
|
|
|
type->brush/* = this*/;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2021-05-25 00:29:12 -03:00
|
|
|
NpcBrush::~NpcBrush()
|
2015-12-06 11:42:37 -03:00
|
|
|
{
|
|
|
|
|
////
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2021-05-25 00:29:12 -03:00
|
|
|
int NpcBrush::getLookID() const
|
2015-12-06 11:42:37 -03:00
|
|
|
{
|
2012-06-29 16:44:26 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-25 00:29:12 -03:00
|
|
|
std::string NpcBrush::getName() const
|
2015-12-06 11:42:37 -03:00
|
|
|
{
|
2021-05-25 00:29:12 -03:00
|
|
|
if(npc_type)
|
|
|
|
|
return npc_type->name;
|
|
|
|
|
return "Npc Brush";
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2021-05-25 00:29:12 -03:00
|
|
|
bool NpcBrush::canDraw(BaseMap* map, const Position& position) const
|
2014-03-01 14:44:11 +01:00
|
|
|
{
|
|
|
|
|
Tile* tile = map->getTile(position);
|
2021-05-25 00:29:12 -03:00
|
|
|
if(npc_type && tile && !tile->isBlocking()) {
|
|
|
|
|
if (tile->getLocation()->getSpawnNpcCount() != 0 || g_settings.getInteger(Config::AUTO_CREATE_SPAWN_NPC)) {
|
2015-12-06 11:42:37 -03:00
|
|
|
if(tile->isPZ()) {
|
2021-05-25 00:29:12 -03:00
|
|
|
return true;
|
2012-06-29 16:44:26 +02:00
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-25 00:29:12 -03:00
|
|
|
void NpcBrush::undraw(BaseMap* map, Tile* tile)
|
2015-12-06 11:42:37 -03:00
|
|
|
{
|
2021-05-25 00:29:12 -03:00
|
|
|
delete tile->npc;
|
|
|
|
|
tile->npc = nullptr;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2021-05-25 00:29:12 -03:00
|
|
|
void NpcBrush::draw(BaseMap* map, Tile* tile, void* parameter)
|
2015-12-06 11:42:37 -03:00
|
|
|
{
|
2012-06-29 16:44:26 +02:00
|
|
|
ASSERT(tile);
|
|
|
|
|
ASSERT(parameter);
|
|
|
|
|
if(canDraw(map, tile->getPosition())) {
|
|
|
|
|
undraw(map, tile);
|
2021-05-25 00:29:12 -03:00
|
|
|
if(npc_type) {
|
|
|
|
|
if(tile->spawnNpc == nullptr && tile->getLocation()->getSpawnNpcCount() == 0) {
|
|
|
|
|
// manually place npc spawn on location
|
|
|
|
|
tile->spawnNpc = newd SpawnNpc(1);
|
2014-12-17 02:05:09 +13:00
|
|
|
}
|
2021-05-25 00:29:12 -03:00
|
|
|
tile->npc = newd Npc(npc_type);
|
|
|
|
|
tile->npc->setSpawnNpcTime(*(int*)parameter);
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|