View Single Post
  #25  
Old 03-01-2008, 09:39 PM
Bulle
Hill Giant
 
Join Date: Jan 2008
Posts: 102
Default World Hooks

Here is my code for the hero_world.dll library (hero_world_Hooks.cpp) :
#include "../common/debug.h"
#include "../common/default_Hooks.h"
#include "../common/classes.h"
#include "../common/races.h"


#ifdef WIN32
#define exportfunc extern "C" __declspec(dllexport)
#else
#define exportfunc extern "C"
#endif


/** Makes all newly-created characters Rangers - It is the class chosen for heroes as it can cast spells
* and have dual-wield. After all, aren't all rangers heroes ?
*/
exportfunc void hero_world_CharacterCreation_ChangeCreationInfo(Ch arCreate_Struct *cc)
{ cc->class_ = RANGER;

/* Adjust the stats to provide a similar amount of points per race.
* Good or neutral races get 535 points total, evil races 555.
*/
switch(cc->race)
{ case BARBARIAN: break;
case DARK_ELF: cc->CHA += 23; break;
case DWARF: cc->CHA += 7; break;
case ERUDITE: cc->CHA += 5; break;
case FROGLOK: cc->CHA -= 15; break;
case GNOME: cc->CHA += 10; break;
case HALF_ELF: cc->CHA += 10; break;
case HALFLING: cc->CHA += 3; break;
case HIGH_ELF: cc->AGI -= 7; break;
case HUMAN: cc->CHA += 10; break;
case IKSAR: break;
case OGRE: cc->CHA += 1; break;
case TROLL: cc->DEX += 10; cc->STA += 18; break;
case VAHSHIR: cc->DEX += 10; break;
case WOOD_ELF: break;
default: printf("unknown race %d\n", cc->race);
}
}
CheckHookSignature(CharacterCreation, ChangeCreationInfo, hero_world_CharacterCreation_ChangeCreationInfo);

Enlarge one column in the database to allow specifying looong values :
ALTER TABLE rule_values MODIFY rule_value VARCHAR(256);

The hook is activated with the following SQL query in the database :
INSERT INTO rule_values VALUES ('1','(world) CharacterCreation:ChangeCreationInfo','hero_world: hero_world_CharacterCreation_ChangeCreationInfo');

The entry name is of the form "(world) <hook>" for world hooks. The value is the name of the shared library (no extension, for Unix compatibility) then the name of the function implementing the hook.
Reply With Quote