作者laechan (打死不投马冏,李系咩安抓)
看板mud_sanc
标题Re: □ [wizs]问题请教(十六)
时间Tue Jul 31 10:37:26 2007
※ 引述《amosdeus (幽素)》之铭言:
: 请问以下程式有节省记忆体或是好一点的写法吗?
: 档案位置:/u/p/plain/wide/virtue/room2/test.c
只要房间有自订 init, 都要有一个概念, 就是任何生物(含怪物),
只要进入该房间, 就一定会呼叫一次 init 函数.
所以你可以先行剔除掉一些你觉得不必要的. 我举例, 例如只有玩
家进入该房间触发的 init 才有效, 如底下...
: void init()
: {
if(!userp(this_player())) return ; // 可以先做的一种判断
: int r;
: r=random(2);
: switch(r)
: {
: case 1:
: set("long",@PLAIN
: ...
: PLAIN
: );
: set("exits",([
: ...
: ...
: ]));
: set("pre_exit_func",(["....":"hi"]));
: break;
: default:
: set("long",@PLAIN
: ...
: PLAIN
: );
: set("exits",([
: ...
: ...
: ]));
: set("pre_exit_func",(["....":"hi"]));
: break;
: }
: }
底下的函数是, 只要玩家往特定方向走, 就会呼叫.
基本上底下应该就是最精简了.
: int hi()
: {
: object ppl = this_player();
: if(ppl->query_temp("xxxx"))
: {
: ppl->delete_temp("xxxxx");
: ppl->set_temp("yyyy",1);
: return 0;
: }
: if(ppl->query_temp("yyyy"))
: {
: ppl->delete_temp("yyyyy");
: ppl->set_temp("zzzz",1);
: return 0;
: }
: if(ppl->query_temp("zzzz"))
: {
: ppl->delete_temp("zzzz");
: ppl->move_player(VR2"ccc","SNEAK");
: return 0;
: }
: return 1;
: }
: 以上
: 谢谢
: Plain@Sanc
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 125.231.126.91