Author Topic: Custom inventories, gear slots and OXCE limitations  (Read 6826 times)

Offline darkestaxe

  • Colonel
  • ****
  • Posts: 256
  • Emissary of the Brain
    • View Profile
Custom inventories, gear slots and OXCE limitations
« on: August 24, 2018, 06:55:18 am »
I was looking into the idea of adding gear slot functionality into CE and while I think I've found the right part of the OXCE code, but then things got strange...

Is Piratez using a custom version of OXCE to add inventory layouts to armor types? And why/how are we using fixed weapons as inventory slots? If someone did add proper support for custom inventory layouts into OXCE ... would that even help piratez?

I mean what the flying tits is this?
Code: [Select]
armors:
  - type: STR_PIR_CASTAWAY_ARMOR_UC
    spriteSheet: PIR_489.PCK
    spriteInv: MAN_489
    builtInWeapons: // WAAAAAAHt?!?
      - INV_NULL_4X3
      - INV_NULL_2X1_LS
           ...
      - INV_NULL_1X2_QD //This built in weapon is the Quickdraw slot for this armor?
items:
  - type: INV_NULL_1X2_QD
    invWidth: 1
    invHeight: 2
    fixedWeapon: true
    defaultInventorySlot: STR_QD_SLOT //But where is STR_QD_SLOT defined?

Offline Solarius Scorch

  • Global Moderator
  • Commander
  • *****
  • Posts: 9779
  • WE MUST DISSENT
    • View Profile
    • Nocturmal Productions modding studio website
Re: Custom inventories, gear slots and OXCE limitations
« Reply #1 on: August 24, 2018, 09:25:01 am »
Built-in weapons are the vanillest vanilla. The only thing OXCE+ adds is forcing the item into a specific inventory slot.

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 6530
  • OXCE developer
    • View Profile
    • My Wiki
Re: Custom inventories, gear slots and OXCE limitations
« Reply #2 on: August 24, 2018, 10:50:28 am »
//But where is STR_QD_SLOT defined?

This is also vanilla:

Code: [Select]
invs:
  - id: STR_QD_SLOT
    x: 176
    y: 104
    slots:
      - [0, 0]
      - [0, 1]
    costs:
      STR_BACK_PACK: 14
      STR_BELT: 8
      STR_GROUND: 5
      STR_LEFT_HAND: 3
      STR_LEFT_LEG: 10
      STR_LEFT_SHOULDER: 10
      STR_RIGHT_HAND: 3
      STR_RIGHT_LEG: 10
      STR_RIGHT_SHOULDER: 10

Offline Yankes

  • Commander
  • *****
  • Posts: 2374
    • View Profile
Re: Custom inventories, gear slots and OXCE limitations
« Reply #3 on: August 24, 2018, 12:31:52 pm »
This was done because there is only one possible layout for inventory. Add more would made code lot time more complex.
Forcing fixed weapons in some defined slot was small hack that allow reuse normal item behavior to limit inventory space per armor.

and remember xpiratez use OXCE+ not OXCE, there are diffrences and if you look on OXCE you will miss some logic that was add to OXCE+

Offline darkestaxe

  • Colonel
  • ****
  • Posts: 256
  • Emissary of the Brain
    • View Profile
Re: Custom inventories, gear slots and OXCE limitations
« Reply #4 on: August 25, 2018, 09:26:58 am »
Oh, ok I get it now. The fixed weapons in the armors are being used to plug unused inventory slots, and OXC already allowed u to define extra slots, and Piratez just put that in a different .rul somewhere.

So now we just need to figure out how to add a property to an item that limits which inventory sections it can be placed in, add a hook right where the game checks to see if the item fits and there are enough time units, input an extra check for whether the given item can be placed in said inventory slot, else inform user STR_ITEM_CANT_GO_HERE.

Quote from: Inventory.cpp
Code: [Select]
void Inventory::mouseClick(Action *action, State *state)
{
  ...
// Check if this inventory section supports the item
if (!_selItem->getRules()->canBePlacedIntoInventorySection(slot->getId()))
{
_warning->showMessage(_game->getLanguage()->getString("STR_CANNOT_PLACE_ITEM_INTO_THIS_SECTION"));
}
Quote from: RuleItem.cpp
Code: [Select]
/**
 * Checks if the item can be placed into a given inventory section.
 * @param inventorySection Name of the inventory section (RuleInventory->id).
 * @return True if the item can be placed into a given inventory section.
 */
bool RuleItem::canBePlacedIntoInventorySection(const std::string &inventorySection) const
{
// backwards-compatibility
if (_supportedInventorySections.empty())
return true;

// always possible to put an item on the ground
if (inventorySection == "STR_GROUND")
return true;

// otherwise check allowed inventory sections
return std::find(_supportedInventorySections.begin(), _supportedInventorySections.end(), inventorySection) != _supportedInventorySections.end();
}
Code: [Select]
/**
 * Loads the item from a YAML file.
 * @param node YAML node.
 * @param mod Mod for the item.
 * @param listOrder The list weight for this item.
 */
void RuleItem::load(const YAML::Node &node, Mod *mod, int listOrder, const ModScript& parsers)
_supportedInventorySections = node["supportedInventorySections"].as< std::vector<std::string> >(_supportedInventorySections);

OMFG it was there all along?!?!?!?! WTF
Quote from: MeridianOXC committed on Oct 31, 2016
Items can now be limited to certain inventory slots only

hahaha 2 years ago? WOW! NVM guys meridian already gone and done fixed it already. Guess the next project is making a mod for Piratez that adds the new slots and associated item requirements.

Offline Dioxine

  • Moderator
  • Commander
  • ***
  • Posts: 5224
  • punk not dead
    • View Profile
    • Nocturnal Productions
Re: Custom inventories, gear slots and OXCE limitations
« Reply #5 on: August 27, 2018, 11:27:11 am »
So now we just need to figure out how to add a property to an item that limits which inventory sections it can be placed in, add a hook right where the game checks to see if the item fits and there are enough time units, input an extra check for whether the given item can be placed in said inventory slot, else inform user STR_ITEM_CANT_GO_HERE.

For what purpose, pissing the player off?

Offline darkestaxe

  • Colonel
  • ****
  • Posts: 256
  • Emissary of the Brain
    • View Profile
Re: Custom inventories, gear slots and OXCE limitations
« Reply #6 on: August 27, 2018, 08:43:33 pm »
For what purpose, pissing the player off?

No, my whole idea is that bras and towels should have their own dedicated inventory location. I had thought that was the intended idea with those 'gear' items in the first place. I thought the whole idea was that scarf equips to the neck slot like it says, and we only stick it in backpacks because OXC doesn't support a 'neck' slot for only neck slot items.

If I were to make a mod that shifted the standard equipment slots around and added dedicated gear holder slots, then I'd need a way to make those slots a place only for those items. Otherwise I'd just be adding a place to stick a Canteen o Wisdom or booze on nude armor. Aside from breaking balance, there still wouldn't be any way to justify equipping a scarf or towel.

Due to size concerns on the equip screen I don't think there's room for a neck, back, bra, legs each so they might have to share 1 or 2 slots, but at least they wouldn't just fill up your backpack.

Offline Dioxine

  • Moderator
  • Commander
  • ***
  • Posts: 5224
  • punk not dead
    • View Profile
    • Nocturnal Productions
Re: Custom inventories, gear slots and OXCE limitations
« Reply #7 on: August 27, 2018, 09:13:30 pm »
Yeah, now I get you. I had that idea too - basically making an equippable paperdoll for outfits, like in RPG games, but it's impossible with what we have. Although, maybe with clever scripting, or new code? The community needs dedicated coders, step up and make your dreams come true :)

KZad Bhat

  • Guest
Re: Custom inventories, gear slots and OXCE limitations
« Reply #8 on: August 28, 2018, 09:41:51 am »
There is someone who did a mod to add a whole bunch of inventory slots, but I haven't checked it out to see if he managed to do it all through ruleset and art resources, if he had to do patch to the executable. If just by ruleset, it may only need some new exec code to add a condition for certain gear requirements.
Edit: I did find it here:
https://openxcom.org/forum/index.php/topic,4848.0.html
It is done just by ruleset, but I'm guessing nothing new here for you really, Dioxine. It would be nice to add some restriction to extra slots for special equipment. Especially since with such you could actually have the Ushanka and shawl even while nude without letting people use the extra gear slots to sneak extra weapons they can't carry.
« Last Edit: August 28, 2018, 09:57:43 am by KZad Bhat »

Offline darkestaxe

  • Colonel
  • ****
  • Posts: 256
  • Emissary of the Brain
    • View Profile
Re: Custom inventories, gear slots and OXCE limitations
« Reply #9 on: August 28, 2018, 01:48:03 pm »
I posted the remaining code to restrict by slot over in the extended+ forum so we'll just have to wait and see, unless someone wants to add a list of allowed slots to the ruleset for every single equipable item in all of Piratez.

In the meantime it's quite easy to add, remove, or rearrange equipment slots in the ruleset, so I went ahead and toyed with a proof of concept.

It works, sort-of, as seen in the first image, but it's basically just a couple more spots to put anything you want for now.

The bigger issue now, I think, is that many gear items are simply to large to make small slots for them. For my demo I used type 1 slots (holds 1 item of any size) which take up a lot of space. Hypothetically if we did use my layout, someone would need to go through all the soldier images and shift each one about 8 pixels over. That wouldn't be too difficult, but whoever had to do it might very well break down and just start crying after a few hundred of them. I wouldn't blame them.

A better solution might be to shrink the graphics for the gear items themselves, especially since many of them aren't all that big anyway. Also, as you can see in my images, the text on top of gear slots is optional, though I still don't really like the idea of putting brown boxes all over the beautiful outfit art.

A more ambitious implementation would be to add a 'hidden' option to gear slots as well as a 'behind' option. Hide the squares (more accurately, don't draw them) and let players seem to put the gear items directly on the soldier, with the back-slot items rendering behind (before) the soldier image. Then scale/edit gear items graphics to match the soldier image. That way when you put a bra on a gal, it looks like she's just wearing the bra. (Changes to render order might be more then Meridian would allow.)

As an added bonus it would look absolutely hilarious for a male slave wearing a bra over his superman outfit! As for the height difference there'd have to be 2 versions of some of the slots with one blocked off by fixed weapons, though the fakes could be transparent for slots that are already invisible.

If there's interest in my more ambitious idea, I'm game for attempting to figure out the CE+ code to make it work. Assuming it's not already there...

Offline Dioxine

  • Moderator
  • Commander
  • ***
  • Posts: 5224
  • punk not dead
    • View Profile
    • Nocturnal Productions
Re: Custom inventories, gear slots and OXCE limitations
« Reply #10 on: August 28, 2018, 03:44:17 pm »
I am not aware of any code that lets you limit what can be carried in an inventory slot.

Offline darkestaxe

  • Colonel
  • ****
  • Posts: 256
  • Emissary of the Brain
    • View Profile
Re: Custom inventories, gear slots and OXCE limitations
« Reply #11 on: August 29, 2018, 05:22:12 am »
I am not aware of any code that lets you limit what can be carried in an inventory slot.

supportedInventorySections: on an item. That's the code I was showing earlier. I made an example that works with current OXCE+ for the last couple years.

https://openxcom.org/forum/index.php/topic,6543.0.html - Thread where I posted code changes to add a property to the actual slot that limits default items with no supportedInventorySections: also.

Code: [Select]
#We can use the supportedInventorySections: parameter to limit an item to certian inventory locations.
#This has no effect on the ground, which is always allowed, and no effect on other items.
items:
  - type: STR_NOOSE
    #With everything listed except QD, we block the rope from the QD slot.
    supportedInventorySections:
      - STR_RIGHT_HAND
      - STR_LEFT_HAND
      - STR_BELT
      - STR_BACK_PACK
      - STR_RIGHT_LEG
      - STR_LEFT_LEG
      - STR_RIGHT_SHOULDER
      - STR_LEFT_SHOULDER
  - type: STR_FIRST_AID_KIT
    #Same thing, but first aid kit can now only go in your left hand.
    supportedInventorySections:
      - STR_LEFT_HAND

Pic shows this example being tested, the medkit in the belt was already there, attempting to pick it up and put it back in the belt generated the same error.
« Last Edit: August 29, 2018, 05:29:19 am by darkestaxe »

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1873
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: Custom inventories, gear slots and OXCE limitations
« Reply #12 on: August 29, 2018, 05:36:24 am »
I am not aware of any code that lets you limit what can be carried in an inventory slot.

It's two years old, bladum requested it and Solarius seconded, Meridian implemented and then we all apparently forgot about it until this thread.  You seemed to be busy talking about how you reversed the inventory TU costs for backpacks in the same thread.

Offline Dioxine

  • Moderator
  • Commander
  • ***
  • Posts: 5224
  • punk not dead
    • View Profile
    • Nocturnal Productions
Re: Custom inventories, gear slots and OXCE limitations
« Reply #13 on: August 29, 2018, 07:08:07 am »
Lol. OK, good thing you reminded me of this. It is an interesting feature, however I don't see how this would allow fitting all the cool gear... Maybe if you used 1x1 slots? There is at least 10 gear slots atm.
Not even mentioning the scary amount of work it would take to set these parameters for every single item in the game.

So, darkestaxe? Do you think it is possible to rearrange slots in such a way that this works? 2 aux slots are nice but likely not enough... And it's not really acceptable how the paperdoll is squashed from our right.

Hmm, I think you could add a sequence of aux slots, each next about 16 px lower than the last to save space, each partially occluding the previous one. Would not look pretty, but could work...
« Last Edit: August 29, 2018, 07:15:11 am by Dioxine »

Offline darkestaxe

  • Colonel
  • ****
  • Posts: 256
  • Emissary of the Brain
    • View Profile
Re: Custom inventories, gear slots and OXCE limitations
« Reply #14 on: August 30, 2018, 04:21:54 am »
Lol. OK, good thing you reminded me of this. It is an interesting feature, however I don't see how this would allow fitting all the cool gear... Maybe if you used 1x1 slots? There is at least 10 gear slots atm.
Not even mentioning the scary amount of work it would take to set these parameters for every single item in the game.

The link is to a thread where I posted code so we wouldn't have to add those parameters for every single item. https://openxcom.org/forum/index.php/topic,6543.0.html

So, darkestaxe? Do you think it is possible to rearrange slots in such a way that this works? 2 aux slots are nice but likely not enough... And it's not really acceptable how the paperdoll is squashed from our right.

If we're willing to put the slots over the doll, then yes. Some items might have to be shrunk a little but I think all the slots should be able to fit. Problem, there would be squares all over the doll!

Hmm, I think you could add a sequence of aux slots, each next about 16 px lower than the last to save space, each partially occluding the previous one. Would not look pretty, but could work...

But 10? IDK about 10. That would create a lot of cursor bugs.

We could use all 1x1 slots and make all the gear items 1x1. At least coat and towel would have to shrink or they would cover way too many squares around them. We would also have to cut the backpack max size down to 3x3 or limit to 5, maybe 6 slots.

Dioxine, what do you think of reworking some of the gear-slot items' art to be able to fit on something like the pics below? Because overlapping a little is one thing, but a raincoat centered on a box in that grid would cover-up an awful lot of stuff, and even more overlap on the ground.

Otherwise there's the idea I talked about in my last post up; about putting the slots on the doll and making code to hide (not draw) the squares. Dioxine would you want to have items go directly on the doll? Because some things like the bra already look kinda like you could just stick them right on the doll. Then the bootypedia could say "To equip a synthread bra on a Gal, put it onto her boobs so it covers up both of her nipples. :P"