aboutsummaryrefslogtreecommitdiff
path: root/gst
diff options
context:
space:
mode:
Diffstat (limited to 'gst')
-rw-r--r--gst/info.c12
-rw-r--r--gst/info.h1
-rw-r--r--gst/units.c10
3 files changed, 21 insertions, 2 deletions
diff --git a/gst/info.c b/gst/info.c
index eab41a2..2329baf 100644
--- a/gst/info.c
+++ b/gst/info.c
@@ -238,6 +238,17 @@ float info_unit_get_range(infos *info, info_unit *u, int w) {
return sum;
}
+float info_unit_get_maxrange(infos *info, info_unit *u) {
+ int lc = u->levels[LEVEL_CHASSIS];
+ float sum = 0;
+ for(int i=0; i<info->chassis[u->chassis].slot_weapon[lc]; i++) {
+ if (u->weapons[i] != -1) {
+ sum += info_unit_get_range(info, u, i);
+ }
+ }
+ return sum;
+}
+
float info_unit_get_charge_per_shot (infos *info, info_unit *u, int w) {
float sum = 0;
int lw = u->levels[LEVEL_WEAPONS+w];
@@ -311,6 +322,7 @@ float info_unit_get_cost (infos *info, info_unit *u) {
}
+
void weapon_init (info_weapon *w) {
strcpy(w->name, "nameless");
for (int l=0; l<MAXLEVEL; l++) {
diff --git a/gst/info.h b/gst/info.h
index 2fe0973..6417cda 100644
--- a/gst/info.h
+++ b/gst/info.h
@@ -115,6 +115,7 @@ float info_unit_get_damage_target(infos *info, info_unit *u, int w,
info_unit *t);
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_maxrange(infos *info, info_unit *u);
float info_unit_get_armor(infos *info, info_unit *u, int d);
float info_unit_get_cost(infos *info, info_unit *u);
diff --git a/gst/units.c b/gst/units.c
index b0ae2b0..409f9b1 100644
--- a/gst/units.c
+++ b/gst/units.c
@@ -116,11 +116,17 @@ int army_move_step (infos *info, army *ar, map *m) {
if (u->move_points <= 0) continue;
if (u->hp <= 0) continue;
if (u->charge <= 0) continue;
- // search target
+ // search target inside max range
unit *t[32];
+ float maxrange = info_unit_get_maxrange(info, &u->info);
+ unit_search(info, ar, m, u, t, maxrange);
+ // stop if found
+ if (t[0] != NULL) { continue; }
+
+ // search target
unit_search(info, ar, m, u, t, 100);
if (t[0] != NULL) {
- // in range to shoot
+ // in range to move
diff[0] = u->gridpos[0] - t[0]->gridpos[0];
diff[1] = u->gridpos[1] - t[0]->gridpos[1];
if (vec2_mag(diff) > /*info->units[u->who].range*/1) {