diff options
author | Lance <Lance@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-06-16 14:42:16 +0000 |
---|---|---|
committer | Lance <Lance@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-06-16 14:42:16 +0000 |
commit | 5e053d4db7ef162f13246219a5e0b12046a7c7f8 (patch) | |
tree | d6a2f311c63cb3fafae5033679d7c7f8c9ab6cc9 /src | |
parent | e07326b0aa71a74cacd425e30745bb01a60b153f (diff) | |
download | hercules-5e053d4db7ef162f13246219a5e0b12046a7c7f8.tar.gz hercules-5e053d4db7ef162f13246219a5e0b12046a7c7f8.tar.bz2 hercules-5e053d4db7ef162f13246219a5e0b12046a7c7f8.tar.xz hercules-5e053d4db7ef162f13246219a5e0b12046a7c7f8.zip |
* [Improved]:
- Cleaned up Custom Mob Script Callback codes. Looks much better now :B.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@7202 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src')
-rw-r--r-- | src/char/char.c | 2 | ||||
-rw-r--r-- | src/map/map.h | 1 | ||||
-rw-r--r-- | src/map/mob.c | 68 | ||||
-rw-r--r-- | src/map/mob.h | 12 | ||||
-rw-r--r-- | src/map/pc.c | 9 | ||||
-rw-r--r-- | src/map/unit.c | 9 |
6 files changed, 54 insertions, 47 deletions
diff --git a/src/char/char.c b/src/char/char.c index fc8631c88..527a68ac6 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -2562,7 +2562,7 @@ int parse_frommap(int fd) { if (max_account_id != DEFAULT_MAX_ACCOUNT_ID || max_char_id != DEFAULT_MAX_CHAR_ID)
mapif_send_maxid(max_account_id, max_char_id); //Send the current max ids to the server to keep in sync [Skotlex]
}
- WFIFOHEAD(fd, 3 + NAME_LENGTH);
+ WFIFOHEAD(fd, 3 + NAME_LENGTH);
WFIFOW(fd,0) = 0x2afb;
WFIFOB(fd,2) = 0;
memcpy(WFIFOP(fd,3), wisp_server_name, NAME_LENGTH); // name for wisp to player
diff --git a/src/map/map.h b/src/map/map.h index f8685109e..4fa89f7aa 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -875,6 +875,7 @@ struct mob_data { int master_id,master_dist;
struct npc_data *nd;
+ unsigned char callback_flag;
short skillidx;
unsigned int skilldelay[MAX_MOBSKILL];
diff --git a/src/map/mob.c b/src/map/mob.c index 65331f343..a12b0fcb0 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -772,11 +772,7 @@ static int mob_ai_sub_hard_activesearch(struct block_list *bl,va_list ap) return 0; if(md->nd){ - setd_sub(NULL, NULL, ".ai_action", 0, (void *)(int)2, &md->nd->u.scr.script->script_vars); - setd_sub(NULL, NULL, ".ai_action", 1, (void *)(int)bl->type, &md->nd->u.scr.script->script_vars); - setd_sub(NULL, NULL, ".ai_action", 2, (void *)bl->id, &md->nd->u.scr.script->script_vars); - setd_sub(NULL, NULL, ".ai_action", 3, (void *)md->bl.id, &md->nd->u.scr.script->script_vars); - run_script(md->nd->u.scr.script, 0, 0, md->nd->bl.id); + mob_script_callback(md, bl, CALLBACK_DETECT); return 1; // We have script handling the work. } @@ -951,11 +947,8 @@ static int mob_ai_sub_hard_slavemob(struct mob_data *md,unsigned int tick) } if (tbl && status_check_skilluse(&md->bl, tbl, 0, 0)) { if(md->nd){ - setd_sub(NULL, NULL, ".ai_action", 0, (void *)(int)4, &md->nd->u.scr.script->script_vars); - setd_sub(NULL, NULL, ".ai_action", 1, (void *)(int)tbl->type, &md->nd->u.scr.script->script_vars); - setd_sub(NULL, NULL, ".ai_action", 2, (void *)tbl->id, &md->nd->u.scr.script->script_vars); - setd_sub(NULL, NULL, ".ai_action", 3, (void *)md->bl.id, &md->nd->u.scr.script->script_vars); - run_script(md->nd->u.scr.script, 0, 0, md->nd->bl.id); + mob_script_callback(md, bl, CALLBACK_ASSIST); + return 0; } md->target_id=tbl->id; md->min_chase=md->db->range3+distance_bl(&md->bl, tbl); @@ -975,14 +968,8 @@ int mob_unlocktarget(struct mob_data *md,int tick) { nullpo_retr(0, md); - if(md->nd){ - struct block_list *tbl = map_id2bl(md->target_id); - setd_sub(NULL, NULL, ".ai_action", 0, (void *)(int)6, &md->nd->u.scr.script->script_vars); - setd_sub(NULL, NULL, ".ai_action", 1, (void *)(int)(tbl?tbl->type:0), &md->nd->u.scr.script->script_vars); - setd_sub(NULL, NULL, ".ai_action", 2, (void *)(tbl?tbl->id:0), &md->nd->u.scr.script->script_vars); - setd_sub(NULL, NULL, ".ai_action", 3, (void *)md->bl.id, &md->nd->u.scr.script->script_vars); - run_script(md->nd->u.scr.script, 0, 0, md->nd->bl.id); - } + if(md->nd) + mob_script_callback(md, map_id2bl(md->target_id), CALLBACK_UNLOCK); md->target_id=0; md->state.skillstate=MSS_IDLE; @@ -1604,13 +1591,7 @@ void mob_damage(struct mob_data *md, struct block_list *src, int damage) md->attacked_players++; if(md->nd) - { - setd_sub(NULL, NULL, ".ai_action", 0, (void *)(int)1, &md->nd->u.scr.script->script_vars); - setd_sub(NULL, NULL, ".ai_action", 1, (void *)(int)src->type, &md->nd->u.scr.script->script_vars); - setd_sub(NULL, NULL, ".ai_action", 2, (void *)src->id, &md->nd->u.scr.script->script_vars); - setd_sub(NULL, NULL, ".ai_action", 3, (void *)md->bl.id, &md->nd->u.scr.script->script_vars); - run_script(md->nd->u.scr.script, 0, 0, md->nd->bl.id); - } + mob_script_callback(md, src, CALLBACK_ATTACK); switch (src->type) { case BL_PC: @@ -2112,22 +2093,13 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) if(src && src->type == BL_MOB){ struct mob_data *smd = (struct mob_data *)src; - if(smd->nd){ - setd_sub(NULL, NULL, ".ai_action", 0, (void *)(int)5, &smd->nd->u.scr.script->script_vars); - setd_sub(NULL, NULL, ".ai_action", 1, (void *)(int)md->bl.type, &smd->nd->u.scr.script->script_vars); - setd_sub(NULL, NULL, ".ai_action", 2, (void *)md->bl.id, &smd->nd->u.scr.script->script_vars); - setd_sub(NULL, NULL, ".ai_action", 3, (void *)smd->bl.id, &smd->nd->u.scr.script->script_vars); - run_script(smd->nd->u.scr.script, 0, 0, smd->nd->bl.id); - } + if(smd->nd) + mob_script_callback(smd, &md->bl, CALLBACK_KILL); } - if(md->nd){ - setd_sub(NULL, NULL, ".ai_action", 0, (void *)(int)3, &md->nd->u.scr.script->script_vars); - setd_sub(NULL, NULL, ".ai_action", 1, (void *)(int)(src?src->type:0), &md->nd->u.scr.script->script_vars); - setd_sub(NULL, NULL, ".ai_action", 2, (void *)(src?src->id:0), &md->nd->u.scr.script->script_vars); - setd_sub(NULL, NULL, ".ai_action", 3, (void *)md->bl.id, &md->nd->u.scr.script->script_vars); - run_script(md->nd->u.scr.script, 0, 0, md->nd->bl.id); - } else if(md->npc_event[0]){ + if(md->nd) + mob_script_callback(md, src, CALLBACK_DEAD); + else if(md->npc_event[0]){ if(src && src->type == BL_PET) sd = ((struct pet_data *)src)->msd; if(sd && battle_config.mob_npc_event_type) @@ -2449,6 +2421,10 @@ int mob_summonslave(struct mob_data *md2,int *value,int amount,int skill_id) clif_skill_nodamage(&md->bl,&md->bl,skill_id,amount,1); } + + if(md2->nd) + mob_convertslave(md2); + return 0; } @@ -3012,6 +2988,20 @@ int mob_clone_delete(int class_) return 0; } +void mob_script_callback(struct mob_data *md, struct block_list *target, unsigned char action_type) +{ + // I will not add any protection here since I assume everything is checked before coming here. + if(md->callback_flag&action_type){ + setd_sub(NULL, NULL, ".ai_action", 0, (void *)(int)action_type, &md->nd->u.scr.script->script_vars); + if(target){ + setd_sub(NULL, NULL, ".ai_action", 1, (void *)(int)target->type, &md->nd->u.scr.script->script_vars); + setd_sub(NULL, NULL, ".ai_action", 2, (void *)target->id, &md->nd->u.scr.script->script_vars); + } + setd_sub(NULL, NULL, ".ai_action", 3, (void *)md->bl.id, &md->nd->u.scr.script->script_vars); + run_script(md->nd->u.scr.script, 0, 0, md->nd->bl.id); + } +} + // // ‰Šú‰» // diff --git a/src/map/mob.h b/src/map/mob.h index 4bfc76603..34b3988ad 100644 --- a/src/map/mob.h +++ b/src/map/mob.h @@ -25,6 +25,18 @@ #define MOB_CLONE_START 9001
#define MOB_CLONE_END 10000
+// Scripted Mob AI Constants
+#define CALLBACK_ATTACK 0x80
+#define CALLBACK_DETECT 0x40
+#define CALLBACK_DEAD 0x20
+#define CALLBACK_ASSIST 0x10
+#define CALLBACK_KILL 0x08
+#define CALLBACK_UNLOCK 0x04
+#define CALLBACK_WALKACK 0x02
+#define CALLBACK_WARPACK 0x01
+
+void mob_script_callback(struct mob_data *md, struct block_list *target, unsigned char action_type);
+
struct mob_skill {
short state;
short skill_id,skill_lv;
diff --git a/src/map/pc.c b/src/map/pc.c index c3e533a21..e42aa454f 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -4663,13 +4663,8 @@ int pc_dead(struct map_session_data *sd,struct block_list *src) status_calc_mob(md, 0);
status_percent_heal(src,10,0);
}
- if(md->nd){
- setd_sub(NULL, NULL, ".ai_action", 0, (void *)(int)5, &md->nd->u.scr.script->script_vars);
- setd_sub(NULL, NULL, ".ai_action", 1, (void *)(int)sd->bl.type, &md->nd->u.scr.script->script_vars);
- setd_sub(NULL, NULL, ".ai_action", 2, (void *)sd->bl.id, &md->nd->u.scr.script->script_vars);
- setd_sub(NULL, NULL, ".ai_action", 3, (void *)md->bl.id, &md->nd->u.scr.script->script_vars);
- run_script(md->nd->u.scr.script, 0, 0, md->nd->bl.id);
- }
+ if(md->nd)
+ mob_script_callback(md, &sd->bl, CALLBACK_KILL);
}
break;
case BL_PC:
diff --git a/src/map/unit.c b/src/map/unit.c index 5ec465d43..249b1db71 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -27,6 +27,7 @@ #include "party.h"
#include "intif.h"
#include "chrif.h"
+#include "script.h"
static int dirx[8]={0,-1,-1,-1,0,1,1,1};
static int diry[8]={1,1,0,-1,-1,-1,0,1};
@@ -244,6 +245,8 @@ static int unit_walktoxy_timer(int tid,unsigned int tick,int id,int data) } else { //Stopped walking. Update to_x and to_y to current location [Skotlex]
ud->to_x = bl->x;
ud->to_y = bl->y;
+ if(md && md->nd) // Tell the script engine we've finished walking (for AI pathfinding)
+ mob_script_callback(md, NULL, CALLBACK_WALKACK);
}
return 0;
}
@@ -530,6 +533,12 @@ int unit_warp(struct block_list *bl,int m,short x,short y,int type) map_addblock(bl);
clif_spawn(bl);
skill_unit_move(bl,gettick(),1);
+
+ if(bl->type == BL_MOB){
+ TBL_MOB *md = (TBL_MOB *)bl;
+ if(md->nd) // Tell the script engine we've warped
+ mob_script_callback(md, NULL, CALLBACK_WARPACK);
+ }
return 0;
}
|