Opened 5 years ago

Closed 5 years ago

Last modified 3 months ago

#2749 closed enhancement (fixed)

[PATCH] Ceasefire

Reported by: stanislas69 Owned by: sanderd17
Priority: Should Have Milestone: Alpha 19
Component: UI & Simulation Keywords: patch
Cc: Patch:

Description

Currently you can't set a time for the players to be unable to attack each others. I used to play with that on other games and I found it interesting, cause you have a stronger economy and you can make more interesting battles.

It's not really needed so nice to have.

How I see it :

_ Buttons on the game setup menu (15-25-45min) _ A Timer near the FPS counter with the time remaining _ Complete inability to attack your enemy (This should be a different state than ally cause no shared vision, and no winning if both on the same team.

Attachments (9)

t2749_prevent_neutral_players_from_attacking_each_other.patch (2.3 KB) - added by elexis 5 years ago.
Implemented that neutral players can't attack each other with the code changes suggested by sanderd17 above. Tested and boats, CCs and units won't attack and can't start capture attacks. As soon as one sets the neutral player to enemy, both diplomacy states will be reset to enemy and attacks start immediately. Not sure about the distribution of capture points though.
t2749_ceasefire_v1.patch (32.1 KB) - added by elexis 5 years ago.
t2749_ceasefire_v2.patch (34.0 KB) - added by elexis 5 years ago.
topright_corner.jpg (32.6 KB) - added by elexis 5 years ago.
The following patch will also move the fps + ceasefire counter and ingame + realtime overlay to the right, so that all tech upgrades are displayed properly.
t2749_ceasefire_v3.patch (31.2 KB) - added by elexis 5 years ago.
t2749_ceasefire_v3.2.patch (37.8 KB) - added by elexis 5 years ago.
t2749_ceasefire_cleanup.patch (6.6 KB) - added by elexis 5 years ago.
(1) Shows ceasefire message for observers; (2) fixes GuiInterface? test error caused by missing CeasefireManager?; (3) cleans some code in CeasefireManager?.
t2749_ceasefire_cleanup_v2.patch (7.1 KB) - added by elexis 5 years ago.
Same patch as the other cleanup before, but also does more simplifications, (4) remove two unused variables and (5) removes some unneeded brackets.
t2749_ceaefire_add_3minute_limit.patch (1.8 KB) - added by elexis 5 years ago.
Adds another ceasefire timeout option (3 minutes).

Download all attachments as: .zip

Change History (27)

comment:1 Changed 5 years ago by leper

Component: Core engineUI & Simulation

Probably better phrased as ceasefire.

Also see #77.

comment:2 Changed 5 years ago by Erik Johansson

Summary: [GAMEMODE] Peace TimeCeasefire

comment:3 Changed 5 years ago by elexis

According to leper and sanderd17, the best way to implement this is to make all players neutral for that time and to prevent neutral players from attacking each other (like allies).

Some relevant code: GuiInterface::1742 and Capturable::67,77,119.

Changed 5 years ago by elexis

Implemented that neutral players can't attack each other with the code changes suggested by sanderd17 above. Tested and boats, CCs and units won't attack and can't start capture attacks. As soon as one sets the neutral player to enemy, both diplomacy states will be reset to enemy and attacks start immediately. Not sure about the distribution of capture points though.

Changed 5 years ago by elexis

Attachment: t2749_ceasefire_v1.patch added

comment:4 Changed 5 years ago by elexis

Keywords: patch review added
Milestone: BacklogAlpha 19
Priority: Nice to HaveShould Have
Summary: Ceasefire[PATCH] Ceasefire

comment:5 Changed 5 years ago by elexis

Description for the patch above:

Logic: -When ceasefire starts, all enemies will be set to neutral. -Neutral players can't attack each other. -While ceasefire is active, you can tribute resources, but not change the diplomacy or request allied attacks. -When ceasefire ends, all earlier enemies will be set back to enemy and the diplomacy options are enabled again. -When reporting the game to the wildfiregames server, report ceasefiretime too.

New Options: -An option in the gamesetup allows you to chose the ceasefire timeout in minutes (0, 5, 10, 15, 20, 30, 45, 60). This option will be saved correctly with persist match settings. For quick debugging, a 15 second ceasefire timeout has been added. -In the game settings, there is an other option that enables an overlay counter.

Countdown Messages: -While ceasefire is active, an optional overlay counter will be displayed at the top right. -For the last 10 seconds, a message will appear in the middle of the screen ("Ceasefire will end in %(time)s") -When ceasefire stops, another message will appear for 5 seconds ("Ceasefire has ended!") -In the diplomacy tab, a counter will be displayed too ("Time remaining until ceasefire is over: %(time)s.")

Tests -Tested with r16605. -Works with teams locked. -Works if a player resigns before ceasefire has ended.

Open questions

  1. The code should be refactored and moved into a single component CeasefireManager?, since StartCeasefire? (in LoadPlayerSettings? in the player component) and GetCeasefireTime? (in GetSimulationState? in GuiInterface?) must be called for only one player (currently the last player). FIXED
  2. Why is displaying the chat notification ("You have declared war on player X") slow? They immediately start fighting after ceasefire ended, but the chat messages take a while. #3222
  3. This patch cleans some code in gamesetup.js for scenario maps. Maybe add a ceasefire option to atlas and let scenario maps determine the ceasefire timeout?
  4. Send a message when the ceasefire starts / ends? Maybe the AI can use it. Yes.

This patch will fix #3195 too :-)

Last edited 5 years ago by elexis (previous) (diff)

Changed 5 years ago by elexis

Attachment: t2749_ceasefire_v2.patch added

comment:6 Changed 5 years ago by elexis

Patch works for r16614.

-Refactored. Moved the ceasefire code to a new component called CeasefireManager?. -Should support activating ceasefire multiple times (will extend ceasefire then). -Simplified loops using GetAllPlayerEntities?()

Notice that gaia doesn't abide ceasefire.

Tested with two instances of 0ad, one host and client. Tested rejoining too and surprisingly no oos on rejoin.

Changed 5 years ago by elexis

Attachment: topright_corner.jpg added

The following patch will also move the fps + ceasefire counter and ingame + realtime overlay to the right, so that all tech upgrades are displayed properly.

Changed 5 years ago by elexis

Attachment: t2749_ceasefire_v3.patch added

comment:7 Changed 5 years ago by elexis

The third version of the patch has the following changes:

[x] AI doesn't attack anymore before ceasefire is over (At least in all my testcases) [x] Chat messages slow (cause identified and patch attached #3222) [x] "You are now at war with player X" was shown for allies, not enemies. [x] Moved all overlays (fps, ingame time, realtime, ceasefire countdown) see http://trac.wildfiregames.com/attachment/ticket/2749/topright_corner.jpg [x] Sends an internal message when ceasefire starts or stops. Will probably be needed for AI. [x] using cmpTimer.GetTime?() instead of GetSimState?().timeElapsed [x] changed "Ceasefire has ended" message to "You can attack now" (the other message accordingly) [x] fixed missing semicolons [x] updated wrong comment in CeasefireManager?.js L49

With this patch I couldn't reproduce the issue that the last patch had, where chat messages don't appear at all. With this version they appeared in each of my tests.

Changed 5 years ago by elexis

Attachment: t2749_ceasefire_v3.2.patch added

comment:8 Changed 5 years ago by sanderd17

Owner: set to sanderd17
Resolution: fixed
Status: newclosed

In 16624:

Add optional ceasefire time to the game. Patch by elexis. Fixes #2749

comment:9 Changed 5 years ago by sanderd17

Keywords: review removed

Changed 5 years ago by elexis

(1) Shows ceasefire message for observers; (2) fixes GuiInterface? test error caused by missing CeasefireManager?; (3) cleans some code in CeasefireManager?.

Changed 5 years ago by elexis

Same patch as the other cleanup before, but also does more simplifications, (4) remove two unused variables and (5) removes some unneeded brackets.

comment:10 Changed 5 years ago by elexis

Resolution: fixed
Status: closedreopened

Reopened as the test is currently broken. The patches above fix it and clean the code as well.

comment:11 Changed 5 years ago by elexis

Keywords: review added

comment:12 Changed 5 years ago by elexis

I think the IsOwnedByNeutralOfPlayer? check in UnitAI.prototype.CanAttack? should be removed as well, since neutral players aren't supposed to be able to attack each other.

comment:13 Changed 5 years ago by elexis

Before its forgotton i post it here:

(19:36:09) sanderd17: mimo, I think it's safe to remove the IsNeutral?* from (UnitAI.js) 5586, and change 5588 to IsOwnedByAlliedPlayer?. That would make neutral players only attackable when they attacked, and not make allied players attackable.

comment:14 Changed 5 years ago by mimo

In 16656:

fix attackable players in unitai, refs #2749

comment:15 Changed 5 years ago by sanderd17

Resolution: fixed
Status: reopenedclosed

In 16657:

Cleanup some ceasefire code. Patch by elexis. Fixes #2749

comment:16 Changed 5 years ago by sanderd17

Keywords: review removed

Changed 5 years ago by elexis

Adds another ceasefire timeout option (3 minutes).

comment:17 Changed 4 years ago by elexis

In 17814:

Prohibit user-initiated diplomacy-changes in the simulation while ceasefire is active, refs #2749.

comment:18 Changed 3 months ago by elexis

In 23087:

Refactor session lobby bot client code to use object orientation, refs #5387.

Adapt rating score for exploration score and add comment to keep calculateExplorationScore and calculateScoreTotal in sync following rP14752 (following the formula in rP12914 and rP14098 being otherwise in sync with the summary screen measures), refs #686.
Adapt rating score for captured entities and add comment to keep calculateMilitaryScore in sync following rP18395, refs #3216, rP16550.
Adapt rating score for trade and vegetarian food and add comment to keep calculateEconomyScore in sync following rP19584/D494 and rP20543/D1052, refs #3948.
Remove ceasefire sending from the client from rP16624 since the bot doesn't record it and since ceasefire time is expected to be 0 after a 1v1 was decided, refs #2749.
Resolve column value computation fragmentation and remove unneeded intermediary object encoding following rP14703, refs #686.
Remove hardcoding/duplication of unit and structure classes and send domesticUnitsTrained too, refs rP23086/D2384.
Move session code including the two globals to a separate folder so as to maximize separation of and ease distribution without lobby code.
Migrate useless ugly trailing commas from rP14098, to be removed in a patch modifying the bot code.

Differential Revision: https://code.wildfiregames.com/D2385

Note: See TracTickets for help on using tickets.