Browse Source

* Fixed sleep command.

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@6705 54d463be-8e91-2dee-dedb-b68131a5f0ec
Lance 19 years ago
parent
commit
56005cb610
2 changed files with 59 additions and 58 deletions
  1. 1 0
      Changelog-Trunk.txt
  2. 58 58
      src/map/script.c

+ 1 - 0
Changelog-Trunk.txt

@@ -4,6 +4,7 @@ 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.
 IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 
 
 2006/05/23
 2006/05/23
+	* Fixed sleep command. [Lance]
 	* Added 'setd' support for local NPC scope (') variables. [Lance]
 	* Added 'setd' support for local NPC scope (') variables. [Lance]
 	* [Scripting Engine Update] New variables are ready to be used. [Lance]
 	* [Scripting Engine Update] New variables are ready to be used. [Lance]
 2006/05/22
 2006/05/22

+ 58 - 58
src/map/script.c

@@ -11224,7 +11224,6 @@ int run_script_main(struct script_state *st)
 	int cmdcount=script_config.check_cmdcount;
 	int cmdcount=script_config.check_cmdcount;
 	int gotocount=script_config.check_gotocount;
 	int gotocount=script_config.check_gotocount;
 	struct script_stack *stack=st->stack;
 	struct script_stack *stack=st->stack;
-	TBL_PC *sd=NULL;
 
 
 	if(st->state == RERUNLINE) {
 	if(st->state == RERUNLINE) {
 		st->state = RUN;
 		st->state = RUN;
@@ -11324,20 +11323,12 @@ int run_script_main(struct script_state *st)
 			st->state=END;
 			st->state=END;
 		}
 		}
 	}
 	}
-	sd = map_id2sd(st->rid);
-	if(st->sleep.tick > 0) {
-		// スタック情報をsleep_dbに保存
-		unsigned int tick = gettick()+st->sleep.tick;
-		st->sleep.charid = sd ? sd->char_id : 0;
-		st->sleep.timer  = add_timer(tick, run_script_timer, st->sleep.charid, (int)st);
-		linkdb_insert(&sleep_db, (void*)st->oid, st);
-	} else {
-		switch(st->state){
+	switch(st->state){
 		case STOP:
 		case STOP:
 			break;
 			break;
 		case END:
 		case END:
 			{
 			{
-				struct map_session_data *sd=map_id2sd(st->rid);
+				struct map_session_data *sd=st->rid?map_id2sd(st->rid):NULL;
 				st->pos=-1;
 				st->pos=-1;
 				if(sd && (sd->npc_id==st->oid || sd->state.using_fake_npc)){
 				if(sd && (sd->npc_id==st->oid || sd->state.using_fake_npc)){
 					if(sd->state.using_fake_npc){
 					if(sd->state.using_fake_npc){
@@ -11357,9 +11348,11 @@ int run_script_main(struct script_state *st)
 			// 	st->pos=rerun_pos;
 			// 	st->pos=rerun_pos;
 			// }
 			// }
 			break;
 			break;
-		}
 	}
 	}
 
 
+	if(st->state == END)
+		script_free_stack (st->stack);
+
 	return 0;
 	return 0;
 }
 }
 
 
@@ -11369,7 +11362,7 @@ int run_script_main(struct script_state *st)
  */
  */
 int run_script(struct script_code *rootscript,int pos,int rid,int oid)
 int run_script(struct script_code *rootscript,int pos,int rid,int oid)
 {
 {
-	struct script_state st;
+	struct script_state *st;
 	struct map_session_data *sd=NULL;
 	struct map_session_data *sd=NULL;
 
 
 	//Variables for backing up the previous script and restore it if needed. [Skotlex]
 	//Variables for backing up the previous script and restore it if needed. [Skotlex]
@@ -11381,13 +11374,13 @@ int run_script(struct script_code *rootscript,int pos,int rid,int oid)
 	if (rootscript == NULL || pos < 0)
 	if (rootscript == NULL || pos < 0)
 		return -1;
 		return -1;
 
 
-	memset(&st, 0, sizeof(struct script_state));
+	st = calloc(sizeof(struct script_state), 1);
 
 
 	if ((sd = map_id2sd(rid)) && sd->stack && sd->npc_scriptroot == rootscript){
 	if ((sd = map_id2sd(rid)) && sd->stack && sd->npc_scriptroot == rootscript){
 		// we have a stack for the same script, should continue exec.
 		// we have a stack for the same script, should continue exec.
-		st.script = sd->npc_script;
-		st.stack = sd->stack;
-		st.state  = sd->npc_scriptstate;
+		st->script = sd->npc_script;
+		st->stack = sd->stack;
+		st->state  = sd->npc_scriptstate;
 		// and clear vars
 		// and clear vars
 		sd->stack           = NULL;
 		sd->stack           = NULL;
 		sd->npc_script      = NULL;
 		sd->npc_script      = NULL;
@@ -11395,14 +11388,14 @@ int run_script(struct script_code *rootscript,int pos,int rid,int oid)
 		sd->npc_scriptstate = 0;
 		sd->npc_scriptstate = 0;
 	} else {
 	} else {
 		// the script is different, make new script_state and stack
 		// the script is different, make new script_state and stack
-		st.stack = aMalloc (sizeof(struct script_stack));
-		st.stack->sp = 0;
-		st.stack->sp_max = 64;
-		st.stack->stack_data = (struct script_data *) aCalloc (st.stack->sp_max,sizeof(st.stack->stack_data[0]));
-		st.stack->defsp = st.stack->sp;
-		st.stack->var_function = aCalloc(1, sizeof(struct linkdb_node*));
-		st.state  = RUN;
-		st.script = rootscript;
+		st->stack = aMalloc (sizeof(struct script_stack));
+		st->stack->sp = 0;
+		st->stack->sp_max = 64;
+		st->stack->stack_data = (struct script_data *) aCalloc (st->stack->sp_max,sizeof(st->stack->stack_data[0]));
+		st->stack->defsp = st->stack->sp;
+		st->stack->var_function = aCalloc(1, sizeof(struct linkdb_node*));
+		st->state  = RUN;
+		st->script = rootscript;
 	
 	
 		if (sd && sd->stack) {	// if there's a sd and a stack - back it up and restore it if possible.
 		if (sd && sd->stack) {	// if there's a sd and a stack - back it up and restore it if possible.
 			bck_script      = sd->npc_script;
 			bck_script      = sd->npc_script;
@@ -11412,41 +11405,48 @@ int run_script(struct script_code *rootscript,int pos,int rid,int oid)
 			sd->stack = NULL;
 			sd->stack = NULL;
 		}
 		}
 	}
 	}
-	st.pos = pos;
-	st.rid = rid;
-	st.oid = oid;
-	st.sleep.timer = -1;
+	st->pos = pos;
+	st->rid = rid;
+	st->oid = oid;
+	st->sleep.timer = -1;
 	// let's run that stuff
 	// let's run that stuff
-	run_script_main(&st);
-
-	sd = map_id2sd(st.rid);
-	if (st.state != END && sd) {
-		// script is not finished, store data in sd.
-		sd->npc_script      = st.script;
-		sd->npc_scriptroot  = rootscript;
-		sd->npc_scriptstate = st.state;
-		sd->stack           = st.stack;
-		if (bck_stack) //Get rid of the backup as it can't be restored.
-			script_free_stack (bck_stack);
+	run_script_main(st);
+
+	if(st->sleep.tick > 0) {
+		// スタック情報をsleep_dbに保存
+		unsigned int tick = gettick()+st->sleep.tick;
+		st->sleep.charid = sd ? sd->char_id : 0;
+		st->sleep.timer  = add_timer(tick, run_script_timer, st->sleep.charid, (int)st);
+		linkdb_insert(&sleep_db, (void*)st->oid, st);
 	} else {
 	} else {
-		// we are done with stuff, free the stack
-		script_free_stack (st.stack);
-		// and if there was a sd associated - zero vars.
-		if (sd) {
-			//Clear or restore previous script.
-			sd->npc_script      = bck_script;
-			sd->npc_scriptroot  = bck_scriptroot;
-			sd->npc_scriptstate = bck_scriptstate;
-			sd->stack = bck_stack;
-			//Since the script is done, save any changed account variables [Skotlex]
-			if (sd->state.reg_dirty&2)
-				intif_saveregistry(sd,2);
-			if (sd->state.reg_dirty&1)
-				intif_saveregistry(sd,1);
-		}
-	}
-
-	return st.pos;
+		if (st->state != END && sd) {
+			// script is not finished, store data in sd.
+			sd->npc_script      = st->script;
+			sd->npc_scriptroot  = rootscript;
+			sd->npc_scriptstate = st->state;
+			sd->stack           = st->stack;
+			if (bck_stack) //Get rid of the backup as it can't be restored.
+				script_free_stack (bck_stack);
+		} else {
+			// and if there was a sd associated - zero vars.
+			if (sd) {
+				//Clear or restore previous script.
+				sd->npc_script      = bck_script;
+				sd->npc_scriptroot  = bck_scriptroot;
+				sd->npc_scriptstate = bck_scriptstate;
+				sd->stack = bck_stack;
+				//Since the script is done, save any changed account variables [Skotlex]
+				if (sd->state.reg_dirty&2)
+					intif_saveregistry(sd,2);
+				if (sd->state.reg_dirty&1)
+					intif_saveregistry(sd,1);
+			}
+			//aFree(st);
+			return 0;
+		}
+	}
+
+	return st->pos;
 }
 }
 
 
 /*==========================================
 /*==========================================