cyphesis/server/CorePropertyManager.cpp

279 lines
10 KiB
C++
Raw Normal View History

// Cyphesis Online RPG Server and AI Engine
// Copyright (C) 2006 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 "CorePropertyManager.h"
#include "server/Juncture.h"
#include "server/ServerRouting.h"
#include "server/TeleportProperty.h"
#include "rulesets/LineProperty.h"
#include "rulesets/OutfitProperty.h"
#include "rulesets/SolidProperty.h"
#include "rulesets/StatusProperty.h"
#include "rulesets/StatisticsProperty.h"
#include "rulesets/TerrainModProperty.h"
#include "rulesets/TerrainProperty.h"
#include "rulesets/TransientProperty.h"
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
#include "rulesets/BBoxProperty.h"
2013-01-09 22:26:12 +00:00
#include "rulesets/BiomassProperty.h"
#include "rulesets/BurnSpeedProperty.h"
2013-01-10 10:07:44 +00:00
#include "rulesets/DecaysProperty.h"
#include "rulesets/MindProperty.h"
#include "rulesets/InternalProperties.h"
#include "rulesets/SpawnProperty.h"
#include "rulesets/AreaProperty.h"
2011-01-07 22:57:26 +00:00
#include "rulesets/VisibilityProperty.h"
#include "rulesets/SuspendedProperty.h"
#include "rulesets/TasksProperty.h"
#include "rulesets/EntityProperty.h"
#include "rulesets/SpawnerProperty.h"
#include "rulesets/ImmortalProperty.h"
#include "rulesets/RespawningProperty.h"
#include "rulesets/DefaultLocationProperty.h"
#include "rulesets/DomainProperty.h"
#include "rulesets/LimboProperty.h"
#include "rulesets/ModeProperty.h"
#include "rulesets/PropelProperty.h"
#include "rulesets/DensityProperty.h"
#include "rulesets/AngularFactorProperty.h"
#include "rulesets/GeometryProperty.h"
#include "rulesets/QuaternionProperty.h"
#include "rulesets/Vector3Property.h"
#include "common/Eat.h"
#include "common/Burn.h"
#include "common/Teleport.h"
#include "common/types.h"
#include "common/Inheritance.h"
#include "common/PropertyFactory_impl.h"
#include "common/debug.h"
#include <Atlas/Objects/Operation.h>
#include <iostream>
using Atlas::Message::Element;
using Atlas::Message::ListType;
using Atlas::Message::MapType;
using Atlas::Objects::Root;
static const bool debug_flag = false;
template<typename T>
void CorePropertyManager::installBaseProperty(const std::string & type_name,
const std::string & parent)
{
installFactory(type_name,
atlasType(type_name, parent, true),
new PropertyFactory<Property<T>>);
}
template<typename PropertyT>
void CorePropertyManager::installProperty(const std::string & type_name,
const std::string & parent)
{
installFactory(type_name,
atlasType(type_name, parent),
2013-02-22 23:48:52 +00:00
new PropertyFactory<PropertyT>);
}
template<typename PropertyT>
void CorePropertyManager::installProperty(const std::string & parent)
{
this->installProperty<PropertyT>(PropertyT::property_name, parent);
}
template<typename PropertyT>
void CorePropertyManager::installProperty()
{
this->installProperty<PropertyT>(PropertyT::property_name, PropertyT::property_atlastype);
}
CorePropertyManager::CorePropertyManager()
{
// Core types, for inheritance only generally.
installBaseProperty<int>("int", "root_type");
installBaseProperty<double>("float", "root_type");
installBaseProperty<std::string>("string", "root_type");
installBaseProperty<ListType>("list", "root_type");
installBaseProperty<MapType>("map", "root_type");
installProperty<Property<double>>("stamina", "float");
2018-02-06 13:08:23 +01:00
installProperty<ModeProperty>();
installProperty<LineProperty>("coords", "list");
installProperty<LineProperty>("points", "list");
2017-08-02 10:04:31 +02:00
//installProperty<Property<IdList> >("start_intersections", "list");
//installProperty<Property<IdList> >("end_intersections", "list");
installProperty<DecaysProperty>("decays", "string");
installProperty<OutfitProperty>("outfit", "map");
installProperty<SolidProperty>("solid", "int");
installProperty<SimpleProperty>("simple", "int");
installProperty<StatusProperty>("status", "float");
installProperty<BiomassProperty>("biomass", "float");
installProperty<BurnSpeedProperty>("burn_speed", "float");
installProperty<TransientProperty>("transient", "float");
installProperty<Property<double> >("food", "float");
installProperty<Property<double> >("mass", "float");
installProperty<BBoxProperty>("bbox", "list");
installProperty<MindProperty>("mind", "map");
installProperty<SetupProperty>("init", "int");
installProperty<TickProperty>("ticks", "float");
installProperty<StatisticsProperty>("statistics", "map");
installProperty<SpawnProperty>("spawn", "map");
installProperty<AreaProperty>("area", "map");
installProperty<VisibilityProperty>("visibility", "float");
installProperty<TerrainModProperty>();
installProperty<TerrainProperty>("terrain", "map");
installProperty<TeleportProperty>("linked", "string");
installProperty<SuspendedProperty>("suspended", "int");
installProperty<TasksProperty>("tasks", "map");
installProperty<EntityProperty>("right_hand_wield", "string");
installProperty<SpawnerProperty>("spawner", "map");
installProperty<ImmortalProperty>("immortal", "int");
installProperty<RespawningProperty>("respawning", "string");
installProperty<DefaultLocationProperty>("default_location", "int");
2016-06-26 13:18:56 +02:00
installProperty<DomainProperty>("domain", "string");
installProperty<LimboProperty>("limbo", "int");
installProperty<PropelProperty>();
installProperty<DensityProperty>();
2016-07-19 17:07:51 +02:00
/**
* Friction is used by the physics system. 0 is no friction, 1 is full friction.
2018-03-09 20:05:41 +01:00
* This is for "sliding", see "friction-roll" and "friction-spin".
2016-07-19 17:07:51 +02:00
*/
2018-03-09 20:05:41 +01:00
installProperty<Property<double>>("friction", "float");
/**
* Friction for rolling is used by the physics system. 0 is no friction, 1 is full friction.
*/
installProperty<Property<double>>("friction_roll", "float");
/**
* Friction for spinning is used by the physics system. 0 is no friction, 1 is full friction.
*/
installProperty<Property<double>>("friction_spin", "float");
installProperty<AngularFactorProperty>();
installProperty<GeometryProperty>();
2018-03-23 19:22:35 +01:00
installProperty<EntityProperty>("planted_on", "string");
/**
* Vertical offset to use when entity is planted, and adjusted to the height of the terrain.
*/
installProperty<Property<double>>("planted-offset", "float");
/**
* Vertical scaled offset to use when entity is planted, and adjusted to the height of the terrain.
* The resulting offset is a product of this value and the height of the entity.
*/
installProperty<Property<double>>("planted-scaled-offset", "float");
/**
* The rotation applied to the entity when it's planted.
*/
installProperty<QuaternionProperty>("planted-rotation", QuaternionProperty::property_atlastype);
/**
* The current extra rotation applied to the entity.
* This is closely matched with "planted-rotation" to keep track of when the entity has the planted rotation applied and not.
*/
installProperty<QuaternionProperty>("active-rotation", QuaternionProperty::property_atlastype);
/**
* Used for things that grows, to limit the size.
*/
installProperty<Vector3Property>("maxsize", Vector3Property::property_atlastype);
/**
* Specifies how much the entity is allowed to step onto things when moving, as a factor of the entity's height.
*/
installProperty<Property<double>>("step_factor", "float");
/**
* Specifies a mesh, model or mapping to use for client side presentation.
*/
installProperty<Property<std::string> >("present", "string");
/**
* The max speed in meters per second (m/s) when moving over ground.
*/
installProperty<Property<double>>("speed-ground", "float");
/**
* The max speed in meters per second (m/s) when moving in water.
*/
installProperty<Property<double>>("speed-water", "float");
/**
* The max speed in meters per second (m/s) when flying.
*/
installProperty<Property<double>>("speed-flight", "float");
/**
* The max speed in meters per second (m/s) when jumping.
*/
installProperty<Property<double>>("speed-jump", "float");
/**
* If set to 1 the entity is a body of water, i.e. either an Ocean (if no bbox) or a lake/pond (if a bbox).
*/
installProperty<Property<int>>("water_body", "int");
}
int CorePropertyManager::installFactory(const std::string & type_name,
const Root & type_desc,
PropertyKit * factory)
{
Inheritance & i = Inheritance::instance();
if (i.addChild(type_desc) == 0) {
return -1;
}
PropertyManager::installFactory(type_name, factory);
return 0;
}
PropertyBase * CorePropertyManager::addProperty(const std::string & name,
int type)
{
assert(!name.empty());
assert(name != "objtype");
PropertyBase * p = 0;
PropertyFactoryDict::const_iterator I = m_propertyFactories.find(name);
if (I == m_propertyFactories.end()) {
switch (type) {
case Element::TYPE_INT:
p = new Property<int>;
break;
case Element::TYPE_FLOAT:
p = new Property<double>;
break;
case Element::TYPE_STRING:
p = new Property<std::string>;
break;
default:
p = new SoftProperty;
break;
}
} else {
p = I->second->newProperty();
}
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
debug(std::cout << name << " property found. " << std::endl << std::flush;);
return p;
}