Initial sauer
[SauerbratenRemote.git] / src / rpggame / rpg.cpp
blob8e8e8f3b659928ee4fa307491593473194a02a93
2 #include "pch.h"
3 #include "cube.h"
4 #include "iengine.h"
5 #include "igame.h"
6 #include "stubs.h"
9 struct rpgclient : igameclient, g3d_callback
11 struct rpgent;
13 #include "entities.h"
14 #include "stats.h"
15 #include "rpgobj.h"
16 #include "rpgobjset.h"
17 #include "rpgent.h"
19 rpgentities et;
20 rpgdummycom cc;
21 rpgobjset os;
23 rpgent player1;
25 int lastmillis, maptime;
26 string mapname;
28 int menutime, menutab, menuwhich;
29 vec menupos;
31 rpgclient() : et(*this), os(*this), player1(os.playerobj, *this, vec(0, 0, 0), 0, 100, ENT_PLAYER), lastmillis(0), maptime(0), menutime(0), menutab(1), menuwhich(0)
33 CCOMMAND(map, "s", (rpgclient *self, char *s), load_world(s));
34 CCOMMAND(showplayergui, "i", (rpgclient *self, int *which), self->showplayergui(*which));
36 ~rpgclient() {}
38 icliententities *getents() { return &et; }
39 iclientcom *getcom() { return &cc; }
41 void updateworld(vec &pos, int curtime, int lm)
43 if(!maptime) { maptime = lm + curtime; return; }
44 lastmillis = lm;
45 if(!curtime) return;
46 physicsframe();
47 os.update(curtime);
48 player1.updateplayer(curtime, pos);
49 checktriggers();
52 void showplayergui(int which)
54 if((menutime && which==menuwhich) || !which)
56 menutime = 0;
58 else
60 menutime = starttime();
61 menupos = menuinfrontofplayer();
62 menuwhich = which;
66 void gui(g3d_gui &g, bool firstpass)
68 g.start(menutime, 0.03f, &menutab);
69 switch(menuwhich)
71 default:
72 case 1:
73 g.tab("inventory", 0xFFFFF);
74 os.playerobj->invgui(g);
75 break;
77 case 2:
78 g.tab("stats", 0xFFFFF);
79 os.playerobj->st_show(g);
80 break;
82 case 3:
83 g.tab("active quests", 0xFFFFF);
84 os.listquests(false, g);
85 g.tab("completed quests", 0xFFFFF);
86 os.listquests(true, g);
88 g.end();
91 void initclient() {}
93 void physicstrigger(physent *d, bool local, int floorlevel, int waterlevel)
95 if (waterlevel>0) playsoundname("free/splash1", d==&player1 ? NULL : &d->o);
96 else if(waterlevel<0) playsoundname("free/splash2", d==&player1 ? NULL : &d->o);
97 if (floorlevel>0) { if(local) playsoundname("aard/jump"); else if(d->type==ENT_AI) playsoundname("aard/jump", &d->o); }
98 else if(floorlevel<0) { if(local) playsoundname("aard/land"); else if(d->type==ENT_AI) playsoundname("aard/land", &d->o); }
101 void edittrigger(const selinfo &sel, int op, int arg1 = 0, int arg2 = 0, int arg3 = 0) {}
102 char *getclientmap() { return mapname; }
103 void resetgamestate() {}
104 void suicide(physent *d) {}
105 void newmap(int size) {}
107 void startmap(const char *name)
109 os.clearworld();
110 s_strcpy(mapname, name);
111 maptime = 0;
112 findplayerspawn(&player1);
113 if(*name) os.playerobj->st_init();
114 et.startmap();
117 void quad(int x, int y, int xs, int ys)
119 glBegin(GL_QUADS);
120 glTexCoord2f(0, 0); glVertex2i(x, y);
121 glTexCoord2f(1, 0); glVertex2i(x+xs, y);
122 glTexCoord2f(1, 1); glVertex2i(x+xs, y+ys);
123 glTexCoord2f(0, 1); glVertex2i(x, y+ys);
124 glEnd();
127 void gameplayhud(int w, int h)
129 glLoadIdentity();
130 glOrtho(0, w*2, h*2, 0, -1, 1);
131 draw_textf("using: %s", 636*2, h*2-256+149, os.selected ? os.selected->name : "(none)"); // temp
133 glLoadIdentity();
134 glOrtho(0, w, h, 0, -1, 1);
135 settexture("data/hud_rpg.png", true);
137 glEnable(GL_BLEND);
138 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
139 quad(0, h-128, 768, 128);
140 settexture("data/hbar.png", true);
141 glColor4f(1, 0, 0, 0.5f);
142 quad(130, h-128+57, 193*os.playerobj->s_hp/os.playerobj->eff_maxhp(), 17);
143 glColor4f(0, 0, 1, 0.5f);
144 quad(130, h-128+87, 193*os.playerobj->s_mana/os.playerobj->eff_maxmana(), 17);
145 glDisable(GL_BLEND);
148 void drawhudmodel(int anim, float speed = 0, int base = 0)
150 vec color, dir;
151 lightreaching(player1.o, color, dir);
152 rendermodel(color, dir, "hudguns/fist", anim, 0, 0, player1.o, player1.yaw+90, player1.pitch, speed, base, NULL, 0);
155 void drawhudgun()
157 if(editmode) return;
159 int rtime = 250;
160 if(lastmillis-player1.lastaction<rtime)
162 drawhudmodel(ANIM_GUNSHOOT, rtime/17.0f, player1.lastaction);
164 else
166 drawhudmodel(ANIM_GUNIDLE|ANIM_LOOP);
170 bool canjump() { return true; }
171 void doattack(bool on) { player1.attacking = on; }
172 dynent *iterdynents(int i) { return i ? os.set[i-1]->ent : &player1; }
173 int numdynents() { return os.set.length()+1; }
175 void rendergame()
177 if(isthirdperson()) renderclient(&player1, "monster/ogro", NULL, ANIM_PUNCH, 300, player1.lastaction, player1.lastpain);
178 os.render();
181 void g3d_gamemenus() { os.g3d_npcmenus(); if(menutime) g3d_addgui(this, menupos); }
183 void writegamedata(vector<char> &extras) {}
184 void readgamedata (vector<char> &extras) {}
186 const char *gameident() { return "rpg"; }
187 const char *defaultmap() { return "rpg_01"; }
188 const char *savedconfig() { return "rpg_config.cfg"; }
189 const char *defaultconfig() { return "data/defaults.cfg"; }
190 const char *autoexec() { return "rpg_autoexec.cfg"; }
193 #define N(n) int rpgclient::stats::pointscale_##n, rpgclient::stats::percentscale_##n;
194 RPGSTATNAMES
195 #undef N
197 REGISTERGAME(rpggame, "rpg", new rpgclient(), new rpgdummyserver());