Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 14 15 [16]

Author Topic: LCS 4.12.34 Now With a Save Editor (And other flags... sort of)  (Read 38335 times)

IsaacG

  • Bay Watcher
  • Mad Engineer
    • View Profile
    • JJoseph on Deviantart
Re: LCS 4.12.33 Now With a Save Editor (And other flags... sort of)
« Reply #225 on: February 02, 2019, 01:36:20 pm »

You've moved a lot of things around in the code, but you should really be focusing on moving things out of the code.
That is the goal.  Back in Nov 1, 2017, 4.12.04 I introduced 196 external files of formerly hard-coded data.
I've mixed feelings about a string:string mapping system.  Typos can bungle things up real fast, I'll have to include a fail-fast setup where if a new creature/weapon/etc. is created, but has no way to spawn in-game, it autogenerates a warning.  Maybe even refuses to load.  My experience with modding, spending more time trying to spawn my new armor than I spent making it.

'cuz if I want to build it, I have to research it.  But to research it I have to mod in a new research category for the new equipment, then I have to add it to the list of items that can be manufactured at the heavy-armor smithing station, and then I have to calculate the influence quality levels have on the final product even though I don't want it to have quality levels to begin with.  And then, even though I copied the texture straight from Samurai Armor, it spawns without an inventory icon, and whenever someone wears it it appears on the character in solid white, but Samurai Armor isn't solid white, despite this being a line-for-line copy of Samurai Armor.  Then the game crashes whenever I have a Shek player character try on the pants, so I upload to the Steam workshop version 0.4 where Shek aren't able to wear the modded pants.  It wouldn't be so bad, but the game map is enormous, and starting up the game requires loading the entire map, so there's no fast way to test minor changes.  Still, it's the easiest, most intuitive modding system I've ever used.
Whatever you do, strongly avoid any desire to add new features. Turn code into external data, and let others play with the data to make mods. This is your most efficient way forward.
Absotively
For the naming convention, I think adding in some prefixes for the cpp file and function name that use the strings would be advisable. It would make things much clearer than just "WILL_STEAL" since you've now removed the semantic information that this had something to do with "sleepers", which makes it less clear what the string is intended to be for. For example, if the "WILL_STEAL" string is used in sleepers.cpp by a function called actions (for example), you could name it "SLEEPERS__ACTIONS__WILL_STEAL". So, just be reading the name you can tell where to look for uses of that string (note the double-underscore between parts of the name to clarify what's what).
Valid consideration.  The context information is valuable, but I do not believe it should be tied to cpp filenames.  The whole file structure is based off C style procedural programming.  e.g. The code that determines news headlines is the same code that transfers those headlines to the screen.
It leads to a fair amount of redundancy and duplicate code.  Just separating these from one another has drastically reduced filesizes.
Ideally, the code that generates the string "X reaches to find xer head missing." doesn't know or care whether it's being used by the sleeper prompt, combat log, or news headline.  There are about six thousand lines of hard-coded text still remaining in LCS.  The data structure that will hold these will probably be grammar based.
After that, make it so that it reads the string:string mappings from a JSON file, and translators can then just mod a text file to make language-specific full conversions, no compile needed.

However, when that happens, I'd suggest sill maintaining a hard-coded list of "known" strings in the code (by their "name"), which the JSON-strings get loaded against. Then, each code-type mod can maintain their own list of known strings, and there could be a command-line option to just spit out the "list of strings" (e.g. "lcs -dumpstrings") that each variant of the game needs. This would allow translators to pull out a list of all the strings they need to implement for each and every mod that is compliant with the system. e.g. if Terra Vitae mod was adapted, then any translator could just spit out a list of strings needed for Terra Vitae mod and start adapting their translation to Terra Vitae without looking at the source code whatsoever.
That is a very good idea.  I almost want to go back and remove what I said about string:string mapping.
I'm going to try to make that a reality.
Logged
LCS 4.12.33 Custom NewGame, Edit Savefile!
Quote
Many people, meeting Aziraphale for the first time, formed three impressions: that he was English, that he was intelligent, and that he was gayer than a tree full of monkeys on nitrous oxide.
Constitution of the Confederate States
Article I Sec. 9 4
No bill of attainder, ex post facto law, or law denying or impairing the right of property in negro slaves shall be passed.

Azerty

  • Bay Watcher
    • View Profile
Re: LCS 4.12.33 Now With a Save Editor (And other flags... sort of)
« Reply #226 on: February 02, 2019, 03:58:01 pm »

It could make the work easier for translators.
Logged
"Just tell me about the bits with the forest-defending part, the sociopath part is pretty normal dwarf behavior."

Reelya

  • Bay Watcher
    • View Profile
Re: LCS 4.12.33 Now With a Save Editor (And other flags... sort of)
« Reply #227 on: February 02, 2019, 08:05:40 pm »

I'm going to try to make that a reality.

Actually, I just remembered something about stringification macros. You can have the strings but keep the benefits of having enums if you like. There are various approaches to that.

This is one way to do it, which I'd recommend since it's straightforward and doesn't use any bleeding edge C++14 trickery that nobody will understand:

http://www.jakeshirley.com/2014/11/

In this example, you have an input file, the example given is this:
Code: [Select]
FRUIT(Banana)
FRUIT(Apple)
FRUIT(Strawberry)
FRUIT(Pineapple)
FRUIT(Snozberry)

The trick here is that each CPP file is free to define the macro "FRUIT" any way they like. e.g. this file creates a fruit enum:

Code: [Select]
// Fruit Enum
#define FRUIT(x) x,
enum Fruit
{
#include "FruitDeclarations.h"
  Count
};
#undef FRUIT

And this file creates an array of fruit strings:

Code: [Select]
// Fruit Strings
#define FRUIT(x) #x,
const char *FruitStrings[] = {
#include "FruitDeclarations.h"
  "Invalid"
};
#undef FRUIT
 

... you can see where this is going. You get the benefit of still using the enums for the hard-coded parts, which ensures that compile-time checking picks up typos, but you get all the strings for the tokens auto-generated, to match, at compile time, so they can be spit out by the program and also used for parsing a translation file.

To make this approach work for LCS, you'd need to refactor in several steps
 
first you need to get rid of the individually named strings in favor of an array referenced via enums. To make that easier, you can use a std::map (what follows is entirely pseudocode so YMMV)

So, you have the list of enums:

enum string_tokens =
{
  WILL_STEAL,
  WILL_EMBEZZLE,
  (etc)
}

and a map

std::map string_values =
{
    {WILL_STEAL, "String for will steal"},
    {WILL_EMBEZZLE, "String for will embezzle"}
    {etc, etc}
}

Note, that all direct accesses to these string literals must now be passed through the map lookup, but preferably through a new function to keep the boiler-plate to a minimum.

However, this part could be touchy since you'll need to convert every call to drawing the strings directly into a call to the "lookup the needed string" function. If they're not all changed, it could try and print out the numerical value of the enums and not the strings. So, if you're going to rename the tokens, this would be the point at which to do it, to ensure the compiler picks up everywhere you need to change to the new string-lookup-function.

After this is achieved, then the code can be refactored again using the code from the FRUIT example given above: make a separate file called string_tokens.h and move all the enum names in there written as:

S(WILL_STEAL) 
S(WILL_EMBEZZLE) 
etc
(calling the macro "S" will minimize the boiler plate. I'm hoping to find better methods that will do away with the need for the S-macros completely, which I believe exist but can't find).

After that, the game can be modded so that it also generates the string array from this file (as shown in the FRUIT example) and at run-time it then looks for translation files, and parses them against the keys, over-writing any string in the map which matches a key. This would allow anything from partial fixes/mods to complete text rewrites for users without compiling. Also, a benefit for the main developers: if someone reports a typo, there's no need to recompile, merely have a typo-fixing translation file that's pulled in before any other translation file, and you can issue short-term patches without needing recompilation. Typos would then be folded into the code once the next code version is released.

Another benefit of having all the string literals in a map or table is that you can write a function to dump out all the moddable text from the game at runtime, for example, a "-dumpstrings" command-line option, but it can be expanded with a few sub-parameters to expand the usefulness. Here are some ideas about how that could work:

LCS -dumpstrings // dump all tokens and current strings (after translation)
LCS -dumpstrings changed // only dump ones where a file changed the string
LCS -dumpstrings not-changed // only dump ones that were not changed by a file
LCS -dumpstrings default // dump the original/default strings - would stack with changed/not-changed
LCS -dumpstrings tokens // only dump token names - again, would stack with changed/not-changed
LCS -dumpstrings both // show tokens, plus both default and translated strings.

I think that set of command line parameters relating to the strings would give people all the tools they need to quickly see what needs to be updated if the version changes and they're working on a language / mod.
« Last Edit: February 02, 2019, 09:05:39 pm by Reelya »
Logged

IsaacG

  • Bay Watcher
  • Mad Engineer
    • View Profile
    • JJoseph on Deviantart
Re: LCS 4.12.34 Now With a Save Editor (And other flags... sort of)
« Reply #228 on: February 13, 2019, 07:04:43 am »

X    Encounter warnings no longer work
X    Some people you encounter in neutral places (e.g the apartment buildings) cannot be talked to but instead have an option to "release oppressed". Doing so in front of others alerts conservatives but doesn't actually count as having caused a crime (as checked by inspecting a liberal's status after doing so.
X- When the Liberal Guardian publishes a news story about my valiant actions, the LCS is referred to as the CCS in the article text.
X- Got a feature in one my newspaper reports which tells me I've found a bug: https://imgur.com/a/G615ez9. This also shows what I mean in point 4 where my troops are called the CCS
Fixed in 4.12.34

The sell option at the pawn shop is not on the menu of possible actions, but can still be accessed by pressing "s"
This one is already in 4.10, so it predates my involvement :D
Not sure how to fix it.

- Potential recruits, through dating and meetings, often turn up naked when you'd expect them to be clothed - this is however rather funny if you imagine LCS takes place in a nudist USA.
- At the IT cafe site, the CPUs never actually spawn with people using them. When you walk up to a computer and the game prompts "The Computer is occupied" no one is ever actually there.
:'(
These have come up before.
- When liberals are sentenced, it sometimes doesn't tells you the result. It will say "The jury leaves to discuss..." but doesn't show the result. I find this is more common with innocent verdicts.
- The display for vehicles is broken for me. I cannot see more than one car on my vehicles screen.
Reprinting as a self-reminder.
Logged
LCS 4.12.33 Custom NewGame, Edit Savefile!
Quote
Many people, meeting Aziraphale for the first time, formed three impressions: that he was English, that he was intelligent, and that he was gayer than a tree full of monkeys on nitrous oxide.
Constitution of the Confederate States
Article I Sec. 9 4
No bill of attainder, ex post facto law, or law denying or impairing the right of property in negro slaves shall be passed.
Pages: 1 ... 14 15 [16]