123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- #ifndef __GAME_RENDERING_H
- #define __GAME_RENDERING_H
- void Game::make_screen(mainloop::screen_params_t& sp, GameState& state) {
- sp.w = GRID_W;
- sp.h = GRID_H;
- sp.w2 = sp.w;
- sp.h2 = sp.h;
- auto& themes = state.render.ui_symbol_themes;
- for (const auto& i : constants().ui_symbols) {
- themes.push_back(i[n_skin]);
- }
- state.render.set_ui_symbol();
- }
- void Game::set_skin(GameState& state, unsigned int x, unsigned int y) {
- bool walkable = state.grid.is_walk(x, y);
- bool water = state.grid.is_water(x, y);
- state.render.set_is_viewblock(x, y, 0, !walkable);
- state.render.set_is_walkblock(x, y, 0, !walkable);
- grender::Grid::skin s;
- double z = state.grid._get(x, y);
- const Levelskin& lev = levelskins().get(p.worldz);
- if (walkable) {
- if (water) {
- if (z <= -5) {
- s = lev.deep_water[n_skin];
- } else {
- s = lev.shallow_water[n_skin];
- }
- } else {
- if (z <= -8) {
- s = lev.floor1[n_skin];
- } else if (z <= -7) {
- s = lev.floor2[n_skin];
- } else if (z <= -6) {
- s = lev.floor3[n_skin];
- } else if (z <= -5) {
- s = lev.floor4[n_skin];
- } else if (z <= -4) {
- s = lev.floor5[n_skin];
- } else if (z <= -3) {
- s = lev.floor6[n_skin];
- } else if (z <= -2) {
- s = lev.floor7[n_skin];
- } else {
- s = lev.floor8[n_skin];
- }
- }
- } else {
- if (water) {
- s = lev.water_wall[n_skin];
- } else {
- s = lev.wall[n_skin];
- }
- }
- state.render.set_skin(x, y, 0, s);
- // //
- features::Feature feat;
- if (state.features.get(x, y, feat)) {
- const Terrain& t = terrain().get(feat.tag);
- state.render.set_skin(x, y, 1, t.skin[n_skin]);
- state.render.set_is_viewblock(x, y, 1, t.viewblock);
- state.render.set_is_walkblock(x, y, 1, t.walkblock);
- state.render.set_is_lit(x, y, 1, t.is_lit);
- state.render.set_is_lightsource(x, y, 1, t.is_lightsource);
- } else {
- state.render.unset_skin(x, y, 1);
- state.render.set_is_viewblock(x, y, 1, false);
- state.render.set_is_walkblock(x, y, 1, false);
- state.render.set_is_lit(x, y, 1, false);
- state.render.set_is_lightsource(x, y, 1, false);
- }
- // //
- items::Item item;
- if (state.items.get(x, y, 0, item)) {
- const Design& d = designs().get(item.tag);
- state.render.set_skin(x, y, 4, d.skin[n_skin]);
- state.render.set_is_lit(x, y, 4, d.is_lit);
- } else {
- state.render.unset_skin(x, y, 4);
- state.render.set_is_lit(x, y, 4, false);
- }
- // //
- if (x == p.px && y == p.py) {
- s = p.get_species().skin[n_skin];
- state.render.set_skin(x, y, 5, s);
- } else {
- monsters::Monster& mon = state.monsters.get(x, y);
- if (!mon.null() && !mon.hidden) {
- const Species& s = species().get(mon.tag);
- auto skin = s.skin[n_skin];
- if (!mon.ally.null()) {
- skin.underline = true;
- }
- state.render.set_skin(x, y, 5, skin);
- state.render.set_is_walkblock(x, y, 5, true);
-
- } else {
- state.render.unset_skin(x, y, 5);
- state.render.set_is_walkblock(x, y, 5, false);
- }
- }
- state.render.validate(x, y);
- }
- void drawing_context_center_at(mainloop::drawing_context_t& ctx, unsigned int x, unsigned int y) {
-
- unsigned int grid_x = ctx.view_w / 4;
- unsigned int grid_y = ctx.view_h / 4;
- if (!ctx.do_center_view && grid_x > 1) {
- ctx.voff_off_x = -(x % grid_x) + (grid_x / 2);
- } else {
- ctx.voff_off_x = 0;
- }
- if (!ctx.do_center_view && grid_y > 1) {
- ctx.voff_off_y = -(y % grid_y) + (grid_y / 2);
- } else {
- ctx.voff_off_y = 0;
- }
- ctx.centerx = x;
- ctx.centery = y;
- }
- unsigned int get_lightradius(const Player& p, const GameState& state) {
- int r = -1;
- features::Feature feat;
- if (state.features.get(p.px, p.py, feat)) {
- r = terrain().get(feat.tag).view_radius;
- }
- if (!p.polymorph.species.null()) {
- r = p.get_species().range;
- }
- if (r < 0) {
- const Levelskin& ls = levelskins().get(p.worldz);
- r = std::min(ls.lightradius_max, ls.lightradius + p.get_lightradius());
- }
- if (p.blind > 0) {
- r = std::max(1, (int)(r * (1.0 - p.blind)));
- }
- return r;
- }
- void Game::drawing_context(mainloop::drawing_context_t& ctx, const GameState& state) {
- ctx.px = p.px;
- ctx.py = p.py;
- ctx.lightradius = get_lightradius(p, state);
- if (p.state & Player::LOOKING) {
- if (p.look.rangemin >= 0) {
- ctx.rangemin = p.look.rangemin;
- }
- if (p.look.rangemax >= 0) {
- ctx.rangemax = p.look.rangemax;
- }
- ctx.hlx = p.look.x;
- ctx.hly = p.look.y;
- drawing_context_center_at(ctx, p.look.x, p.look.y);
- } else {
- drawing_context_center_at(ctx, p.px, p.py);
- }
- }
- void draw_one_stat(Player& p, GameState& state, tag_t s, size_t n_skin) {
- const Stat& st = stats().get(s);
- double val = p.stats.gets(s);
- if (st.hidden && val == 0)
- return;
- double v;
- double min;
- double max;
- if (st.reversed) {
- max = st.min;
- min = st.max;
- } else {
- max = st.max;
- min = st.min;
- }
- if (st.progressbar) {
- v = 6.0 * (val - min) / (max - min);
- } else {
- v = 3.0 * (2 * val - max - min) / (max - min);
- }
- int vp = v;
- if (v < 0) {
- --vp;
- }
- const auto& zs = st.label;
- if (st.progressbar) {
- state.render.push_hud_line(vp, zs.label, zs.lskin[n_skin], zs.pskin[n_skin]);
- } else {
- state.render.push_hud_line(vp, zs.label, zs.lskin[n_skin], zs.pskin[n_skin], zs.nskin[n_skin]);
- }
- }
- void draw_one_count(Player& p, GameState& state, tag_t s, size_t n_skin) {
- const Count& ct = counts().get(s);
- double val = p.stats.getc(s);
- if (ct.hidden && val == 0)
- return;
- unsigned int v = (6u * val) / ct.cmax;
- const auto& zs = ct.label;
- state.render.push_hud_line(v, zs.label, zs.lskin[n_skin], (state.ticks & 1 ? zs.pskin[n_skin] : zs.nskin[n_skin]));
- }
- void Game::draw_hud(GameState& state) {
- const auto& hso = constants().hud_stats_order;
- const auto& hco = constants().hud_counts_order;
- for (const tag_t& i : hso) {
- draw_one_stat(p, state, i, n_skin);
- }
- for (const tag_t& i : hco) {
- draw_one_count(p, state, i, n_skin);
- }
- }
- #endif
|