Author Topic: Ai + Command Packets  (Read 2235 times)

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3238
Ai + Command Packets
« on: March 22, 2010, 06:50:21 AM »
So lately I've been dissatisfied with some of the behaviors caused by various AI functions.  Specifically, mining groups.  I really don't like how AI-controlled Cargo Trucks will just stop moving if ore storages are full.  It'd be much smarter if they just waited on the Smelter dock so they could unload their cargo the moment storage is not full.  I'm hoping the command packet ctMoCargoRoute will allow an AI player to more accurately emulate the ore-hauling behavior used by human players.  Any idea how I can use command packets, though?  Info on how to issue them to units, what arguments would be needed, etc., would be useful.
"As usual, colonist opinion is split between those who think the plague is a good idea, and those who are dying from it." - Outpost Evening Star

Outpost 2 Coding 101 Tutorials

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Ai + Command Packets
« Reply #1 on: March 22, 2010, 09:51:51 PM »
Umm, first, have you tried setting the proper rect for the mining group? It controls where the cargo trucks wait when the smelters are full. You can place that rect around the dock area.
 

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3238
Ai + Command Packets
« Reply #2 on: March 22, 2010, 10:29:16 PM »
Yes, but I think you missed the point Hooman.  I want the AI to behave more like a human and less like an AI.  Just having the Cargo Trucks park closer to the Smelter doesn't really deal with my underlying issue.
« Last Edit: March 22, 2010, 10:30:08 PM by Sirbomber »
"As usual, colonist opinion is split between those who think the plague is a good idea, and those who are dying from it." - Outpost Evening Star

Outpost 2 Coding 101 Tutorials

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3238
Ai + Command Packets
« Reply #3 on: March 29, 2010, 05:12:39 PM »
So, uh, any ideas?

Anybody?

I'm not asking for much... At least, I don't think I am?
"As usual, colonist opinion is split between those who think the plague is a good idea, and those who are dying from it." - Outpost Evening Star

Outpost 2 Coding 101 Tutorials

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Ai + Command Packets
« Reply #4 on: March 30, 2010, 01:48:58 AM »
It's mostly just a matter of figuring out the stuct used for each command packet type, and then filling in all the struct info in the right place in memory. When the time comes, the game will try to execute the next one in the queue. It sounds like you have the easy case of a new custom level too.


Check out the pack of text files on Internal Info that was posted with the OllyDbg .udd file. The main one of interest is DataStructure CommandPacket.txt. That should tell you what all the types of command packets are, and the struct/layout information is fairly extensive, although not quite complete. Mostly the missing information seems to be for fields that can be ignored, or are only used by triggers and groups, which it sounds like you're trying to avoid anyway.

You can also check out the Player information from that pack, although, the ForcedExport project will likely have more up to date information. The main pieces of information are the memory locations and offsets you'll need.

Code: [Select]
class Player {
  // ...
  CommandPacket cp[16]; // 0x4C8
  // ...
};

// ...
// extern Player player[7]; // 0x56EF1C [TethysGame.Player[7]]


You'll notice there are 16 slots for command packets. They form a circular buffer. Every 16 processing cycles, it loops back to the beginning. There is a delay between the one being filled, and the one being executed. This is mostly noticable in multiplayer. That delay gives the packet a chance to be sent to the other computers, so the game doesn't need to constantly pause and wait, but adds that latency, where you're units don't respond right away when you click.

I don't seem to have a description of the processing intervals handy, but I think it was something like every 4 ticks it would process a new packet. Hence, you'd index the packets as:
Code: [Select]
cpIndex = (tick + cpTickOffset) / 4;
The cpTickOffset depends on what you're doing exactly. If you're writing the packet, versus reading one to be excuted. I guess try a value of 0, and if that doesn't work, try the other numbers below 15 until it does. Watch the latency though, as more than one value might work, but will have higher latency.


You should be able to just fill in the command packets in AIProc, or a trigger callback or something. Just make sure you do the same on all computers so the game doesn't go out of sync. If you're filling in these structs in AIProc or equivalent, they won't be replicated over the network like player commands are. That function runs after the packet replication happens for the current cycle. (I think, it's been a while).

Basically, that method will work well for a custom level that executes symmetrically on all machines. Don't try that technique from a custom mod that not all players have loaded though. But, it sounds like you're going for the easier custom level approach.

 

Offline evecolonycamander

  • Hero Member
  • *****
  • Posts: 602
Ai + Command Packets
« Reply #5 on: April 03, 2010, 03:56:38 PM »
im not sure but my idea may work just have each unit by its self wait on the dock at the same time
« Last Edit: April 03, 2010, 03:56:52 PM by evecolonycamander »
''The blight cant get us up here!''
-famous last words
--------------o0o--------------
Outpost 2: EoM project status: Re-planning

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Ai + Command Packets
« Reply #6 on: April 03, 2010, 06:52:15 PM »
They'd just push each other off. If you did this with a mining group, the move commands would probably keep getting issued, and they'd keep fighting over who was on the dock. That kind of senseless motion makes the AI look dumb, and is also a little annoying to watch.