diff options
Diffstat (limited to 'gst')
-rw-r--r-- | gst/generate.c | 63 | ||||
-rw-r--r-- | gst/generate.h | 2 | ||||
-rw-r--r-- | gst/gst.c | 17 | ||||
-rw-r--r-- | gst/gst.h | 4 | ||||
-rw-r--r-- | gst/info.c | 28 | ||||
-rw-r--r-- | gst/info.h | 2 | ||||
-rw-r--r-- | gst/units.c | 7 |
7 files changed, 94 insertions, 29 deletions
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; i<base->frame.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; i<base->frame.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; i<base->frame.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; i<base.frame.slot_weapon; i++) { - u->weapons[i] = rand() % info->statslen[STATS_WEAPONS]; - if (!accept_cond(info, u, cost_max)) { u->weapons[i] = -1; return; } - } - for (int i=0; i<base.frame.slot_armor; i++) { - u->armor[i] = rand() % info->statslen[STATS_ARMOR]; - if (!accept_cond(info, u, cost_max)) { u->armor[i] = -1; return; } - } - for (int i=0; i<base.frame.slot_aug; i++) { - u->augs[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<GENERATE_UNIT_MAX_ATTEMPTS; i++) { - cand = *u; + info_unit_init(&cand); gen_unit_attempt(info, &cand, cost_max); if (accept_cond(info, &cand, cost_max)) { if (calc_unit_cost(info, &cand) @@ -63,6 +99,7 @@ int generate_unit (infos *info, info_unit *u, float cost_max) { } } if (candmax.chassis != -1) { + printf("i generated!\n"); *u = candmax; return 0; } diff --git a/gst/generate.h b/gst/generate.h index a4da2d6..4c30a96 100644 --- a/gst/generate.h +++ b/gst/generate.h @@ -3,7 +3,7 @@ #include "info.h" -#define GENERATE_UNIT_MAX_ATTEMPTS 48637 +#define GENERATE_UNIT_MAX_ATTEMPTS 128 void generate_init (); int generate_unit (infos *info, info_unit *u, float cost); @@ -14,6 +14,7 @@ void gst_init (gamestate *gst) { gst->turn = 0; gst->coveredtime = 0; gst->turnspeed = 0.75; + gst->waitstep = 0; } void gst_destroy (gamestate *gst) { @@ -172,12 +173,18 @@ void gst_next_turn (gamestate *gst, infos *info, fxs *fx, float t) { gst_spawn_bullets(gst, fx, dmgs, fire, t); } -void gst_process (gamestate *gst, infos *info, fxs *fx, float t) { +void gst_process (gamestate *gst, infos *info, MKb *mkb, fxs *fx, float t) { if (gst->state == 1) { - if (gst->starttime > t) gst->starttime = t; - float t_elapsed = t-gst->starttime; - if (t_elapsed >= gst->coveredtime) { - gst_next_turn(gst, info, fx, t); + if (gst->waitstep) { + if (mkb_search(mkb, SDL_SCANCODE_SPACE)) { + gst_next_turn(gst, info, fx, t); + } + } else { + if (gst->starttime > t) gst->starttime = t; + float t_elapsed = t-gst->starttime; + if (t_elapsed >= gst->coveredtime) { + gst_next_turn(gst, info, fx, t); + } } } } @@ -6,6 +6,7 @@ #include "map.h" #include "fxs.h" #include "../render/render_text.h" +#include "../mkb/mkb.h" #include <SDL2/SDL.h> @@ -30,6 +31,7 @@ typedef struct { float turnspeed; int turn_until_finish; int over; + int waitstep; } gamestate; void gst_init (gamestate *gst); @@ -42,7 +44,7 @@ void gst_toeditor (gamestate *gst); void gst_next_turn (gamestate *gst, infos *info, fxs *fx, float t); int gst_check_victory (gamestate *gst); -void gst_process (gamestate *gst, infos *info, fxs *fx, float t); +void gst_process (gamestate *gst, infos *info, MKb *mkb, fxs *fx, float t); void gst_render (SDL_Renderer *rend, SDL_Texture *txsprites, txtd *textd, gamestate *gst, infos *info, float t); @@ -240,8 +240,8 @@ int stats_frame_sprintf (infos *info, stats_frame *frame, char arr[][64]) { PRINT_STRUCT(frame, "capacity", capacity, .0f); PRINT_STRUCT(frame, "recharge", recharge, .1f); LOOP(7) { - char str[64]; sprintf(str, "%s armor", info->damage_types[i]); - PRINT_STRUCT(frame, str, armor[z], f); + char str[64]; sprintf(str, "%s armor", info->damage_types[z]); + PRINT_STRUCT(frame, str, armor[z], .1f); } return i; } @@ -249,7 +249,7 @@ int stats_frame_sprintf (infos *info, stats_frame *frame, char arr[][64]) { int stats_weapon_sprintf (infos *info, stats_weapon *weap, char arr[][64]) { int i = 0; LOOP(7) { - char str[64]; sprintf(str, "%s damage", info->damage_types[i]); + char str[64]; sprintf(str, "%s damage", info->damage_types[z]); PRINT_STRUCT(weap, str, damage[z], .1f); } PRINT_STRUCT(weap, "cooldown", cooldown, .2f); @@ -260,7 +260,7 @@ int stats_weapon_sprintf (infos *info, stats_weapon *weap, char arr[][64]) { PRINT_STRUCT(weap, "stun", stun, .0f); PRINT_STRUCT(weap, "charge per shot", charge_per_shot, .2f); LOOP(7) { - char str[64]; sprintf(str, "%s armor reduce", info->damage_types[i]); + char str[64]; sprintf(str, "%s armor reduce", info->damage_types[z]); PRINT_STRUCT(weap, str, armor_reduce[z], .1f); } return i; @@ -540,6 +540,25 @@ float f_add1 (float x) { return x+1; } void cost_weights_init (stats_unit *w) { stats_unit_init(w); stats_unit_map(w, f_add1); + w->frame.hp = 0.2; + w->frame.weight = 0; + w->frame.weight_max = 0; + w->frame.slot_weapon = 50; + w->frame.slot_armor = 20; + w->frame.slot_aug = 10; + w->frame.speed = 35; + w->frame.capacity = 0.05; + LOOP(7) w->frame.armor[z] = 0.1; + for (int i=0; i<8; i++) { + LOOP(7) w->weapon[i].damage[z] = 1; + LOOP(7) w->weapon[i].armor_reduce[z] = 0.02; + w->weapon[i].cooldown = -20; + w->weapon[i].range = 30; + w->weapon[i].aoe = 240; + w->weapon[i].knockback = 20; + w->weapon[i].damage_battery = 0.01; + w->weapon[i].stun = 100; + } } float f_sum (float a, float b) { return a+b; } @@ -548,6 +567,7 @@ float stats_compute_cost (stats_unit *w, stats_unit *base) { stats_unit costed = *base; stats_unit_mul(&costed, w); float cost = stats_unit_fold(&costed, f_sum); + if (cost < 0) cost = 0; return cost; } @@ -1,7 +1,7 @@ #ifndef INFO_H #define INFO_H -#define MAXTEMPLATES 128 +#define MAXTEMPLATES 1024 #define MAXLEVEL 3 #include <stdint.h> diff --git a/gst/units.c b/gst/units.c index 0297266..b5d05a9 100644 --- a/gst/units.c +++ b/gst/units.c @@ -155,10 +155,8 @@ int army_move_step (infos *info, army *ar, map *m, stats_unit *ustats) { } } // execution - int sum = 0, lastsum = -1, step = 0; + int sum = 0, step = 0; for (; step<MAXSOLVESTEPS; step++) { - if (sum == lastsum) { break; } - lastsum = sum; sum = 0; for (int i=0; i<mclen; i++) { int dest[2] = { @@ -170,9 +168,10 @@ int army_move_step (infos *info, army *ar, map *m, stats_unit *ustats) { mcs[i].done = 1; mcs[i].u->move_points -= 1; orders++; + sum++; } - sum += mcs[i].done; } + if (sum == 0) { break; } } if (step == MAXSOLVESTEPS) { printf("army: max steps reached\n"); } if (orders > 0) return 0; |