UID178554
帖子
精華
主題
積分16695
現金
積極性
威望
違規
熱心
推廣次數
閱讀權限30
註冊時間2009-7-26
在線時間 小時
最後登錄1970-1-1
TA的每日心情 | 慵懶 2013-7-11 12:09 AM |
---|
簽到天數: 118 天 連續簽到: 1 天 [LV.6]常住居民II
|
本帖最後由 Alopex 於 2011-8-29 03:56 PM 編輯
已測試,副作用不知道...
map.h
add- #define MAX_WAYPOINT 100
- struct Waypoint{
- int x[MAX_WAYPOINT];
- int y[MAX_WAYPOINT];
- int num;
- }waypoint[MAX_WAYPOINT];
複製代碼 map.c
add- void Do_Init_Waypoint(const char *filename);
- void Do_Init_Waypoint(const char *filename){
- FILE* fp;
- int line_num = 0,read_waypoint_num = 0;
- char line[1024];
- if((fp = fopen(filename, "r")) == NULL )
- {
- ShowWarning("Do_Init_Waypoint: File "%s" does not exist.\n ",filename);
- return;
- }
- while(fgets(line, sizeof(line), fp) && ++line_num && read_waypoint_num < MAX_WAYPOINT)
- {
- int i;
- char *str[2],*p = line;
- while(ISSPACE(*p))p++;//skip space.
- if(*p == '/' && *(p+1) == '/')
- continue; // skip "//"
- for(i=0 ; i < 100 ;i++){
- str[0] = p;
- p = strchr(p, ',');
- if(p == NULL){
- waypoint[read_waypoint_num].num = 0;
- break;
- }
- *p = '\0';
- p++;
- str[1] = p;
- p = strchr(p, ',');
- waypoint[read_waypoint_num].x[i] = atoi(str[0]);
- waypoint[read_waypoint_num].y[i] = atoi(str[1]);
- waypoint[read_waypoint_num].num++;
- if(p == NULL){
- read_waypoint_num++;
- break;
- }
- *p = '\0';
- p++;
- }
- }
- }
複製代碼 find:上方增加- Do_Init_Waypoint("db/waypoint.txt");
複製代碼 script.c
add- BUILDIN_FUNC(setwaypoint)
- {
- TBL_MOB *bl;
- int way_point ;
- bl = (TBL_MOB*)map_id2bl(script_getnum(st,2)); way_point = script_getnum(st,3);
- if( bl == NULL || way_point >= 100) {
- script_pushint(st, 0);
- return 0;
- }
- bl->self_waypoint = &waypoint[way_point];
- bl->waypoint_move = 0;
- script_pushint(st, 1);
- return 0;
- }
- BUILDIN_DEF(setwaypoint, "ii"),
複製代碼 mob.c
找- int mob_randomwalk(struct mob_data *md,unsigned int tick)
複製代碼 內下方增加- if(md->self_waypoint != NULL){
- if(md->waypoint_move < md->self_waypoint->num){
- int _x = md->self_waypoint->x[md->waypoint_move];
- int _y = md->self_waypoint->y[md->waypoint_move];
- md->waypoint_move++;
- if((map_getcell(md->bl.m,_x,_y,CELL_CHKPASS)) && unit_walktoxy(&md->bl,_x,_y,1)){
- speed=status_get_speed(&md->bl);
- for(i=c=0;i<md->ud.walkpath.path_len;i++){ // The next walk start time is calculated.
- if(md->ud.walkpath.path[i]&1)
- c+=speed*14/10;
- else
- c+=speed;
- }
- md->state.skillstate=MSS_WALK;
- md->next_walktime =tick + c -10;
- return 1;
- }
- }else{
- md->self_waypoint = NULL;
- md->waypoint_move = 0;
- }
- }else if((map_getcell(md->bl.m,x,y,CELL_CHKPASS)) && unit_walktoxy(&md->bl,x,y,1)){
- break;
- }
複製代碼 mob.h
找下方增加:- //點路
- struct Waypoint *self_waypoint;
- int waypoint_move;
複製代碼 map.c
找- char name[NAME_LENGTH],eventname[50]; //Name/event
複製代碼 下方增加:- //點路
- struct Waypoint *self_waypoint;
- int waypoint_move;
複製代碼 db/waypoint.txt- //支持100行,每行100個座標
- //請參照如下格式填寫,
- //格式:
- 55,111,56,111,57,111,59,111,63,111,67,111,69,111
- 111,11,123,15,133//這是不合格的
- //注意:座標ID從0遞加
- //只帶一個座標的行列無效
複製代碼 腳本:- - script TT -1,{
- OnWhisperGlobal:
- getmapxy(.@map$,.@x,.@y,0);
- set @gid,bg_monster(0,.@map$,55,111,"Test",1002,"");
- setwaypoint(@gid,0);
- }
複製代碼 怪物走起路來可能會頓頓的,畢竟是加在Randomwalk...
=======================================
8/29優化
mob.c
找 - static int mob_ai_sub_lazy(struct mob_data *md, va_list args)
複製代碼
內兩個 - rand()%1000 < MOB_LAZYMOVEPERC(md)
複製代碼
替代成 - md->self_waypoint != NULL || rand()%1000 < MOB_LAZYMOVEPERC(md)
複製代碼 |
|