From d1af4269c4130d11d77f61f1a2ac8f3e249f72f2 Mon Sep 17 00:00:00 2001 From: jacopo grandi Date: Fri, 5 Mar 2021 16:54:26 +0100 Subject: unit generator in hud, minor fix in movement, % in view and cost weights --- gst/generate.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 13 deletions(-) (limited to 'gst/generate.c') diff --git a/gst/generate.c b/gst/generate.c index 1d8a340..3339ad7 100644 --- a/gst/generate.c +++ b/gst/generate.c @@ -10,6 +10,7 @@ void generate_init () { } float calc_unit_cost (infos *info, info_unit *u) { + if (u->chassis == -1) return 0; stats_unit base; stats_unit_compute(info, u, &base); return stats_compute_cost(&info->cost_weights, &base); @@ -24,6 +25,35 @@ int accept_cond (infos *info, info_unit *u, float cost_max) { return 1; } +int gen_add_comp (infos *info, stats_unit *base, info_unit *u) { + int sel = rand() % 3; + if (sel == 0) { + for (int i=0; iframe.slot_weapon; i++) { + if (u->weapons[i] == -1) { + u->weapons[i] = rand() % info->statslen[STATS_WEAPONS]; + break; + } + } + } + else if (sel == 1) { + for (int i=0; iframe.slot_armor; i++) { + if (u->armor[i] == -1) { + u->armor[i] = rand() % info->statslen[STATS_ARMOR]; + break; + } + } + } + else if (sel == 2) { + for (int i=0; iframe.slot_aug; i++) { + if (u->augs[i] == -1) { + u->augs[i] = rand() % info->statslen[STATS_AUGS]; + break; + } + } + } + return sel; +} + // generates randomly a valid unit void gen_unit_attempt (infos *info, info_unit *u, float cost_max) { info_unit_init(u); @@ -32,27 +62,33 @@ void gen_unit_attempt (infos *info, info_unit *u, float cost_max) { u->battery = rand() % info->statslen[STATS_BATTERY]; u->brain = rand() % info->statslen[STATS_BRAIN]; stats_unit_compute(info, u, &base); - for (int i=0; iweapons[i] = rand() % info->statslen[STATS_WEAPONS]; - if (!accept_cond(info, u, cost_max)) { u->weapons[i] = -1; return; } - } - for (int i=0; iarmor[i] = rand() % info->statslen[STATS_ARMOR]; - if (!accept_cond(info, u, cost_max)) { u->armor[i] = -1; return; } - } - for (int i=0; iaugs[i] = rand() % info->statslen[STATS_AUGS]; - if (!accept_cond(info, u, cost_max)) { u->augs[i] = -1; return; } + for (int i=0; i<8*8*16; i++) { + int sel = gen_add_comp(info, &base, u); + if (sel == 0) { + if (!accept_cond(info, u, cost_max)) { + u->weapons[i] = -1; return; + } + } + if (sel == 1) { + if (!accept_cond(info, u, cost_max)) { + u->armor[i] = -1; return; + } + } + if (sel == 2) { + if (!accept_cond(info, u, cost_max)) { + u->augs[i] = -1; return; + } + } } } // selects the max cost generated unit int generate_unit (infos *info, info_unit *u, float cost_max) { - info_unit cand = *u; + info_unit cand; info_unit candmax; info_unit_init(&candmax); float cost; for (int i=0; i