aboutsummaryrefslogtreecommitdiff
path: root/game/gst.cpp
diff options
context:
space:
mode:
authorjacopograndi <jak.sk8@hotmail.it>2021-09-06 20:11:36 +0200
committerjacopograndi <jak.sk8@hotmail.it>2021-09-06 20:11:36 +0200
commit411d2f6d6a6e5370d33f0f54b2f2de7147a9d977 (patch)
tree82b631079a3d7226ce6384f695f2e3b213a2c635 /game/gst.cpp
parent522a43d16e812e10ff69747ee916918b4bd29f2f (diff)
started ai
Diffstat (limited to 'game/gst.cpp')
-rw-r--r--game/gst.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/game/gst.cpp b/game/gst.cpp
index 52dfe81..334844a 100644
--- a/game/gst.cpp
+++ b/game/gst.cpp
@@ -261,8 +261,8 @@ BattleResult Gst::battle_res (Entity &atk, Entity &def) {
}
void Gst::battle (Entity &atk, Entity &def) {
- std::cout << "! attack " << atk.info->name << "(hp:" << atk.hp << "), "
- << def.info->name << "(hp:" << def.hp << ") \n";
+ /*std::cout << "! attack " << atk.info->name << "(hp:" << atk.hp << "), "
+ << def.info->name << "(hp:" << def.hp << ") \n";*/
auto result = battle_res(atk, def);
atk.hp = result.atk_hp;
@@ -271,8 +271,8 @@ void Gst::battle (Entity &atk, Entity &def) {
if (atk.info->unit == 1) atk.fights += 1;
if (def.info->unit == 1) def.fights += 1;
- std::cout << "! result " << atk.info->name << "(hp:" << atk.hp << "), "
- << def.info->name << "(hp:" << def.hp << ") \n";
+ /*std::cout << "! result " << atk.info->name << "(hp:" << atk.hp << "), "
+ << def.info->name << "(hp:" << def.hp << ") \n";*/
clear_dead();
}
@@ -320,6 +320,20 @@ void Gst::convert (Entity &atk, Entity &def) {
}
+int Gst::get_nearest_enemy (Entity &ent, int &mindist) {
+ auto &ground = inv->ground;
+ int pos = -1; mindist = 9999999;
+ for (Entity &oth : entities) {
+ if (oth.owner == ent.owner) continue;
+ int dist = abs(oth.x-ent.x) + abs(oth.y-ent.y);
+ if (dist < mindist) {
+ mindist = dist;
+ pos = ground.at(oth.x, oth.y);
+ }
+ }
+}
+
+
std::vector<int> Gst::get_possible_trains (Entity &ent) {
Player &player = get_player(ent.owner);
auto &cls = ent.info->train_class;