summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorcelest <celest@54d463be-8e91-2dee-dedb-b68131a5f0ec>2005-01-10 15:25:24 +0000
committercelest <celest@54d463be-8e91-2dee-dedb-b68131a5f0ec>2005-01-10 15:25:24 +0000
commitf4d39edff58dc2a8db9e517a6ffbe738e36b31e9 (patch)
tree8439f43fc788c0df4fb5b412a7a8cfe828cb9368 /src/map
parent2ef5d159733a6d8ee3fd3ff2d9c887874acc3b5f (diff)
downloadhercules-f4d39edff58dc2a8db9e517a6ffbe738e36b31e9.tar.gz
hercules-f4d39edff58dc2a8db9e517a6ffbe738e36b31e9.tar.bz2
hercules-f4d39edff58dc2a8db9e517a6ffbe738e36b31e9.tar.xz
hercules-f4d39edff58dc2a8db9e517a6ffbe738e36b31e9.zip
* Completed adding packet DB reading
* Added Shinomori's suggestions for npc timers, * Removed checking for script event timers' length, and added Shinomori's changes git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/branches/stable@947 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map')
-rw-r--r--src/map/clif.c110
-rw-r--r--src/map/map.h2
-rw-r--r--src/map/npc.c4
-rw-r--r--src/map/pc.c6
-rw-r--r--src/map/script.c9
-rw-r--r--src/map/script.h1
6 files changed, 69 insertions, 63 deletions
diff --git a/src/map/clif.c b/src/map/clif.c
index 00de30b59..54bf3a452 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -55,6 +55,9 @@
#define MAX_PACKET_DB 0x224
int packet_db_ver = -1;
+int *packet_db_size;
+void (**packet_db_parse_func)();
+short packet_db_pos[MAX_PACKET_DB][20];
static const int packet_len_table[MAX_PACKET_DB] = {
10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -10159,11 +10162,14 @@ void clif_parse_debug(int fd,struct map_session_data *sd)
{
int i, cmd;
+ if (packet_db_ver < 0)
+ return;
+
cmd = RFIFOW(fd,0);
printf("packet debug 0x%4X\n",cmd);
printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
- for(i=0;i<packet_size_table[packet_db_ver - 5][cmd];i++){
+ for(i=0;i<packet_db_size[cmd];i++){
if((i&15)==0)
printf("\n%04X ",i);
printf("%02X ",RFIFOB(fd,i));
@@ -10630,7 +10636,8 @@ static int packetdb_readdb(void)
};
// memset(packet_db,0,sizeof(packet_db));
-
+ memset(packet_db_pos,0,sizeof(packet_db_pos));
+
if( (fp=fopen("db/packet_db.txt","r"))==NULL ){
printf("can't read db/packet_db.txt\n");
return 1;
@@ -10645,62 +10652,64 @@ static int packetdb_readdb(void)
continue;
if(strcmpi(w1,"packet_db_ver")==0) {
packet_db_ver = atoi(w2);
- printf ("packet db version = %d\n", packet_db_ver);
break; // stop reading config and load the rest of the file
}
}
}
- while(fgets(line,1020,fp)){
- if (packet_db_ver <= 7) // minimum packet version allowed
- break;
- if(line[0]=='/' && line[1]=='/')
- continue;
- memset(str,0,sizeof(str));
- for(j=0,p=line;j<4 && p;j++){
- str[j]=p;
- p=strchr(p,',');
- if(p) *p++=0;
- }
- if(str[0]==NULL)
- continue;
+ if (packet_db_ver > 7) { // minimum packet version allowed
+ packet_db_size = packet_size_table[packet_db_ver - 5];
+ packet_db_parse_func = clif_parse_func_table[packet_db_ver - 7];
- cmd=strtol(str[0],(char **)NULL,0);
- if(cmd<=0 || cmd>=MAX_PACKET_DB)
- continue;
+ while(fgets(line,1020,fp)){
+ if(line[0]=='/' && line[1]=='/')
+ continue;
+ memset(str,0,sizeof(str));
+ for(j=0,p=line;j<4 && p;j++){
+ str[j]=p;
+ p=strchr(p,',');
+ if(p) *p++=0;
+ }
+ if(str[0]==NULL)
+ continue;
- if(str[1]==NULL){
- sprintf(tmp_output, "packet_db: packet len error\n");
- ShowError(tmp_output);
- continue;
- }
- packet_size_table[packet_db_ver - 5][cmd] = atoi(str[1]);
+ cmd=strtol(str[0],(char **)NULL,0);
+ if(cmd<=0 || cmd>=MAX_PACKET_DB)
+ continue;
- if(str[2]==NULL){
- ln++;
- continue;
- }
- for(j=0;j<sizeof(clif_parse_func)/sizeof(clif_parse_func[0]);j++){
- if(clif_parse_func[j].name != NULL &&
- strcmp(str[2],clif_parse_func[j].name)==0){
- clif_parse_func_table[packet_db_ver - 7][cmd] = clif_parse_func[j].func;
- break;
+ if(str[1]==NULL){
+ sprintf(tmp_output, "packet_db: packet len error\n");
+ ShowError(tmp_output);
+ continue;
+ }
+ packet_db_size[cmd] = atoi(str[1]);
+
+ if(str[2]==NULL){
+ ln++;
+ continue;
+ }
+ for(j=0;j<sizeof(clif_parse_func)/sizeof(clif_parse_func[0]);j++){
+ if(clif_parse_func[j].name != NULL &&
+ strcmp(str[2],clif_parse_func[j].name)==0){
+ packet_db_parse_func[cmd] = clif_parse_func[j].func;
+ break;
+ }
+ }
+ if(str[3]==NULL){
+ sprintf(tmp_output, "packet_db: packet error\n");
+ ShowError(tmp_output);
+ exit(1);
+ }
+ for(j=0,p2=str[3];p2;j++){
+ str2[j]=p2;
+ p2=strchr(p2,':');
+ if(p2) *p2++=0;
+ packet_db_pos[cmd][j]=atoi(str2[j]);
}
- }
- if(str[3]==NULL){
- sprintf(tmp_output, "packet_db: packet error\n");
- ShowError(tmp_output);
- exit(1);
- }
- for(j=0,p2=str[3];p2;j++){
- str2[j]=p2;
- p2=strchr(p2,':');
- if(p2) *p2++=0;
-// packet_db[cmd].pos[j]=atoi(str2[j]); // since this isn't implemented yet
- }
- ln++;
-// if(packet_size_table[packet_db_ver - 5][cmd] > 2 /* && packet_db[cmd].pos[0] == 0 */)
-// printf("packet_db: %d 0x%x %d %s %p\n",ln,cmd,packet_size_table[packet_db_ver - 5][cmd],str[2],clif_parse_func_table[packet_db_ver - 7][cmd]);
+ ln++;
+// if(packet_size_table[packet_db_ver - 5][cmd] > 2 /* && packet_db[cmd].pos[0] == 0 */)
+// printf("packet_db: %d 0x%x %d %s %p | %p\n",ln,cmd,packet_db_size[cmd],str[2],packet_db_parse_func[cmd],clif_parse_func_table[packet_db_ver - 7][cmd]);
+ }
}
fclose(fp);
sprintf(tmp_output,"Done reading '"CL_WHITE"%s"CL_RESET"'.\n","db/packet_db.txt");
@@ -10982,6 +10991,9 @@ int do_init_clif(void) {
// Size of packet version 16 (packet db)
memcpy(&packet_size_table[11], &packet_size_table[10], sizeof(packet_len_table));
+ packet_db_size = packet_size_table[0];
+ packet_db_parse_func = clif_parse_func_table[0];
+
packetdb_readdb();
set_defaultparse(clif_parse);
diff --git a/src/map/map.h b/src/map/map.h
index e6ad63b08..26fc3e6c8 100644
--- a/src/map/map.h
+++ b/src/map/map.h
@@ -375,7 +375,7 @@ struct npc_data {
char *script;
short xs,ys;
int guild_id;
- int timer,timerid,timeramount,nexttimer,timerrid;
+ int timer,timerid,timeramount,nexttimer,rid;
unsigned int timertick;
struct npc_timerevent_list *timer_event;
int label_list_num;
diff --git a/src/map/npc.c b/src/map/npc.c
index d2379e5a8..ff752192a 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -589,7 +589,7 @@ int npc_timerevent(int tid,unsigned int tick,int id,int data)
nd->u.scr.timerid = add_timer(tick+next,npc_timerevent,id,next);
}
- run_script(nd->u.scr.script,te->pos,nd->u.scr.timerrid,nd->bl.id);
+ run_script(nd->u.scr.script,te->pos,nd->u.scr.rid,nd->bl.id);
return 0;
}
/*==========================================
@@ -612,7 +612,7 @@ int npc_timerevent_start(struct npc_data *nd)
}
nd->u.scr.nexttimer=j;
nd->u.scr.timertick=gettick();
- nd->u.scr.timerrid=0; // no players attached by default [celest]
+ nd->u.scr.rid=0; // reset attached player [celest]
if(j>=n)
return 0;
diff --git a/src/map/pc.c b/src/map/pc.c
index 5ff5f06fd..2954dfddf 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -6791,14 +6791,12 @@ int pc_addeventtimer(struct map_session_data *sd,int tick,const char *name)
nullpo_retr(0, sd);
- Assert(strlen(name) < script_config.max_eventtimer_len);
-
for(i=0;i<MAX_EVENTTIMER;i++)
if( sd->eventtimer[i]==-1 )
break;
if(i<MAX_EVENTTIMER){
- char *evname=(char *)aCalloc(script_config.max_eventtimer_len,sizeof(char));
- memcpy(evname,name,script_config.max_eventtimer_len);
+ char *evname=(char *)aMalloc((strlen(name)+1)*sizeof(char));
+ memcpy(evname,name,(strlen(name)+1));
sd->eventtimer[i]=add_timer(gettick()+tick,
pc_eventtimer,sd->bl.id,(int)evname);
sd->eventcount++;
diff --git a/src/map/script.c b/src/map/script.c
index 6e00d15cb..64e4a7692 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -3893,6 +3893,7 @@ int buildin_initnpctimer(struct script_state *st)
npc_settimerevent_tick(nd,0);
npc_timerevent_start(nd);
+ nd->u.scr.rid=st->rid;
return 0;
}
/*==========================================
@@ -3985,7 +3986,7 @@ int buildin_attachnpctimer(struct script_state *st)
if (sd==NULL)
return 0;
- nd->u.scr.timerrid = sd->bl.id;
+ nd->u.scr.rid = sd->bl.id;
return 0;
}
@@ -4001,7 +4002,7 @@ int buildin_detachnpctimer(struct script_state *st)
else
nd=(struct npc_data *)map_id2bl(st->oid);
- nd->u.scr.timerrid = 0;
+ nd->u.scr.rid = 0;
return 0;
}
@@ -7204,7 +7205,6 @@ int script_config_read(char *cfgName)
script_config.warn_cmd_mismatch_paramnum=1;
script_config.check_cmdcount=8192;
script_config.check_gotocount=512;
- script_config.max_eventtimer_len=32;
fp=fopen(cfgName,"r");
if(fp==NULL){
@@ -7238,9 +7238,6 @@ int script_config_read(char *cfgName)
else if(strcmpi(w1,"check_gotocount")==0) {
script_config.check_gotocount = battle_config_switch(w2);
}
- else if(strcmpi(w1,"max_eventtimer_length")==0) {
- script_config.max_eventtimer_len = battle_config_switch(w2);
- }
else if(strcmpi(w1,"import")==0){
script_config_read(w2);
}
diff --git a/src/map/script.h b/src/map/script.h
index 5dd266174..50aac9dd7 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -9,7 +9,6 @@ extern struct Script_Config {
int warn_cmd_mismatch_paramnum;
int check_cmdcount;
int check_gotocount;
- int max_eventtimer_len;
} script_config;
struct script_data {