5 vector
<rpgobj
*> set
, stack
;
6 hashtable
<char *, char *> names
;
13 rpgquest
*currentquest
;
15 rpgobjset(rpgclient
&_cl
) : cl(_cl
), pointingat(NULL
), playerobj(NULL
), selected(NULL
), quests(NULL
), currentquest(NULL
)
17 #define N(n) CCOMMAND(r_##n, "i", (rpgobjset *self, int *val), { self->stack[0]->s_##n = *val; }); \
18 CCOMMAND(r_get_##n, "", (rpgobjset *self), { intret(self->stack[0]->s_##n); });
22 #define N(n) CCOMMAND(r_def_##n, "ii", (rpgobjset *self, int *i1, int *i2), { stats::def_##n(*i1, *i2); }); \
23 CCOMMAND(r_eff_##n, "", (rpgobjset *self), { intret(self->stack[0]->eff_##n()); });
27 CCOMMAND(r_model
, "s", (rpgobjset
*self
, char *s
), { self
->stack
[0]->model
= self
->stringpool(s
); });
28 CCOMMAND(r_spawn
, "s", (rpgobjset
*self
, char *s
), { self
->spawn(self
->stringpool(s
)); });
29 CCOMMAND(r_contain
, "s", (rpgobjset
*self
, char *s
), { self
->stack
[0]->decontain(); self
->stack
[1]->add(self
->stack
[0], atoi(s
)); });
30 CCOMMAND(r_pop
, "", (rpgobjset
*self
), { self
->popobj(); });
31 CCOMMAND(r_swap
, "", (rpgobjset
*self
), { swap(self
->stack
[0], self
->stack
[1]); });
32 CCOMMAND(r_say
, "s", (rpgobjset
*self
, char *s
), { self
->stack
[0]->abovetext
= self
->stringpool(s
); });
33 CCOMMAND(r_quest
, "ss", (rpgobjset
*self
, char *s
, char *a
), { self
->stack
[0]->addaction(self
->stringpool(s
), self
->stringpool(a
), true); });
34 CCOMMAND(r_action
, "ss", (rpgobjset
*self
, char *s
, char *a
), { self
->stack
[0]->addaction(self
->stringpool(s
), self
->stringpool(a
), false); });
35 CCOMMAND(r_action_use
, "s", (rpgobjset
*self
, char *s
), { self
->stack
[0]->action_use
.script
= self
->stringpool(s
); });
36 CCOMMAND(r_take
, "sss", (rpgobjset
*self
, char *name
, char *ok
, char *notok
), { self
->takefromplayer(name
, ok
, notok
); });
37 CCOMMAND(r_give
, "s", (rpgobjset
*self
, char *s
), { self
->givetoplayer(s
); });
38 CCOMMAND(r_use
, "", (rpgobjset
*self
), { self
->stack
[0]->selectuse(); });
39 CCOMMAND(r_applydamage
, "i", (rpgobjset
*self
, int *d
), { self
->stack
[0]->takedamage(*d
, *self
->stack
[1]); });
46 loopi(10) stack
.add(playerobj
); // determines the stack depth
51 if(playerobj
) { playerobj
->ent
= NULL
; delete playerobj
; }
52 playerobj
= new rpgobj("player", *this);
53 playerobj
->ent
= &cl
.player1
;
54 cl
.player1
.ro
= playerobj
;
57 set
.deletecontentsp();
60 playerobj
->scriptinit(); // will fail when this is called from emptymap(), which is ok
63 void removefromsystem(rpgobj
*o
)
67 if(pointingat
==o
) pointingat
= NULL
;
68 if(selected
==o
) selected
= NULL
;
73 void update(int curtime
)
79 set
[i
]->update(curtime
);
81 float dist
= cl
.player1
.o
.dist(set
[i
]->ent
->o
);
82 if(dist
<50 && intersect(set
[i
]->ent
, cl
.player1
.o
, worldpos
) && (!pointingat
|| cl
.player1
.o
.dist(pointingat
->ent
->o
)>dist
))
89 void spawn(char *name
)
91 rpgobj
*o
= new rpgobj(name
, *this);
96 void placeinworld(vec
&pos
, float yaw
)
98 stack
[0]->placeinworld(new rpgent(stack
[0], cl
, pos
, yaw
));
102 void pushobj(rpgobj
*o
) { stack
.pop(); stack
.insert(0, o
); } // never overflows, just removes bottom
103 void popobj() { stack
.add(stack
.remove(0)); } // never underflows, just puts it at the bottom
105 void removefromworld(rpgobj
*worldobj
)
107 set
.removeobj(worldobj
);
108 DELETEP(worldobj
->ent
);
111 void take(rpgobj
*worldobj
, rpgobj
*newowner
)
113 removefromworld(worldobj
);
114 newowner
->add(worldobj
, false);
117 void takefromplayer(char *name
, char *ok
, char *notok
)
119 rpgobj
*o
= playerobj
->take(name
);
122 stack
[0]->add(o
, false);
123 conoutf("\f2you hand over a %s", o
->name
);
126 conoutf("\f2you finish a quest for %s", currentquest
->npc
);
127 currentquest
->completed
= true;
130 execute(o
? ok
: notok
);
133 void givetoplayer(char *name
)
135 rpgobj
*o
= stack
[0]->take(name
);
138 conoutf("\f2you receive a %s", o
->name
);
139 playerobj
->add(o
, false);
143 void addquest(rpgaction
*a
, const char *questline
, const char *npc
)
145 a
->q
= quests
= new rpgquest(quests
, npc
, questline
);
146 conoutf("\f2you have accepted a quest for %s", npc
);
149 void listquests(bool completed
, g3d_gui
&g
)
151 for(rpgquest
*q
= quests
; q
; q
= q
->next
) if(q
->completed
==completed
)
153 s_sprintfd(info
)("%s: %s", q
->npc
, q
->questline
);
154 g
.text(info
, 0xAAAAAA, "info");
158 char *stringpool(char *name
)
160 char **n
= names
.access(name
);
162 name
= newstring(name
);
167 void render() { loopv(set
) set
[i
]->render(); }
168 void g3d_npcmenus() { loopv(set
) set
[i
]->g3d_menu(); }