Merge lp:~widelands-dev/widelands/attack_fix into lp:widelands

Proposed by TiborB
Status: Merged
Merged at revision: 7503
Proposed branch: lp:~widelands-dev/widelands/attack_fix
Merge into: lp:widelands
Diff against target: 73 lines (+21/-6)
1 file modified
src/ai/defaultai.cc (+21/-6)
To merge this branch: bzr merge lp:~widelands-dev/widelands/attack_fix
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+266796@code.launchpad.net

Description of the change

This is purely (a quick) AI fix of attacking logic:
- visibility of enemy site is checked (there is no "fog of war" for AI so we must check it...)
- changed algorithm to pick random amount of available soldiers for attack (generally AI tent to pick "almost all" available soldiers, now it pick lesser number)

To post a comment you must log in.
Revision history for this message
GunChleoc (gunchleoc) wrote :

Code LGTM - Just one question in the diff comments.

review: Approve
Revision history for this message
TiborB (tiborb95) wrote :

I am going to change it - you are right

Revision history for this message
GunChleoc (gunchleoc) wrote :

BTW there is another one: Wh->can_attack() && is_visible

Sorry, I was being lazy.

Revision history for this message
TiborB (tiborb95) wrote :

no, I had to remember it. How to clean it up? Can we reverse trunk? Or commit another revision to trunk?

Revision history for this message
TiborB (tiborb95) wrote :

I fixed it in my branch in the meantime

Revision history for this message
GunChleoc (gunchleoc) wrote :

Since the branch is already pushed and it's a small change, I'd say you can do the change directly on trunk - just make sure that you don't break anything.

Or you can do it in this branch and merge it again.

Revision history for this message
TiborB (tiborb95) wrote :

I will merge my branch to trunk again...

2015-08-03 23:19 GMT+02:00 GunChleoc <email address hidden>:

> Since the branch is already pushed and it's a small change, I'd say you
> can do the change directly on trunk - just make sure that you don't break
> anything.
>
> Or you can do it in this branch and merge it again.
> --
>
> https://code.launchpad.net/~widelands-dev/widelands/attack_fix/+merge/266796
> Your team Widelands Developers is subscribed to branch
> lp:~widelands-dev/widelands/attack_fix.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~widelands-dev
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~widelands-dev
> More help : https://help.launchpad.net/ListHelp
>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/ai/defaultai.cc'
--- src/ai/defaultai.cc 2015-07-27 20:25:32 +0000
+++ src/ai/defaultai.cc 2015-08-03 21:09:23 +0000
@@ -4893,6 +4893,9 @@
4893 uint8_t defenders_strength = 0;4893 uint8_t defenders_strength = 0;
4894 bool is_warehouse = false;4894 bool is_warehouse = false;
4895 bool is_attackable = false;4895 bool is_attackable = false;
4896 // we cannot attack unvisible site and there is no other way to find out
4897 const bool is_visible = (1 < player_->vision
4898 (Map::get_index(coords_unhash(site->first), map.get_width())));
4896 uint16_t owner_number = 100;4899 uint16_t owner_number = 100;
48974900
4898 // testing if we can attack the building - result is a flag4901 // testing if we can attack the building - result is a flag
@@ -4900,6 +4903,7 @@
4900 FCoords f = map.get_fcoords(coords_unhash(site->first));4903 FCoords f = map.get_fcoords(coords_unhash(site->first));
4901 uint32_t site_to_be_removed = std::numeric_limits<uint32_t>::max();4904 uint32_t site_to_be_removed = std::numeric_limits<uint32_t>::max();
4902 Flag* flag = nullptr;4905 Flag* flag = nullptr;
4906
4903 if (upcast(MilitarySite, bld, f.field->get_immovable())) {4907 if (upcast(MilitarySite, bld, f.field->get_immovable())) {
4904 if (player_->is_hostile(bld->owner())) {4908 if (player_->is_hostile(bld->owner())) {
4905 std::vector<Soldier *> defenders;4909 std::vector<Soldier *> defenders;
@@ -4907,7 +4911,7 @@
4907 defenders_strength = calculate_strength(defenders);4911 defenders_strength = calculate_strength(defenders);
49084912
4909 flag = &bld->base_flag();4913 flag = &bld->base_flag();
4910 if (bld->can_attack()) {4914 if (is_visible && bld->can_attack()) {
4911 is_attackable = true;4915 is_attackable = true;
4912 }4916 }
4913 owner_number = bld->owner().player_number();4917 owner_number = bld->owner().player_number();
@@ -4922,7 +4926,7 @@
49224926
4923 flag = &Wh->base_flag();4927 flag = &Wh->base_flag();
4924 is_warehouse = true;4928 is_warehouse = true;
4925 if (Wh->can_attack()) {4929 if (Wh->can_attack() && is_visible) {
4926 is_attackable = true;4930 is_attackable = true;
4927 }4931 }
4928 owner_number = Wh->owner().player_number();4932 owner_number = Wh->owner().player_number();
@@ -5054,9 +5058,9 @@
5054 // attacking5058 // attacking
5055 FCoords f = map.get_fcoords(coords_unhash(best_target));5059 FCoords f = map.get_fcoords(coords_unhash(best_target));
5056 // setting no attack counter here5060 // setting no attack counter here
5057 // this gauranties that it will not be attacked in next 45061 // this gauranties that it will not be attacked in next 3
5058 // turns5062 // turns
5059 enemy_sites[best_target].no_attack_counter = -4;5063 enemy_sites[best_target].no_attack_counter = -3;
50605064
5061 Flag* flag = nullptr; // flag of a building to be attacked5065 Flag* flag = nullptr; // flag of a building to be attacked
5062 if (upcast(MilitarySite, bld, f.field->get_immovable())) {5066 if (upcast(MilitarySite, bld, f.field->get_immovable())) {
@@ -5069,8 +5073,19 @@
50695073
5070 // how many attack soldiers we can send?5074 // how many attack soldiers we can send?
5071 uint32_t attackers = player_->find_attack_soldiers(*flag);5075 uint32_t attackers = player_->find_attack_soldiers(*flag);
5072 // Just add some randomness5076
5073 attackers -= gametime % 3;5077 // Of course not all of them:
5078 // reduce by 0-3 for attackers below 10
5079 // but for soldiers in range 10-40 reduce by much more.
5080 // Soldiers above 40 are ignored for calculation
5081
5082 // Number of soldiers in the range 10-40, random portion of
5083 // them will be used
5084 uint32_t above_ten = (attackers > 10)? attackers - 10 : 0;
5085 above_ten = (above_ten > 30) ? 30 : above_ten;
5086
5087 attackers = attackers - (gametime % 3) - ((above_ten > 0) ? gametime % above_ten : 0);
5088
5074 if (attackers <= 0) {5089 if (attackers <= 0) {
5075 return false;5090 return false;
5076 }5091 }

Subscribers

People subscribed via source and target branches

to status/vote changes: