Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2 3

Author Topic: LCS and XML  (Read 5811 times)

Kay12

  • Bay Watcher
  • Fighting for Elite Liberal values since 2009!
    • View Profile
LCS and XML
« on: June 14, 2010, 07:18:54 am »

LCS isn't easy to mod. LCS could be easy to mod. LCS should be easy to mod.

I am not a genius when it comes to C++ (Arch-Arch-Conservative?) but having read the source quite much, I believe that many elements of the game could be stored in easily modifiable XML-files (eXtra Modding Liberty), ultimately making the game much more flexible both for modders and core developers. XML-ifying would make it easy to add new sites, character types, weapons... well, new anything, as well as making it easier to modify the existing ones.

Of course, there's a downside as well. This will take a lot of work. A LOT. And being not exactly the best C++ coder around, I can't exactly say how much is A LOT. But I'll do my best to help if someone else likes the idea.
« Last Edit: June 14, 2010, 07:20:51 am by Kay12 »
Logged
Try Liberal Crime Squad, an excellent Liberal Crime adventure game by Toady One and the open source community!
LCS in SourceForge - LCS Wiki - Forum thread for 4.04

Jonathan S. Fox

  • Bay Watcher
    • View Profile
    • http://www.jonathansfox.com/
Re: LCS and XML
« Reply #1 on: June 14, 2010, 10:40:09 am »

The downside is why it hasn't happened already. Well, it's why LCS doesn't at least use text data files more extensively, like the map data files; though I would have gone with XML if I were doing it now.
Logged

Kay12

  • Bay Watcher
  • Fighting for Elite Liberal values since 2009!
    • View Profile
Re: LCS and XML
« Reply #2 on: June 15, 2010, 01:51:50 am »

LCS is open source, we should have no shortage of eager coders. I'm afraid we might have, though. I'll do my best, but I'd like the more experienced C++ people around to participate as well, so this may have any chance of becoming more than just a suggestion.
« Last Edit: June 15, 2010, 01:54:37 am by Kay12 »
Logged
Try Liberal Crime Squad, an excellent Liberal Crime adventure game by Toady One and the open source community!
LCS in SourceForge - LCS Wiki - Forum thread for 4.04

Jonathan S. Fox

  • Bay Watcher
    • View Profile
    • http://www.jonathansfox.com/
Re: LCS and XML
« Reply #3 on: June 15, 2010, 11:11:02 am »

I wish I could offer to help, but it wouldn't be a prudent use of my time; I'm on the team developing Empire & State while also taking summer classes, and spending a lot of time with LCS would overload my responsibilities.
Logged

Kay12

  • Bay Watcher
  • Fighting for Elite Liberal values since 2009!
    • View Profile
Re: LCS and XML
« Reply #4 on: June 15, 2010, 01:30:21 pm »

Well, I think you've done very much work on the project, it would make me feel rotten to demand this from you. I, being "all ideas, little coding" could seriously do some programming work on the LCS as well. There are always enough bugs for one more pair of eyes. I'm not the best C++ programmer around, but I've already learned a lot about C++ by simply reading the LCS source, so maybe I can be of some help should someone a bit more experienced join me.
Logged
Try Liberal Crime Squad, an excellent Liberal Crime adventure game by Toady One and the open source community!
LCS in SourceForge - LCS Wiki - Forum thread for 4.04

Carlos Gustavos

  • Bay Watcher
    • View Profile
Re: LCS and XML
« Reply #5 on: June 15, 2010, 02:07:35 pm »

I have also had thoughts about this. The end goal tempts me so I could be up for a shot.
Logged

Kay12

  • Bay Watcher
  • Fighting for Elite Liberal values since 2009!
    • View Profile
Re: LCS and XML
« Reply #6 on: June 15, 2010, 03:32:28 pm »

Nice! And remember, it'll save a lot of time in the future, since modifying XML values is far easier than hard-coding new stuff. Let's keep in touch and see if more people are interested.
Logged
Try Liberal Crime Squad, an excellent Liberal Crime adventure game by Toady One and the open source community!
LCS in SourceForge - LCS Wiki - Forum thread for 4.04

Blacken

  • Bay Watcher
  • Orange Polar Bear
    • View Profile
Re: LCS and XML
« Reply #7 on: June 16, 2010, 09:28:29 am »

Nice idea, but I think you greatly underestimate how much of a dick it is to effectively use what is essentially dynamically typed data in C++. It is not simple to provide effective extension points in a language that doesn't really support them. You're in for a very large project if you intend to do it right.

Which is one of the reasons that for Sharplike we're using Mono.Addins and Python for actual scripting and dynamic runtimes, but LCS doesn't have that luxury.
Logged
"There's vermin fish, which fisherdwarves catch, and animal fish, which catch fisherdwarves." - Flame11235

Kay12

  • Bay Watcher
  • Fighting for Elite Liberal values since 2009!
    • View Profile
Re: LCS and XML
« Reply #8 on: June 18, 2010, 06:19:08 am »

I am aware that it'll be a large project (games are, no exceptions) but as it would improve the game, I think it should be done sooner or later. However, I think there might be better solutions than XML for this, but sadly I must once again admit my lack of knowledge on this subject.
Logged
Try Liberal Crime Squad, an excellent Liberal Crime adventure game by Toady One and the open source community!
LCS in SourceForge - LCS Wiki - Forum thread for 4.04

Innominate

  • Bay Watcher
    • View Profile
Re: LCS and XML
« Reply #9 on: June 19, 2010, 02:28:15 am »

Nice idea, but I think you greatly underestimate how much of a dick it is to effectively use what is essentially dynamically typed data in C++. It is not simple to provide effective extension points in a language that doesn't really support them. You're in for a very large project if you intend to do it right.
You're spot on here. The only real options for dynamic typing in C++ - that don't require massive rewrites and bloated, unclear code - are both horrible practice (even when they work) - universal base class and "magic wrapper". Essentially you have to manually implement type-checking in every single function which uses your dynamically typed variables. Ugh. Anyway, my experience with python taught me that dynamic typing sucks above all else: accidentally convert an int to a string and your addition function becomes a concatenation operation; speed of development doesn't compensate for messy, hard-to-find bugs.
Logged

Jonathan S. Fox

  • Bay Watcher
    • View Profile
    • http://www.jonathansfox.com/
Re: LCS and XML
« Reply #10 on: June 19, 2010, 05:01:55 am »

I honestly don't understand what dynamic typing has to do with reading in items, sites, and other content from XML files.
Logged

Carlos Gustavos

  • Bay Watcher
    • View Profile
Re: LCS and XML
« Reply #11 on: June 20, 2010, 05:38:58 pm »

I've been looking at xml. I haven't used it before, but it seems trivial. I could write my own parser for it, but that would be tedious and there already exist some to use. The first problem I see with the existing xml parser solutions though is that I would have to ensure license compliance. The two I have looked at are TinyXML++ and XSD. I think TinyXML++ used some MIT license and XSD Gnu 2 with a floss exception. Does anyone know if using one of those in LCS can work with their license demands? Or does anyone know a better option?

Aside from that, I have been working on vehicles as I guessed those would be the easiest to try this on and, except the reading xml part, I only have left to determine whether some things are vehicle properties or not. Example, I haven't decided if vehicle types should keep track of if they are available at the car dealership and at what price or if that is something for the car dealership later when/if it is defined in an xml file.
« Last Edit: June 20, 2010, 05:47:50 pm by Carlos Gustavos »
Logged

Blacken

  • Bay Watcher
  • Orange Polar Bear
    • View Profile
Re: LCS and XML
« Reply #12 on: June 20, 2010, 06:36:44 pm »

I honestly don't understand what dynamic typing has to do with reading in items, sites, and other content from XML files.
If all you want to do is modify numbers, yes. If you want to actually have different effects for items and the ability for modders to do something without modifying the core binary, then XML is woefully under-featured. Seems like it'd be smarter to work at hooking in Lua or Boost::Python into LCS and converting as much non-core game logic to something that's actually meant to be modified.
Logged
"There's vermin fish, which fisherdwarves catch, and animal fish, which catch fisherdwarves." - Flame11235

Ari Rahikkala

  • Bay Watcher
    • View Profile
Re: LCS and XML
« Reply #13 on: June 20, 2010, 09:16:17 pm »

having read the source quite much, I believe that many elements of the game could be stored in easily modifiable XML-files (eXtra Modding Liberty), ultimately making the game much more flexible both for modders and core developers. XML-ifying would make it easy to add new sites, character types, weapons... well, new anything, as well as making it easier to modify the existing ones.

Remember, creature types are not fully described by their entries in creature/creaturetypes.cpp. For instance, special attacks are handled in combat/fight.cpp, sleeper liberal activism is handled in a different place, aging effects in daily/daily.cpp can even change a creature type. Do a grep for CREATURE_ if you're interested in finding (hopefully) every instance of this. The same sort of thing applies to sites (special handling in all sorts of places), vehicles, etc..

If you tried to put creature definitions into data files while keeping all this "switch polymorphic" code in place you'd end up either with a very poor extension facility (since you wouldn't be able to add special attacks and such things) or hugely complicated code (since you'd have to carry information about the creature types to everywhere they're used). The solution? Define an interface for creatures that allows client code to not mention specific creature types. Since this is C++ you might as well even go all object-oriented with it and go with a Creature class that encapsulates all features you might want to customise per creature type - and when you can define all the features of a creature in one place it should be easier to figure out what should go into the data file, too.

For instance, things like special attacks could be handled by giving the Creature class an attack() method that takes another Creature as an argument and where the attacker object decides precisely what kind of attack to make. Alternatively, less pure-OO-ly, it could have a public attribute describing what kind of special attack it uses. Optimally every mention of specific creature types outside the Creature class definition should be removable, but do note that this means the interface will have all sorts of niggly little facets in it, for instance it will have to have some way to determine if the creature should age, and if it should perhaps age into a different creature type. For what it's worth there already is a Creature class but the only things it hides behind an interface are the attributes and skills.

Creatures are used absolutely everywhere so if you're actually interested in the task of reducing coupling in the code you should probably start with something less complicated... let's say cars for instance. I grepped the code for VEHICLE_ to see what I'm dealing with, and... if I were implementing this change, keeping in mind the intent to eventually start moving data off into data file, I'd probably make a CarType and Car class: CarTypes have a name, a price, a bool determining whether they can be for sale at the used car store, a security difficulty for approaching and touching, a heat and juice modifier for stealing, a difficulty for finding them off the street, a driveskill bonus, a set of appropriate colours, and a range of models (construction years) for old and new vehicles. Cars have a... actually, I think they only have a reference to a CarType for now - I was thinking of the plan to have per-car heat here, though. Check if there already is something like a Vehicle type or such and what it contains already. Once you've pulled together everything you need to describe a CarType and a Car, defined an interface for it, and written the code to slurp a definition file containing CarTypes into the game state, just change combat/chase.cpp, common/getnames.cpp, daily/activities.cpp, daily/shopnstuff.cpp and game.cpp accordingly.

See what I'm going for here? I'm far from an object purist who'll insist you do everything by message dispatch and never make any decisions based on any object that isn't *this (in fact if I'm a purist of anything it would be of functional languages), I'm just pointing out that before you can describe something in a data file you had better pull together all the code depending on that description.

(if I'm talking out of my ass, I'd appreciate it if Carlos Gustavos called me out: How are you going to go about from having parsed the data describing a car type to having the shop know its price, for instance?)

If all you want to do is modify numbers, yes. If you want to actually have different effects for items and the ability for modders to do something without modifying the core binary, then XML is woefully under-featured. Seems like it'd be smarter to work at hooking in Lua or Boost::Python into LCS and converting as much non-core game logic to something that's actually meant to be modified.

Ehh, LCS doesn't have a lot of core game logic that you wouldn't likely be interested in modifying, and it also doesn't have an engine with strict performance requirements. It would be difficult to come up with a place to start hooking Python or Lua into. I'd say keep the whole thing C++, and if someone wants to develop LCS in Python, they can reimplement their own from scratch.



More generally, I think the one thing I would work on if I were intent on committing acts of software engineering on LCS would be hooking in a good widget library (hopefully without having to write one first) and converting as much code as I can to use it. I'm very much not a fan of reimplementing things like menus and paged lists every time there's need for one, as it causes complexity and LOC blowups, and most of all discourages someone like me who doesn't just know offhand what code to copypaste in from doing things like tossing up a list because it's unnecessarily much effort to get it right - thus making modding (of the actually interesting, adding-new-features kind) more difficult. Might as well do things like add a message buffer and see about making the interface scalable to different terminal sizes while one was at it.

I'm not going to do it since I'm lazy. But I'm putting the idea out there because in my opinion the lack of a UI library is the worst problem holding back interesting development on LCS, and the one part of it that could be improved with very little risk of getting it wrong and making the game more difficult to mod rather than less difficult.
Logged

Carlos Gustavos

  • Bay Watcher
    • View Profile
Re: LCS and XML
« Reply #14 on: June 21, 2010, 04:52:18 pm »

I've done as you suggest. I created a Vehicle and a VehicleType class and replaced all use of the VEHICLE_ enums and the vehiclest struct. New Vehicles are created from VehicleTypes and VehicleTypes are supposed to be read in from file. A short test made it look succesful. I just need to do xml read-in now and maybe improve the oo more. A new thought though is whether vechile types should be stored in the save file or not.

I still haven't decided if the car shop or the car should decide the price of a car. If the car knows the price then you wouldn't have to make an entry for it in the car shop's possible future xml file and if the car shop keeps track of the prices then ... that would make it easier to have more than one car shop in the future. I doubt more car shops will ever be wanted (unless maybe buying stolen cars from gang members?) so I'll probably let the vehicle types keep track of their prices now. But then maybe they should also keep track of whether they are for sale or not in the car shop.
Logged
Pages: [1] 2 3