aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjacopo grandi <jak.sk8@hotmail.it>2021-03-02 18:26:39 +0100
committerjacopo grandi <jak.sk8@hotmail.it>2021-03-02 18:26:39 +0100
commita988df656b4d37dfa2472a4cde390185cfcea8b5 (patch)
tree262b48644a5aff086b6ead687d0f2297bf946c2b
parent7932daa7e308b1c92ab97dde00fcc0ed790895a6 (diff)
test foundation and functional reimplementation of cost function
-rw-r--r--CMakeLists.txt4
-rw-r--r--Makefile60
-rw-r--r--build/Arena.exebin166687 -> 170795 bytes
-rw-r--r--build/army/all maul.txtbin0 -> 25656 bytes
-rw-r--r--build/army/hidden/__test0.txtbin0 -> 25656 bytes
-rw-r--r--build/army/hidden/__test1.txtbin0 -> 25656 bytes
-rw-r--r--build/army/new army 0.txtbin25656 -> 25656 bytes
-rw-r--r--build/army/new army.txtbin25656 -> 25656 bytes
-rw-r--r--build/content/cost.txt22
-rw-r--r--build/content/templates/default.txt4
-rw-r--r--design/design.txt2
-rw-r--r--design/notes.txt18
-rw-r--r--gst/fxs.c1
-rw-r--r--gst/gst.c46
-rw-r--r--gst/gst.h3
-rw-r--r--gst/info.c150
-rw-r--r--gst/info.h5
-rw-r--r--gst/units.c1
-rw-r--r--hud/hud.c27
-rw-r--r--hud/hud_views.c8
-rw-r--r--main.c15
-rw-r--r--test/test.c11
-rw-r--r--test/test.h10
-rw-r--r--test/test_gst.c53
-rw-r--r--test/test_gst.h8
25 files changed, 379 insertions, 69 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d47afaa..25f5fbf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -40,6 +40,10 @@ add_executable(Arena
umath/vec.h
umath/intersect.c
umath/intersect.h
+ test/test.c
+ test/test.h
+ test/test_gst.c
+ test/test_gst.h
main.c)
target_include_directories(Arena PUBLIC "C:/MinGW_libs/include")
diff --git a/Makefile b/Makefile
index 18fcece..40337ec 100644
--- a/Makefile
+++ b/Makefile
@@ -492,6 +492,60 @@ render/render_text.c.s:
$(MAKE) $(MAKESILENT) -f CMakeFiles\Arena.dir\build.make CMakeFiles/Arena.dir/render/render_text.c.s
.PHONY : render/render_text.c.s
+test/test.obj: test/test.c.obj
+
+.PHONY : test/test.obj
+
+# target to build an object file
+test/test.c.obj:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles\Arena.dir\build.make CMakeFiles/Arena.dir/test/test.c.obj
+.PHONY : test/test.c.obj
+
+test/test.i: test/test.c.i
+
+.PHONY : test/test.i
+
+# target to preprocess a source file
+test/test.c.i:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles\Arena.dir\build.make CMakeFiles/Arena.dir/test/test.c.i
+.PHONY : test/test.c.i
+
+test/test.s: test/test.c.s
+
+.PHONY : test/test.s
+
+# target to generate assembly for a file
+test/test.c.s:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles\Arena.dir\build.make CMakeFiles/Arena.dir/test/test.c.s
+.PHONY : test/test.c.s
+
+test/test_gst.obj: test/test_gst.c.obj
+
+.PHONY : test/test_gst.obj
+
+# target to build an object file
+test/test_gst.c.obj:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles\Arena.dir\build.make CMakeFiles/Arena.dir/test/test_gst.c.obj
+.PHONY : test/test_gst.c.obj
+
+test/test_gst.i: test/test_gst.c.i
+
+.PHONY : test/test_gst.i
+
+# target to preprocess a source file
+test/test_gst.c.i:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles\Arena.dir\build.make CMakeFiles/Arena.dir/test/test_gst.c.i
+.PHONY : test/test_gst.c.i
+
+test/test_gst.s: test/test_gst.c.s
+
+.PHONY : test/test_gst.s
+
+# target to generate assembly for a file
+test/test_gst.c.s:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles\Arena.dir\build.make CMakeFiles/Arena.dir/test/test_gst.c.s
+.PHONY : test/test_gst.c.s
+
umath/intersect.obj: umath/intersect.c.obj
.PHONY : umath/intersect.obj
@@ -594,6 +648,12 @@ help:
@echo ... render/render_text.obj
@echo ... render/render_text.i
@echo ... render/render_text.s
+ @echo ... test/test.obj
+ @echo ... test/test.i
+ @echo ... test/test.s
+ @echo ... test/test_gst.obj
+ @echo ... test/test_gst.i
+ @echo ... test/test_gst.s
@echo ... umath/intersect.obj
@echo ... umath/intersect.i
@echo ... umath/intersect.s
diff --git a/build/Arena.exe b/build/Arena.exe
index f4fdba2..11218e1 100644
--- a/build/Arena.exe
+++ b/build/Arena.exe
Binary files differ
diff --git a/build/army/all maul.txt b/build/army/all maul.txt
new file mode 100644
index 0000000..0b6234b
--- /dev/null
+++ b/build/army/all maul.txt
Binary files differ
diff --git a/build/army/hidden/__test0.txt b/build/army/hidden/__test0.txt
new file mode 100644
index 0000000..81ce791
--- /dev/null
+++ b/build/army/hidden/__test0.txt
Binary files differ
diff --git a/build/army/hidden/__test1.txt b/build/army/hidden/__test1.txt
new file mode 100644
index 0000000..3dbd37e
--- /dev/null
+++ b/build/army/hidden/__test1.txt
Binary files differ
diff --git a/build/army/new army 0.txt b/build/army/new army 0.txt
index bfa71b8..a58719b 100644
--- a/build/army/new army 0.txt
+++ b/build/army/new army 0.txt
Binary files differ
diff --git a/build/army/new army.txt b/build/army/new army.txt
index 81ce791..2e7e5da 100644
--- a/build/army/new army.txt
+++ b/build/army/new army.txt
Binary files differ
diff --git a/build/content/cost.txt b/build/content/cost.txt
new file mode 100644
index 0000000..877a473
--- /dev/null
+++ b/build/content/cost.txt
@@ -0,0 +1,22 @@
+{
+ "base_weight": [
+ 10.0,
+ 7.5,
+ 5.0
+ ],
+ "base_weapon_cooldown": [
+ 1.0,
+ 0.75,
+ 0.5
+ ],
+ "base_weapon_damage_pierce": [
+ 10.0,
+ 12.5,
+ 15.0
+ ],
+ "base_weapon_range": [
+ 4.0,
+ 5.0,
+ 6.0
+ ]
+} \ No newline at end of file
diff --git a/build/content/templates/default.txt b/build/content/templates/default.txt
index b70d031..d6d526a 100644
--- a/build/content/templates/default.txt
+++ b/build/content/templates/default.txt
@@ -4,7 +4,7 @@
"chassis": "0",
"brain": "0",
"battery": "0",
- "weapons": [ -1, -1, -1, -1, -1, -1, -1, -1 ],
+ "weapons": [ 0, -1, -1, -1, -1, -1, -1, -1 ],
"armor": [ -1, -1, -1, -1, -1, -1, -1, -1 ],
"augs": [ 4, -1, -1, -1, -1, -1, -1, -1 ],
"levels": [ 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
@@ -17,7 +17,7 @@
"weapons": [ 0, 0, -1, -1, -1, -1, -1, -1 ],
"armor": [ 10, 0, 0, 0, -1, -1, -1, -1 ],
"augs": [ 0, 0, -1, -1, -1, -1, -1, -1 ],
- "levels": [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
+ "levels": [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
},
{
"name": "well done",
diff --git a/design/design.txt b/design/design.txt
index aebfcfb..9c6d18c 100644
--- a/design/design.txt
+++ b/design/design.txt
@@ -43,7 +43,7 @@ raid:
by battleing and scrapping enemy stuff
by events
get to a spaceship
-
+
you go around by train, combat troops do not transport themselves
every station has events/battles/shops
when you have a large enough army, get to a large spaceship and leave
diff --git a/design/notes.txt b/design/notes.txt
index e1ee8f0..2f39ba2 100644
--- a/design/notes.txt
+++ b/design/notes.txt
@@ -18,11 +18,12 @@ tasks: (date)
[ ] implement 3d units (issued on 18:02:21)
[ ] design component sprites (issued on 18:02:21)
[ ] implement sound (issued on 18:02:21)
+[ ] implement component aoe bonus (issued on 02:03:21)
[x] migrated to cmake env (issued on 01:03:21, done on 02:03:21)
[x] implement stats hud view (issued on 18:02:21, done on 25:02:21)
[x] implement fire animation (issued on 18:02:21, done on 24:02:21)
-[x] implement move animation (issued on 18:02:21, done on 24:02:21)
+[x] implement move animation (issued oyn 18:02:21, done on 24:02:21)
[x] implement army hud view (issued on 18:02:21, done on 22:02:21)
[x] implement naming template and army (issued on 18:02:21, done on 22:02:21)
[x] implement cost function (issued on 18:02:21, done on 20:02:21)
@@ -39,15 +40,19 @@ bugs:
[ ] symmetric integration (found on 18:02:21)
(on army movement and fire, equal armies should fair equally)
-[ ] cross platform net broken (found on 02:03:21)
+[ ] cross pc net broken (found on 02:03:21)
+
+[x] ip text edit rect too small (found on 02:03:21, done on 02:03:21)
+[x] cannot modify level of first aug (found on 02:03:21, done on 02:03:21)
testing:
-[ ] write test suit (issued on 19:02:21)
-[ ] armor calculations (issued on 18:02:21)
+[ ] write test suite (issued on 19:02:21)
[ ] hud states/flags/input interactions (issued on 22:02:21)
+[x] armor calculations (issued on 18:02:21, done on 02:03:21)
+
balance:
@@ -63,6 +68,10 @@ view from 18:02:21 to the end:
details:
+test suite:
+ automatic common test cases
+ is it necessary? yes
+
implement fire animation:
istantaneous: shot fxs and explosions are with their own timing
get an fx module -> bullets, damage, aoe explosions
@@ -163,6 +172,7 @@ implement cost function:
i can also price components based on no bonuses to provide a price gauge -> meh
i think it's better to focus on the cost indipendently of weight for now
-> done inpependent wrt weight
+-> reimplemented for stats introduction
implement end of battle condition:
i was thinking i can detect the end as no damage is being dealt in 10 turns
diff --git a/gst/fxs.c b/gst/fxs.c
index 90f56b2..25ddf18 100644
--- a/gst/fxs.c
+++ b/gst/fxs.c
@@ -12,6 +12,7 @@ void fx_init (fxs *fx) {
}
void fx_add_bullet (fxs *fx, bullet *b) {
+ if (fx->bulletslen >= 1024-1) return;
fx->bullets[fx->bulletslen] = *b;
fx->bulletslen++;
}
diff --git a/gst/gst.c b/gst/gst.c
index 77ca46d..d3d4ee8 100644
--- a/gst/gst.c
+++ b/gst/gst.c
@@ -76,6 +76,7 @@ void gst_tobattle (gamestate *gst, infos *info) {
gst->ar.us[gst->ar.uslen].owner = i;
}
}
+
gst_compute_stats(gst, info);
gst_lastpos(gst);
gst->starttime = FLT_MAX;
@@ -139,7 +140,9 @@ void gst_spawn_bullets (gamestate *gst, fxs *fx, a_dmg dmgs[], int dmgslen,
int gst_check_victory (gamestate *gst) {
int counts[gst->playernum], max=-1, imax = -1;
- for (int i=0; i<gst->ar.uslen; i++) {
+ for (int i=0; i<gst->ar.uslen; i++) {
+ if (gst->ar.us[i].hp <= 0) continue;
+ if (gst->ar.us[i].charge <= 0) continue;
counts[gst->ar.us[i].owner] ++;
if (counts[gst->ar.us[i].owner] > max) {
imax = gst->ar.us[i].owner;
@@ -149,29 +152,32 @@ int gst_check_victory (gamestate *gst) {
return imax;
}
+void gst_next_turn (gamestate *gst, infos *info, fxs *fx, float t) {
+ gst_lastpos(gst);
+ gst->coveredtime += gst->turnspeed;
+ gst->turn ++;
+ map *m; army *ar;
+ gst_get_maparmy(gst, &m, &ar);
+ int move = army_move(info, ar, m, gst->ustats);
+
+ a_dmg dmgs[1024*8];
+ int fire = army_fire(info, ar, m, dmgs, gst->ustats);
+ army_upkeep(info, ar, m, gst->ustats);
+ if (move == 0 && fire == 0) {
+ gst->turn_until_finish--;
+ } else { gst->turn_until_finish = 5; }
+ if (gst->turn_until_finish <= 0) {
+ gst->over = 1;
+ }
+ gst_spawn_bullets(gst, fx, dmgs, fire, t);
+}
+
void gst_process (gamestate *gst, infos *info, 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) {
- // next turn
- gst_lastpos(gst);
- gst->coveredtime += gst->turnspeed;
- gst->turn ++;
- map *m; army *ar;
- gst_get_maparmy(gst, &m, &ar);
- int move = army_move(info, ar, m, gst->ustats);
-
- a_dmg dmgs[1024*8];
- int fire = army_fire(info, ar, m, dmgs, gst->ustats);
- army_upkeep(info, ar, m, gst->ustats);
- if (move == 0 && fire == 0) {
- gst->turn_until_finish--;
- } else { gst->turn_until_finish = 5; }
- if (gst->turn_until_finish <= 0) {
- gst->over = 1;
- }
- gst_spawn_bullets(gst, fx, dmgs, fire, t);
+ if (t_elapsed >= gst->coveredtime) {
+ gst_next_turn(gst, info, fx, t);
}
}
}
diff --git a/gst/gst.h b/gst/gst.h
index 3178278..c7ba752 100644
--- a/gst/gst.h
+++ b/gst/gst.h
@@ -39,6 +39,9 @@ void gst_get_maparmy(gamestate *gst, map **m, army **ar);
void gst_tobattle (gamestate *gst, infos *info);
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_render (SDL_Renderer *rend, SDL_Texture *txsprites, txtd *textd,
gamestate *gst, infos *info, float t);
diff --git a/gst/info.c b/gst/info.c
index a1ad3b2..74b2d19 100644
--- a/gst/info.c
+++ b/gst/info.c
@@ -31,7 +31,6 @@ int damage_type_map (char *strdmg) {
printf("info: damage type unknown\n"); return -1;
}
-
void info_unit_init (info_unit *u) {
strcpy(u->name, "nameless");
u->chassis = -1;
@@ -334,43 +333,117 @@ void stats_unit_comp_sum (stats_unit *base, stats_unit *perc,
}
}
-#define PERC_NORM(x) x*0.01+1
+float f_perc_norm (float x) { return x*0.01+1; }
// frame a *= b
void stats_frame_mul (stats_frame *a, stats_frame *b) {
- a->hp *= PERC_NORM(b->hp);
- a->weight *= PERC_NORM(b->weight);
- a->weight_max *= PERC_NORM(b->weight_max);
- a->slot_weapon *= PERC_NORM(b->slot_weapon);
- a->slot_armor *= PERC_NORM(b->slot_armor);
- a->slot_aug *= PERC_NORM(b->slot_aug);
- a->speed *= PERC_NORM(b->speed);
- a->upkeep *= PERC_NORM(b->upkeep);
- a->capacity *= PERC_NORM(b->capacity);
- a->recharge *= PERC_NORM(b->recharge);
- LOOP(7) a->armor[z] *= PERC_NORM(b->armor[z]);
+ a->hp *= b->hp;
+ a->weight *= b->weight;
+ a->weight_max *= b->weight_max;
+ a->slot_weapon *= b->slot_weapon;
+ a->slot_armor *= b->slot_armor;
+ a->slot_aug *= b->slot_aug;
+ a->speed *= b->speed;
+ a->upkeep *= b->upkeep;
+ a->capacity *= b->capacity;
+ a->recharge *= b->recharge;
+ LOOP(7) a->armor[z] *= b->armor[z];
}
// weapon a *= b
void stats_weapon_mul (stats_weapon *a, stats_weapon *b) {
- LOOP(7) a->damage[z] *= PERC_NORM(b->damage[z]);
- a->cooldown *= PERC_NORM(b->cooldown);
- a->range *= PERC_NORM(b->range);
- a->aoe *= PERC_NORM(b->aoe);
- a->knockback *= PERC_NORM(b->knockback);
- a->damage_battery *= PERC_NORM(b->damage_battery);
- a->stun *= PERC_NORM(b->stun);
- LOOP(7) a->armor_reduce[z] *= PERC_NORM(b->armor_reduce[z]);
- a->charge_per_shot * PERC_NORM(b->charge_per_shot);
-}
-
-void stats_unit_apply_perc (stats_unit *base, stats_unit *perc) {
+ LOOP(7) a->damage[z] *= b->damage[z];
+ a->cooldown *= b->cooldown;
+ a->range *= b->range;
+ a->aoe *= b->aoe;
+ a->knockback *= b->knockback;
+ a->damage_battery *= b->damage_battery;
+ a->stun *= b->stun;
+ LOOP(7) a->armor_reduce[z] *= b->armor_reduce[z];
+ a->charge_per_shot *= b->charge_per_shot;
+}
+
+void stats_unit_mul (stats_unit *base, stats_unit *perc) {
stats_frame_mul (&base->frame, &perc->frame);
for (int i=0; i<8; i++) {
stats_weapon_mul (&base->weapon[i], &perc->weapon[i]);
}
}
+// map
+void stats_frame_map (stats_frame *a, float (*f)(float)) {
+ a->hp = f(a->hp);
+ a->weight = f(a->weight);
+ a->weight_max = f(a->weight_max);
+ a->slot_weapon = f(a->slot_weapon);
+ a->slot_armor = f(a->slot_armor);
+ a->slot_aug = f(a->slot_aug);
+ a->speed = f(a->speed);
+ a->upkeep = f(a->upkeep);
+ a->capacity = f(a->capacity);
+ a->recharge = f(a->recharge);
+ LOOP(7) a->armor[z] = f(a->armor[z]);
+}
+
+void stats_weapon_map (stats_weapon *a, float (*f)(float)) {
+ LOOP(7) a->damage[z] = f(a->damage[z]);
+ a->cooldown = f(a->cooldown);
+ a->range = f(a->range);
+ a->aoe = f(a->aoe);
+ a->knockback = f(a->knockback);
+ a->damage_battery = f(a->damage_battery);
+ a->stun = f(a->stun);
+ LOOP(7) a->armor_reduce[z] = f(a->armor_reduce[z]);
+ a->charge_per_shot = f(a->charge_per_shot);
+}
+
+void stats_unit_map (stats_unit *base, float (*f)(float)) {
+ stats_frame_map (&base->frame, f);
+ for (int i=0; i<8; i++) {
+ stats_weapon_map (&base->weapon[i], f);
+ }
+}
+
+// fold
+float stats_frame_fold (stats_frame *frame, float (*f)(float, float)) {
+ float v = 0;
+ v = f(v, frame->hp);
+ v = f(v, frame->weight);
+ v = f(v, frame->weight_max);
+ v = f(v, frame->slot_weapon);
+ v = f(v, frame->slot_armor);
+ v = f(v, frame->slot_aug);
+ v = f(v, frame->speed);
+ v = f(v, frame->upkeep);
+ v = f(v, frame->capacity);
+ v = f(v, frame->recharge);
+ LOOP(7) v = f(v, frame->armor[z]);
+ return v;
+}
+
+float stats_weapon_fold (stats_weapon *weapon, float (*f)(float, float)) {
+ float v = 0;
+ LOOP(7) v = f(v, weapon->damage[z]);
+ v = f(v, weapon->cooldown);
+ v = f(v, weapon->range);
+ v = f(v, weapon->aoe);
+ v = f(v, weapon->knockback);
+ v = f(v, weapon->damage_battery);
+ v = f(v, weapon->stun);
+ LOOP(7) v = f(v, weapon->armor_reduce[z]);
+ v = f(v, weapon->charge_per_shot);
+ return v;
+}
+
+float stats_unit_fold (stats_unit *base, float (*f)(float, float)) {
+ float v = 0;
+ v = f(v, stats_frame_fold (&base->frame, f));
+ for (int i=0; i<8; i++) {
+ v = f(v, stats_weapon_fold (&base->weapon[i], f));
+ }
+ return v;
+}
+
// compute all necessary components stats of u into base
void stats_unit_compute (infos *info, info_unit *u, stats_unit *base) {
stats_unit_init(base);
@@ -423,7 +496,8 @@ void stats_unit_compute (infos *info, info_unit *u, stats_unit *base) {
}
base->weaponlen = wn;
- stats_unit_apply_perc(base, &perc);
+ stats_unit_map(&perc, f_perc_norm);
+ stats_unit_mul(base, &perc);
}
float stats_compute_damage (stats_weapon *weapon, stats_frame *frame,
@@ -437,6 +511,23 @@ float stats_compute_damage (stats_weapon *weapon, stats_frame *frame,
return damage;
}
+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);
+}
+
+
+float f_sum (float a, float b) { return a+b; }
+
+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);
+ return cost;
+}
+
#define MATCH(frame, attr, type) {\
if (strcmp(key, #frame"_"#attr) == 0) {\
@@ -462,7 +553,6 @@ float stats_compute_damage (stats_weapon *weapon, stats_frame *frame,
}\
}
-/* REMOVE AFTER THIS */ #include <conio.h>
void stats_comp_parse (char *json, stats_comp *comp, jsmntok_t *t, int r,
infos *info)
@@ -555,8 +645,6 @@ void info_stats_parse (infos *info, char *json, int stats_type) {
stats_comp_parse(json, comp, t+i+1, rt, info);
info->statslen[stats_type] ++;
i += rt-1;
-
- //stats_comp_printf(info, comp);
}
}
}
@@ -577,6 +665,7 @@ void info_load (infos *info) {
int size = 1024*64;
char json[size];
type_damage_map(info->damage_types);
+ cost_weights_init(&info->cost_weights);
info->templateslen = 0;
info_read_file(json, "content/templates/default.txt", size);
@@ -596,14 +685,15 @@ void info_load (infos *info) {
info->statslen[i] = 0;
info_read_file(json, files[i], size);
info_stats_parse(info, json, i);
- printf("info->statslen[%d]: %d\n", i, info->statslen[i]);
} else { printf("error: out of memory in allocating for stats"); }
}
+ /*
info_unit *u = info->templates+0;
stats_unit base;
stats_unit_compute(info, u, &base);
stats_unit_printf(info, &base);
+ */
}
diff --git a/gst/info.h b/gst/info.h
index ce4d3fd..e0d784a 100644
--- a/gst/info.h
+++ b/gst/info.h
@@ -80,6 +80,8 @@ typedef struct {
typedef struct {
char damage_types[7][32];
+ stats_unit cost_weights;
+
info_unit templates[MAXTEMPLATES];
int templateslen;
@@ -89,13 +91,14 @@ typedef struct {
void info_unit_init (info_unit *u);
-
int stats_frame_sprintf (infos *info, stats_frame *frame, char arr[][64]);
int stats_weapon_sprintf (infos *info, stats_weapon *weap, char arr[][64]);
void stats_unit_compute (infos *info, info_unit *u, stats_unit *base);
float stats_compute_damage (stats_weapon *weapon, stats_frame *frame,
float *red);
+
+float stats_compute_cost (stats_unit *w, stats_unit *base);
void info_load (infos *info);
diff --git a/gst/units.c b/gst/units.c
index 78b28ab..0297266 100644
--- a/gst/units.c
+++ b/gst/units.c
@@ -17,6 +17,7 @@ void army_grid_init(army *ar) {
}
void army_init (army *ar, map *m) {
+ ar->grid = NULL;
ar->uslen = 0;
ar->sx = m->sx; ar->sy = m->sy;
strcpy(ar->name, "-");
diff --git a/hud/hud.c b/hud/hud.c
index f2eb361..dfb4f24 100644
--- a/hud/hud.c
+++ b/hud/hud.c
@@ -44,7 +44,7 @@ void init_form_new_unit (graphic_settings *gs, form_new_unit *fnu, txtd *t) {
SDL_Rect_init(&fnu->rect_chassis, x+20, y+20+145+10+30, 300, 300);
SDL_Rect_init(&fnu->rect_brain, x+20, y+20+30, 145, 145);
- SDL_Rect_init(&fnu->rect_battery, 0+25, y+20+30, 145, 145);
+ SDL_Rect_init(&fnu->rect_battery, x+150+25, y+20+30, 145, 145);
for (int i=0; i<8; i++) {
SDL_Rect_init(&fnu->rect_weapons[i],
x+20+300+10+30, y+20+120*i +30, 200, 110);
@@ -376,7 +376,7 @@ void hud_process_form_new_unit (graphic_settings *gs, hud *h, MKb *mkb,
}
}
}
- for (int i=0; i<comp->base[lc].slot_armor; i++) {
+ for (int i=0; i<comp->base[lc].slot_aug; i++) {
float possa[2] = {
h->fnu.rect_augs[i].x, h->fnu.rect_augs[i].y };
float sizesa[2] = {
@@ -655,7 +655,7 @@ void hud_process_overlay_game (graphic_settings *gs, hud *h, MKb *mkb,
float wjoin = get_text_width("join game", t);
float pn[2] = { h->og.join_game.pos[0]+wjoin + 4*2+10,
h->og.join_game.pos[1]+4 };
- char sn[64]; sprintf(sn, "IP: %s", h->og.playername);
+ char sn[64]; sprintf(sn, "IP: %s", h->og.ip);
float sizen[2] = { get_text_width(sn, t), 10 };
if (pt_rect(mousepos, pn, sizen)) {
h->nameedit = h->og.ip;
@@ -996,7 +996,12 @@ void hud_render_overlay_game (overlay_game *og, MKb *mkb,
float cost = 0;
for (int i=0; i<gst->army_bp[0].uslen; i++) {
- cost += 10;
+ if (gst->army_bp[0].us[i].info.chassis != -1
+ && gst->army_bp[0].us[i].owner == 0) {
+ stats_unit base;
+ stats_unit_compute(info, &gst->army_bp[0].us[i].info, &base);
+ cost += stats_compute_cost(&info->cost_weights, &base);
+ }
}
float cx = og->rect_army.x+5;
float cy = og->rect_army.y+5 + 30;
@@ -1111,7 +1116,12 @@ void hud_render_overlay_battle (overlay_battle *ob, MKb *mkb,
{
float cost = 0;
for (int i=0; i<gst->army_bp[0].uslen; i++) {
- cost += 10;
+ if (gst->army_bp[0].us[i].info.chassis != -1
+ && gst->army_bp[0].us[i].owner == 0) {
+ stats_unit base;
+ stats_unit_compute(info, &gst->army_bp[0].us[i].info, &base);
+ cost += stats_compute_cost(&info->cost_weights, &base);
+ }
}
float p[2] = { x+10, y+h };
char s[64]; sprintf(s, "COST: %.0f", cost);
@@ -1119,7 +1129,12 @@ void hud_render_overlay_battle (overlay_battle *ob, MKb *mkb,
float cost2 = 0;
for (int i=0; i<gst->army_bp[1].uslen; i++) {
- cost2 += 10;
+ if (gst->army_bp[0].us[i].info.chassis != -1
+ && gst->army_bp[0].us[i].owner == 1) {
+ stats_unit base;
+ stats_unit_compute(info, &gst->army_bp[0].us[i].info, &base);
+ cost += stats_compute_cost(&info->cost_weights, &base);
+ }
}
char p2[64]; sprintf(p2, "COST: %.0f", cost2);
float p2w = get_text_width(p2, t);
diff --git a/hud/hud_views.c b/hud/hud_views.c
index b2192b3..385501e 100644
--- a/hud/hud_views.c
+++ b/hud/hud_views.c
@@ -72,6 +72,10 @@ void render_view_stats_unit (SDL_Renderer* rend, txtd *t, int px, int py,
int n = stats_weapon_sprintf(info, u->weapon +i, arr);
for (int i=0; i<n; i++) { LABEL(px+pad, py+h, arr[i], 1); h += 15; }
}
+ h += 5;
+ float cost = stats_compute_cost(&info->cost_weights, u);
+ char s[64]; sprintf(s, "COST: %.2f", cost);
+ LABEL(px+pad, py+h, s, 1); h += 15;
}
@@ -84,7 +88,9 @@ void render_view_stats (SDL_Renderer* rend, txtd *t, int px, int py,
stats_unit base;
stats_unit_compute(info, tm, &base);
- render_view_stats_unit(rend, t, px+10, py+h, info, &base);
+ if (tm->chassis != -1) {
+ render_view_stats_unit(rend, t, px+10, py+h, info, &base);
+ }
}
diff --git a/main.c b/main.c
index c9ee420..3090135 100644
--- a/main.c
+++ b/main.c
@@ -22,6 +22,10 @@
#include "hud/hud.h"
#include "net/net.h"
+#define TEST 1
+#if TEST == 1
+#include "test/test.h"
+#endif
//The music that will be played
Mix_Music *gMusic = NULL;
@@ -32,8 +36,7 @@ Mix_Chunk *sounds[16];
#define A(a, arg) printf("value: %d", a.arg);
struct a { int v; } biga;
-int main( int argc, char* args[] ) {
-
+int main( int argc, char* args[] ) {
graphic_settings gs = { 1250, 700 };
SDL_Window* window = NULL;
@@ -80,7 +83,6 @@ int main( int argc, char* args[] ) {
sounds[SOUND_SUCCESS] = Mix_LoadWAV(
"content/sounds/success.wav" );
Mix_Volume(-1,MIX_MAX_VOLUME/16);
- // Mix_PlayChannel( -1, mouse_over, 0 );
// frame timing
const double FRAME_TIME = (double)1/60; // delta time for 60 FPS
@@ -94,7 +96,6 @@ int main( int argc, char* args[] ) {
MKb mkb;
mkb_init(&mkb);
-
// info
infos info;
info_load(&info);
@@ -127,6 +128,12 @@ int main( int argc, char* args[] ) {
int server = 0;
int quit = 0;
+
+ if (TEST) {
+ int result = test_run(&info);
+ if (result != 0) quit = 1;
+ }
+
SDL_Event e;
while(!quit) {
while(SDL_PollEvent(&e) != 0) {
diff --git a/test/test.c b/test/test.c
new file mode 100644
index 0000000..81a5fc8
--- /dev/null
+++ b/test/test.c
@@ -0,0 +1,11 @@
+#include <stdio.h>
+
+#include "test.h"
+#include "test_gst.h"
+
+
+int test_run (infos *info) {
+ int result = 0;
+ result += test_gst_run(info);
+ return result;
+} \ No newline at end of file
diff --git a/test/test.h b/test/test.h
new file mode 100644
index 0000000..a6524bc
--- /dev/null
+++ b/test/test.h
@@ -0,0 +1,10 @@
+#ifndef TEST_H
+#define TEST_H
+
+#include "../gst/info.h"
+
+#define TEST_VERBOSE 1
+
+int test_run (infos *info);
+
+#endif \ No newline at end of file
diff --git a/test/test_gst.c b/test/test_gst.c
new file mode 100644
index 0000000..75e2606
--- /dev/null
+++ b/test/test_gst.c
@@ -0,0 +1,53 @@
+#include <stdio.h>
+
+#include "test.h"
+
+#include "../gst/fxs.h"
+#include "../gst/gst.h"
+
+int test_gst_mirror_match (infos *info, int n);
+
+
+int test_gst_run (infos *info) {
+ int result = 0;
+ for (int i=0; i<1; i++) {
+ result += test_gst_mirror_match(info, i);
+ }
+ return result;
+}
+
+int test_gst_mirror_match (infos *info, int n) {
+ if(TEST_VERBOSE) printf("test_gst: mirror match __test%d\n", n);
+ fxs fx;
+ fx_init(&fx);
+ gamestate gst;
+ gst_init(&gst);
+
+ char name[64]; sprintf(name, "hidden/__test%d", n);
+ info_load_army(gst.army_bp+0, name);
+ info_load_army(gst.army_bp+1, name);
+ gst.playernum = 2;
+ gst_tobattle(&gst, info);
+
+ float t = 0; int i=0;
+ for (; i < 2000; i++) {
+ gst_process(&gst, info, &fx, t);
+ t += gst.turnspeed;
+ if (gst.over == 1) {
+ break;
+ }
+ }
+ if (i < 2000) {
+ if(TEST_VERBOSE) printf("test_gst: %d turns\n", i);
+ int winner = gst_check_victory(&gst);
+ if (winner == -1) {
+ if(TEST_VERBOSE) printf("test_gst success: draw\n");
+ } else {
+ printf("test_gst failed: not draw (%d)\n", winner);
+ return 1;
+ }
+ gst_destroy(&gst);
+ return 0;
+ }
+ return 1;
+} \ No newline at end of file
diff --git a/test/test_gst.h b/test/test_gst.h
new file mode 100644
index 0000000..4d14ee2
--- /dev/null
+++ b/test/test_gst.h
@@ -0,0 +1,8 @@
+#ifndef TEST_GST_H
+#define TEST_GST_H
+
+#include "../gst/info.h"
+
+int test_gst_run (infos *info);
+
+#endif \ No newline at end of file