2008-08-14 00:03:12 +00:00
|
|
|
// Cyphesis Online RPG Server and AI Engine
|
|
|
|
|
// Copyright (C) 2004 Alistair Riddoch
|
|
|
|
|
//
|
|
|
|
|
// This program 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 2 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program 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, write to the Free Software Foundation,
|
|
|
|
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "TerrainModProperty.h"
|
|
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
#include "LocatedEntity.h"
|
2011-01-06 19:49:24 +00:00
|
|
|
#include "TerrainModTranslator.h"
|
2010-09-13 02:09:26 +01:00
|
|
|
#include "TerrainProperty.h"
|
2008-08-14 00:03:12 +00:00
|
|
|
|
2010-09-12 20:20:24 +01:00
|
|
|
#include "common/compose.hpp"
|
2008-08-14 00:03:12 +00:00
|
|
|
#include "common/log.h"
|
|
|
|
|
#include "common/debug.h"
|
|
|
|
|
|
|
|
|
|
#include "modules/Location.h"
|
2010-09-17 22:00:59 +01:00
|
|
|
#include "modules/TerrainContext.h"
|
|
|
|
|
|
|
|
|
|
#include <Mercator/TerrainMod.h>
|
2008-08-14 00:03:12 +00:00
|
|
|
|
2013-01-10 00:19:31 +00:00
|
|
|
#include <Atlas/Objects/RootEntity.h>
|
2013-02-14 00:04:58 +00:00
|
|
|
#include <Atlas/Objects/Operation.h>
|
2013-01-10 00:19:31 +00:00
|
|
|
#include <Atlas/Objects/SmartPtr.h>
|
|
|
|
|
|
2008-08-14 00:03:12 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
|
|
static const bool debug_flag = false;
|
|
|
|
|
|
|
|
|
|
using Atlas::Message::Element;
|
|
|
|
|
using Atlas::Message::MapType;
|
|
|
|
|
using Atlas::Message::ListType;
|
|
|
|
|
using Atlas::Message::FloatType;
|
2013-01-10 00:19:31 +00:00
|
|
|
using Atlas::Objects::Entity::RootEntity;
|
|
|
|
|
using Atlas::Objects::Root;
|
2008-08-14 00:03:12 +00:00
|
|
|
|
|
|
|
|
/// \brief TerrainModProperty constructor
|
|
|
|
|
///
|
2013-02-14 00:04:58 +00:00
|
|
|
TerrainModProperty::TerrainModProperty() : m_modptr(0), m_innerMod(0)
|
2008-08-14 00:03:12 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-05 21:04:56 +01:00
|
|
|
TerrainModProperty::~TerrainModProperty()
|
|
|
|
|
{
|
2010-11-11 17:32:53 +00:00
|
|
|
// TODO remove the mod from the terrain
|
2010-09-12 20:20:24 +01:00
|
|
|
// This is already covered from the Delete op handler when
|
|
|
|
|
// the entity is deleted
|
2010-11-11 17:53:32 +00:00
|
|
|
delete m_innerMod;
|
2009-01-05 21:04:56 +01:00
|
|
|
}
|
|
|
|
|
|
2013-01-08 00:19:23 +00:00
|
|
|
TerrainModProperty * TerrainModProperty::copy() const
|
|
|
|
|
{
|
|
|
|
|
// This is for instantiation of a class property.
|
|
|
|
|
// This is complex here, as is it not yet clear if this
|
|
|
|
|
// class can be a class property.
|
|
|
|
|
return new TerrainModProperty(*this);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-13 00:45:36 +00:00
|
|
|
void TerrainModProperty::install(LocatedEntity * owner, const std::string & name)
|
2008-09-08 Al Riddoch <alriddoch@googlemail.com>
* rulesets/ActivePropertyFactory_impl.h: Re-work the active property
factories so they just pass handler information to the property
classes rather than installing it themselves, so the property
can now handle installing the handlers each time they are installed
on an entity, making class default properties work.
* client/ClientPropertyManager.cpp, client/ClientPropertyManager.h,
common/PropertyFactory.h, common/PropertyFactory_impl.h,
common/PropertyManager.h, rulesets/ActivePropertyFactory.h,
server/CorePropertyManager.cpp, server/CorePropertyManager.h:
Modify the property manager and property factory interfaces so they
do not take a pointer to the owner, as this is never required any
more.
* rulesets/Character.cpp, rulesets/Entity.cpp: Modify code that uses
property managers to use the new interface.
* rulesets/SolidProperty.cpp, rulesets/SolidProperty.h: Make use of
the bool flag to implement this, preventing it from being tied to
having a pointer to the owner at creation time.
* rulesets/StatusProperty.cpp, rulesets/StatusProperty.h: Remove
the need for an owner pointer at construction time by using the
apply method.
* rulesets/TerrainModProperty.cpp, rulesets/TerrainModProperty.h:
Use new MultiActivePropertyManager and install method to handle
installing handlers rather than relying on the factory to do it.
* server/CorePropertyManager.cpp: Change many of the property
factories now that none get get an owner pointer.
* server/EntityFactory.cpp: Set up default properties on all type
nodes when a new class is installed, and don't apply instance
properties based on class defaults, relying on class properties.
* rulesets/Entity.cpp: Remove hard coded BBox property now that the
functionality is handled by a more special property.
2008-09-08 00:17:08 +00:00
|
|
|
{
|
2013-02-14 00:04:58 +00:00
|
|
|
owner->installDelegate(Atlas::Objects::Operation::DELETE_NO, name);
|
|
|
|
|
owner->installDelegate(Atlas::Objects::Operation::MOVE_NO, name);
|
2008-09-08 Al Riddoch <alriddoch@googlemail.com>
* rulesets/ActivePropertyFactory_impl.h: Re-work the active property
factories so they just pass handler information to the property
classes rather than installing it themselves, so the property
can now handle installing the handlers each time they are installed
on an entity, making class default properties work.
* client/ClientPropertyManager.cpp, client/ClientPropertyManager.h,
common/PropertyFactory.h, common/PropertyFactory_impl.h,
common/PropertyManager.h, rulesets/ActivePropertyFactory.h,
server/CorePropertyManager.cpp, server/CorePropertyManager.h:
Modify the property manager and property factory interfaces so they
do not take a pointer to the owner, as this is never required any
more.
* rulesets/Character.cpp, rulesets/Entity.cpp: Modify code that uses
property managers to use the new interface.
* rulesets/SolidProperty.cpp, rulesets/SolidProperty.h: Make use of
the bool flag to implement this, preventing it from being tied to
having a pointer to the owner at creation time.
* rulesets/StatusProperty.cpp, rulesets/StatusProperty.h: Remove
the need for an owner pointer at construction time by using the
apply method.
* rulesets/TerrainModProperty.cpp, rulesets/TerrainModProperty.h:
Use new MultiActivePropertyManager and install method to handle
installing handlers rather than relying on the factory to do it.
* server/CorePropertyManager.cpp: Change many of the property
factories now that none get get an owner pointer.
* server/EntityFactory.cpp: Set up default properties on all type
nodes when a new class is installed, and don't apply instance
properties based on class defaults, relying on class properties.
* rulesets/Entity.cpp: Remove hard coded BBox property now that the
functionality is handled by a more special property.
2008-09-08 00:17:08 +00:00
|
|
|
}
|
|
|
|
|
|
2014-08-25 22:42:00 +02:00
|
|
|
void TerrainModProperty::remove(LocatedEntity *owner, const std::string & name)
|
|
|
|
|
{
|
|
|
|
|
owner->removeDelegate(Atlas::Objects::Operation::DELETE_NO, name);
|
|
|
|
|
owner->removeDelegate(Atlas::Objects::Operation::MOVE_NO, name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
void TerrainModProperty::apply(LocatedEntity * owner)
|
2010-09-12 20:20:24 +01:00
|
|
|
{
|
|
|
|
|
// Find the terrain
|
2010-11-11 17:32:53 +00:00
|
|
|
const TerrainProperty * terrain = getTerrain(owner);
|
2010-09-12 20:20:24 +01:00
|
|
|
|
2010-11-11 17:32:53 +00:00
|
|
|
if (terrain == 0) {
|
2010-09-12 20:20:24 +01:00
|
|
|
log(ERROR, "Terrain Modifier could not find terrain");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Parse the Atlas data for our mod
|
2010-11-11 17:32:53 +00:00
|
|
|
Mercator::TerrainMod * mod = parseModData(owner, m_data);
|
2010-09-12 20:20:24 +01:00
|
|
|
|
2010-11-11 17:32:53 +00:00
|
|
|
if (mod == 0) {
|
2010-09-12 20:20:24 +01:00
|
|
|
log(ERROR, "Terrain Modifier could not be parsed!");
|
2010-11-11 17:32:53 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If there is an old mod ...
|
|
|
|
|
if (m_modptr != 0) {
|
|
|
|
|
// and the new one is the same, just update
|
|
|
|
|
if (mod == m_modptr) {
|
|
|
|
|
terrain->updateMod(m_modptr);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// If the mod has changed then remove the old one and dlete it.
|
|
|
|
|
terrain->removeMod(m_modptr);
|
|
|
|
|
delete m_modptr;
|
2010-09-12 20:20:24 +01:00
|
|
|
}
|
2011-01-11 13:09:23 +00:00
|
|
|
|
|
|
|
|
m_modptr = mod;
|
|
|
|
|
|
2010-11-11 17:32:53 +00:00
|
|
|
// Apply the new mod to the terrain; retain the returned pointer
|
|
|
|
|
terrain->addMod(m_modptr);
|
|
|
|
|
m_modptr->setContext(new TerrainContext(owner));
|
|
|
|
|
m_modptr->context()->setId(owner->getId());
|
2010-09-12 20:20:24 +01:00
|
|
|
}
|
|
|
|
|
|
2013-02-14 00:04:58 +00:00
|
|
|
HandlerResult TerrainModProperty::operation(LocatedEntity * ent,
|
|
|
|
|
const Operation & op,
|
|
|
|
|
OpVector & res)
|
|
|
|
|
{
|
|
|
|
|
if (op->getClassNo() == Atlas::Objects::Operation::DELETE_NO) {
|
|
|
|
|
return delete_handler(ent, op, res);
|
|
|
|
|
} else if (op->getClassNo() == Atlas::Objects::Operation::MOVE_NO) {
|
|
|
|
|
return move_handler(ent, op, res);
|
|
|
|
|
}
|
|
|
|
|
return OPERATION_IGNORED;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
void TerrainModProperty::move(LocatedEntity* owner)
|
2008-08-17 18:12:09 +00:00
|
|
|
{
|
2010-09-13 00:16:01 +01:00
|
|
|
const TerrainProperty* terrain = getTerrain(owner);
|
2010-11-11 17:32:53 +00:00
|
|
|
|
|
|
|
|
if (terrain == 0) {
|
|
|
|
|
log(ERROR, "Terrain Modifier could not find terrain");
|
|
|
|
|
return;
|
2009-01-06 13:33:18 +01:00
|
|
|
}
|
2010-11-11 17:32:53 +00:00
|
|
|
|
|
|
|
|
Mercator::TerrainMod* mod = parseModData(owner, m_data);
|
|
|
|
|
|
|
|
|
|
if (mod == 0) {
|
|
|
|
|
log(ERROR, "Terrain Modifier could not be parsed!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mod != m_modptr) {
|
|
|
|
|
log(ERROR, "Terrain Modifier mysteriously changed when moved!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
terrain->updateMod(mod);
|
2008-08-17 18:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
void TerrainModProperty::remove(LocatedEntity * owner)
|
2008-08-18 18:59:48 +00:00
|
|
|
{
|
2009-01-06 13:33:18 +01:00
|
|
|
if (m_modptr) {
|
2010-09-13 00:16:01 +01:00
|
|
|
const TerrainProperty* terrain = getTerrain(owner);
|
2009-01-06 13:33:18 +01:00
|
|
|
if (terrain) {
|
|
|
|
|
terrain->removeMod(m_modptr);
|
2010-11-11 17:32:53 +00:00
|
|
|
delete m_modptr;
|
|
|
|
|
m_modptr = 0;
|
2015-04-06 21:42:14 +02:00
|
|
|
} else {
|
|
|
|
|
log(WARNING, "Terrain property was removed from an entity from which no terrain was available.");
|
2009-01-06 13:33:18 +01:00
|
|
|
}
|
|
|
|
|
}
|
2008-08-18 18:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
Mercator::TerrainMod * TerrainModProperty::parseModData(LocatedEntity * owner,
|
2010-10-28 19:21:53 +01:00
|
|
|
const MapType & modMap)
|
2008-08-14 00:03:12 +00:00
|
|
|
{
|
2010-10-28 19:21:53 +01:00
|
|
|
if (m_innerMod == 0) {
|
2011-01-06 19:01:37 +00:00
|
|
|
m_innerMod = new TerrainModTranslator;
|
2009-01-06 13:33:18 +01:00
|
|
|
}
|
2008-08-17 21:48:22 +00:00
|
|
|
|
2010-11-10 16:11:21 +00:00
|
|
|
if (m_innerMod->parseData(owner->m_location.pos(),
|
|
|
|
|
owner->m_location.orientation(), modMap)) {
|
2010-10-28 19:21:53 +01:00
|
|
|
return m_innerMod->getModifier();
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-11 17:32:53 +00:00
|
|
|
return 0;
|
2008-08-14 00:03:12 +00:00
|
|
|
}
|
2010-09-18 23:59:30 +01:00
|
|
|
|
|
|
|
|
int TerrainModProperty::getAttr(const std::string & name,
|
|
|
|
|
Element & val)
|
|
|
|
|
{
|
|
|
|
|
MapType::const_iterator I = m_data.find(name);
|
|
|
|
|
if (I != m_data.end()) {
|
|
|
|
|
val = I->second;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TerrainModProperty::setAttr(const std::string & name,
|
|
|
|
|
const Element & val)
|
|
|
|
|
{
|
|
|
|
|
m_data[name] = val;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
HandlerResult TerrainModProperty::move_handler(LocatedEntity * e,
|
2013-01-10 00:19:31 +00:00
|
|
|
const Operation & op,
|
|
|
|
|
OpVector & res)
|
|
|
|
|
{
|
2013-02-14 00:04:58 +00:00
|
|
|
// FIXME Force instantiation of a class property?
|
2013-01-10 00:19:31 +00:00
|
|
|
|
|
|
|
|
// Check the validity of the operation.
|
|
|
|
|
const std::vector<Root> & args = op->getArgs();
|
|
|
|
|
if (args.empty()) {
|
|
|
|
|
return OPERATION_IGNORED;
|
|
|
|
|
}
|
|
|
|
|
RootEntity ent = Atlas::Objects::smart_dynamic_cast<RootEntity>(args.front());
|
|
|
|
|
if (!ent.isValid()) {
|
|
|
|
|
return OPERATION_IGNORED;
|
|
|
|
|
}
|
|
|
|
|
if (e->getId() != ent->getId()) {
|
|
|
|
|
return OPERATION_IGNORED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update the modifier
|
2013-02-14 00:04:58 +00:00
|
|
|
move(e);
|
2013-01-10 00:19:31 +00:00
|
|
|
return OPERATION_IGNORED;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-17 10:17:07 +00:00
|
|
|
HandlerResult TerrainModProperty::delete_handler(LocatedEntity * e,
|
2013-01-10 00:19:31 +00:00
|
|
|
const Operation & op,
|
|
|
|
|
OpVector & res)
|
|
|
|
|
{
|
2013-02-14 00:04:58 +00:00
|
|
|
remove(e);
|
2013-01-10 00:19:31 +00:00
|
|
|
|
|
|
|
|
return OPERATION_IGNORED;
|
|
|
|
|
}
|
|
|
|
|
|