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"
|
|
|
|
|
|
|
|
|
|
#include "creature_brush.h"
|
2021-10-02 21:42:57 -04:00
|
|
|
#include "gui.h"
|
2012-06-29 16:44:26 +02:00
|
|
|
#include "settings.h"
|
|
|
|
|
#include "tile.h"
|
|
|
|
|
#include "creature.h"
|
|
|
|
|
#include "basemap.h"
|
2014-12-17 02:05:09 +13:00
|
|
|
#include "spawn.h"
|
2012-06-29 16:44:26 +02:00
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// Creature brush
|
|
|
|
|
|
|
|
|
|
CreatureBrush::CreatureBrush(CreatureType* type) :
|
|
|
|
|
Brush(),
|
|
|
|
|
creature_type(type)
|
|
|
|
|
{
|
2014-01-22 20:16:17 +01:00
|
|
|
ASSERT(type->brush == nullptr);
|
2012-06-29 16:44:26 +02:00
|
|
|
type->brush = this;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
CreatureBrush::~CreatureBrush()
|
|
|
|
|
{
|
|
|
|
|
////
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
int CreatureBrush::getLookID() const
|
|
|
|
|
{
|
2012-06-29 16:44:26 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
std::string CreatureBrush::getName() const
|
|
|
|
|
{
|
2012-06-29 16:44:26 +02:00
|
|
|
if(creature_type)
|
|
|
|
|
return creature_type->name;
|
|
|
|
|
return "Creature Brush";
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-01 14:44:11 +01:00
|
|
|
bool CreatureBrush::canDraw(BaseMap* map, const Position& position) const
|
|
|
|
|
{
|
|
|
|
|
Tile* tile = map->getTile(position);
|
2015-12-06 11:42:37 -03:00
|
|
|
if(creature_type && tile && !tile->isBlocking()) {
|
2016-09-29 20:37:43 -03:00
|
|
|
if(tile->getLocation()->getSpawnCount() != 0 || g_settings.getInteger(Config::AUTO_CREATE_SPAWN)) {
|
2015-12-06 11:42:37 -03:00
|
|
|
if(tile->isPZ()) {
|
|
|
|
|
if(creature_type->isNpc) {
|
2012-06-29 16:44:26 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
void CreatureBrush::undraw(BaseMap* map, Tile* tile)
|
|
|
|
|
{
|
2012-06-29 16:44:26 +02:00
|
|
|
delete tile->creature;
|
2014-01-22 20:16:17 +01:00
|
|
|
tile->creature = nullptr;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-06 11:42:37 -03:00
|
|
|
void CreatureBrush::draw(BaseMap* map, Tile* tile, void* parameter)
|
|
|
|
|
{
|
2012-06-29 16:44:26 +02:00
|
|
|
ASSERT(tile);
|
|
|
|
|
ASSERT(parameter);
|
2021-10-02 21:42:57 -04:00
|
|
|
draw_creature(map, tile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CreatureBrush::draw_creature(BaseMap* map, Tile* tile)
|
|
|
|
|
{
|
2023-01-25 21:44:24 -03:00
|
|
|
if(canDraw(map, tile->getPosition())) {
|
2012-06-29 16:44:26 +02:00
|
|
|
undraw(map, tile);
|
|
|
|
|
if(creature_type) {
|
2015-12-06 11:42:37 -03:00
|
|
|
if(tile->spawn == nullptr && tile->getLocation()->getSpawnCount() == 0) {
|
2014-12-17 02:05:09 +13:00
|
|
|
// manually place spawn on location
|
|
|
|
|
tile->spawn = newd Spawn(1);
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
tile->creature = newd Creature(creature_type);
|
2021-10-02 21:42:57 -04:00
|
|
|
tile->creature->setSpawnTime(g_gui.GetSpawnTime());
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|