[1.3] [KV] Weapon Storage [ModSync RW]

Started by Kiame, September 05, 2017, 05:46:47 PM

Previous topic - Next topic

Kiame

When a weapon is assigned to a pawn it will stay with them going forward.

If you assign weapons with this mod, simple sidearms is not needed.

2.71828

I've got a weird problem: My (single and only) weapon storage doesn't accept weapons anymore and remains empty, although it should accept weapons (via the storage options). I know that it worked before in this particular save, but somehow it doesn't work anymore. Could this be related to your last update?

I tried rebuilding the weapon storage, reinstalling it somewhere else, forbidding and then enabling everything in the storage options, reloading the safe, etc., but nothing helps. If the weapon storage is the only "stockpile" that accepts weapons, and I try to "haul some weapons urgently", Rimworld tells me there is no available storage. This happens both with modded weapons and vanilla weapons, although it worked perfectly a couple of days ago.

Is there anything I can do to either get rid of this problem myself or to help you with tracking it down? AFAIK, I don't get any error messages that have anything to do with this. Should I try to remove and re-add the mod to my save, or something?

Canute

You should try at first, happen that problem at  new colony too, use hugslib quickstart option to create a new test colony.
Then try to disable all mods beside hugslib,Weapon storage and try it again.

Then you can see if it is maybe a modconflict or a general problem.
On a modconflict you still can try to move Weapon storage at the end or at the beginning of the modlist and check if that help.

And btw. how did you update he mod, did you delete the older folder or just overwrite it ?

2.71828

Quote from: Canute on January 16, 2019, 02:20:50 PM
You should try at first, happen that problem at  new colony too, use hugslib quickstart option to create a new test colony.
Then try to disable all mods beside hugslib,Weapon storage and try it again.

Then you can see if it is maybe a modconflict or a general problem.
On a modconflict you still can try to move Weapon storage at the end or at the beginning of the modlist and check if that help.

And btw. how did you update he mod, did you delete the older folder or just overwrite it ?

Thanks for the tip. However, because I'm very lazy, I did something even simpler and just started a new game with my current modlist. Turns out it was simply user error. I'm using the "Survival Tools" mod which adds tools, and these tools are kind of a hybrid between weapons and clothing, I guess, since with the "Outfitted" mod, my colonists pretty much equip the correct tools by themselves (unless the tools are within a weapon storage), but they're still added to the storage options in the weapons storage. Since I don't want to do by hand which happens automatically, I forbid tools from being stored in the weapon storage. This, however also forbade smeltable and non-smeltable things (because the tool category has these filters, as well), so now my weapon storage was only allowed to store weapons (check mark for the weapon category), but not smeltable or non-smeltable items (crossed out by forbidding the tools category), so nothing was allowed to be stored in the weapon storage, anymore... Thus, I have fixed my own stupid mistake, now.

Too bad, however, that there is no "tool storage", or something...

Kiame

#184
Update:
-Fixed an issue where the slide bars were not showing up in shared weapons dialog
-Pawns incapable of violence will no longer show up in the list of pawns to assign weapons to or in shared weapons
-Better support for imbued weapons

Kiame

#185
Update:
Added Combat Extended support! Make sure to update Weapon Storage (d/l link) at the same time you download the patch

Patch for Combat Extended:
Steam: https://steamcommunity.com/sharedfiles/filedetails/?id=1711864630
Direct Download: https://github.com/KiameV/rimworld-weaponstorage/releases/download/1.0/WeaponStorageCombatExtended.zip

Combat Extended Patch Notes:
Pawns will be able to retrieve ammo from Weapon Storages for reloading weapons and turrets.
- Pawns reloading their weapons will have ammo put into their hands from weapon storage - no longer will pawns need to run and reload
- Ammo for turrets will appear outside of Weapon Storages if a pawn is not manning a turret. If a pawn is manning a turret, the ammo will appear in the pawn's hands

It is strongly recommended not to use the Combat Extended loadouts for weapons and ammo. Instead assign weapons through Weapon Storage. Loadouts can still be used for food, meds, etc.

Using Grenades:
To assign grenades select any Weapon Storage then Manage Shared Weapons
-From the new window create a new filter and call it something like "emp frag"
-In the list select the grenades you want available to colonists, like "frag grenade" and " EMP grenade"
-Close the Filter window
-Assign colonists to the "emp frag" group

Now when you select a colonist that's assigned "emp frag" they can equip either frag or emp grenades (if there are any stored in Weapon Storage)

Load Order
-Combat Extended
-Weapon Storage
-Weapon Storage Combat Extended Patch

Kiame

Update:
Pawns who are assigned both a sharp (sword) and blunt (club/mace) melee weapons will now switch to the best weapon for the target they're attacking. This can be disabled in the mod's settings. The preferred weapon type is used if the target has the same blunt and sharp armor ratings.

Kiame

Update (Combat Extended Patch):
-Fixed an issue where bows were not getting arrows when firing
-Fixed an issue where pawn could continuously remove ammo from a Weapon Storage then promptly lose the ammo as it was automatically moved to the Weapon Storage

Important
For those using CE you'll need to update both Weapon Storage and the CE Patch. I'm trying to keep this to a minimal  :)

For those not using CE Patch, you can ignore this update.

Weapon Storage: https://github.com/KiameV/rimworld-weaponstorage/releases/download/1.0/WeaponStorage.zip
CE Patch: https://github.com/KiameV/rimworld-weaponstorage/releases/download/1.0/WeaponStorageCombatExtended.zip

Pelador

The following mod uses AI to make use of a couple of items to fight fires. The items are a Fire Extinguisher and Firebeater (technically a gun and a melee item as the game sees them): https://steamcommunity.com/sharedfiles/filedetails/?id=1653848897

As a result, it has been reported by a player that there is an incompatibility with the use of both mods. Largely as it appears that both mods apply a technique of managing the primary equipment to be used for differing activities. The firewarden mod will equip items from inventory to be used in response to a fire, and unequip after completion.

As an immediate solution to the issue, I thought that if certain items could be excluded from the Weapon Storage functionality then this may allow for continuity with the above items as intended tools. Which could be a similar case for any other mod that wishes to employ AI to similar items. If Weapon Storage could exclude certain items and include a mod extension for thingDef to be able to mark these items then other modders could then easily apply this to their items to be treated as such, which would alleviate the headache of trying to maintain a list or have complicated recognition sets/user definitions.

Kiame

The pawn will hold the weapon that's currently assigned to them. If the pawn has multiple weapons and the equipped weapon changes, the original weapon goes back into storage and the selected weapon is then equipped by the pawn.

I have not run this with simple sidearms but i have heard they are compatible

Pelador

Quote from: Kiame on April 27, 2019, 12:29:55 AM
The pawn will hold the weapon that's currently assigned to them. If the pawn has multiple weapons and the equipped weapon changes, the original weapon goes back into storage and the selected weapon is then equipped by the pawn.

I have not run this with simple sidearms but i have heard they are compatible

It is required that the Fire fighting tools be held in the pawn's inventory for use however by the Fire Warden AI. Hence this creates issues with the use of the pocket space process removing items from them. Hence the need to exclude them from this behavior.

Kiame

You'll need to discuss that with whatever mod author adds the Fire Warden

Pelador

I am the author of the Fire Warden mod. And the mod uses normal vanilla behavior with the use of vanilla storage and pockets (pawn inventory) in order to achieve what it needs to do in swapping equipment to respond to fires. It is only the interruption from KV Storage that is causing the problem due to the non-vanilla behavior of how the Storage mod has to manage things with the "pocket dimension". Therefore, the only solution to the issue lies within changing the way in which KV Storage relates to other mods and associated AI. Otherwise, there will be incompatibility remaining between the two mods and potentially the same with any other mod that applies tools for use with AI behavior in a similar fashion.

Kiame

Quote from: Pelador on April 28, 2019, 08:55:44 AM
I am the author of the Fire Warden mod. And the mod uses normal vanilla behavior with the use of vanilla storage and pockets (pawn inventory) in order to achieve what it needs to do in swapping equipment to respond to fires. It is only the interruption from KV Storage that is causing the problem due to the non-vanilla behavior of how the Storage mod has to manage things with the "pocket dimension". Therefore, the only solution to the issue lies within changing the way in which KV Storage relates to other mods and associated AI. Otherwise, there will be incompatibility remaining between the two mods and potentially the same with any other mod that applies tools for use with AI behavior in a similar fashion.

Using reflection you can access any item the pawn can equip and call the methods in Weapon Storage to facilitate the switching of equipment. All source code is posted on github - https://github.com/KiameV/rimworld-weaponstorage

The main method you'd use is WeaponStorage.WorldComp.AssignedWeapons.TryGetValue(Pawn, out AssignedWeaponContainer)

If this is true then you can see if the pawn is equipped a specific weapon (extinguisher i guess) and then use WeaponStorage.HarmonyPatchUtil.EquipWeapon(ThingWithComps, Pawn pawn, AssignedWeaponContainer) to change the pawn's equipment

For the reflection there are two approaches:
Pure abstraction (reflection on objects) - https://github.com/KiameV/rimworld-SaveStorageSettings/blob/master/Source/SaveStorageSettingsUtil/SaveStorageSettingsGizmoUtil.cs
note Exists finds the assembly then AddSaveLoadGizmos uses the assembly to make reflection calls. This is the best option and there's not much in the way of abstraction in this case
OR create a new project in the solution - see the CombatExtended directory  https://github.com/KiameV/rimworld-weaponstorage/tree/master/Source
This is easier to program but requires a second patch to be maintained and users to have two mods to enable functionality

Kiame

I am not in a position to test this atm but this should be very close to what you're looking for

Basically you'd just call


if (!WeaponStorageUtil.TryEquipType(pawn, >def of item to equip<)
{
     // Original Code
}


Just make a new .cs file and put the below code there

using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using Verse;

namespace WeaponStorageUtil
{
    class WeaponStorageUtil
    {
        private static Assembly wsAssembly = null;
        private static bool initialized = false;
        public static bool Exists
        {
            get
            {
                if (!initialized)
                {
                    foreach (ModContentPack pack in LoadedModManager.RunningMods)
                    {
                        foreach (Assembly assembly in pack.assemblies.loadedAssemblies)
                        {
                            if (assembly.GetName().Name.Equals("WeaponStorage") &&
                                assembly.GetType("WeaponStorage.WorldComp") != null)
                            {
                                initialized = true;
                                wsAssembly = assembly;
                                break;
                            }
                        }
                        if (initialized)
                        {
                            break;
                        }
                    }
                    initialized = true;
                }
                return wsAssembly != null;
            }
        }

        public static bool TryEquipType(Pawn p, ThingDef def)
        {
            if (Exists)
            {
                try
                {
                    IDictionary assignedWeapons = wsAssembly.GetType("WeaponStorage.WorldComp").GetField("AssignedWeapons", BindingFlags.Static | BindingFlags.Public).GetValue(null) as IDictionary;
                    if (assignedWeapons != null)
                    {
                        object aw = assignedWeapons[p];
                        if (aw != null)
                        {
                            List<ThingWithComps> weapons = aw.GetType().GetField("Weapons", BindingFlags.Instance | BindingFlags.Public).GetValue(aw) as List<ThingWithComps>;
                            if (weapons != null)
                            {
                                foreach (ThingWithComps w in weapons)
                                {
                                    if (w.def == def)
                                    {
                                        wsAssembly.GetType("WeaponStorage.HarmonyPatchUtil").GetMethod("EquipWeapon", BindingFlags.Static | BindingFlags.Public).Invoke(null, new object[] { w, p, aw });
                                        return true;
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    // Do nothing
                    Log.Warning(e.GetType().Name + " " + e.Message + "\n" + e.StackTrace);
                }
            }
            return false;
        }
    }
}