Skip to content

Instantly share code, notes, and snippets.

@JCWasmx86
Last active December 1, 2021 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JCWasmx86/27d757d40fac65b15fecb6836444661e to your computer and use it in GitHub Desktop.
Save JCWasmx86/27d757d40fac65b15fecb6836444661e to your computer and use it in GitHub Desktop.
[Concept] Emergency mode for 0ad

Concept

Refs

#2195 #2644

What is an emergency?

An emergency occurs if one or more of these statements are true:

  1. A lot of buildings are lost and a lot of people are killed.
  2. A certain amount of CCs/territory roots are lost.
  3. Over a long time: A lot of people are killed.

How will the AI act in case of emergency?

The emergency state is divided into three states:

  1. Initialization
  2. Behavior-specific
  3. Optionally: Return to normal

Initialization

  1. All resources except those required to build a CC are tributed to the enemies + sending neutrality requests (Except in 1v1 or with fixed alliances)
  2. All AttackPlans are cancelled
  3. All units are ungarrisoned

Behavior-specific

Aggressive

  1. All own buildings are destroyed
  2. All units are divided into smaller armies (Based on the location, probably O(n^n)).
  3. Each of these armies is looking for an enemy nearby.
  4. Each army should kill enemies, but they should converge to one point, so at the end there is one big army.
  5. Two smaller armies that are nearby will be merged.
  6. If there are really no enemies left, build a CC/territory root if there are enough resources. Otherwise ask the allies for resources.
  7. If the AI really doesn't get any resources, it should resign.

Defensive

  1. All units will retreat to one point
  2. Wait until all units are there, or a certain time has passed (E.g. 3-5 minutes)
  3. Then count all units that are at the meeting point. (=$REMAINING)
  4. The units are collected there and "forced" to stay in a certain radius.
  5. If the AI is attacked and only a certain percentage of $REMAINING is left, resign.
  6. If every neutrality request is accepted and there are no enemies left, go back to normal
  7. Wait for a certain timespan. After e.g. 90% of this time passed, ask for resources.
  8. 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
  9. If it doesn't have enough resources, it will wait n times for a certain timespan t. Each time one t passed, the AI once again asks for resources
  10. If there are enough resources, go back to normal.
  11. Otherwise resign.

Going back to normal

  1. Diplomacy will only go into a positive direction: No betrayals or breaking alliances
  2. The frequency of attacks will be reduced for a certain amount of time
  3. More defensive buildings will be built.

Optional features

Map flares

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.

Chat

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.

Open questions

  1. How to model this mode?
  2. Should ships be used to bring units from e.g. islands to the island of the retreat-point?
  3. Should the aggressive AI use ships to move units?

Appendix

Defensive AI - Choose point to retreat to

  1. If there are own territory roots, retreat to one these.
  2. Otherwise collect at a temple
  3. The last resort is collecting the average x,z-Position of all units.

Milestones

  1. Implement detection of emergency mode
  2. Implement initialization
  3. Implement behavior-specific actions AND "Return to Normal"
  4. Implement optional features

Example modelling

(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 {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment