2006-06-26 00:21:32 +00:00
|
|
|
// 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
|
|
|
|
|
|
2007-06-22 12:42:35 +00:00
|
|
|
// $Id: CorePropertyManager.cpp,v 1.21 2007-06-22 12:42:36 alriddoch Exp $
|
2006-10-26 00:48:00 +00:00
|
|
|
|
2006-06-26 00:21:32 +00:00
|
|
|
#include "CorePropertyManager.h"
|
|
|
|
|
|
2006-12-03 06:31:43 +00:00
|
|
|
#include "rulesets/ActivePropertyFactory_impl.h"
|
2007-01-27 16:35:36 +00:00
|
|
|
#include "rulesets/EntityPropertyFactory_impl.h"
|
|
|
|
|
|
2006-06-29 14:57:19 +00:00
|
|
|
#include "rulesets/LineProperty.h"
|
2006-12-29 00:41:18 +00:00
|
|
|
#include "rulesets/OutfitProperty.h"
|
2007-01-27 16:35:36 +00:00
|
|
|
#include "rulesets/SolidProperty.h"
|
2006-07-03 01:29:07 +00:00
|
|
|
#include "rulesets/Entity.h"
|
2006-06-29 14:57:19 +00:00
|
|
|
|
2007-06-21 20:26:53 +00:00
|
|
|
#include "common/Eat.h"
|
2007-06-22 12:42:35 +00:00
|
|
|
#include "common/Burn.h"
|
2007-06-21 20:26:53 +00:00
|
|
|
#include "common/Nourish.h"
|
2007-06-22 12:42:35 +00:00
|
|
|
|
|
|
|
|
#include "common/types.h"
|
2006-06-29 14:57:19 +00:00
|
|
|
#include "common/PropertyFactory_impl.h"
|
|
|
|
|
#include "common/DynamicProperty_impl.h"
|
|
|
|
|
|
2006-07-04 23:48:19 +00:00
|
|
|
#include "common/debug.h"
|
|
|
|
|
|
2006-12-03 06:31:43 +00:00
|
|
|
#include <Atlas/Objects/Operation.h>
|
2007-01-10 21:58:49 +00:00
|
|
|
#include <Atlas/Objects/Anonymous.h>
|
2006-12-03 06:31:43 +00:00
|
|
|
|
2007-01-21 19:53:37 +00:00
|
|
|
#include <wfmath/atlasconv.h>
|
|
|
|
|
|
2006-07-03 01:29:07 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
|
2007-06-21 21:02:39 +00:00
|
|
|
using Atlas::Objects::Root;
|
2007-01-10 21:58:49 +00:00
|
|
|
using Atlas::Message::Element;
|
2007-06-21 20:26:53 +00:00
|
|
|
using Atlas::Objects::Operation::Set;
|
2007-06-22 12:42:35 +00:00
|
|
|
using Atlas::Objects::Operation::Burn;
|
2007-01-10 21:58:49 +00:00
|
|
|
using Atlas::Objects::Operation::Create;
|
2007-06-21 20:26:53 +00:00
|
|
|
using Atlas::Objects::Operation::Nourish;
|
2007-01-10 21:58:49 +00:00
|
|
|
using Atlas::Objects::Entity::Anonymous;
|
|
|
|
|
|
2006-07-04 23:48:19 +00:00
|
|
|
static const bool debug_flag = false;
|
|
|
|
|
|
2006-06-29 14:57:19 +00:00
|
|
|
template class PropertyBuilder<Dynamic<LineProperty, CoordList> >;
|
2006-06-26 00:21:32 +00:00
|
|
|
|
2007-01-10 21:58:49 +00:00
|
|
|
HandlerResult test_handler(Entity *, const Operation &, OpVector & res)
|
2006-12-03 06:31:43 +00:00
|
|
|
{
|
2007-01-14 21:55:21 +00:00
|
|
|
debug(std::cout << "TEST HANDLER CALLED" << std::endl << std::flush;);
|
2007-01-03 22:29:46 +00:00
|
|
|
return OPERATION_IGNORED;
|
2006-12-03 06:31:43 +00:00
|
|
|
}
|
|
|
|
|
|
2007-01-10 21:58:49 +00:00
|
|
|
HandlerResult del_handler(Entity * e, const Operation &, OpVector & res)
|
|
|
|
|
{
|
2007-01-14 21:55:21 +00:00
|
|
|
debug(std::cout << "Delete HANDLER CALLED" << std::endl << std::flush;);
|
2007-01-10 21:58:49 +00:00
|
|
|
PropertyBase * pb = e->getProperty("decays");
|
|
|
|
|
if (pb == NULL) {
|
2007-01-14 21:55:21 +00:00
|
|
|
debug(std::cout << "Delete HANDLER no decays" << std::endl
|
|
|
|
|
<< std::flush;);
|
2007-01-10 21:58:49 +00:00
|
|
|
return OPERATION_IGNORED;
|
|
|
|
|
}
|
|
|
|
|
Element val;
|
|
|
|
|
pb->get(val);
|
|
|
|
|
if (!val.isString()) {
|
2007-01-14 21:55:21 +00:00
|
|
|
debug(std::cout << "Delete HANDLER decays non-string" << std::endl
|
|
|
|
|
<< std::flush;);
|
2007-01-10 21:58:49 +00:00
|
|
|
return OPERATION_IGNORED;
|
|
|
|
|
}
|
|
|
|
|
const std::string & type = val.String();
|
|
|
|
|
|
|
|
|
|
Anonymous create_arg;
|
|
|
|
|
create_arg->setParents(std::list<std::string>(1, type));
|
2007-01-21 19:53:37 +00:00
|
|
|
::addToEntity(e->m_location.pos(), create_arg->modifyPos());
|
|
|
|
|
create_arg->setLoc(e->m_location.m_loc->getId());
|
|
|
|
|
create_arg->setAttr("orientation", e->m_location.orientation().toAtlas());
|
|
|
|
|
|
|
|
|
|
Create create;
|
2007-01-11 00:26:44 +00:00
|
|
|
create->setTo(e->m_location.m_loc->getId());
|
2007-01-10 21:58:49 +00:00
|
|
|
create->setArgs1(create_arg);
|
|
|
|
|
res.push_back(create);
|
|
|
|
|
|
|
|
|
|
return OPERATION_IGNORED;
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-21 20:26:53 +00:00
|
|
|
HandlerResult eat_handler(Entity * e, const Operation & op, OpVector & res)
|
|
|
|
|
{
|
|
|
|
|
PropertyBase * pb = e->getProperty("biomass");
|
|
|
|
|
if (pb == NULL) {
|
|
|
|
|
debug(std::cout << "Eat HANDLER no biomass" << std::endl
|
|
|
|
|
<< std::flush;);
|
|
|
|
|
return OPERATION_IGNORED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Element val;
|
|
|
|
|
pb->get(val);
|
|
|
|
|
if (!val.isNum()) {
|
2007-06-21 21:02:39 +00:00
|
|
|
debug(std::cout << "Eat HANDLER biomass non-float" << std::endl
|
2007-06-21 20:26:53 +00:00
|
|
|
<< std::flush;);
|
|
|
|
|
return OPERATION_IGNORED;
|
|
|
|
|
}
|
|
|
|
|
double biomass = val.asNum();
|
|
|
|
|
|
|
|
|
|
Anonymous self;
|
|
|
|
|
self->setId(e->getId());
|
|
|
|
|
self->setAttr("status", -1);
|
|
|
|
|
|
|
|
|
|
Set s;
|
|
|
|
|
s->setTo(e->getId());
|
|
|
|
|
s->setArgs1(self);
|
|
|
|
|
|
|
|
|
|
const std::string & to = op->getFrom();
|
|
|
|
|
Anonymous nour_arg;
|
|
|
|
|
nour_arg->setId(to);
|
|
|
|
|
nour_arg->setAttr("mass", biomass);
|
|
|
|
|
|
|
|
|
|
Nourish n;
|
|
|
|
|
n->setTo(to);
|
|
|
|
|
n->setArgs1(nour_arg);
|
|
|
|
|
|
|
|
|
|
res.push_back(s);
|
|
|
|
|
res.push_back(n);
|
|
|
|
|
|
|
|
|
|
return OPERATION_IGNORED;
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-21 21:02:39 +00:00
|
|
|
HandlerResult burn_handler(Entity * e, const Operation & op, OpVector & res)
|
|
|
|
|
{
|
|
|
|
|
if (op->getArgs().empty()) {
|
|
|
|
|
e->error(op, "Fire op has no argument", res, e->getId());
|
|
|
|
|
return OPERATION_IGNORED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PropertyBase * pb = e->getProperty("burn_speed");
|
|
|
|
|
if (pb == NULL) {
|
|
|
|
|
debug(std::cout << "Eat HANDLER no burn_speed" << std::endl
|
|
|
|
|
<< std::flush;);
|
|
|
|
|
return OPERATION_IGNORED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Element val;
|
|
|
|
|
pb->get(val);
|
|
|
|
|
if (!val.isNum()) {
|
|
|
|
|
debug(std::cout << "Burn HANDLER burn_speed non-float" << std::endl
|
|
|
|
|
<< std::flush;);
|
|
|
|
|
return OPERATION_IGNORED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double burn_speed = val.asNum();
|
|
|
|
|
const Root & fire_ent = op->getArgs().front();
|
|
|
|
|
double consumed = burn_speed * fire_ent->getAttr("status").asNum();
|
|
|
|
|
|
|
|
|
|
const std::string & to = fire_ent->getId();
|
|
|
|
|
Anonymous nour_ent;
|
|
|
|
|
nour_ent->setId(to);
|
|
|
|
|
nour_ent->setAttr("mass", consumed);
|
|
|
|
|
|
|
|
|
|
Set s;
|
|
|
|
|
s->setTo(e->getId());
|
|
|
|
|
|
|
|
|
|
Anonymous self_ent;
|
|
|
|
|
self_ent->setId(e->getId());
|
|
|
|
|
self_ent->setAttr("status", e->getStatus() - (consumed / e->getMass()));
|
|
|
|
|
s->setArgs1(self_ent);
|
|
|
|
|
|
|
|
|
|
res.push_back(s);
|
|
|
|
|
|
|
|
|
|
Nourish n;
|
|
|
|
|
n->setTo(to);
|
|
|
|
|
n->setArgs1(nour_ent);
|
|
|
|
|
|
|
|
|
|
res.push_back(n);
|
|
|
|
|
|
|
|
|
|
return OPERATION_IGNORED;
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-26 00:21:32 +00:00
|
|
|
CorePropertyManager::CorePropertyManager()
|
|
|
|
|
{
|
2006-06-26 15:50:43 +00:00
|
|
|
m_propertyFactories["stamina"] = new PropertyBuilder<DynamicProperty<double> >;
|
2006-06-29 14:57:19 +00:00
|
|
|
m_propertyFactories["coords"] = new PropertyBuilder<Dynamic<LineProperty, CoordList> >;
|
2006-07-03 01:29:07 +00:00
|
|
|
m_propertyFactories["points"] = new PropertyBuilder<Dynamic<LineProperty, CoordList> >;
|
2006-06-29 15:45:55 +00:00
|
|
|
m_propertyFactories["start_intersections"] = new PropertyBuilder<DynamicProperty<IdList> >;
|
|
|
|
|
m_propertyFactories["end_intersections"] = new PropertyBuilder<DynamicProperty<IdList> >;
|
2006-12-03 06:31:43 +00:00
|
|
|
m_propertyFactories["attachment"] = new ActivePropertyBuilder<DynamicProperty<int> >(Atlas::Objects::Operation::MOVE_NO, test_handler);
|
2007-01-10 21:58:49 +00:00
|
|
|
m_propertyFactories["decays"] = new ActivePropertyBuilder<DynamicProperty<std::string> >(Atlas::Objects::Operation::DELETE_NO, del_handler);
|
2006-12-29 00:41:18 +00:00
|
|
|
m_propertyFactories["outfit"] = new PropertyBuilder<OutfitProperty>;
|
2007-01-27 16:35:36 +00:00
|
|
|
m_propertyFactories["solid"] = new EntityPropertyBuilder<SolidProperty>;
|
2007-06-21 20:26:53 +00:00
|
|
|
m_propertyFactories["biomass"] = new ActivePropertyBuilder<DynamicProperty<double> >(Atlas::Objects::Operation::EAT_NO, eat_handler);
|
2007-06-22 12:42:35 +00:00
|
|
|
m_propertyFactories["burn_speed"] = new ActivePropertyBuilder<DynamicProperty<double> >(Atlas::Objects::Operation::BURN_NO, burn_handler);
|
2006-06-26 00:21:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CorePropertyManager::~CorePropertyManager()
|
|
|
|
|
{
|
2006-08-07 20:02:54 +00:00
|
|
|
std::map<std::string, PropertyFactory *>::const_iterator I = m_propertyFactories.begin();
|
|
|
|
|
std::map<std::string, PropertyFactory *>::const_iterator Iend = m_propertyFactories.end();
|
|
|
|
|
for (; I != Iend; ++I) {
|
|
|
|
|
assert(I->second != 0);
|
|
|
|
|
delete I->second;
|
|
|
|
|
}
|
2006-06-26 00:21:32 +00:00
|
|
|
}
|
|
|
|
|
|
2006-07-03 01:29:07 +00:00
|
|
|
PropertyBase * CorePropertyManager::addProperty(Entity * entity,
|
|
|
|
|
const std::string & name)
|
2006-06-26 00:21:32 +00:00
|
|
|
{
|
2006-07-03 01:29:07 +00:00
|
|
|
assert(entity != 0);
|
|
|
|
|
assert(!name.empty());
|
|
|
|
|
PropertyFactoryDict::const_iterator I = m_propertyFactories.find(name);
|
|
|
|
|
if (I == m_propertyFactories.end()) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2006-07-04 23:48:19 +00:00
|
|
|
debug(std::cout << name << " property found. " << entity->getId() << std::endl << std::flush;);
|
2006-10-24 Al Riddoch <alriddoch@zepler.org>
* man/Makefile.am: Add rules to create man pages for every command,
which refer to the combined pages for all commands.
* man/cyaddrules.1, man/cyconvertrules.1, man/cydumprules.1,
man/cyloadrules.1, man/cypasswd.1: Generate new pages as described
above.
* man/cycmd.sgml: Fix argument name in cycmd man page.
* man/cyclient.1, man/cycmd.1, man/cycmd.sgml, man/cyphesis-tools.1,
man/cyphesis.1: Re-generate existing man pages.
* common/PropertyFactory.h, common/PropertyFactory_impl.h: Pass in
pointer to the entity when creating a new property using the
factory.
* server/CorePropertyManager.cpp: Make sure the entity pointer is
passed to the property factory as required.
2006-10-23 23:38:41 +00:00
|
|
|
PropertyBase * p = I->second->newProperty(entity);
|
2006-07-03 01:29:07 +00:00
|
|
|
return p;
|
2006-06-26 00:21:32 +00:00
|
|
|
}
|