An emergency occurs if one or more of these statements are true:
- A lot of buildings are lost and a lot of people are killed.
- A certain amount of CCs/territory roots are lost.
- Over a long time: A lot of people are killed.
The emergency state is divided into three states:
- Initialization
- Behavior-specific
- Optionally: Return to normal
- All resources except those required to build a CC are tributed to the enemies + sending neutrality requests (Except in 1v1 or with fixed alliances)
- All AttackPlans are cancelled
- All units are ungarrisoned
- All own buildings are destroyed
- All units are divided into smaller armies (Based on the location, probably O(n^n)).
- Each of these armies is looking for an enemy nearby.
- Each army should kill enemies, but they should converge to one point, so at the end there is one big army.
- Two smaller armies that are nearby will be merged.
- If there are really no enemies left, build a CC/territory root if there are enough resources. Otherwise ask the allies for resources.
- If the AI really doesn't get any resources, it should resign.
- All units will retreat to one point
- Wait until all units are there, or a certain time has passed (E.g. 3-5 minutes)
- Then count all units that are at the meeting point. (=
$REMAINING
) - The units are collected there and "forced" to stay in a certain radius.
- If the AI is attacked and only a certain percentage of
$REMAINING
is left, resign. - If every neutrality request is accepted and there are no enemies left, go back to normal
- Wait for a certain timespan. After e.g. 90% of this time passed, ask for resources.
- If this timespan passed and the AI got enough resources to build a CC and have a bit of head start, go back to normal
- If it doesn't have enough resources, it will wait
n
times for a certain timespant
. Each time onet
passed, the AI once again asks for resources - If there are enough resources, go back to normal.
- Otherwise resign.
- Diplomacy will only go into a positive direction: No betrayals or breaking alliances
- The frequency of attacks will be reduced for a certain amount of time
- More defensive buildings will be built.
An aggressive AI could use flares to mark each unit that will be attacked next. The defensive ones could use it to mark the point to retreat to.
The AI could use the chat in the initialization of the emergency state to call for help. (E.g. Our enemies attacked me and devastated my empire, send help
)
After that, the aggressive AI could call for help in its last raid. (E.g. Will you join me in my last raid?
)
The defensive AI could ask for auxiliary troops at the retreat-point. (E.g. Send troops or I will perish!
or Do you remember our alliance, even in the darkest hour?
)
After that it could periodically ask for resources (E.g. I need resources to rebuild my empire, so we can conquer the world together!
)
After returning, it could thank all AIs that gave resources (Although this may be really chatty).
If the AI resigns, it could doubt the sense of an alliance, if there is no help between allies.
- How to model this mode?
- Should ships be used to bring units from e.g. islands to the island of the retreat-point?
- Should the aggressive AI use ships to move units?
- If there are own territory roots, retreat to one these.
- Otherwise collect at a temple
- The last resort is collecting the average x,z-Position of all units.
- Implement detection of emergency mode
- Implement initialization
- Implement behavior-specific actions AND "Return to Normal"
- Implement optional features
(Pseudocode-Like)
class EmergencyManager {
List<EmergencyDetector> detectors;
EmergencyHandler handler;
}
interface EmergencyDetector {
boolean detected(...);
}
// Structures+Units are lost
class EmpireAttackedDetector : EmergencyDetector {}
// Territory Roots are lost
class TerritoryRootCounter : EmergencyDetector {}
// Structues/Units are lost over a long time
class LongRangeDetector : EmergencyDetector {}
interface EmergencyHandler {
void handle(...);
}
class AggressiveHandler : EmergencyHandler {}
class DefensiveHandler : EmergencyHandler {}