summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changelog-Trunk.txt7
-rw-r--r--src/map/clif.c3
-rw-r--r--src/map/npc.c54
-rw-r--r--src/map/pc.c10
-rw-r--r--src/map/pc.h1
5 files changed, 31 insertions, 44 deletions
diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt
index fd9d05f97..f10deb0d1 100644
--- a/Changelog-Trunk.txt
+++ b/Changelog-Trunk.txt
@@ -4,6 +4,13 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
2006/10/25
+ * Cleaned up some more the event dequeue code, it will no longer clear out
+ the npc_id if there's no events waiting to be executed (why does it clears
+ the npc_id anyway?) [Skotlex]
+ * Because of possible conflicts with this change and the on-login script,
+ now the on-login script is executed when the player has finished loading
+ into their start-up map rather than as soon as receiving the registry
+ variables from the char-server. [Skotlex]
* Some cleaning of the pc_eventtimer and pc enqueue code, it should fix
some memory leaks when the event counter does not matches with the actual
number of queued timers during logout. [Skotlex]
diff --git a/src/map/clif.c b/src/map/clif.c
index a667b74be..6bfe4ef50 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -8344,7 +8344,8 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
//Removed, for some reason chars get stuck on map-change when you send this packet!? [Skotlex]
//[LuzZza]
//clif_guild_send_onlineinfo(sd);
-
+ //On Login Script.
+ npc_script_event(sd, NPCE_LOGIN);
} else
//New 'night' effect by dynamix [Skotlex]
if (night_flag && map[sd->bl.m].flag.nightenabled)
diff --git a/src/map/npc.c b/src/map/npc.c
index 4e982b69d..77b6667f9 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -162,32 +162,19 @@ int npc_event_dequeue(struct map_session_data *sd)
{
nullpo_retr(0, sd);
- sd->npc_id=0;
- if (sd->eventqueue[0][0]) { // キューのイベント処理
- size_t ev;
+ if (!sd->eventqueue[0][0])
+ return 0; //Nothing to dequeue
- // find an empty place in eventtimer list
- for(ev=0;ev<MAX_EVENTTIMER;ev++)
- if( sd->eventtimer[ev]==-1 )
- break;
- if(ev<MAX_EVENTTIMER)
- { // generate and insert the timer
- int i;
- // copy the first event name
- char *name=(char *)aMalloc(50*sizeof(char));
- memcpy(name,sd->eventqueue[0],50);
- // shift queued events down by one
- for(i=1;i<MAX_EVENTQUEUE;i++)
- memcpy(sd->eventqueue[i-1],sd->eventqueue[i],50);
- // clear the last event
- sd->eventqueue[MAX_EVENTQUEUE-1][0]=0;
- // add the timer
- sd->eventtimer[ev]=add_timer(gettick()+100,pc_eventtimer,sd->bl.id,(int)name);//TODO: Someone wrote here "!!todo!!", but what the hell is missing?
- sd->eventcount++;
- }else
- ShowWarning("npc_event_dequeue: event timer is full !\n");
+ if (!pc_addeventtimer(sd,100,sd->eventqueue[0]))
+ { //Failed to dequeue, couldn't set a timer.
+ ShowWarning("npc_event_dequeue: event timer is full !\n");
+ return 0;
}
- return 0;
+ //Event dequeued successfully, shift other elements.
+ sd->npc_id=0; //FIXME: Shouldn't dequeueing fail when you have an npc_id set?
+ memmove(sd->eventqueue[0], sd->eventqueue[1], (MAX_EVENTQUEUE-1)*sizeof(sd->eventqueue[0]));
+ sd->eventqueue[MAX_EVENTQUEUE-1][0]=0;
+ return 1;
}
/*==========================================
@@ -801,27 +788,22 @@ int npc_settimerevent_tick(struct npc_data *nd,int newtimer)
int npc_event_sub(struct map_session_data *sd, struct event_data *ev, const unsigned char *eventname){
if ( sd->npc_id!=0) {
-// if (battle_config.error_log)
-// printf("npc_event: npc_id != 0\n");
+ //Enqueue the event trigger.
int i;
- for(i=0;i<MAX_EVENTQUEUE;i++)
- if (!sd->eventqueue[i][0])
- break;
+ for(i=0;i<MAX_EVENTQUEUE && sd->eventqueue[i][0];i++)
+
if (i==MAX_EVENTQUEUE) {
if (battle_config.error_log)
ShowWarning("npc_event: event queue is full !\n");
- }else{
-// if (battle_config.etc_log)
-// printf("npc_event: enqueue\n");
+ }else //Event enqueued.
memcpy(sd->eventqueue[i],eventname,50);
- }
return 1;
}
- if (ev->nd->sc.option&OPTION_INVISIBLE) { // 無効化されている
+ if (ev->nd->sc.option&OPTION_INVISIBLE) {
+ //Disabled npc, shouldn't trigger event.
npc_event_dequeue(sd);
- return 0;
+ return 2;
}
-
run_script(ev->nd->u.scr.script,ev->pos,sd->bl.id,ev->nd->bl.id);
return 0;
}
diff --git a/src/map/pc.c b/src/map/pc.c
index c3e68a807..663667207 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -861,8 +861,6 @@ int pc_reg_received(struct map_session_data *sd)
sd->state.event_joblvup = 1;
sd->state.event_loadmap = 1;
}
-
- npc_script_event(sd, NPCE_LOGIN);
return 0;
}
@@ -6131,7 +6129,7 @@ int pc_setregistry_str(struct map_session_data *sd,char *reg,char *val,int type)
* イベントタイマ??理
*------------------------------------------
*/
-int pc_eventtimer(int tid,unsigned int tick,int id,int data)
+static int pc_eventtimer(int tid,unsigned int tick,int id,int data)
{
struct map_session_data *sd=map_id2sd(id);
char *p = (char *)data;
@@ -6142,9 +6140,9 @@ int pc_eventtimer(int tid,unsigned int tick,int id,int data)
for(i=0;i < MAX_EVENTTIMER && sd->eventtimer[i]!=tid; i++);
if(i < MAX_EVENTTIMER){
+ sd->eventcount--;
sd->eventtimer[i]=-1;
npc_event(sd,p,0);
- sd->eventcount--;
} else if(battle_config.error_log)
ShowError("pc_eventtimer: no such event timer\n");
@@ -6173,7 +6171,7 @@ int pc_addeventtimer(struct map_session_data *sd,int tick,const char *name)
pc_eventtimer,sd->bl.id,(int)evname);
sd->eventcount++;
- return 0;
+ return 1;
}
/*==========================================
@@ -6197,7 +6195,7 @@ int pc_deleventtimer(struct map_session_data *sd,const char *name)
sd->eventtimer[i]=-1;
sd->eventcount--;
aFree(p);
- break;
+ return 1;
}
}
diff --git a/src/map/pc.h b/src/map/pc.h
index a9ec1dd09..7672bf415 100644
--- a/src/map/pc.h
+++ b/src/map/pc.h
@@ -286,7 +286,6 @@ int pc_addspiritball(struct map_session_data *sd,int,int);
int pc_delspiritball(struct map_session_data *sd,int,int);
void pc_addfame(struct map_session_data *sd,int count);
unsigned char pc_famerank(int char_id, int job);
-int pc_eventtimer(int tid,unsigned int tick,int id,int data); // for npc_dequeue
int pc_set_hate_mob(struct map_session_data *sd, int pos, struct block_list *bl);
extern struct fame_list smith_fame_list[MAX_FAME_LIST];