2016-01-28 14:52:40 +01:00
|
|
|
/** @file
|
|
|
|
|
*
|
|
|
|
|
* @par History
|
|
|
|
|
*/
|
2014-08-29 21:26:06 +02:00
|
|
|
|
|
|
|
|
|
2014-11-01 15:31:44 +01:00
|
|
|
#include "attribute.h"
|
2014-08-29 21:26:06 +02:00
|
|
|
|
2018-01-29 21:55:48 +01:00
|
|
|
#include <stddef.h>
|
|
|
|
|
|
2014-08-29 21:26:06 +02:00
|
|
|
#include "../../clib/cfgelem.h"
|
|
|
|
|
#include "../../clib/passert.h"
|
|
|
|
|
#include "../../plib/pkg.h"
|
2015-01-02 14:46:44 +01:00
|
|
|
#include "../globals/settings.h"
|
2018-01-29 21:55:48 +01:00
|
|
|
#include "../globals/uvars.h"
|
|
|
|
|
#include "../syshook.h"
|
2020-08-02 00:05:47 +02:00
|
|
|
#include "../uoskills.h"
|
2014-08-29 21:26:06 +02:00
|
|
|
|
2016-02-19 19:26:35 +01:00
|
|
|
namespace Pol
|
|
|
|
|
{
|
|
|
|
|
namespace Mobile
|
|
|
|
|
{
|
|
|
|
|
Attribute* Attribute::FindAttribute( const std::string& str )
|
|
|
|
|
{
|
|
|
|
|
Core::AttributesByName::const_iterator citr = Core::gamestate.attributes_byname.find( str );
|
|
|
|
|
if ( citr != Core::gamestate.attributes_byname.end() )
|
|
|
|
|
return ( *citr ).second;
|
|
|
|
|
else
|
2018-07-31 14:30:29 +02:00
|
|
|
return nullptr;
|
2016-02-19 19:26:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Attribute::Attribute( const Plib::Package* pkg, Clib::ConfigElem& elem )
|
|
|
|
|
: pkg( pkg ),
|
|
|
|
|
name( elem.rest() ),
|
|
|
|
|
attrid( 0 ),
|
|
|
|
|
aliases(),
|
|
|
|
|
getintrinsicmod_func( nullptr ),
|
|
|
|
|
delay_seconds( elem.remove_ushort( "DELAY", 0 ) ),
|
|
|
|
|
unhides( elem.remove_bool( "UNHIDES", true ) ),
|
|
|
|
|
disable_core_checks( elem.remove_bool( "DisableCoreChecks", false ) ),
|
|
|
|
|
default_cap(
|
|
|
|
|
elem.remove_ushort( "DefaultCap", Core::settingsManager.ssopt.default_attribute_cap ) ),
|
2020-08-02 00:05:47 +02:00
|
|
|
script_( elem.remove_string( "SCRIPT", "" ), pkg, "scripts/skills/" ),
|
|
|
|
|
skillid( static_cast<Core::USKILLID>( -1 ) )
|
2016-02-19 19:26:35 +01:00
|
|
|
{
|
|
|
|
|
aliases.push_back( name );
|
|
|
|
|
std::string tmp;
|
|
|
|
|
while ( elem.remove_prop( "Alias", &tmp ) )
|
|
|
|
|
aliases.push_back( tmp );
|
|
|
|
|
|
|
|
|
|
if ( elem.remove_prop( "GetIntrinsicModFunction", &tmp ) )
|
|
|
|
|
{
|
|
|
|
|
getintrinsicmod_func = Core::FindExportedFunction( elem, pkg, tmp, 1 );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Attribute::~Attribute()
|
|
|
|
|
{
|
|
|
|
|
if ( getintrinsicmod_func != nullptr )
|
|
|
|
|
delete getintrinsicmod_func;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t Attribute::estimateSize() const
|
|
|
|
|
{
|
|
|
|
|
size_t size = sizeof( Attribute );
|
|
|
|
|
size += name.capacity();
|
|
|
|
|
for ( const auto& alias : aliases )
|
|
|
|
|
size += alias.capacity();
|
|
|
|
|
size += sizeof( Core::ExportedFunction );
|
|
|
|
|
size += script_.estimatedSize();
|
|
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void load_attribute_entry( const Plib::Package* pkg, Clib::ConfigElem& elem )
|
|
|
|
|
{
|
|
|
|
|
auto attr = new Attribute( pkg, elem );
|
|
|
|
|
|
|
|
|
|
const Attribute* existing = Attribute::FindAttribute( attr->name );
|
|
|
|
|
if ( existing )
|
|
|
|
|
{
|
|
|
|
|
elem.throw_error( "Attribute " + attr->name + " already defined by " + existing->pkg->desc() );
|
|
|
|
|
}
|
|
|
|
|
attr->attrid = static_cast<unsigned int>( Core::gamestate.attributes.size() );
|
|
|
|
|
Core::gamestate.attributes.push_back( attr );
|
|
|
|
|
for ( unsigned i = 0; i < attr->aliases.size(); ++i )
|
|
|
|
|
{
|
|
|
|
|
Core::gamestate.attributes_byname[attr->aliases[i]] = attr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void load_attributes_cfg()
|
|
|
|
|
{
|
|
|
|
|
load_packaged_cfgs( "attributes.cfg", "Attribute", load_attribute_entry );
|
|
|
|
|
Core::gamestate.numAttributes = static_cast<unsigned int>( Core::gamestate.attributes.size() );
|
|
|
|
|
|
|
|
|
|
Core::gamestate.pAttrStrength = Attribute::FindAttribute( "Strength" );
|
|
|
|
|
Core::gamestate.pAttrIntelligence = Attribute::FindAttribute( "Intelligence" );
|
|
|
|
|
Core::gamestate.pAttrDexterity = Attribute::FindAttribute( "Dexterity" );
|
|
|
|
|
|
|
|
|
|
Core::gamestate.pAttrParry = Attribute::FindAttribute( "Parry" );
|
|
|
|
|
Core::gamestate.pAttrTactics = Attribute::FindAttribute( "Tactics" );
|
|
|
|
|
|
|
|
|
|
passert_always( Core::gamestate.pAttrStrength );
|
|
|
|
|
passert_always( Core::gamestate.pAttrIntelligence );
|
|
|
|
|
passert_always( Core::gamestate.pAttrDexterity );
|
|
|
|
|
passert_always( Core::gamestate.pAttrParry );
|
|
|
|
|
passert_always( Core::gamestate.pAttrTactics );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void clean_attributes()
|
|
|
|
|
{
|
|
|
|
|
auto iter = Core::gamestate.attributes.begin();
|
|
|
|
|
for ( ; iter != Core::gamestate.attributes.end(); ++iter )
|
|
|
|
|
{
|
|
|
|
|
delete *iter;
|
2018-07-31 14:30:29 +02:00
|
|
|
*iter = nullptr;
|
2014-08-29 21:26:06 +02:00
|
|
|
}
|
2016-02-19 19:26:35 +01:00
|
|
|
Core::gamestate.attributes.clear();
|
|
|
|
|
Core::gamestate.attributes_byname.clear();
|
|
|
|
|
}
|
2020-08-02 00:05:47 +02:00
|
|
|
|
|
|
|
|
void combine_attributes_skillid()
|
|
|
|
|
{
|
|
|
|
|
for ( auto& attr : Core::gamestate.attributes )
|
|
|
|
|
{
|
|
|
|
|
for ( const auto& skill : Core::gamestate.uo_skills )
|
|
|
|
|
{
|
|
|
|
|
if ( skill.pAttr == attr )
|
|
|
|
|
{
|
|
|
|
|
attr->skillid = static_cast<Core::USKILLID>( skill.skillid );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-19 19:26:35 +01:00
|
|
|
}
|
2020-08-02 00:05:47 +02:00
|
|
|
} // namespace Mobile
|
|
|
|
|
} // namespace Pol
|