13 #include "../bscript/bobject.h" 14 #include "../clib/cfgelem.h" 15 #include "../clib/cfgfile.h" 16 #include "../clib/fileutil.h" 17 #include "../clib/logfacility.h" 18 #include "../plib/pkg.h" 19 #include "../plib/systemstate.h" 28 using namespace Bscript;
31 : export_script( shs ), PC( in_PC )
91 : check_skill_hook( nullptr ),
92 open_spellbook_hook( nullptr ),
93 get_book_page_hook( nullptr ),
94 combat_advancement_hook( nullptr ),
95 parry_advancement_hook( nullptr ),
96 attack_hook( nullptr ),
97 pushthrough_hook( nullptr ),
98 speechmul_hook( nullptr ),
99 hitmiss_hook( nullptr ),
100 on_cast_hook( nullptr ),
101 can_decay( nullptr ),
102 ouch_hook( nullptr ),
105 close_customhouse_hook( nullptr ),
106 warmode_change( nullptr ),
107 can_trade( nullptr ),
108 consume_ammunition_hook( nullptr )
116 if ( hookname ==
"CheckSkill" )
121 else if ( hookname ==
"OpenSpellbook" )
126 else if ( hookname ==
"GetBookPage" )
131 else if ( hookname ==
"CombatAdvancement" )
136 else if ( hookname ==
"ParryAdvancement" )
141 else if ( hookname ==
"Attack" )
146 else if ( hookname ==
"Pushthrough" )
151 else if ( hookname ==
"SpeechMul" )
156 else if ( hookname ==
"HitMiss" )
161 else if ( hookname ==
"OnCast" )
166 else if ( hookname ==
"CanDecay" )
171 else if ( hookname ==
"Ouch" )
176 else if ( hookname ==
"CanDie" )
181 else if ( hookname ==
"UnHide" )
186 else if ( hookname ==
"CloseCustomHouse" )
191 else if ( hookname ==
"WarmodeChange" )
196 else if ( hookname ==
"CanTrade" )
201 else if ( hookname ==
"ConsumeAmmunition" )
208 INFO_PRINT <<
"Unknown SystemHook " << hookname <<
"\n";
212 if ( *pphook !=
nullptr )
214 INFO_PRINT <<
"SystemHook " << hookname <<
" multiply defined\n" 217 <<
" Also defined in: " << shs->
scriptname() <<
"\n";
252 while ( cf.read( elem ) )
258 std::string hookname, exfuncname;
259 while ( elem.remove_first_prop( &hookname, &exfuncname ) )
261 if ( exfuncname.empty() )
262 exfuncname = hookname;
263 hook( shs, hookname, exfuncname );
345 const std::string& descriptor,
unsigned nargs,
346 bool complain_if_missing )
349 auto colon_pos = descriptor.find_last_of(
':' );
350 if ( colon_pos == std::string::npos )
351 elem.
throw_error(
"Expected ':' in exported function descriptor (" + descriptor +
")" );
353 std::string scriptname = descriptor.substr( 0, colon_pos );
354 std::string functionname = descriptor.substr( colon_pos + 1, std::string::npos );
359 if ( !export_script )
361 if ( complain_if_missing )
370 if ( complain_if_missing )
371 elem.
throw_error(
"Exported Function " + functionname +
" not found in " +
std::string call_string(unsigned PC, Bscript::BObjectImp *p0, Bscript::BObjectImp *p1)
ExportedFunction * speechmul_hook
const std::string & scriptname() const
bool call(Bscript::BObjectImp *p0)
ExportedFunction * close_customhouse_hook
ExportedFunction * open_spellbook_hook
Bscript::BObject call_object(unsigned PC, Bscript::BObjectImp *p0, Bscript::BObjectImp *p1)
ExportedFunction * combat_advancement_hook
ExportedFunction * warmode_change
bool call(unsigned PC, Bscript::BObjectImp *p0)
ExportedFunction * attack_hook
const std::string & scriptname() const
ExportedFunction * on_cast_hook
ExportedFunction(ExportScript *, unsigned PC)
const std::string & name() const
POL_NORETURN void throw_error(const std::string &errmsg) const
ExportScript * export_script
ExportedFunction * can_decay
std::string call_string(Bscript::BObjectImp *p0, Bscript::BObjectImp *p1)
bool FindExportedFunction(const std::string &name, unsigned args, unsigned &PC) const
void hook(ExportScript *shs, const std::string &hookname, const std::string &exfuncname)
ExportScript * FindExportScript(const ScriptDef &sd)
ExportedFunction * ouch_hook
ExportedFunction * pushthrough_hook
ExportedFunction * can_trade
void unload_system_hooks()
Bscript::BObject call_object(Bscript::BObjectImp *p0, Bscript::BObjectImp *p1)
ExportedFunction * FindExportedFunction(Clib::ConfigElem &elem, const Plib::Package *pkg, const std::string &descriptor, unsigned nargs, bool complain_if_missing)
std::string GetPackageCfgPath(const Package *pkg, const std::string &filename)
ExportedFunction * can_die
std::vector< ExportScript * > export_scripts
int call_long(Bscript::BObjectImp *p0)
ExportedFunction * un_hide
ExportedFunction * get_book_page_hook
bool FileExists(const char *filename)
ExportedFunction * consume_ammunition_hook
ExportedFunction * parry_advancement_hook
ExportedFunction * check_skill_hook
int call_long(unsigned PC, Bscript::BObjectImp *p0)
ExportedFunction * hitmiss_hook