summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-12-06 12:59:12 +0000
committerskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-12-06 12:59:12 +0000
commit71392bc0305b06e18c99892d0a5b3fb4aaaf22c9 (patch)
treebcc6bedfb729d9b4e20baaba984c674b4642b946 /src/map
parent09a89593b983a9ade807175192fcf63971748f7c (diff)
downloadhercules-71392bc0305b06e18c99892d0a5b3fb4aaaf22c9.tar.gz
hercules-71392bc0305b06e18c99892d0a5b3fb4aaaf22c9.tar.bz2
hercules-71392bc0305b06e18c99892d0a5b3fb4aaaf22c9.tar.xz
hercules-71392bc0305b06e18c99892d0a5b3fb4aaaf22c9.zip
- The default event script behaviour is to trigger on labels rather than NPCs now.
- Removed several script config options which break NPC compatibility when you mess with them (event_script_type, event_requires_trigger, die_event_name, kill_pc_event_name, kill_mob_event_name, logout_event_name, login_event_name, loadmap_event_name, baselvup_event_name, joblvup_event_name) - LoadMap events no longer set the variable "@maploaded$" to the name of the new map. - Optimized/simplified the code now that the previous config options were removed. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@11859 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map')
-rw-r--r--src/map/clif.c5
-rw-r--r--src/map/map.c3
-rw-r--r--src/map/map.h11
-rw-r--r--src/map/mob.c2
-rw-r--r--src/map/npc.c52
-rw-r--r--src/map/npc.h4
-rw-r--r--src/map/pc.c56
-rw-r--r--src/map/script.c77
-rw-r--r--src/map/script.h18
9 files changed, 49 insertions, 179 deletions
diff --git a/src/map/clif.c b/src/map/clif.c
index 54b696db3..9ebf50600 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -7913,11 +7913,8 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
npc_event_dequeue(sd);
}
- // Lance
- if(sd->state.event_loadmap && map[sd->bl.m].flag.loadevent){
- pc_setregstr(sd, add_str("@maploaded$"), map[sd->bl.m].name);
+ if(map[sd->bl.m].flag.loadevent) // Lance
npc_script_event(sd, NPCE_LOADMAP);
- }
if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
diff --git a/src/map/map.c b/src/map/map.c
index d113e8a6d..7a8520061 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -1683,9 +1683,8 @@ int map_quit(struct map_session_data *sd)
if(!sd->state.waitingdisconnect) {
if (sd->npc_timer_id != -1) //Cancel the event timer.
npc_timerevent_quit(sd);
- if (sd->state.event_disconnect)
- npc_script_event(sd, NPCE_LOGOUT);
+ npc_script_event(sd, NPCE_LOGOUT);
sd->state.waitingdisconnect = 1;
if (sd->pd) unit_free(&sd->pd->bl,0);
if (sd->hd) unit_free(&sd->hd->bl,0);
diff --git a/src/map/map.h b/src/map/map.h
index 2608cee05..7a3e6ae02 100644
--- a/src/map/map.h
+++ b/src/map/map.h
@@ -531,16 +531,7 @@ struct map_session_data {
unsigned storage_flag : 2; //0: closed, 1: Normal Storage open, 2: guild storage open [Skotlex]
unsigned snovice_call_flag : 2; //Summon Angel (stage 1~3)
unsigned snovice_dead_flag : 2; //Explosion spirits on death: 0 off, 1 active, 2 used.
- // originally by Qamera, adapted by celest
- unsigned event_death : 1;
- unsigned event_kill_pc : 1;
- unsigned event_disconnect : 1;
- unsigned event_kill_mob : 1;
- unsigned event_baselvup : 1;
- unsigned event_joblvup : 1;
- unsigned event_loadmap : 1;
- // Abracadabra bugfix by Aru
- unsigned abra_flag : 1;
+ unsigned abra_flag : 1; // Abracadabra bugfix by Aru
unsigned autotrade : 1; //By Fantik
unsigned reg_dirty : 3; //By Skotlex (marks whether registry variables have been saved or not yet)
unsigned showdelay :1;
diff --git a/src/map/mob.c b/src/map/mob.c
index 7f4aa8ee1..2d0eb04b9 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -2218,7 +2218,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
npc_event(mvp_sd,md->npc_event,0);
}
md->status.hp = 1;
- } else if (mvp_sd && mvp_sd->state.event_kill_mob) { //lordalfa
+ } else if (mvp_sd) { //lordalfa
pc_setglobalreg(mvp_sd,"killedrid",md->class_);
npc_script_event(mvp_sd, NPCE_KILLNPC); // PCKillNPC [Lance]
}
diff --git a/src/map/npc.c b/src/map/npc.c
index 7b44c4afa..26ce12757 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -67,7 +67,6 @@ static struct view_data npc_viewdb[MAX_NPC_CLASS];
static struct script_event_s
{ //Holds pointers to the commonly executed scripts for speedup. [Skotlex]
- struct npc_data *nd;
struct event_data *event[UCHAR_MAX];
const char *event_name[UCHAR_MAX];
uint8 event_count;
@@ -2688,26 +2687,18 @@ void npc_parsesrcfile(const char* filepath)
return;
}
-int npc_script_event(struct map_session_data* sd, int type)
+int npc_script_event(struct map_session_data* sd, enum npce_event type)
{
int i;
- if (type < 0 || type >= NPCE_MAX)
+ if (type == NPCE_MAX)
return 0;
if (!sd) {
ShowError("npc_script_event: NULL sd. Event Type %d\n", type);
return 0;
}
- if (script_event[type].nd) {
- TBL_NPC *nd = script_event[type].nd;
- run_script(nd->u.scr.script,0,sd->bl.id,nd->bl.id);
- return 1;
- } else if (script_event[type].event_count) {
- for (i = 0; i<script_event[type].event_count; i++) {
- npc_event_sub(sd,script_event[type].event[i],script_event[type].event_name[i]);
- }
- return i;
- }
- return 0;
+ for (i = 0; i<script_event[type].event_count; i++)
+ npc_event_sub(sd,script_event[type].event[i],script_event[type].event_name[i]);
+ return i;
}
static int npc_read_event_script_sub(DBKey key, void* data, va_list ap)
@@ -2735,7 +2726,7 @@ void npc_read_event_script(void)
int i;
struct {
char *name;
- char *event_name;
+ const char *event_name;
} config[] = {
{"Login Event",script_config.login_event_name},
{"Logout Event",script_config.logout_event_name},
@@ -2748,32 +2739,19 @@ void npc_read_event_script(void)
};
for (i = 0; i < NPCE_MAX; i++) {
- script_event[i].nd = NULL;
+ char buf[64]="::";
script_event[i].event_count = 0;
- if (!script_config.event_script_type) {
- //Use a single NPC as event source.
- script_event[i].nd = npc_name2id(config[i].event_name);
- } else {
- //Use an array of Events
- char buf[64]="::";
- strncpy(buf+2,config[i].event_name,62);
- ev_db->foreach(ev_db,npc_read_event_script_sub,buf,
- &script_event[i].event,
- &script_event[i].event_name,
- &script_event[i].event_count);
- }
+ //Use an array of Events
+ strncpy(buf+2,config[i].event_name,62);
+ ev_db->foreach(ev_db,npc_read_event_script_sub,buf,
+ &script_event[i].event,
+ &script_event[i].event_name,
+ &script_event[i].event_count);
}
if (battle_config.etc_log) {
//Print summary.
- for (i = 0; i < NPCE_MAX; i++) {
- if(!script_config.event_script_type) {
- if (script_event[i].nd)
- ShowInfo("%s: Using NPC named '%s'.\n", config[i].name, config[i].event_name);
- else
- ShowInfo("%s: No NPC found with name '%s'.\n", config[i].name, config[i].event_name);
- } else
- ShowInfo("%s: %d '%s' events.\n", config[i].name, script_event[i].event_count, config[i].event_name);
- }
+ for (i = 0; i < NPCE_MAX; i++)
+ ShowInfo("%s: %d '%s' events.\n", config[i].name, script_event[i].event_count, config[i].event_name);
}
}
diff --git a/src/map/npc.h b/src/map/npc.h
index 2d203fdb5..6580e4f21 100644
--- a/src/map/npc.h
+++ b/src/map/npc.h
@@ -27,7 +27,7 @@ int mob_chat_sub(struct block_list* bl, va_list ap);
#endif
//Script NPC events.
-enum {
+enum npce_event {
NPCE_LOGIN,
NPCE_LOGOUT,
NPCE_LOADMAP,
@@ -88,7 +88,7 @@ void npc_unload_duplicates (struct npc_data* nd);
int npc_unload(struct npc_data* nd);
int npc_reload(void);
void npc_read_event_script(void);
-int npc_script_event(struct map_session_data* sd, int type);
+int npc_script_event(struct map_session_data* sd, enum npce_event type);
extern struct npc_data* fake_nd;
diff --git a/src/map/pc.c b/src/map/pc.c
index 368f355f0..7d8a44e2e 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -727,11 +727,6 @@ int pc_authok(struct map_session_data *sd, int login_id2, time_t connect_until_t
//Prevent S. Novices from getting the no-death bonus just yet. [Skotlex]
sd->die_counter=-1;
- //Until the reg values arrive, set them to not require trigger...
- sd->state.event_death = 1;
- sd->state.event_kill_pc = 1;
- sd->state.event_disconnect = 1;
- sd->state.event_kill_mob = 1;
{ //Add IP field
uint32 ip = session[sd->fd]->client_addr;
@@ -867,25 +862,6 @@ int pc_reg_received(struct map_session_data *sd)
}
}
- // Automated script events
- if (script_config.event_requires_trigger) {
- sd->state.event_death = pc_readglobalreg(sd, script_config.die_event_name);
- sd->state.event_kill_pc = pc_readglobalreg(sd, script_config.kill_pc_event_name);
- sd->state.event_kill_mob = pc_readglobalreg(sd, script_config.kill_mob_event_name);
- sd->state.event_disconnect = pc_readglobalreg(sd, script_config.logout_event_name);
- sd->state.event_baselvup = pc_readglobalreg(sd, script_config.baselvup_event_name);
- sd->state.event_joblvup = pc_readglobalreg(sd, script_config.joblvup_event_name);
- sd->state.event_loadmap = pc_readglobalreg(sd, script_config.loadmap_event_name);
- // if script triggers are not required
- } else {
- sd->state.event_death = 1;
- sd->state.event_kill_pc = 1;
- sd->state.event_disconnect = 1;
- sd->state.event_kill_mob = 1;
- sd->state.event_baselvup = 1;
- sd->state.event_joblvup = 1;
- sd->state.event_loadmap = 1;
- }
//Weird... maybe registries were reloaded?
if (sd->state.auth)
return 0;
@@ -4150,9 +4126,7 @@ int pc_checkbaselevelup(struct map_session_data *sd)
sc_start(&sd->bl,SkillStatusChangeTable(AL_BLESSING),100,10,600000);
}
clif_misceffect(&sd->bl,0);
- //LORDALFA - LVLUPEVENT
- if(sd->state.event_baselvup)
- npc_script_event(sd, NPCE_BASELVUP);
+ npc_script_event(sd, NPCE_BASELVUP); //LORDALFA - LVLUPEVENT
if(sd->status.party_id)
party_send_levelup(sd);
@@ -4186,8 +4160,7 @@ int pc_checkjoblevelup(struct map_session_data *sd)
if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
clif_status_change(&sd->bl,SI_DEVIL, 1); //Permanent blind effect from SG_DEVIL.
- if(sd->state.event_joblvup)
- npc_script_event(sd, NPCE_JOBLVUP);
+ npc_script_event(sd, NPCE_JOBLVUP);
return 1;
}
@@ -4973,14 +4946,8 @@ int pc_dead(struct map_session_data *sd,struct block_list *src)
sd->hp_loss.tick = sd->sp_loss.tick = sd->hp_regen.tick = sd->sp_regen.tick = 0;
pc_setglobalreg(sd,"PC_DIE_COUNTER",++sd->die_counter);
-
- if (sd->state.event_death){
- if(!src)
- pc_setglobalreg(sd, "killerrid", 0);
- else
- pc_setglobalreg(sd,"killerrid",src->id);
- npc_script_event(sd,NPCE_DIE);
- }
+ pc_setglobalreg(sd,"killerrid",src?src->id:0);
+ npc_script_event(sd,NPCE_DIE);
if ( sd && sd->spiritball && (sd->class_&MAPID_BASEMASK)==MAPID_GUNSLINGER ) // maybe also monks' spiritballs ?
pc_delspiritball(sd,sd->spiritball,0);
@@ -5008,10 +4975,9 @@ int pc_dead(struct map_session_data *sd,struct block_list *src)
case BL_PC:
{
struct map_session_data *ssd = (struct map_session_data *)src;
- if (ssd->state.event_kill_pc) {
- pc_setglobalreg(ssd, "killedrid", sd->bl.id);
- npc_script_event(ssd, NPCE_KILLPC);
- }
+ pc_setglobalreg(ssd, "killedrid", sd->bl.id);
+ npc_script_event(ssd, NPCE_KILLPC);
+
if (battle_config.pk_mode&2) {
ssd->status.manner -= 5;
if(ssd->status.manner < 0)
@@ -6082,14 +6048,6 @@ int pc_setregistry(struct map_session_data *sd,const char *reg,int val,int type)
i = (!sd->die_counter && (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE);
sd->die_counter = val;
if (i) status_calc_pc(sd,0); //Lost the bonus.
- } else if(strcmp(reg,script_config.die_event_name) == 0){
- sd->state.event_death = val;
- } else if(strcmp(reg,script_config.kill_pc_event_name) == 0){
- sd->state.event_kill_pc = val;
- } else if(strcmp(reg,script_config.kill_mob_event_name) == 0){
- sd->state.event_kill_mob = val;
- } else if(strcmp(reg,script_config.logout_event_name) == 0){
- sd->state.event_disconnect = val;
}
}
switch (type) {
diff --git a/src/map/script.c b/src/map/script.c
index bf8b3ea93..8a479bac6 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -182,7 +182,17 @@ static int parse_options=0;
DBMap* script_get_label_db(){ return scriptlabel_db; }
DBMap* script_get_userfunc_db(){ return userfunc_db; }
-struct Script_Config script_config;
+struct Script_Config script_config = {
+ 1, 65535, 2048, //warn_func_mismatch_paramnum/check_cmdcount/check_gotocount
+ "OnPCDieEvent", //die_event_name
+ "OnPCKillEvent", //kill_pc_event_name
+ "OnNPCKillEvent", //kill_mob_event_name
+ "OnPCLoginEvent", //login_event_name
+ "OnPCLogoutEvent", //logout_event_name
+ "OnPCLoadMapEvent", //loadmap_event_name
+ "OnPCBaseLvUpEvent", //baselvup_event_name
+ "OnPCJobLvUpEvent" //joblvup_event_name
+};
static jmp_buf error_jump;
static char* error_msg;
@@ -3449,7 +3459,7 @@ static int script_autosave_mapreg(int tid,unsigned int tick,int id,int data)
return 0;
}
-int script_config_read_sub(char *cfgName)
+int script_config_read(char *cfgName)
{
int i;
char line[1024],w1[1024],w2[1024];
@@ -3478,54 +3488,8 @@ int script_config_read_sub(char *cfgName)
else if(strcmpi(w1,"check_gotocount")==0) {
script_config.check_gotocount = config_switch(w2);
}
- else if(strcmpi(w1,"event_script_type")==0) {
- script_config.event_script_type = config_switch(w2);
- }
- else if(strcmpi(w1,"event_requires_trigger")==0) {
- script_config.event_requires_trigger = config_switch(w2);
- }
- else if(strcmpi(w1,"die_event_name")==0) {
- strncpy(script_config.die_event_name, w2, NAME_LENGTH-1);
- if (strlen(script_config.die_event_name) != strlen(w2))
- ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.die_event_name);
- }
- else if(strcmpi(w1,"kill_pc_event_name")==0) {
- strncpy(script_config.kill_pc_event_name, w2, NAME_LENGTH-1);
- if (strlen(script_config.kill_pc_event_name) != strlen(w2))
- ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.kill_pc_event_name);
- }
- else if(strcmpi(w1,"kill_mob_event_name")==0) {
- strncpy(script_config.kill_mob_event_name, w2, NAME_LENGTH-1);
- if (strlen(script_config.kill_mob_event_name) != strlen(w2))
- ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.kill_mob_event_name);
- }
- else if(strcmpi(w1,"login_event_name")==0) {
- strncpy(script_config.login_event_name, w2, NAME_LENGTH-1);
- if (strlen(script_config.login_event_name) != strlen(w2))
- ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.login_event_name);
- }
- else if(strcmpi(w1,"logout_event_name")==0) {
- strncpy(script_config.logout_event_name, w2, NAME_LENGTH-1);
- if (strlen(script_config.logout_event_name) != strlen(w2))
- ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.logout_event_name);
- }
- else if(strcmpi(w1,"loadmap_event_name")==0) {
- strncpy(script_config.loadmap_event_name, w2, NAME_LENGTH-1);
- if (strlen(script_config.loadmap_event_name) != strlen(w2))
- ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.loadmap_event_name);
- }
- else if(strcmpi(w1,"baselvup_event_name")==0) {
- strncpy(script_config.baselvup_event_name, w2, NAME_LENGTH-1);
- if (strlen(script_config.baselvup_event_name) != strlen(w2))
- ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.baselvup_event_name);
- }
- else if(strcmpi(w1,"joblvup_event_name")==0) {
- strncpy(script_config.joblvup_event_name, w2, NAME_LENGTH-1);
- if (strlen(script_config.joblvup_event_name) != strlen(w2))
- ShowWarning("script_config_read: Event label truncated (max length is 23 chars): %d\n", script_config.joblvup_event_name);
- }
else if(strcmpi(w1,"import")==0){
- script_config_read_sub(w2);
+ script_config_read(w2);
}
}
fclose(fp);
@@ -3533,21 +3497,6 @@ int script_config_read_sub(char *cfgName)
return 0;
}
-int script_config_read(char *cfgName)
-{ //Script related variables should be initialized once! [Skotlex]
-
- memset (&script_config, 0, sizeof(script_config));
- script_config.warn_func_mismatch_paramnum = 1;
- script_config.check_cmdcount = 65535;
- script_config.check_gotocount = 2048;
-
- script_config.event_script_type = 0;
- script_config.event_requires_trigger = 1;
-
- return script_config_read_sub(cfgName);
-}
-
-
static int do_final_userfunc_sub (DBKey key,void *data,va_list ap)
{
struct script_code *code = (struct script_code *)data;
diff --git a/src/map/script.h b/src/map/script.h
index 2769a3163..e879854f4 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -13,16 +13,14 @@ extern struct Script_Config {
int check_cmdcount;
int check_gotocount;
- unsigned event_script_type : 1;
- unsigned event_requires_trigger : 1;
- char die_event_name[NAME_LENGTH];
- char kill_pc_event_name[NAME_LENGTH];
- char kill_mob_event_name[NAME_LENGTH];
- char login_event_name[NAME_LENGTH];
- char logout_event_name[NAME_LENGTH];
- char loadmap_event_name[NAME_LENGTH];
- char baselvup_event_name[NAME_LENGTH];
- char joblvup_event_name[NAME_LENGTH];
+ const char *die_event_name;
+ const char *kill_pc_event_name;
+ const char *kill_mob_event_name;
+ const char *login_event_name;
+ const char *logout_event_name;
+ const char *loadmap_event_name;
+ const char *baselvup_event_name;
+ const char *joblvup_event_name;
} script_config;
enum c_op {