aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--Makefile30
-rw-r--r--build/Arena.exebin170795 -> 176654 bytes
-rw-r--r--build/army/all maul.txtbin25656 -> 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/augments.txt14
-rw-r--r--build/content/templates/default.txt116
-rw-r--r--design/notes.txt5
-rw-r--r--gst/generate.c70
-rw-r--r--gst/generate.h11
-rw-r--r--gst/info.c40
-rw-r--r--gst/info.h4
-rw-r--r--hud/hud.c56
-rw-r--r--hud/hud.h3
-rw-r--r--main.c10
16 files changed, 240 insertions, 121 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 25f5fbf..fa18857 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -27,6 +27,8 @@ add_executable(Arena
gst/map.h
gst/units.c
gst/units.h
+ gst/generate.c
+ gst/generate.h
hud/hud.c
hud/hud.h
hud/hud_views.c
diff --git a/Makefile b/Makefile
index 40337ec..357eb68 100644
--- a/Makefile
+++ b/Makefile
@@ -168,6 +168,33 @@ gst/fxs.c.s:
$(MAKE) $(MAKESILENT) -f CMakeFiles\Arena.dir\build.make CMakeFiles/Arena.dir/gst/fxs.c.s
.PHONY : gst/fxs.c.s
+gst/generate.obj: gst/generate.c.obj
+
+.PHONY : gst/generate.obj
+
+# target to build an object file
+gst/generate.c.obj:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles\Arena.dir\build.make CMakeFiles/Arena.dir/gst/generate.c.obj
+.PHONY : gst/generate.c.obj
+
+gst/generate.i: gst/generate.c.i
+
+.PHONY : gst/generate.i
+
+# target to preprocess a source file
+gst/generate.c.i:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles\Arena.dir\build.make CMakeFiles/Arena.dir/gst/generate.c.i
+.PHONY : gst/generate.c.i
+
+gst/generate.s: gst/generate.c.s
+
+.PHONY : gst/generate.s
+
+# target to generate assembly for a file
+gst/generate.c.s:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles\Arena.dir\build.make CMakeFiles/Arena.dir/gst/generate.c.s
+.PHONY : gst/generate.c.s
+
gst/gst.obj: gst/gst.c.obj
.PHONY : gst/gst.obj
@@ -612,6 +639,9 @@ help:
@echo ... gst/fxs.obj
@echo ... gst/fxs.i
@echo ... gst/fxs.s
+ @echo ... gst/generate.obj
+ @echo ... gst/generate.i
+ @echo ... gst/generate.s
@echo ... gst/gst.obj
@echo ... gst/gst.i
@echo ... gst/gst.s
diff --git a/build/Arena.exe b/build/Arena.exe
index 11218e1..9015cd1 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
index 0b6234b..2bcb86e 100644
--- a/build/army/all maul.txt
+++ b/build/army/all maul.txt
Binary files differ
diff --git a/build/army/new army 0.txt b/build/army/new army 0.txt
index a58719b..be2643b 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 2e7e5da..5acae18 100644
--- a/build/army/new army.txt
+++ b/build/army/new army.txt
Binary files differ
diff --git a/build/content/augments.txt b/build/content/augments.txt
index 35e5bba..77417fe 100644
--- a/build/content/augments.txt
+++ b/build/content/augments.txt
@@ -221,37 +221,37 @@
-37.5,
-45.0
],
- "base_weapon_damage_pierce": [
+ "perc_weapon_damage_pierce": [
-25.0,
-31.25,
-37.5
],
- "base_weapon_damage_laser": [
+ "perc_weapon_damage_laser": [
-25.0,
-31.25,
-37.5
],
- "base_weapon_damage_impact": [
+ "perc_weapon_damage_impact": [
-25.0,
-31.25,
-37.5
],
- "base_weapon_damage_fusion": [
+ "perc_weapon_damage_fusion": [
-25.0,
-31.25,
-37.5
],
- "base_weapon_damage_explosive": [
+ "perc_weapon_damage_explosive": [
-25.0,
-31.25,
-37.5
],
- "base_weapon_damage_emp": [
+ "perc_weapon_damage_emp": [
-25.0,
-31.25,
-37.5
],
- "base_weapon_damage_spread": [
+ "perc_weapon_damage_spread": [
-25.0,
-31.25,
-37.5
diff --git a/build/content/templates/default.txt b/build/content/templates/default.txt
index d6d526a..aba99e1 100644
--- a/build/content/templates/default.txt
+++ b/build/content/templates/default.txt
@@ -1,122 +1,32 @@
[
{
- "name": "medium rare",
- "chassis": "0",
- "brain": "0",
- "battery": "0",
- "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 ]
- },
- {
- "name": "raw",
- "chassis": "5",
- "brain": "0",
- "battery": "0",
- "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, 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",
- "chassis": "10",
- "brain": "2",
- "battery": "2",
- "weapons": [ 27, -1, -1, -1, -1, -1, -1, -1 ],
- "armor": [ 0, 0, -1, -1, -1, -1, -1, -1 ],
- "augs": [ -1, -1, -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 ]
- },
- {
- "name": "range tester",
- "chassis": "12",
- "brain": "0",
- "battery": "1",
- "weapons": [ 1, -1, -1, -1, -1, -1, -1, -1 ],
- "armor": [ 0, 0, 0, 0, -1, -1, -1, -1 ],
- "augs": [ -1, -1, -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 ]
- },
- {
- "name": "600 dude",
- "chassis": "8",
- "brain": "0",
+ "name": "pussy destoryer",
+ "chassis": "14",
+ "brain": "5",
"battery": "1",
- "weapons": [ 2, -1, -1, -1, -1, -1, -1, -1 ],
- "armor": [ -1, -1, -1, -1, -1, -1, -1, -1 ],
- "augs": [ 8, 8, -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 ]
+ "weapons": [ 19, 19, 19, -1, -1, -1, -1, -1 ],
+ "armor": [ 0, 0, 0, 0, 0, 0, -1, -1 ],
+ "augs": [ 15, 15, 15, 15, 15, 15, -1, -1 ],
+ "levels": [ 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 0, 0, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
},
{
- "name": "300 bot dude",
+ "name": "withname",
"chassis": "0",
"brain": "0",
"battery": "0",
- "weapons": [ 7, -1, -1, -1, -1, -1, -1, -1 ],
+ "weapons": [ -1, -1, -1, -1, -1, -1, -1, -1 ],
"armor": [ -1, -1, -1, -1, -1, -1, -1, -1 ],
"augs": [ -1, -1, -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 ]
},
{
- "name": "400 perfect duud",
- "chassis": "2",
- "brain": "0",
- "battery": "0",
- "weapons": [ 0, 0, -1, -1, -1, -1, -1, -1 ],
- "armor": [ -1, -1, -1, -1, -1, -1, -1, -1 ],
- "augs": [ 16, -1, -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 ]
- },
- {
- "name": "1000 tank boi",
- "chassis": "5",
- "brain": "0",
- "battery": "0",
- "weapons": [ 18, 16, -1, -1, -1, -1, -1, -1 ],
- "armor": [ 0, 0, 0, -1, -1, -1, -1, -1 ],
- "augs": [ 8, 8, -1, -1, 2, -1, -1, -1 ],
- "levels": [ 2, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
- },
- {
- "name": "1000 melee bot friendo",
- "chassis": "5",
- "brain": "3",
- "battery": "0",
- "weapons": [ 10, 1, -1, -1, -1, -1, -1, -1 ],
- "armor": [ 0, 0, 8, -1, -1, -1, -1, -1 ],
- "augs": [ -1, -1, -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 ]
- },
- {
- "name": "2000 maul dodo",
- "chassis": "4",
- "brain": "0",
- "battery": "1",
- "weapons": [ 9, -1, -1, -1, -1, -1, -1, -1 ],
- "armor": [ -1, -1, -1, -1, -1, -1, -1, -1 ],
- "augs": [ -1, -1, -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 ]
- },
- {
- "name": "dongo",
- "chassis": "13",
- "brain": "0",
- "battery": "0",
- "weapons": [ 0, 2, -1, -1, -1, -1, -1, -1 ],
- "armor": [ 1, 0, 1, -1, 3, -1, -1, -1 ],
- "augs": [ 1, -1, 2, -1, 0, -1, -1, -1 ],
- "levels": [ 0, 1, 2, 0, 2, 0, 0, 0, 0, 0, 0, 2, 1, 1, 0, 2, 0, 0, 0, 2, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
- },
- {
"name": "pussy destoryer",
- "chassis": "14",
+ "chassis": "0",
"brain": "5",
"battery": "1",
- "weapons": [ 0, 0, 0, -1, -1, -1, -1, -1 ],
+ "weapons": [ 23, 19, 19, -1, -1, -1, -1, -1 ],
"armor": [ 0, 0, 0, 0, 0, 0, -1, -1 ],
- "augs": [ -1, -1, -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 ]
+ "augs": [ 15, 15, 15, 15, 15, 15, -1, -1 ],
+ "levels": [ 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 0, 0, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
}
] \ No newline at end of file
diff --git a/design/notes.txt b/design/notes.txt
index f8d3303..127dfeb 100644
--- a/design/notes.txt
+++ b/design/notes.txt
@@ -10,7 +10,6 @@ tasks:
[ ] implement net hud and minilobby (issued on 18:02:21)
[ ] implement brain behaviour (issued on 18:02:21)
[ ] implement lobby cost constraints (issued on 18:02:21)
-[ ] implement edit unit directly (issued on 18:02:21)
[ ] implement persistent settings ini (issued on 18:02:21)
[ ] implement explosions (issued on 18:02:21)
[ ] design 3d units (issued on 18:02:21)
@@ -20,6 +19,8 @@ tasks:
[ ] implement sound (issued on 18:02:21)
[ ] implement component aoe bonus (issued on 02:03:21)
+[x] implement edit unit directly (issued on 18:02:21, done on 04:03:21)
+[x] implement rm template (issued on 04:03:21, done on 04: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)
@@ -59,6 +60,8 @@ bugs:
[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)
+[x] damage calculation (found on 04:03:21, done on 04:03:21)
+[x] slots unit_stats not counted (found on 04:03:21, done on 04:03:21)
testing:
diff --git a/gst/generate.c b/gst/generate.c
new file mode 100644
index 0000000..1d8a340
--- /dev/null
+++ b/gst/generate.c
@@ -0,0 +1,70 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+#include <string.h>
+
+#include "generate.h"
+
+void generate_init () {
+ srand(time(NULL));
+}
+
+float calc_unit_cost (infos *info, info_unit *u) {
+ stats_unit base;
+ stats_unit_compute(info, u, &base);
+ return stats_compute_cost(&info->cost_weights, &base);
+}
+
+int accept_cond (infos *info, info_unit *u, float cost_max) {
+ stats_unit base;
+ stats_unit_compute(info, u, &base);
+ float cost = stats_compute_cost(&info->cost_weights, &base);
+ if (base.frame.weight > base.frame.weight_max) return 0;
+ if (cost > cost_max) return 0;
+ return 1;
+}
+
+// generates randomly a valid unit
+void gen_unit_attempt (infos *info, info_unit *u, float cost_max) {
+ info_unit_init(u);
+ stats_unit base;
+ u->chassis = rand() % info->statslen[STATS_CHASSIS];
+ 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; }
+ }
+}
+
+// selects the max cost generated unit
+int generate_unit (infos *info, info_unit *u, float cost_max) {
+ info_unit cand = *u;
+ info_unit candmax; info_unit_init(&candmax);
+ float cost;
+ for (int i=0; i<GENERATE_UNIT_MAX_ATTEMPTS; i++) {
+ cand = *u;
+ gen_unit_attempt(info, &cand, cost_max);
+ if (accept_cond(info, &cand, cost_max)) {
+ if (calc_unit_cost(info, &cand)
+ > calc_unit_cost(info, &candmax)) {
+ candmax = cand;
+ printf("found: %f\n", calc_unit_cost(info, &cand));
+ }
+ }
+ }
+ if (candmax.chassis != -1) {
+ *u = candmax;
+ return 0;
+ }
+ else return 1;
+} \ No newline at end of file
diff --git a/gst/generate.h b/gst/generate.h
new file mode 100644
index 0000000..a4da2d6
--- /dev/null
+++ b/gst/generate.h
@@ -0,0 +1,11 @@
+#ifndef GENERATE_H
+#define GENERATE_H
+
+#include "info.h"
+
+#define GENERATE_UNIT_MAX_ATTEMPTS 48637
+
+void generate_init ();
+int generate_unit (infos *info, info_unit *u, float cost);
+
+#endif \ No newline at end of file
diff --git a/gst/info.c b/gst/info.c
index 91a26a2..cb1d9f1 100644
--- a/gst/info.c
+++ b/gst/info.c
@@ -40,6 +40,23 @@ void info_unit_init (info_unit *u) {
for(int i=0; i<16; u->augs[i] = -1, i++);
for(int i=0; i<34; u->levels[i] = 0, i++);
}
+
+void info_unit_printf (info_unit *u) {
+ printf("name: %s\n", u->name);
+ printf("chassis: %d; ", u->chassis);
+ printf("battery: %d; ", u->battery);
+ printf("brain: %d\n", u->brain);
+ printf("weapon: ");
+ for(int i=0; i<8; printf("%d, ", u->weapons[i]), i++);
+ printf("\narmor: ");
+ for(int i=0; i<8; printf("%d, ", u->armor[i]), i++);
+ printf("\naugs: ");
+ for(int i=0; i<16; printf("%d, ", u->augs[i]), i++);
+ printf("\nlevels: ");
+ for(int i=0; i<34; printf("%d, ", u->levels[i]), i++);
+ printf("\n");
+}
+
/*
float info_unit_get_cost (infos *info, info_unit *u) {
// see design/notes.txt:implement cost function
@@ -273,8 +290,9 @@ void stats_comp_printf (infos *info, stats_comp *comp) {
void stats_unit_printf (infos *info, stats_unit *u) {
char arr[32][64];
{ int n = stats_frame_sprintf (info, &u->frame, arr); printf_arr(arr, n); }
- LOOP(8) {
+ LOOP(u->weaponlen) {
int n = stats_weapon_sprintf(info, u->weapon +z, arr);
+ if (n>0) printf(" weapon: \n");
printf_arr(arr, n);
}
}
@@ -444,6 +462,8 @@ float stats_unit_fold (stats_unit *base, float (*f)(float, float)) {
return v;
}
+float f_clamp_positive (float x) { if (x < 0) x = 0; }
+
// 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);
@@ -467,7 +487,7 @@ void stats_unit_compute (infos *info, info_unit *u, stats_unit *base) {
};
for (int i=0; i<8; i++) {
- if (u->armor[i] != -1) {
+ if (u->armor[i] != -1 && i<base->frame.slot_armor) {
stats_comp *comp = &info->stats[STATS_ARMOR][u->armor[i]];
int lvl = u->levels[LEVEL_ARMOR+i];
stats_unit_comp_sum(base, &perc, comp, lvl);
@@ -475,7 +495,7 @@ void stats_unit_compute (infos *info, info_unit *u, stats_unit *base) {
}
for (int i=0; i<16; i++) {
- if (u->augs[i] != -1) {
+ if (u->augs[i] != -1 && i<base->frame.slot_aug) {
stats_comp *comp = &info->stats[STATS_AUGS][u->augs[i]];
int lvl = u->levels[LEVEL_AUGS+i];
stats_unit_comp_sum(base, &perc, comp, lvl);
@@ -497,6 +517,10 @@ void stats_unit_compute (infos *info, info_unit *u, stats_unit *base) {
base->weaponlen = wn;
stats_unit_map(&perc, f_perc_norm);
+ for (int w=0; w<wn; w++) {
+ stats_weapon_map(perc.weapon +w, f_clamp_positive);
+ }
+
stats_unit_mul(base, &perc);
}
@@ -744,6 +768,15 @@ void info_template_add (infos *info, info_unit *temp) {
}
}
+void info_template_rm (infos *info, int n) {
+ for (int i=0; i<info->templateslen-1; i++) {
+ if (i >= n) {
+ info->templates[i] = info->templates[i+1];
+ }
+ }
+ info->templateslen--;
+}
+
void info_load_army(struct army_ *ar, char *filename) {
strcpy(ar->name, filename);
char buf[1024*64];
@@ -800,3 +833,4 @@ void info_army_remove (char name[]) {
char pathname[64]; sprintf(pathname, "army/%s.txt", name);
remove(pathname);
}
+
diff --git a/gst/info.h b/gst/info.h
index e0d784a..4f04a34 100644
--- a/gst/info.h
+++ b/gst/info.h
@@ -90,9 +90,12 @@ typedef struct {
} infos;
void info_unit_init (info_unit *u);
+void info_unit_printf (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_printf (infos *info, stats_unit *u);
+
void stats_unit_compute (infos *info, info_unit *u, stats_unit *base);
float stats_compute_damage (stats_weapon *weapon, stats_frame *frame,
@@ -104,6 +107,7 @@ void info_load (infos *info);
void info_save_templates (infos *info, char *filename);
void info_template_add (infos *info, info_unit *temp);
+void info_template_rm (infos *info, int n);
#include "units.h"
diff --git a/hud/hud.c b/hud/hud.c
index dfb4f24..d85d618 100644
--- a/hud/hud.c
+++ b/hud/hud.c
@@ -254,11 +254,19 @@ void hud_edit_close(hud *h, infos *info) {
void hud_open_fnu (hud *h, infos *info, info_unit *u, int i) {
h->state = 1;
h->fnu.uinfo = *u;
+ h->fnu.uinfo_ptr = u;
h->og.temp_modify = i;
hud_edit_close(h, info);
}
void hud_close_fnu (hud *h, infos *info) {
+ if (h->og.temp_modify < -1) {
+ if (h->og.temp_modify == -2) {
+ *h->fnu.uinfo_ptr = h->fnu.uinfo;
+ }
+ h->state = 0;
+ return;
+ }
if (hud_fnu_check(&h->fnu.uinfo, info) > 0) return;
if (h->og.temp_modify == -1) {
info_template_add(info, &h->fnu.uinfo);
@@ -391,6 +399,15 @@ void hud_process_form_new_unit (graphic_settings *gs, hud *h, MKb *mkb,
}
}
}
+
+ float pback[2] = {
+ h->fnu.rect_back.x+h->fnu.rect_back.w-10,
+ h->fnu.rect_back.y };
+ float sback[2] = { 10, 10 };
+ if (pt_rect(mousepos, pback, sback)) {
+ h->og.temp_modify = -3;
+ hud_close_fnu(h, info);
+ }
}
}
@@ -468,7 +485,7 @@ void hud_process_overlay_game (graphic_settings *gs, hud *h, MKb *mkb,
hud_edit_close(h, info);
}
}
-
+
float mousepos[2] = { mkb->mx, mkb->my };
if (mkb->mheld[0] == 1) {
if (mouse_in_button(mousepos, t, &h->og.new_template)) {
@@ -669,10 +686,20 @@ void hud_process_overlay_game (graphic_settings *gs, hud *h, MKb *mkb,
if (mouse_in_button(mousepos, t, &h->og.start_battle)) {
h->og.start_battle_flag = 1;
}
+
+ // edit unit
+ int x = (int)((mkb->mx+gst->cam[0])/32);
+ int y = (int)((mkb->my+gst->cam[1])/32);
+ if (x >= 0 && y >= 0 && x < m->sx && y < m->sy) {
+ if (ar->grid[xytoi(m,x,y)] != NULL) {
+ hud_open_fnu(h, info, &ar->grid[xytoi(m,x,y)]->info, -2);
+ h->og.temp_place = -1;
+ }
+ }
}
- // rm unit
if (mkb->mheld[2] == 1) {
+ // rm unit
Mix_PlayChannel( -1, sounds[SOUND_MOUSE_CLICK_0], 0 );
int x = (int)((mkb->mx+gst->cam[0])/32);
int y = (int)((mkb->my+gst->cam[1])/32);
@@ -681,6 +708,19 @@ void hud_process_overlay_game (graphic_settings *gs, hud *h, MKb *mkb,
unit_remove(ar, m, ar->grid[xytoi(m,x,y)]);
}
}
+
+ // rm template
+ for (int i=0; i<info->templateslen; i++) {
+ float x = h->og.rect_templates.x+5;
+ float y = h->og.rect_templates.y+5 + i*20 + 30;
+ float wedit = get_text_width("edit", t);
+ float possa[2] = { x, y };
+ float sizesa[2] = { wedit+4*2, 11+4*2 };
+ if (pt_rect(mousepos, possa, sizesa)) {
+ info_template_rm(info, i);
+ break;
+ }
+ }
}
}
@@ -724,7 +764,7 @@ void hud_edit_name(hud *h, infos *info, MKb *mkb, Mix_Chunk *sounds[]) {
}
if (mkb_search(mkb, SDL_SCANCODE_BACKSPACE)) {
if (strlen(h->nameedit) > 0)
- h->nameedit[strlen(h->nameedit)-1] = '\0';
+ h->nameedit[strlen(h->nameedit)-1] = '\0';
}
if (mkb_search(mkb, SDL_SCANCODE_ESCAPE)
|| mkb_search(mkb, SDL_SCANCODE_RETURN)) {
@@ -941,6 +981,16 @@ void hud_render_form_new_unit (form_new_unit *fnu, MKb *mkb,
render_view_brain(rend, t,
fnu->rect_brain.x, fnu->rect_brain.y, info, fnu->uinfo.brain,
fnu->uinfo.levels[LEVEL_BRAIN]);
+
+ float pback[2] = {
+ fnu->rect_back.x+fnu->rect_back.w-10,
+ fnu->rect_back.y };
+ float sback[2] = { 10, 10 };
+ SDL_Rect rx = { pback[0], pback[1], sback[0], sback[1] };
+ SDL_SetRenderDrawColor(rend, 200, 0, 0, 255);
+ SDL_RenderFillRect(rend, &rx);
+ SDL_SetRenderDrawColor(rend, 0, 0, 0, 255);
+ SDL_RenderDrawRect(rend, &rx);
}
void hud_render_overlay_game (overlay_game *og, MKb *mkb,
diff --git a/hud/hud.h b/hud/hud.h
index e767c4b..48c877b 100644
--- a/hud/hud.h
+++ b/hud/hud.h
@@ -38,9 +38,9 @@ typedef struct {
button join_game;
SDL_Rect rect_battle;
SDL_Rect rect_templates;
+ SDL_Rect rect_army;
int temp_modify;
int temp_place;
- SDL_Rect rect_army;
char army_list[64][32];
int army_listlen;
int army_listcur;
@@ -66,6 +66,7 @@ typedef struct {
SDL_Rect rect_stats;
button done;
info_unit uinfo;
+ info_unit *uinfo_ptr;
int sel, ind;
} form_new_unit;
diff --git a/main.c b/main.c
index 3090135..5c7400b 100644
--- a/main.c
+++ b/main.c
@@ -18,6 +18,7 @@
#include "gst/map.h"
#include "gst/info.h"
#include "gst/gst.h"
+#include "gst/generate.h"
#include "hud/hud.h"
#include "net/net.h"
@@ -33,9 +34,6 @@ Mix_Music *gMusic = NULL;
//The sound effects that will be used
Mix_Chunk *sounds[16];
-#define A(a, arg) printf("value: %d", a.arg);
-struct a { int v; } biga;
-
int main( int argc, char* args[] ) {
graphic_settings gs = { 1250, 700 };
@@ -46,6 +44,7 @@ int main( int argc, char* args[] ) {
SDL_Init(SDL_INIT_VIDEO);
net_init();
+ generate_init();
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0");
@@ -100,6 +99,11 @@ int main( int argc, char* args[] ) {
infos info;
info_load(&info);
+ info_unit ugen; generate_unit(&info, &ugen, 10000);
+ stats_unit base; stats_unit_compute(&info, &ugen, &base);
+ stats_unit_printf(&info, &base);
+ info_unit_printf(&ugen);
+ printf("COST: %.2f\n", stats_compute_cost(&info.cost_weights, &base));
gamestate gst;
gst_init(&gst);