Opened 7 years ago

Last modified 7 years ago

#4607 new defect

Petra: do not create trade routes through enemy territory

Reported by: Sandarac Owned by:
Priority: Should Have Milestone: Backlog
Component: AI Keywords:
Cc: mimo Patch:

Description

Currently, Petra may create trade routes straight through enemy territory if it has markets in disconnected pieces of territory, as it only tries to maximize trade gain when placing markets/setting up trade routes. This is especially noticeable on the random map "Empire", where every player starts with two civic centers that are on different sides on the map, and the AI will usually try to set up a trade route that crosses directly through enemy territory.

In theory, Engine.ComputePath() could be used, and the AI could check that every point in the returned array is in non-enemy territory (combined with checks that HQ.isDangerousLocation() is false for each point). Unfortunately, calling Engine.ComputePath() is very slow and causes noticeable lag, and it would have to be called multiple times whenever Petra is prospecting for a new trade route (which can be often), so it likely cannot be used to solve this.

Somewhat related: #3003.

Change History (4)

comment:1 by mimo, 7 years ago

As approximate fix, we may just check a straight line between the two markets for land trade route: in the checkRoutes function of tradeManager, taking N points (spaced every 50m or so) and checking that none are in enemy territory should work in most cases.

comment:3 by Sandarac, 7 years ago

phab:D600 / r19755 added the straight line check (which helps), but there are still cases where this is still very much an issue; traders do not follow the exact straight line between two markets, but rather the route they take is oval-shaped as they move back and forth between the markets. So traders can still end up in enemy territory, where they are subject to harm, and Petra will not prospect for a new route if its traders are repeatedly losing health.

In addition, the trade route that traders take may be in the range of enemy defensive structures, and again Petra will not adapt to this, but will continue training traders and sending them on the same route, effectively rendering Petra's trading useless.

comment:4 by elexis, 7 years ago

In r19902:

Petra: Move land traders to safety when a trade route is destroyed instead of leaving them idle in the open

Patch by Sandarac

Reviewed By: mimo

Differential Revision: ​https://code.wildfiregames.com/D730

Note: See TracTickets for help on using tickets.