Group reform
Posted: Sun Feb 01, 2009 3:04 pm
The system of ship groups in Oolite is currently murky, confusing, and almost certainly broken in several hard-to-overview ways. I have a set of changes intended to address this, but I could do with some feedback.
The old system works like this: each ship has a group ID. If the group ID is 0, the ship is not a member of a group. If the group ID is the same as the ship's entity ID, the ship is in some contexts considered the leader of the group.
Group IDs are set in, at least, the following contexts:
Another issue is how it will change AI semantics. The following methods are particularly significant. (Note: “AI ship” below means the ship the method is being called on, i.e. the ship the AI is attached to.)
The only use of wormholeGroup in built-in AIs is in pirateAI.plist: "WITCHSPACE OKAY" = (wormholeEscorts, wormholeGroup);. In light of that a reasonable new behaviour would be to wormhole only the group (i.e., peers) and not the escortGroup, making wormholeEntireGroup equivalent to (wormholeEscorts, wormholeGroup). Another option would be to make wormholeGroup equivalent to wormholeEntireGroup. It sort of depends how these commands are used by existing OXP AIs, and what the authors thought they meant.
I guess I should, at some point, download every OXP in existence and index all their AIs and scripts. Maybe when EliteWiki is back on a real host. :-)
The old system works like this: each ship has a group ID. If the group ID is 0, the ship is not a member of a group. If the group ID is the same as the ship's entity ID, the ship is in some contexts considered the leader of the group.
Group IDs are set in, at least, the following contexts:
- All thargoids spawned by the system populator are one group, and all pirates spawned by the system populator are another group. Thargoid and pirate ships added by other means are not automatically added to a group.
- All escorts have their group ID set to the entity ID of their mothership. The mothership’s group ID is also set to its entity ID if it was previously zero, otherwise not. In addition, the mothership has a separate list of IDs of escorts. Some escort-related commands use this list, some use the group ID. In further addition, the escorts have the mothership set as their owner.
- Ships launched by a station using of the methods launchPolice, launchDefenseShip, launchScavenger, launchMiner, launchPirateShip, launchEscort, launchPatrol or launchShipWithRole: (but not launchShuttle or launchTrader) have their group ID set to the station’s entity ID. The station’s group ID is normally set to its own entity ID.
- If a ship attacks a member of its own group (and is not forgiven, which depends on a random roll and the bounty of the target), it is expelled from the group, unless the attacking ship is the leader of the group, in which case the attacked ship leaves the group.
- Missiles are put in the same group as their launcher.
- If a ship dies, and it has escorts, and its ID is reused for a new ship, the old ship’s escorts will think the new ship is their mummy. Conversely, if an escort dies, and its ID is reused, the old escort’s mothership will think the new ship is one of its escorts. (This kind of thing is a fundamental problem with the entity ID system, which is why I’ve been gradually moving away from it.)
- Groups are stand-alone objects which track their members.
- A ship can be a member of arbitrarily many groups, but also has a “main” group represented by its group property, and an “escort group” consisting of itself and its escorts. An escort’s group property is the escort group of its parent.
- A group may optionally have a leader, initially used for escort groups. The leader is always a member of the group.
- Each group has a name, purely to make debugging easier.
- It may be worth adding a separate “auxiliary group” for a station’s scavengers and miners.
- Group objects will be exposed to JavaScript. The current Ship.groupID property will be removed (with no deprecation period, since the underlying groupID property no longer exists). Additionally, the Entity.ID property will be deprecated, since I want to eventually eliminate all uses of entity IDs.
Another issue is how it will change AI semantics. The following methods are particularly significant. (Note: “AI ship” below means the ship the method is being called on, i.e. the ship the AI is attached to.)
- wormholeEscorts – old behaviour was to go through a list of element IDs for escorts, look up the corresponding entity for each ID and, if it’s a ship, set its target to the AI ship’s destination wormhole and send it an “ENTER WORMHOLE” AI message. Proposed new behaviour is to go through the AI ship’s escort group and do the same thing for each ship that isn’t the AI ship itself.
- wormholeGroup – old behaviour was to look for every ship whose group ID matches the AI ship’s entity ID, and tell it to wormhole as above. I’m not entirely sure what to do with this one, see below.
- wormholeEntireGroup – old behaviour was to look for every ship whose group ID matches the AI ship’s group ID, and tell it to wormhole as above. If the AI ship has escorts and is not a member of a wolfpack or thargoid swarm, this means the same as wormholeEscorts. If it is a member of a group other than its own escorts, it will wormhole the group but not the escorts. For a station/carrier whose group ID is its entity ID, this will wormhole all the carrier’s defense ships, patrol ships, miners, scavengers etc. Proposed new behaviour: wormhole the AI ship’s group and escortGroup.
The only use of wormholeGroup in built-in AIs is in pirateAI.plist: "WITCHSPACE OKAY" = (wormholeEscorts, wormholeGroup);. In light of that a reasonable new behaviour would be to wormhole only the group (i.e., peers) and not the escortGroup, making wormholeEntireGroup equivalent to (wormholeEscorts, wormholeGroup). Another option would be to make wormholeGroup equivalent to wormholeEntireGroup. It sort of depends how these commands are used by existing OXP AIs, and what the authors thought they meant.
I guess I should, at some point, download every OXP in existence and index all their AIs and scripts. Maybe when EliteWiki is back on a real host. :-)