Opened 11 years ago

Last modified 6 months ago

#2010 new enhancement

[PATCH] Improved BuildingAI + implemented different Attack tags for BuildingAI

Reported by: sanderd17 Owned by:
Priority: Should Have Milestone: Backlog
Component: Simulation Keywords: patch
Cc: Patch:

Description (last modified by real_tabasco_sauce)

I tried to improve the buildingAI in the following ways:

  • Better arrow spread over time(see #2009)
  • Reduce the number of loops. With the old code, it would even try to shoot if no units were in the range, just to find on the end of the loop that it can't. This won't happen anymore as the timer is only started when a unit comes in the range.
  • Implement the RepeatTime and PrepareTime Attack tags as a building also has to prepare when starting to attack
  • Implement an "ArcherClasses" tag, where you can choose for which classes extra arrows will be rewarded
  • Implement the RestrictedClasses tag, and restricted buildings from attacking other buildings (just as a test, if you think it's no good idea, those changes can be reverted)
  • Implement forced attack. When an attack is forced by UnitAI (and the target can be reached), all arrows will have the same target.

I also added the BuildingAI to the quinquireme ships, but with ballistas as the only members for which extra arrows (or rocks) are counted. To compensate, I also reduced the attack values of the ship, but that would need further balancing.

Attachments (2)

buildingAI.diff (18.6 KB ) - added by sanderd17 11 years ago.
buildingAI_with_preferred_classes.diff (28.1 KB ) - added by sanderd17 11 years ago.

Download all attachments as: .zip

Change History (20)

comment:1 by sanderd17, 11 years ago

Summary: Improved BuildingAI + implemented different Attack tags for BuildingAI[PATCH] Improved BuildingAI + implemented different Attack tags for BuildingAI

comment:2 by sanderd17, 11 years ago

Description: modified (diff)

I'm wondering if there should also be an implementation for PreferredTargets.

comment:3 by historic_bruno, 11 years ago

Component: Core engineUI & Simulation
Milestone: BacklogAlpha 15

comment:4 by wraitii, 11 years ago

Some comments about buildingAI.js:
There's a needless empty line added line 178

At line181, you should probably call

var cmpIdentity = Engine.QueryInterface(entity, IID_Identity);
var targetClasses = cmpIdentity.GetClassesList();

only once before the loop, because this will be needlessly inefficient.

You use "some" a lot, is that efficient? I'd benchmark it against indexOf. In particular using "!some" seems like using it for something it's not designed for.
line 195: the brackets could be removed around "this.targetUnits.splice(index, 1);"

Using a uniform distribution for arrows seems much more natural to me too.

line 274: I dislike the use of a comment in such a situation without brackets, and it seems kind of obvious, so I'd remove the comment.

lines 273 and 277 should probably use ===

line 291 should use ++i.


Other comments: I'm not sure about the name "ArcherClasses", given other names are verbose already I'd go for "GarrisonArrowClasses" or something. I like the other changes, repeat time and preparetime are good, having restricted classes is good too. Restricting building to building shots makes sense for me for buildings that fire arrows, but we might not want it (and if we do, you should add it at the top level, for "template_structure.xml", and special-case removing it instead of what you're doing now).
Forced attack is a nice bonus which I wholeheartedly approve.

I don't really have an opinion on your templates change, ask Mythos_Ruler about those.

After some testing: seems to work fine, but I can't really force to attack, I just set a rallypoint (with towers). This could be a GUI limitation.

comment:5 by sanderd17, 11 years ago

  • empty line at 178, will remove
  • At line 181, I get the classes from a possible target entity. As I loop over the entities, I need to have that part in the loop
  • I didn't benchmark some vs indexOf, but it's a suggestion from leper (fight it out with him ;). I first used indexOf, but as I needed to compare two lists, that caused an extra loop (thus extra code and possible a speed loss).
  • line 195, will remove the brackets
  • line 274, that comment was there, but I'll remove it
  • lines 273 and 277, will replace it with ===, I didn't know it gave performance advantages
  • line 291, will use ++i

And setting a forced target is only possible for entities with UnitAI (ie ships and siege towers)

by sanderd17, 11 years ago

Attachment: buildingAI.diff added

comment:6 by michael, 11 years ago

Sounds like a nice patch.

With the risk of complicating things, how about a "MaxNumProjectiles" element that caps the number of projectiles from garrisoned units. Say, the fortress can garrison 30 units, but can only have a maximum of 20 arrows. Something like that. Maybe that should be a different ticket. Up to you.

comment:7 by sanderd17, 11 years ago

A new patch, including an implementation of preferred classes (not all arrows will be fired at the preferred class, but only a part).

I also changed all instances of "arrow" to "projectile" as requested.

And a MaxNumberOfProjectiles tag is also implemented.

Currently, the target can only be forced by entities with UnitAI, because I don't know how to register the needed messages.

comment:8 by historic_bruno, 11 years ago

Owner: set to sanderd17

comment:9 by sanderd17, 11 years ago

In 13670:

Improved building AI. Refs #2010

comment:10 by sanderd17, 11 years ago

Description: modified (diff)
Keywords: review removed

I commited the things that were clearly an improvement.

I didn't commit "forced attack", as it didn't work with entities that had no UnitAI. So that should be fixed first.

I also didn't commit the "restricted classes", as that would more or less work together with the "preferred classes", which wasn't really well done so far.

I did edit the quinquiremes to be on par with ballistas, statistics wise.

comment:11 by sanderd17, 11 years ago

In 13671:

fix coding style for buildingAI. Refs #2010

comment:12 by wraitii, 10 years ago

Milestone: Alpha 15Alpha 16

Might want to create a ticket for th GUI issue (I don't believe its been done et).

comment:13 by leper, 10 years ago

Milestone: Alpha 16Alpha 17

comment:14 by Itms, 10 years ago

Milestone: Alpha 17Alpha 18

comment:15 by leper, 9 years ago

Milestone: Alpha 18Backlog

comment:16 by Stan, 8 years ago

Owner: sanderd17 removed

comment:17 by Imarok, 5 years ago

Component: UI & SimulationSimulation

Move tickets to Simulation as UI & Simulation got some sub components.

comment:18 by real_tabasco_sauce, 6 months ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.