diff options
author | jacopo grandi <jak.sk8@hotmail.it> | 2021-02-20 00:11:23 +0100 |
---|---|---|
committer | jacopo grandi <jak.sk8@hotmail.it> | 2021-02-20 00:11:23 +0100 |
commit | 2eef87c8970db643c4ef09e0fd9e8110c8193043 (patch) | |
tree | 78a9bcc7932ab8edb8669ded755ee2c81afc0912 /gst | |
parent | c135f85fcdc1eeedd04e0c9e9f626b907500f20a (diff) |
finish condition and bad cost function
Diffstat (limited to 'gst')
-rw-r--r-- | gst/gst.c | 29 | ||||
-rw-r--r-- | gst/gst.h | 3 | ||||
-rw-r--r-- | gst/info.c | 86 | ||||
-rw-r--r-- | gst/info.h | 1 | ||||
-rw-r--r-- | gst/units.c | 9 | ||||
-rw-r--r-- | gst/units.h | 4 |
6 files changed, 122 insertions, 10 deletions
@@ -66,6 +66,24 @@ void gst_tobattle (gamestate *gst) { gst->starttime = FLT_MAX; gst->turn = 0; gst->coveredtime = 0; + gst->turn_until_finish = 5; + gst->over = 0; +} + +void gst_toeditor(gamestate *gst) { + gst->playernum = 1; +} + +int gst_check_victory (gamestate *gst) { + int counts[gst->playernum], max=-1, imax = -1; + for (int i=0; i<gst->ar.uslen; i++) { + counts[gst->ar.us[i].owner] ++; + if (counts[gst->ar.us[i].owner] > max) { + imax = gst->ar.us[i].owner; + max = counts[gst->ar.us[i].owner]; + } + } + return imax; } void gst_process (gamestate *gst, infos *info, float t) { @@ -76,8 +94,15 @@ void gst_process (gamestate *gst, infos *info, float t) { gst->turn ++; map *m; army *ar; gst_get_maparmy(gst, &m, &ar); - army_move(info, ar, m); - army_fire(info, ar, m); + int move = army_move(info, ar, m); + int fire = army_fire(info, ar, m); army_upkeep(info, ar, m); + printf("%d, %d\n", move, fire); + if (move == 0 && fire == 0) { + gst->turn_until_finish--; + } else { gst->turn_until_finish = 5; } + if (gst->turn_until_finish <= 0) { + gst->over = 1; + } } }
\ No newline at end of file @@ -19,12 +19,15 @@ typedef struct { float coveredtime; int turn; float turnspeed; + int turn_until_finish; + int over; } gamestate; void gst_init (gamestate *gst); void gst_destroy (gamestate *gst); void gst_get_maparmy(gamestate *gst, map **m, army **ar); void gst_tobattle (gamestate *gst); +void gst_toeditor (gamestate *gst); void gst_process (gamestate *gst, infos *info, float t); #endif
\ No newline at end of file @@ -130,8 +130,10 @@ float info_unit_get_health(infos *info, info_unit *u) { sum += info->augs[u->augs[i]].add_hp[lvl]; } } - sum += info->chassis[u->chassis].hp[lc]; - return sum; + float mult = (1 + sum/100.0f); + if (mult < 0) mult = 0; + float ret = info->chassis[u->chassis].hp[lc] * mult; + return ret; } float info_unit_get_speed(infos *info, info_unit *u) { @@ -175,6 +177,39 @@ float info_unit_get_damage_target (infos *info, info_unit *u, int w, return damage * mult; } +float info_unit_get_aoe (infos *info, info_unit *u, int w) { + int lc = u->levels[LEVEL_CHASSIS]; + float sum = 0; + for(int i=0; i<16; i++) { + if (u->augs[i] != -1 && info->chassis[u->chassis].slot_aug[lc]) { + int lvl = u->levels[LEVEL_AUGS+i]; + //sum += info->augs[u->augs[i]].add_aoe[lvl]; + } + } + int lw = u->levels[LEVEL_WEAPONS+w]; + float dam = info->weapons[u->weapons[w]].aoe[lw] + sum; + return dam; +} + +float info_unit_get_knockback (infos *info, info_unit *u, int w) { + int lc = u->levels[LEVEL_CHASSIS]; + float sum = 0; + for(int i=0; i<16; i++) { + if (u->augs[i] != -1 && info->chassis[u->chassis].slot_aug[lc]) { + int lvl = u->levels[LEVEL_AUGS+i]; + //sum += info->augs[u->augs[i]].add_knockback[lvl]; + } + } + int lw = u->levels[LEVEL_WEAPONS+w]; + float dam = info->weapons[u->weapons[w]].knockback[lw] + sum; + return dam; +} + +float info_unit_get_stun (infos *info, info_unit *u, int w) { + // TODO + return 0; +} + float info_unit_get_cooldown(infos *info, info_unit *u, int w) { int lc = u->levels[LEVEL_CHASSIS]; float sum = 0; @@ -228,6 +263,53 @@ float info_unit_get_armor(infos *info, info_unit *u, int d) { return sum; } +float info_unit_get_cost (infos *info, info_unit *u) { + // see design/notes.txt:implement cost function + float sum = 0; + int lc = u->levels[LEVEL_CHASSIS]; + info_chassis *chassis = info->chassis+u->chassis; + float sumchassis = 0; + sumchassis += powf(2, chassis->slot_weapon[lc])*20; + sumchassis += powf(2, chassis->slot_armor[lc])*10; + sumchassis += powf(2, chassis->slot_aug[lc])*5; + sumchassis += chassis->weight_max[lc]/5; + sumchassis += chassis->hp[lc]/20; + sumchassis += chassis->speed[lc]*32; + sum += sumchassis; + if (u->battery != -1) { + int lb = u->levels[LEVEL_BATTERY]; + info_battery *battery = info->batteries+u->battery; + float sumbattery = 0; + sumbattery += battery->capacity[lb]; + sum += sumbattery; + } + for(int i=0; i<8; i++) { + int lw = u->levels[LEVEL_WEAPONS+i]; + int la = u->levels[LEVEL_ARMOR+i]; + if (u->weapons[i] != -1 && i<chassis->slot_weapon[lc]) { + info_weapon *weapon = info->weapons+u->weapons[i]; + float sumweap = 0; + float dam = info_unit_get_damage(info, u, i); + float cool = info_unit_get_cooldown(info, u, i); + float damtot = dam / cool; + float aoe = info_unit_get_aoe(info, u, i); + float knockback = info_unit_get_knockback(info, u, i); + float stun = info_unit_get_stun(info, u, i); + float mult = 1+aoe*5 + 10; + damtot = damtot*mult; + damtot += knockback * 20 + stun * 50; + sumweap = damtot; + sum += sumweap; + } + } + for(int t=0; t<7; t++) { + float armortot = info_unit_get_armor(info, u, t) * 3; + sum += armortot; + } + + return sum; +} + void weapon_init (info_weapon *w) { strcpy(w->name, "nameless"); @@ -116,6 +116,7 @@ float info_unit_get_damage_target(infos *info, info_unit *u, int w, float info_unit_get_cooldown(infos *info, info_unit *u, int w); float info_unit_get_range(infos *info, info_unit *u, int w); float info_unit_get_armor(infos *info, info_unit *u, int d); +float info_unit_get_cost(infos *info, info_unit *u); void info_load (infos *info); diff --git a/gst/units.c b/gst/units.c index dbf177b..b247e3c 100644 --- a/gst/units.c +++ b/gst/units.c @@ -168,18 +168,18 @@ int army_move_step (infos *info, army *ar, map *m) { else return 1; } -void army_move (infos *info, army *ar, map *m) { +int army_move (infos *info, army *ar, map *m) { for (int i=0; i<ar->uslen; i++) { ar->us[i].move_points += info_unit_get_speed(info, &ar->us[i].info); } - int iter = 0, finished = 0; + int iter = 0, finished = army_move_step(info, ar, m); for (; iter<5 && !finished; iter++) { finished = army_move_step(info, ar, m); } - //printf("stepped %d %d\n", iter, finished); + return iter; } -void army_fire (infos *info, army *ar, map *m) { +int army_fire (infos *info, army *ar, map *m) { for (int i=0; i<ar->uslen; i++) { unit *u = ar->us+i; int lw = u->info.levels[LEVEL_CHASSIS]; @@ -216,6 +216,7 @@ void army_fire (infos *info, army *ar, map *m) { unit_dead(ar, m, dmgs[i].u); } } + return dmgslen; } void army_upkeep (infos *info, army *ar, map *m) { diff --git a/gst/units.h b/gst/units.h index 615eaa7..8e78d8d 100644 --- a/gst/units.h +++ b/gst/units.h @@ -34,8 +34,8 @@ void army_grid_init(army *ar); void army_init (army *ar, map *m); void army_destory(army *ar); void army_spawn (army *ar, map *m, unit u); -void army_move (infos *info, army *ar, map *m); -void army_fire (infos *info, army *ar, map *m); +int army_move (infos *info, army *ar, map *m); +int army_fire (infos *info, army *ar, map *m); void army_upkeep (infos *info, army *ar, map *m); #endif
\ No newline at end of file |