cyphesis/rulesets/DomainProperty.cpp
Erik Ogenvik 72fc2d7923 Added an InventoryDomain for characters.
The Inventory domain is meant for all characters, i.e. those than can have
an "inventory".

It's a non physical domain, which means that entities contained in it won't
be affected by any physical constraints, or have physics applied to them.
Visibility for outside entities are by default forbidden unless an entity is
outfitted or wielded.
The idea is that other playes shouldn't see what's in the inventory of another
player, unless things are outfitted or wielded.
2016-06-22 17:29:27 +02:00

85 lines
2.4 KiB
C++

/*
Copyright (C) 2014 Erik Ogenvik
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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "DomainProperty.h"
#include "PhysicalDomain.h"
#include "VoidDomain.h"
#include "InventoryDomain.h"
#include "LocatedEntity.h"
PropertyInstanceState<Domain> DomainProperty::sInstanceState;
DomainProperty::DomainProperty()
{
}
DomainProperty::DomainProperty(const DomainProperty& rhs)
: Property(rhs)
{
}
void DomainProperty::install(LocatedEntity *entity, const std::string &)
{
sInstanceState.addState(entity, nullptr);
}
void DomainProperty::remove(LocatedEntity * entity, const std::string &)
{
sInstanceState.removeState(entity);
entity->setFlags(~entity_domain);
}
void DomainProperty::apply(LocatedEntity * entity)
{
if (m_data != "") {
Domain* domain = sInstanceState.getState(entity);
if (!domain) {
if (m_data == "physical") {
domain = new PhysicalDomain(*entity);
sInstanceState.replaceState(entity, domain);
entity->setFlags(entity_domain);
} else if (m_data == "void") {
domain = new VoidDomain(*entity);
sInstanceState.replaceState(entity, domain);
entity->setFlags(entity_domain);
} else if (m_data == "inventory") {
domain = new InventoryDomain(*entity);
sInstanceState.replaceState(entity, domain);
entity->setFlags(entity_domain);
}
}
} else {
sInstanceState.replaceState(entity, nullptr);
entity->setFlags(~entity_domain);
}
}
DomainProperty * DomainProperty::copy() const
{
return new DomainProperty(*this);
}
Domain* DomainProperty::getDomain(const LocatedEntity *entity) const {
return sInstanceState.getState(entity);
}