From e8bc1eab9a45b8893701e3acbd008fe259c53a4c Mon Sep 17 00:00:00 2001 From: jacopo grandi Date: Thu, 25 Feb 2021 16:29:19 +0100 Subject: before was messy, now is MACRO(MACRO(MACRO(MACRO(clean)))) --- hud/hud_views.c | 282 ++++++++++++++++---------------------------------------- 1 file changed, 81 insertions(+), 201 deletions(-) (limited to 'hud/hud_views.c') diff --git a/hud/hud_views.c b/hud/hud_views.c index c767e68..a669034 100644 --- a/hud/hud_views.c +++ b/hud/hud_views.c @@ -29,56 +29,62 @@ render_text_scaled(rend, ss, p, t, 1);\ } + +void render_view_comp (SDL_Renderer* rend, txtd *t, int px, int py, + infos *info, stats_comp *comp, int lvl) +{ + float pad = 0; + float h = 0; + + char arr[32][64]; + { + int n = stats_frame_sprintf(info, comp->base +lvl, arr); + for (int i=0; iperc +lvl, arr); + for (int i=0; ibase_weapon +lvl, arr); + for (int i=0; iperc_weapon +lvl, arr); + for (int i=0; iframe, arr); + for (int i=0; iweaponlen; i++) { + LABEL(px+pad, py+h, " WEAPON", 1); h += 15; + int n = stats_weapon_sprintf(info, u->weapon +i, arr); + for (int i=0; iname, 1); h += 15; - { float val = info_unit_get_cost(info, tm); - char s[64]; sprintf(s, "COST: %.2f", val); - LABEL(px+10, py+h, s, 1); - } h += 20; - - float calcweight = info_unit_get_weight(info, tm); - float maxweight = info->chassis[tm->chassis].weight_max[ - tm->levels[LEVEL_CHASSIS]]; - float pw[2] = { px+10, py+h }; - char sw[64]; sprintf(sw, "WEIGHT: %.0f/%.0f", - calcweight, maxweight); - render_text_scaled(rend, sw, pw, t, 1); - h += 15; - - float hp = info_unit_get_health(info, tm); - float php[2] = { px+10, py+h }; - char shp[64]; sprintf(shp, "HP: %.2f", hp); - render_text_scaled(rend, shp, php, t, 1); - h += 15; - - float speed = info_unit_get_speed(info, tm); - float pspeed[2] = { px+10, py+h }; - char sspeed[64]; sprintf(sspeed, "SPEED: %.2f", speed); - render_text_scaled(rend, sspeed, pspeed, t, 1); - h += 15; - - float dps = info_unit_get_dps(info, tm); - float pdps[2] = { px+10, py+h }; - char sdps[64]; sprintf(sdps, "DAMAGE PER TURN: %.2f", dps); - render_text_scaled(rend, sdps, pdps, t, 1); - h += 20; - - float part[2] = { px+10, py+h }; - render_text_scaled(rend, "ARMOR:", part, t, 1); - h += 15; - - for (int i=0; i<7; i++) { - float ar = info_unit_get_armor(info, tm, i); - float par[2] = { px+10, py+h }; - char sar[64]; sprintf(sar, "%s: %.1f%", info->damage_types[i], ar); - render_text_scaled(rend, sar, par, t, 1); - h += 15; - } - h += 5; + stats_unit base; + stats_unit_compute(info, tm, &base); + render_view_stats_unit(rend, t, px+10, py+h, info, &base); } @@ -112,21 +118,10 @@ void render_view_chassis (SDL_Renderer* rend, txtd *t, int px, int py, info_chassis *ch = info->chassis+chassis; int h = 10; - LABEL(px+10, py+h, info->chassis[chassis].name, 1); h += 30; - - LABEL_F3(px+10, py+h, "MAX WEIGHT", 0, ch->weight_max, 1); h += 15; - LABEL_F3(px+10, py+h, "HP", 0, ch->hp, 1); h += 15; - LABEL_F3(px+10, py+h, "SPEED", 2, ch->speed, 1); h += 15; - LABEL_F3(px+10, py+h, "UPKEEP", 2, ch->upkeep, 1); h += 20; - - LABEL_I3(px+10, py+h, "WEAPON SLOTS", ch->slot_weapon, 1); h += 15; - LABEL_I3(px+10, py+h, "ARMOR SLOTS", ch->slot_armor, 1); h += 15; - LABEL_I3(px+10, py+h, "AUGMENT SLOTS", ch->slot_aug, 1); h += 15; - - SDL_Rect srcRect = { chassis*32, 32, 32, 32 }; - SDL_Rect dstRect = { px+300-32-10, py+10, 32, 32 }; - SDL_RenderCopy(rend, sprites, &srcRect, &dstRect); - + stats_comp *comp = info->stats[STATS_CHASSIS]+chassis; + LABEL(px+10, py+h, comp->name, 2); h += 30; + render_view_comp(rend, t, px+10, py+h, info, comp, lvl); + info_unit u; int8_t *_; int __; int size[2]; hud_map_sel(&u, info, 0, 0, &_, &__, size); size[0] -= 5; size[1] -= 5; @@ -143,16 +138,10 @@ void render_view_battery (SDL_Renderer* rend, txtd *t, int px, int py, if (batt != -1) { info_battery *battery = info->batteries+batt; int h = 10; - LABEL(px+10, py+h, info->batteries[batt].name, 1); h += 30; - LABEL_F3(px+10, py+h, "MAX WEIGHT", 0, battery->weight, 1); h += 15; - LABEL_F3(px+10, py+h, "CAPACITY", 0, battery->capacity, 1); h += 15; - - float prech[2] = { px+10, py+h }; char srech[64]; - if (info->batteries[batt].recharge[lvl] == 0) { - strcpy(srech, "NOT RECHARGEABLE"); - } else { strcpy(srech, "RECHARGEABLE"); } - render_text_scaled(rend, srech, prech, t, 1); + stats_comp *comp = info->stats[STATS_BATTERY]+batt; + LABEL(px+10, py+h, comp->name, 1); h += 30; + render_view_comp(rend, t, px+10, py+h, info, comp, lvl); float size[2] = {145, 145}; size[0] -= 5; size[1] -= 5; render_view_level(rend, px+size[0], py+size[1], lvl); @@ -170,26 +159,9 @@ void render_view_armor (SDL_Renderer* rend, txtd *t, int px, int py, info_armor *arm = info->armors+armor; int h = 10; - LABEL(px+10, py+h, arm->name, 1); h += 20; - LABEL_F3(px+10, py+h, "WEIGHT", 0, arm->weight, 1); h += 20; + stats_comp *comp = info->stats[STATS_ARMOR]+armor; + LABEL(px+10, py+h, comp->name, 1); h += 20; - /*char sa[64]; int j=0; - char temp[16] = "red: "; - strcpy(sa+j, temp); - j += strlen(temp); - for (int i=0; i<7; i++) { - if (i<7-1) { - sprintf(temp, "%.0f, ", info->armors[armor].armor[i][lvl]); - } else { - sprintf(temp, "%.0f", info->armors[armor].armor[i][lvl]); - } - strcpy(sa+j, temp); - j += strlen(temp); - } - sa[j] = '\0'; - float pa[2] = { px+10, py+25 }; - render_text_scaled(rend, sa, pa, t, 1); - */ float size[2] = { 150, 50 }; size[0] -= 5; size[1] -= 5; render_view_level(rend, px+size[0], py+size[1], lvl); } else { @@ -204,20 +176,11 @@ void render_view_armor_detail (SDL_Renderer* rend, txtd *t, int px, int py, if (armor != -1) { info_armor *arm = info->armors+armor; int h = 10; + + stats_comp *comp = info->stats[STATS_ARMOR]+armor; + LABEL(px+10, py+h, comp->name, 1); h += 30; + render_view_comp(rend, t, px+10, py+h, info, comp, lvl); - LABEL(px+10, py+h, arm->name, 1); h += 30; - LABEL_F3(px+10, py+h, "WEIGHT", 0, arm->weight, 1); h += 20; - LABEL(px+10, py+h, "DAMAGE REDUCTION", 1); h += 15; - - for (int i=0; i<7; i++) { - float sum = 0; for(int j=0;jarmor[i][j]); - if (sum > 0) { - LABEL_F3(px+10, py+h, info->damage_types[i], - 1, arm->armor[i], 1); - } - h += 15; - } info_unit u; int8_t *_; int __; int size[2]; hud_map_sel(&u, info, 2, 0, &_, &__, size); size[0] -= 5; size[1] -= 5; @@ -234,17 +197,10 @@ void render_view_weapon (SDL_Renderer* rend, txtd *t, int px, int py, if (weapon != -1) { info_weapon *weap = info->weapons+weapon; int h = 10; - - char dt[32]; - sprintf(dt, "DAMAGE TYPE: %s", - info->damage_types[info->weapons[weapon].damage_type]); - - LABEL(px+10, py+h, weap->name, 1); h += 20; - LABEL_F3(px+10, py+h, "WEIGHT", 0, weap->weight, 1); h += 15; - LABEL(px+10, py+h, dt, 1); h += 15; - LABEL_F3(px+10, py+h, "DAMAGE", 0, weap->damage, 1); h += 15; - LABEL_F3(px+10, py+h, "RANGE", 0, weap->range, 1); h += 15; - LABEL_F3(px+10, py+h, "COOLDOWN", 0, weap->cooldown, 1); h += 15; + + stats_comp *comp = info->stats[STATS_WEAPONS]+weapon; + LABEL(px+10, py+h, comp->name, 1); h += 30; + render_view_comp(rend, t, px+10, py+h, info, comp, lvl); float size[2] = { 200, 110 }; size[0] -= 5; size[1] -= 5; render_view_level(rend, px+size[0], py+size[1], lvl); @@ -261,32 +217,11 @@ void render_view_weapon_detail (SDL_Renderer* rend, txtd *t, if (weapon != -1) { info_weapon *weap = info->weapons+weapon; int h = 10; + + stats_comp *comp = info->stats[STATS_WEAPONS]+weapon; + LABEL(px+10, py+h, comp->name, 1); h += 30; + render_view_comp(rend, t, px+10, py+h, info, comp, lvl); - char dt[32]; - sprintf(dt, "DAMAGE TYPE: %s", - info->damage_types[info->weapons[weapon].damage_type]); - - LABEL(px+10, py+h, weap->name, 1); h += 20; - LABEL_F3(px+10, py+h, "WEIGHT", 0, weap->weight, 1); h += 15; - LABEL(px+10, py+h, dt, 1); h += 15; - LABEL_F3(px+10, py+h, "DAMAGE", 0, weap->damage, 1); h += 15; - LABEL_F3(px+10, py+h, "RANGE", 0, weap->range, 1); h += 15; - LABEL_F3(px+10, py+h, "COOLDOWN", 0, weap->cooldown, 1); h += 15; - LABEL_F3(px+10, py+h, "UPKEEP", 0, weap->upkeep, 1); h += 15; - - float kb = 0; for(int i=0;iknockback[i]); - if (kb > 0) { - LABEL_I3(px+10, py+h, "KNOCKBACK", weap->knockback, 1); - h += 15; - } - - float cps = 0; for(int i=0;icharge_per_shot[i]); - if (cps > 0) { - LABEL_F3(px+10, py+h, "CHARGE PER SHOT",0,weap->charge_per_shot, 1); - h += 15; - } info_unit u; int8_t *_; int __; int size[2]; hud_map_sel(&u, info, 3, 0, &_, &__, size); size[0] -= 5; size[1] -= 5; @@ -304,8 +239,8 @@ void render_view_aug (SDL_Renderer* rend, txtd *t, int px, int py, info_aug *augm = info->augs+aug; int h = 10; - LABEL(px+10, py+h, augm->name, 1); h += 20; - LABEL_F3(px+10, py+h, "WEIGHT", 0, augm->weight, 1); h += 15; + stats_comp *comp = info->stats[STATS_AUGS]+aug; + LABEL(px+10, py+h, comp->name, 1); h += 20; float size[2] = { 150, 50 }; size[0] -= 5; size[1] -= 5; render_view_level(rend, px+size[0], py+size[1], lvl); @@ -322,67 +257,10 @@ void render_view_aug_detail (SDL_Renderer* rend, txtd *t, int px, int py, info_aug *augm = info->augs+aug; int h = 10; - LABEL(px+10, py+h, augm->name, 1); h += 20; - LABEL_F3(px+10, py+h, "WEIGHT", 0, augm->weight, 1); h += 15; + stats_comp *comp = info->stats[STATS_AUGS]+aug; + LABEL(px+10, py+h, comp->name, 1); h += 20; + render_view_comp(rend, t, px+10, py+h, info, comp, lvl); - float range = 0; for(int i=0;iadd_range[i]); - if (range > 0) { - LABEL_F3(px+10, py+h, "RANGE", 0, augm->add_range, 1); h += 15; - } - - float cooldown = 0; for(int i=0;iadd_cooldown[i]); - if (cooldown != 0) { - LABEL_F3(px+10, py+h, "COOLDOWN", 2, augm->add_cooldown, 1); - h += 15; - } - - float speed = 0; for(int i=0;iadd_speed[i]); - if (speed != 0) { - LABEL_F3(px+10, py+h, "SPEED", 2, augm->add_speed, 1); h += 15; - } - - float hp = 0; for(int i=0;iadd_hp[i]); - if (hp != 0) { - LABEL_F3(px+10, py+h, "HP", 1, augm->add_hp, 1); h += 15; - } - - h += 5; - - float sum = 0; - for (int i=0; i<7; i++) - for(int j=0;jadd_armor[i][j]); - if (sum != 0) { - for (int i=0; i<7; i++) { - float suml = 0; for(int j=0;jadd_armor[i][j]); - if (suml > 0) { - LABEL_F3(px+10, py+h, info->damage_types[i], - 1, augm->add_armor[i], 1); - h += 15; - } - } - } - - sum = 0; - for (int i=0; i<7; i++) - for(int j=0;jadd_damage[i][j]); - if (sum != 0) { - for (int i=0; i<7; i++) { - float suml = 0; for(int j=0;jadd_damage[i][j]); - if (suml > 0) { - LABEL_F3(px+10, py+h, info->damage_types[i], - 1, augm->add_damage[i], 1); - h += 15; - } - } - } info_unit u; int8_t *_; int __; int size[2]; hud_map_sel(&u, info, 4, 0, &_, &__, size); size[0] -= 5; size[1] -= 5; @@ -398,9 +276,11 @@ void render_view_brain (SDL_Renderer* rend, txtd *t, int px, int py, { if (brain != -1) { float pname[2] = { px+10, py+10 }; - char sname[64]; sprintf(sname, "%s", - info->brains[brain].name); - render_text_scaled(rend, sname, pname, t, 1); + int h = 10; + + stats_comp *comp = info->stats[STATS_BRAIN]+brain; + LABEL(px+10, py+h, comp->name, 1); h += 20; + render_view_comp(rend, t, px+10, py+h, info, comp, lvl); float size[2] = { 145, 145 }; size[0] -= 5; size[1] -= 5; render_view_level(rend, px+size[0], py+size[1], lvl); -- cgit v1.2.3-54-g00ecf