diff options
author | skotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-10-25 21:35:38 +0000 |
---|---|---|
committer | skotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-10-25 21:35:38 +0000 |
commit | 683822cc659024af2d5050e81e02622e0eb01884 (patch) | |
tree | 2474a20771e2b97a1f86bd126122c5bd960b1556 /src/map/npc.c | |
parent | 7d65a46135c8b8536f48f58ff2a0a26fd40932b6 (diff) | |
download | hercules-683822cc659024af2d5050e81e02622e0eb01884.tar.gz hercules-683822cc659024af2d5050e81e02622e0eb01884.tar.bz2 hercules-683822cc659024af2d5050e81e02622e0eb01884.tar.xz hercules-683822cc659024af2d5050e81e02622e0eb01884.zip |
- 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?)
- 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.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@9073 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/npc.c')
-rw-r--r-- | src/map/npc.c | 54 |
1 files changed, 18 insertions, 36 deletions
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;
}
|