路點系統 8/29優化完畢.
本帖最後由 Alopex 於 2011-8-29 03:56 PM 編輯已測試,副作用不知道...
map.h
add#define MAX_WAYPOINT 100
struct Waypoint{
int x;
int y;
int num;
}waypoint;
map.c
addvoid 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;
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,*p = line;
while(ISSPACE(*p))p++;//skip space.
if(*p == '/' && *(p+1) == '/')
continue; // skip "//"
for(i=0 ; i < 100 ;i++){
str = p;
p = strchr(p, ',');
if(p == NULL){
waypoint.num = 0;
break;
}
*p = '\0';
p++;
str = p;
p = strchr(p, ',');
waypoint.x = atoi(str);
waypoint.y = atoi(str);
waypoint.num++;
if(p == NULL){
read_waypoint_num++;
break;
}
*p = '\0';
p++;
}
}
}find:do_init_battle();上方增加Do_Init_Waypoint("db/waypoint.txt");script.c
addBUILDIN_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;
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)內y+=md->bl.y;下方增加 if(md->self_waypoint != NULL){
if(md->waypoint_move < md->self_waypoint->num){
int _x = md->self_waypoint->x;
int _y = md->self_waypoint->y;
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&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
找char npc_event;下方增加: //點路
struct Waypoint *self_waypoint;
int waypoint_move;map.c
找char name,eventname; //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) #define MAX_WAYPOINT 100
struct Waypoint{
int x;
int y;
int num;
}waypoint;這個安全有問題, waypoint都可以用而且沒有報錯 本帖最後由 Alopex 於 2011-8-29 03:24 PM 編輯
回復 2# 為私服而開
會有問題大概就在這吧...
bl->self_waypoint = &waypoint;
調整一下..
================
要寫的安全些也不是問題,懶了些 = =好效率。。
早上刚说晚上就出来了 - - 狐狸,我改说你什么好呢~~~ 編譯時沒報錯
遊戲運行時就error了 編譯時沒報錯
遊戲運行時就error了
rgrg1234 發表於 2011-8-28 10:53 PM http://okayro.com/images/common/back.gif
哪裡Error?
我測試了...會照著路徑走,只是有點慢... 編譯時沒報錯
遊戲運行時就error了
rgrg1234 發表於 2011-8-28 10:53 PM http://okayro.com/images/common/back.gif
我看到少貼了一段東西.. 本帖最後由 rgrg1234 於 2011-8-29 12:40 PM 編輯
回復 7# Alopex
撲撲= =...
好像怪怪的
摁....成功了 回復Alopex
撲撲= =...
好像怪怪的
摁....成功了
rgrg1234 發表於 2011-8-29 12:31 PM http://okayro.com/images/common/back.gif
有bug再告知吧
走起來好不順xd雖然不會慢,可是看起來像停了在走 回復 9# Alopex
走起來莫名的詭異= =... 本帖最後由 Alopex 於 2011-8-29 02:55 PM 編輯
回復 10# rgrg1234
想個辦法優化吧:114:
==============
優化完畢,看起來順了~.~ 回復 11# Alopex
真的順多了
給你一個:tk_05 map.c
找char name,eventname; //Name/event
//點路
struct Waypoint *self_waypoint;
int waypoint_move;
這個具體加在什麽地方的
我用的是RA的端,在map.c里只在struct map_cache_map_info中找到char name
看不像是,也加了,讀完地圖檔,MAP就檔了
求解~~ moneymuch 發表於 2012-9-21 11:58 PM static/image/common/back.gif
map.c
找char name,eventname; //Name/event
//點路
那段應該是在map.h
char name,eventname; //Name/event
不過RA已經改成
char name, eventname; //Name/event
頁:
[1]