14 #include "../clib/cfgelem.h" 15 #include "../clib/cfgfile.h" 16 #include "../clib/fileutil.h" 17 #include "../clib/logfacility.h" 18 #include "../clib/stlutil.h" 19 #include "../clib/strutil.h" 20 #include "../plib/systemstate.h" 37 std::map<int, double> Costs;
38 std::map<int, double>::iterator itr;
47 double last_mult = 0.0;
48 std::string perc_str, mult_str;
55 if ( ( is1 >> perc ) && ( is2 >> mult ) )
61 Costs.insert( std::pair<int, double>( perc, mult ) );
65 elem.
throw_error(
"poorly formed movecost spec: " + perc_str +
" " + mult_str );
69 for ( itr = Costs.begin(); itr != Costs.end(); ++itr )
73 for (
int i = last_perc + 1; i <= perc; ++i )
75 double m = ( ( last_mult - mult ) / ( last_perc - perc ) );
76 double b = mult - m * perc;
78 movecost.
cost[i] = i * m + b;
90 double costmod( 1.0 );
95 if ( chr->has_movement_cost() )
96 costmod = running ? chr->movement_cost().run_mounted : chr->movement_cost().walk_mounted;
101 if ( chr->has_movement_cost() )
102 costmod = running ? chr->movement_cost().run : chr->movement_cost().walk;
106 if ( carry_perc < 0 )
111 mult = mc->
cost[carry_perc];
113 return static_cast<unsigned short>( 8 * mult * costmod );
123 INFO_PRINT <<
"File config/movecost.cfg not found, skipping.\n";
128 "MovementCost Walking Running Walking_Mounted Running_Mounted" );
131 bool walking_mounted_set =
false;
132 bool running_mounted_set =
false;
134 while ( cf.
read( elem ) )
136 if ( elem.
type_is(
"MovementCost" ) )
142 else if ( elem.
type_is(
"Walking" ) )
146 else if ( elem.
type_is(
"Running" ) )
150 else if ( elem.
type_is(
"Walking_Mounted" ) )
153 walking_mounted_set =
true;
155 else if ( elem.
type_is(
"Running_Mounted" ) )
158 running_mounted_set =
true;
162 if ( !walking_mounted_set )
165 if ( !running_mounted_set )
MovementCost movecost_walking
bool remove_first_prop(std::string *propname, std::string *value)
MovementCost movecost_walking_mounted
std::string decint(unsigned short v)
void read_movecost(Clib::ConfigElem &elem, MovementCost &movecost)
double cost[MAX_CARRY_PERC+1]
double remove_double(const char *propname, double dflt)
POL_NORETURN void throw_error(const std::string &errmsg) const
MovementCost movecost_running
MovementCost movecost_running_mounted
SettingsManager settingsManager
unsigned short movecost(const Mobile::Character *chr, int carry_perc, bool running, bool mounted)
void load_movecost(bool reload)
bool type_is(const char *name) const
bool FileExists(const char *filename)
bool read(ConfigElem &elem)
bool movement_uses_stamina