Rainbowdesign Posted July 19, 2018 Share Posted July 19, 2018 Hey guys, I like to help a bit with the development of Oxygen not Included (oni). I am working with unity 3D now for about 5 years and i think there are some things that oni would really profit of. The first thing i like to introduce is scripting support. Including some snippets of code pros and cons and a manual on how to implement it. Benefits - The mayor benefit of scripts would be that at one it provides basic modding tools if implemented generously: Imagine you expose a function that can modify the underlying Gameset to the script. (Additional Note: I looked at the source code, It has no central gameset or anything comperabe i have trouble to find anything and i think it might be a bit harder to impossible to add something like a building with a function...) In that case the Modder could just use the function to change single entrys like the output of a building, or its costs, or the duration it takes to cure sickness. That way it would add rudimentary modding. - You could expose the start menu, or even better an in game menu or a console to expose scripts. This way a mod could add an universe of start condition and a way to execute scripts in game. - Scripts can be executed on regular events and change the gameflow Just imagine a script which cures or sickens all duplicants every ten turns. Or add or remove buildings on a certain turn . - much more potential When the team starts developing so things can be exposed the uses can be greatly multiplied. - Drawbacks are rather small but i would know 2: First of course scripting might be a security hole you need to know what you do not expose wrong functions. With external Lua support that should however only a small issue it would be hard to write malware in that sandbox. (And i heard cities: skylines does not even use a sandbox) The second is that heavy scripts can impact performance that is one more thing to be careful about. Snippets I wrote and described a snippet that can execute lua scripts the snippet does use moonsharp http://www.moonsharp.org/ Moonsharp is a lua interpreter written in c# means it is quick enough and it does not need special treatment it should even run in the webplayer. First you would need to add Moonsharp as plugin https://www.assetstore.unity3d.com/en/#!/content/33776 The code is much better readable when you insert it into visual studio Here is the first snipped the description is in the lines itself. Quote public void EvalText(string scriptCode, string functionName="StartScript") {//this is the Core of the scripting engine it does the actual work. Script script = new Script(); //Generating the script instance UserData.RegisterAssembly(); //registering the asseblys you need to add [MoonSharpUserData] to the data you want to expose more under http://www.moonsharp.org/objects.html script.Globals["CreateUnit"] = (Func<string, List<string>, objects>)CreateUnit; //exposing a function so it can be called from lua syntax is: Func<parameters, returntype> script.DoString(scriptCode); //The command to load scriptCode as module more under http://www.moonsharp.org/scriptloaders.html DynValue res = script.Call(script.Globals[functionname]); //Calling the function inside the code you should define a default value here More about dynvalue http://www.moonsharp.org/dynvalue.html } What you need more is way to load the string scriptcode from a file. Since this is nothing extraordinary and depents on your filestructure i will not go into details. Here is an example of a Lua script just using one function (i just directly copied it from my own code, it is just an example, newscript is a function which would start a newscript from a file): Quote function StartScript() gates() enemys() buildings() research() inventory() a= newscript("init","debugscript","startscript") end function gates() createunit("magate", { "owner=nature", "instantbuild", "specialpositionx=xmid", "specialpositiony=y90","targetmap=void" }); end function enemys() createunit("Alien_Tower", {"owner=hostile","instantbuild", "specialpositionx=xmid", "specialpositiony=y80","targetmap=void" }); end function buildings() createunit("Control_Center", {"owner=player","instantbuild", "specialpositionx=xmid", "specialpositiony=ymid","targetmap=void" }); createunit("light3", { "owner=player", "instantbuild", "specialpositionx=xmid", "specialpositiony=ymid" ,"targetmap=void"}); createunit("m1tank", { "owner=player", "instantbuild", "specialpositionx=xmid", "specialpositiony=ymid", "specialpositionadjustx=1", "specialpositionadjusty=6" ,"targetmap=void"}); createunit("m1tank", { "owner=player", "instantbuild", "specialpositionx=xmid", "specialpositiony=ymid", "specialpositionadjustx=-1", "specialpositionadjusty=6" ,"targetmap=void"}); createunit("m1tank", { "owner=player", "instantbuild", "specialpositionx=xmid", "specialpositiony=ymid", "specialpositionadjustx=3", "specialpositionadjusty=6" ,"targetmap=void"}); createunit("m1tank", { "owner=player", "instantbuild", "specialpositionx=xmid", "specialpositiony=ymid", "specialpositionadjustx=-3", "specialpositionadjusty=6" ,"targetmap=void"}); createunit("m1tank", { "owner=player", "instantbuild", "specialpositionx=xmid", "specialpositiony=ymid", "specialpositionadjustx=5", "specialpositionadjusty=6" ,"targetmap=void"}); createunit("m1tank", { "owner=player", "instantbuild", "specialpositionx=xmid", "specialpositiony=ymid", "specialpositionadjustx=-5", "specialpositionadjusty=6" ,"targetmap=void"}); end function outpostsite() createunit("Control_Center", {"owner=player","instantbuild", "specialpositionx=xmid", "specialpositiony=ymid","targetmap=void" }); createunit("Control_Center", {"owner=player","instantbuild", "specialpositionx=xmid", "specialpositiony=ymid","targetmap=void" }); createunit("Control_Center", {"owner=player","instantbuild", "specialpositionx=xmid", "specialpositiony=ymid","targetmap=void" }); end So long, essentially that is it. With this snippet i am sure you can add script support within a day, its fairly little work. I hope my code will be helpful. All code snippets were written by me. Greetings Rainbowdesign Link to comment https://forums.kleientertainment.com/forums/topic/93728-feature-script-support-c-code-and-implementation-manual/ Share on other sites More sharing options...
Morse Posted July 20, 2018 Share Posted July 20, 2018 Are you applying for a job or are you asking for modding support? It's hard to tell If it's the first, then probably it's the wrong forum. If it's the second, then it is probably too early. Without the stable API it's no point in discussing mods. Link to comment https://forums.kleientertainment.com/forums/topic/93728-feature-script-support-c-code-and-implementation-manual/#findComment-1066407 Share on other sites More sharing options...
babba Posted July 20, 2018 Share Posted July 20, 2018 On the topic of social community behaviour: I find it great that someone is willing to help and shows his ideas in a transparent way to the public. Good luck Rainbowdesign Link to comment https://forums.kleientertainment.com/forums/topic/93728-feature-script-support-c-code-and-implementation-manual/#findComment-1066463 Share on other sites More sharing options...
Rainbowdesign Posted July 20, 2018 Author Share Posted July 20, 2018 Are you applying for a job or are you asking for modding support? It's hard to tell If it's the first, then probably it's the wrong forum. If it's the second, then it is probably too early. Without the stable API it's no point in discussing mods. Hahaha good one i posted first in the general discussion forum and they are the same opinion: Wrong forum should be in suggestions I wrote Klei that i would write code for them if they want to but Jan said if they want that offer they will answer otherwise not. Well i hope that they pick the code up and implement it but by now i wrote the whole class already so its about the double code now and adapted for oni. I look into the modloader for a way to get it in without Klei... But i must also say that i feel the oni is programmed in a very hard to change way so much hard coded and to lets say add a building with the modloader it takes 3-4 different places where you need to add stuff. Link to comment https://forums.kleientertainment.com/forums/topic/93728-feature-script-support-c-code-and-implementation-manual/#findComment-1066472 Share on other sites More sharing options...
babba Posted July 20, 2018 Share Posted July 20, 2018 I guess a lot of stuff is extreme, as the game utilizes only one cpu core truly and they are always battling the FPS cpu load for all the players. Ive never played a game before which has spent such a great effort on temperature simulation and other handled stuff in the game. I built a dedicated PC just for single core games like ONI and Cities Skylines ( + 2 million peeps map ). When I save an ONI game its actually one of the few times where my giant cpu aircooler starts running for a few seconds ( Noctua nhd15, 1.3 Kilo cooler ), must be some insane compression/calculations on saving a game. Loading a game has been improved, but if every tile is built with lots of transport systems and automation with + 100 dupes results in 2-5 minute loading time, fast ssd`s, no matter if one has 32 or 256 gigs of ram in the system with the fastest single core utlilization ( intel i7 or i9 turboboost cpus with as less cores as possible, turbo clock max ghz on one core and as much cache as possible ). Link to comment https://forums.kleientertainment.com/forums/topic/93728-feature-script-support-c-code-and-implementation-manual/#findComment-1066485 Share on other sites More sharing options...
Rainbowdesign Posted July 20, 2018 Author Share Posted July 20, 2018 14 minutes ago, babba said: When I save an ONI game its actually one of the few times where my giant cpu aircooler starts running for a few seconds ( Noctua nhd15, 1.3 Kilo cooler ), Try to play a 700*500 map and tell me how much memory you need Link to comment https://forums.kleientertainment.com/forums/topic/93728-feature-script-support-c-code-and-implementation-manual/#findComment-1066488 Share on other sites More sharing options...
babba Posted July 20, 2018 Share Posted July 20, 2018 I wish I could get back to the original map size which was 4x bigger on the vanilla game , I dont want to get in to mod stuff with ONI. You believe that playing in 128 x 128 pixels would make the game faster ? Need to check that sometime `` Coffee Break now... Link to comment https://forums.kleientertainment.com/forums/topic/93728-feature-script-support-c-code-and-implementation-manual/#findComment-1066489 Share on other sites More sharing options...
Rainbowdesign Posted July 20, 2018 Author Share Posted July 20, 2018 You dont need to mod something for the mapsize all you need to do for that is to edit \OxygenNotIncluded\OxygenNotIncluded_Data\StreamingAssets\worldgen\worlds\Default.yaml worldsize: X: 384 Y: 512 But be aware the amount of geysers stay the same making the game quite a bit harder. Link to comment https://forums.kleientertainment.com/forums/topic/93728-feature-script-support-c-code-and-implementation-manual/#findComment-1066490 Share on other sites More sharing options...
babba Posted July 20, 2018 Share Posted July 20, 2018 Thanks man, Im afraid I know that. Because ONI has some crashes every now and then ( which the devs fix pretty fast so far, at least for me ), I wont mess with map sizes. Want to avoid more possible crash causes and avoid then being unsure what the problem is. I messed with game resolutions, no fps impact at all here. Graphic card is only working at 3% with the game load maxed out. You could sell an ONI mod which loads the gpu or makes use of multiple cores, I`ll be your first customer...if it runs stable. Probably they want to employ you if you have those skills, without having actually doing hardcore code work on the game from the "inside". Coffeeeeeeeee ! Link to comment https://forums.kleientertainment.com/forums/topic/93728-feature-script-support-c-code-and-implementation-manual/#findComment-1066493 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.