Jump to content

Adding a "restart" option (for random maps)


jonbaer
 Share

Recommended Posts

Was trying to patch this myself but could not get much beyond the GUI bit.  Essential I didn't like the way some random maps were setup initially and wanted to skip resigning/existing and just restart (or more specifically regenerate the map) - but I could not get the game to restart w/ the same attributes using this bit:

Engine.StartGame(g_GameAttributes, Engine.GetPlayerID());
    Engine.SwitchGuiPage("page_loading.xml", {
        "attribs": g_GameAttributes,
        "isNetworked" : g_IsNetworked,
        "playerAssignments": g_PlayerAssignments
    });

I realize MP setup would not be ideal for this but is this something that is possible on a single user game or is it just not that simple to restart programmatically like that?  Could this option be added @ some point?

Screen Shot 2016-10-13 at 1.17.28 AM.png

  • Like 4
Link to comment
Share on other sites

Is it intended to restart the exact same match again? If you randomize the "Seed" value, you should get another generation of the same random map. (Also the "matchID" should be unique for every game.). (And you should also make sure to call EndGame() or whatever is used currently to exit the game properly (without killing the application (in case that isn't already done by the starting of a new game)).

Link to comment
Share on other sites

Ah Engine.EndGame(); got me somewhere.  What it looks like happens is g_GameAttributes don't actually populate correctly (since the new game leaves me on Observer mode) + it seems that the seed is the same, so it looks like a few things do need to be handled manually.  I'd rather this be done proper though (not a hack) should I put this together as a mod or submit a patch? (not 100% sure if a mod would work in this case).

EDIT: OK this is exactly what worked for me, will attach patch shortly ...

function restartGame() 
{
    let playerId = Engine.GetPlayerID();
    let gameAttributes = g_GameAttributes;
    gameAttributes.settings.Seed = Math.floor(Math.random() * Math.pow(2, 32));
    Engine.EndGame();
    Engine.StartGame(gameAttributes, playerId);
    Engine.SwitchGuiPage("page_loading.xml", {
        "attribs": gameAttributes,
        "isNetworked" : g_IsNetworked,
        "playerAssignments": g_PlayerAssignments
    });
}

EDIT: Patch attached (YMMV)

 

restart-menu.diff

Edited by jonbaer
  • Like 1
Link to comment
Share on other sites

Thanks for testing, I saw an old (2+ years) post on this function ... 

But didn't find the Trac ticket in mention there, I realize the multiplayer scenario for a restart would be a bit more complicated, so maybe the dialog just says you can not restart an multiplayer game or something.  I don't play multiplayer enough to know.    

Link to comment
Share on other sites

12 hours ago, jonbaer said:

Thanks for testing, I saw an old (2+ years) post on this function ... 

But didn't find the Trac ticket in mention there, I realize the multiplayer scenario for a restart would be a bit more complicated, so maybe the dialog just says you can not restart an multiplayer game or something.  I don't play multiplayer enough to know.    

Is possible to just disable the button when Multiplayer? No need for dialogue then (maybe just tooltip).

Link to comment
Share on other sites

Yes.  If something like this is called ... Engine.GetGUIObjectByName("menuRestartButton").enabled = !g_IsNetworked;

Are you on OSX by any chance?  I realize I get the following error after ~20 or so restarts so it might be that EndGame() might not clean up something properly ... ERROR: Failed to create initial buffer. OpenAL error: Invalid Value

You lose entire audio output :-\

Link to comment
Share on other sites

7 hours ago, jonbaer said:

Yes.  If something like this is called ... Engine.GetGUIObjectByName("menuRestartButton").enabled = !g_IsNetworked;

Are you on OSX by any chance?  I realize I get the following error after ~20 or so restarts so it might be that EndGame() might not clean up something properly ... ERROR: Failed to create initial buffer. OpenAL error: Invalid Value

You lose entire audio output :-\

I have not try more than 1 restart. I can try and test. I am on Windows 10 (unfortunatly)

Link to comment
Share on other sites

  • Someone should find that ticket or make a new one if there is none.
  • Don't forget the matchID: g_GameAttributes.matchID = Engine.GetMatchID();
  • If you played with AIs, you should reinit the AISeed as well
  • gameAttributes.settings.Seed = Math.floor(Math.random() * Math.pow(2, 32)); -> That 32 might change again, it were better to unify these 3 attribute changes to a new helper function in gui/common/ and use that helper function in the gamesetup and this new place
  • Indeed the button must be disabled for multiplayer. Multiplayer restarting would be handy, but is more involved as there would have to be new network packets telling the clients to reconnect.
Link to comment
Share on other sites

IMO an option in the gamesetup to chose the seed (for non rated games) would be nice to have (with a button like in Atlas to randomize the seed and a vidget to type a specific seed in/show the seed).

The default should be "random seed" or something (No seed shown).

Restarting a match should also have an option to keep all seeds, only that of the random maps or reroll all (default) IMO.

Link to comment
Share on other sites

What would be super ideal is if you went to Save and could actually just save the entire map setup (vs. the game) to the Skirmish menu somehow (thus "saving" the seed w/o needing to explicitly know it).  I am not even sure if that is possible (to dump a .pmp/.xml like that) but some random maps create really good setups and (currently) that it is a real pain to debug the seed (via the replay file) and need to save into Atlas, etc. 

BTW I still don't know, are GUI related options like this best done as patches or mods?

Link to comment
Share on other sites

@jonbaer apparently created a ticket after the last message in this topic: #4284 (linking it here for those unaware and for future reference).

I am not even sure if that is possible (to dump a .pmp/.xml like that)

Why should you dump the entire map data if you just want to save the seed (+maybe gamesetup settings)?

BTW I still don't know, are GUI related options like this best done as patches or mods?

If it's expected to be included into the game (like in this particular case) then a trac ticket + patch (or a link to github branch/compare page) is welcome and desirable. If it's something experimental, then it's better to package as a mod first to gather some feedback and see if there is an interest in the feature.

 

On a different note, seeing this topic title (and 'Restart' menu option on the screenshot above) I'd rather expect that it will start a new match (rather than return to gamesetup) with exactly the same settings (random map seed in particular). I'd call the implemented behaviour 'Back to gamesetup' or something (but I can't came up with a better name). Don't take this as a critique, it's just a subjective opinion/expectation. 

Edited by fcxSanya
Struckthrough the gamesetup note caused by misundestanding of the patch
  • Like 1
Link to comment
Share on other sites

I don't know if this will relate to all cases but this is just my own example, the one random map I enjoy playing the most is Archipelago (revealed/explored) for it's geostrategic nature (markets, chokepoints, islands, etc), and every now and then there is very good re-playable map it generates which I want to save.  Outside of being a developer this type of option is a bit hard to do w/o having to save the entire game.  Setting this up in Atlas is a bit of work as well.  

BTW w/ this patch you don't go back to the game setup, it will just re-seed and bring you to the loading screen w/ those game attributes.  I see what you mean though - a "Restart" in theory is not a "Reset" (all attributes the same) - and might lead to confusion(?) ... someone would say "I selected Restart but it gave me a different map", etc.  

  • Like 1
Link to comment
Share on other sites

@jonbaer

>  <...> and every now and then there is very good re-playable map it generates which I want to save

I agree that this might be desirable to replay the favorite random map instances, but shouldn't be saving only the seed (+map name) enough to renerate the same instance?

>  <...> you don't go back to the game setup

Oh, I didn't try the patch itself and re-reading the topic now I'm not sure where I've got that, probably was confused by last two posts by you and FeXoR where you disussed selecting/saving RMS seeds.

Link to comment
Share on other sites

Interesting, yeah I think when I initially thought of this I set out on the idea that I could somehow magically generate a large preview of seeded maps to see what they looked like (under Archipelago) and then I previously asked where to find the seed ... https://wildfiregames.com/forum/index.php?/topic/21055-random-maps-question-random-seed/

What I get afraid of is people just not understanding what the seed means (it's more for programming terms).  Imagine I want to share the map w/ you, I know you would know what the seed does and where to place it but in other ways it would be ideal to just people able to save the seed under a name and send a .zip that includes map info, seed, preview, etc.

I don't even know if what I am thinking of applies to anything really outside of the Archipelago scripts so I am still thinking about how to handle in the UI.  

Based on the graphics you show from the other games it would make sense to extend a Map Type to be where you could seed.  Are there any open Trac tickets for that?

  • Like 2
Link to comment
Share on other sites

@fcxSanya To generate a random map the seed, the player data (slot, civ, team for each player) and the map size is needed (and ofc. the random map script itself).

(And I also would assume that "restart match" or something generates the same map and seed)

@Lion.Kanzen Please don't call it "code", it's the seed ;) Nothing magical going on here, it's basically just the index of the first used bit in that - quite long - (pseudo) random long raw of bits where all the random values then come from (sometimes it's given as hexidicimal rather than decimal so it may look like a code).
If I'm to technical, ignore me ;p

@jonbaer While this is possible in theory generating a map needs several seconds (like 1-80, I'd guess about 10-20 on an average system, normal or medium map size) and to loading it in the engine to render and then take a screenshot again takes several seconds (I'd say about 10?).
So it might take quite some time to take screenshots of, say, the first 100 seeds of a random map ... like 2 hours CPU lock.
I'm not against adding such a feature but don't use it as an argument "those random maps generate to slow"... (And I'm quite sure if we implement an actual generation for the given player settings as preview I will point back to this post ;p)

Edited by FeXoR
Fixed a typo
Link to comment
Share on other sites

I agree, right now I am trying to add a little checkbox to the restart dialog to specify if you want to reseed.  This seems to be the best (of both worlds) options.  I started thinking it might not even be in the best interest to propose game (map previews) in cases where players don't want an explored/revealed map, in which case my "research" into this might just be one-case hack in cases where I just want to see the variation of the maps I enjoy playing.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...