Item Charges and Imparted Conditions
Yesterday's plot planning was pretty successful. I spent a lot of the day thinking about conspiracies I could try to integrate, and whether there are ways to make different skills relevant to those plot items. I think I have a couple ideas that I like, and I was even able to think of a few ways of using existing factions with those plot ideas (e.g. Blue Frogs, Martha's Army, etc.) I still need to make sure the ideas are sensible when strung together, but I'm liking the ideas so far.
Today, I started working on the problems of item conditions being added to or removed from creatures based on whether that item needs charges or not. For example, putting night vision goggles onto one's head should only give bonuses if the goggles have charged batteries.
That part was pretty easy. I just piggybacked on the existing code for equipping/unequipping items, and made it check for charges.
The tricky part is going to be handling items that are equipped while charges get added to or removed from them. For example, if someone is wearing the goggles, and they run out of charges, that person should lose the bonus. So I needed to write new code to handle adding/removing bonuses every time the contents of an item are changed.
To make things trickier, some items hold charges directly (guns, nanorobotic medkits), while others hold batteries that hold charges. This means that the new code I wrote had to check two levels deep, to make sure the goggles got switched on when the battery inside got new charges. It was a bit tedious doing all the checks for each nested level, but it seemed like the best way to go, given the circumstances.
I considered just making all objects take charges directly. However, that could screw up things like vehicles and fuel, which I'd like to add in the future. A car, for example, might have a lot of storage space. And if gas/electricity gets added directly to the car, then all that storage space could be used for gas/electricity. Cars have a lot of room for boxes and such, but one shouldn't be able to fill the back seat with gasoline or electricity.
With the two-level-deep system, I can specify that gas only fits in gas cans, and electricity only fits in batteries. So if a player wants to load up a car with batteries and/or gas cans, then fine.
Another alternative might've been to make items support multiple storage spaces, and have each space support different items. This has some advantages, but there are some major hurdles scaring me off from trying that. One big hurdle is lack of UI space. There just isn't enough room for the existing container spaces, let alone more per slot. And a lot of the code would have to be rewritten to assume multiple container spaces per item, instead of the current assumption of one per container.
So it was a tricky afternoon. I think it's working, though. I was able to don some charged goggles, and use "right-click->empty out" to drop their battery while they were worn, and the bonuses went away.
Provided that system passes some other tests, the next thing is to make sure charges are deducted each turn/move/use, as necessary.
Hope everyone has a good night, and see you tomorrow!