Overview
OpenFront’s alliance system enables temporary cooperation between players. Alliances are time-limited, require mutual consent, can be extended, and affect various game mechanics including attacks, trades, and diplomacy.Core Concepts
Alliance Properties
- Time-Limited: Alliances expire after a configured duration
- Bilateral: Require acceptance from both players
- Extensible: Can be renewed if both parties agree
- Breakable: Either player can break the alliance
- Embargo-Creating: Attacking creates automatic embargo
Alliance Implementation
TheAllianceImpl class manages alliance state and lifecycle:
src/core/game/AllianceImpl.ts
Player
The player who initiated the alliance request
Player
The player who received and accepted the request
Tick
The game tick when the alliance was formed
Tick
The game tick when the alliance will expire if not extended
number
Unique identifier for this alliance
Alliance Lifecycle
1. Request Phase
A player creates an alliance request:src/core/game/AllianceRequestImpl.ts
2. Acceptance/Rejection
The recipient can accept or reject:- Accept: Creates an
AllianceImplobject - Reject: Removes the request, no alliance formed
3. Active Alliance
Once accepted, the alliance is active until expiration or break:4. Extension System
Alliances can be extended if both players agree:src/core/game/AllianceImpl.ts
Both players must request extension for it to succeed. If only one requests, the alliance expires normally.
5. Expiration
When an alliance expires:src/core/game/AllianceImpl.ts
Alliance Executions
Alliance actions are implemented as executions:AllianceRequestExecution
src/core/execution/alliance/AllianceRequestExecution.ts
AllianceRejectExecution
src/core/execution/alliance/AllianceRejectExecution.ts
AllianceExtensionExecution
src/core/execution/alliance/AllianceExtensionExecution.ts
BreakAllianceExecution
src/core/execution/alliance/BreakAllianceExecution.ts
All alliance executions are single-tick operations that complete immediately in their
init() method.Friendship System
Alliances are part of a broader “friendship” concept:Game Mechanics Affected by Alliances
Attack Restrictions
Players cannot attack friendly players:src/core/execution/AttackExecution.ts
If an alliance is formed while an attack is in progress, the attack immediately retreats with no penalty.
Trade and Donations
Alliances enable resource sharing:Embargoes
Attacking a player creates an automatic embargo:src/core/execution/AttackExecution.ts
Bots don’t participate in embargoes since they can’t trade anyway.
Incoming Request Rejection
Attacking auto-rejects pending alliance requests:src/core/execution/AttackExecution.ts
Player Actions
TheGameRunner provides alliance-related actions:
src/core/GameRunner.ts
boolean
Whether the player can send an alliance request to the other player
boolean
Whether the player can break an existing alliance
AllianceInfo | undefined
Information about the current alliance status, if any
Configuration
Alliance behavior is configured through the game config:- Short: 3000 ticks (~5 minutes at 10 ticks/second)
- Medium: 6000 ticks (~10 minutes)
- Long: 12000 ticks (~20 minutes)
Best Practices
For Players
- Request Early: Alliance requests take time to accept
- Communicate: Use emojis/quick chat to coordinate
- Watch Expiration: Request extension before alliance expires
- Plan Breaks: Breaking alliances has diplomatic consequences
For Developers
- Check Friendship: Use
isFriendly()not justisAlliedWith() - Handle Timing: Alliances can form/break mid-attack
- Update UI: Show alliance status clearly
- Test Edge Cases: Alliance + team, alliance + embargo, etc.
Related Systems
- Intent/Execution - Alliance actions use execution pattern
- Game Loop - Alliance expiration checked each tick
- Pathfinding - Allied players may share vision