Smart patch spiders

A place to discuss mods in development and concepts for new mods.
Post Reply
gunship256
Militia Commander
Militia Commander
Posts: 451
Joined: Sat Jul 25, 2015 11:41 pm
Location: repairing armor

[edit 2015 December 27] I changed the title of the thread to "Smart patch spiders" to better reflect the current version of the mod.

[edit 2016 January 04] I released an alpha and created a new thread in Mod Announcments: https://forums.kronosaur.com/viewtopic. ... 82&p=67019

Original post below:

---

I'm working on a patch spider installer that will automatically use and remove patch spiders based on shield status, armor damage, and whether hostiles are detected within --- ls radius.

Ideally, I'd like for it to be a slotless device that automates installation for all external armor repair devices. Reasons: compatibility with other mods, ability to handle mod versions of the patch spider, and when I implement settings, the settings can be changed for the device instead of for each patch spider individually.

I'm running into a problem with objEnumItems, though. The criteria don't seem to be granular enough to distinguish between armor repair devices and other miscellaneous devices (see bottom of this post).

Is there a way to distinguish between an armor repair device and, say, a jumpdrive? I'd prefer not to have to make any assumptions about the names and UNID's of the devices, as the point of making this mod a device instead of overwriting the patch spider is compatibility with other mods. Thanks if you can offer assistance!
Item Criteria

When retrieving items based on item criteria, these are the flags used:

* all categories
a armor
b miscellaneous devices (Patch Spider, Jumpdrive, Enhancers)
c cargo hold
d device (weapon, shield, drive, etc.)
f fuel
l launcher
m missile/ammo
p weapon, primary (excluding launchers, same as w~l)
r reactor
s shields
t miscellaneous
u useable (armor coating, ROM, etc.)
v drive
w weapon (including launchers)
I is installed
D is damaged
N is not damaged
S is usable
V is Virtual
U is not installed

Some special attributes

canBeDamaged:true only items that can be damaged
damageType:Laser only items that have a certain damage type. Also limits to weapons (obviously)
unid:0xXXXX only items with matching UNID

In addition there exists a special syntax for negating, filtering on levels etc…

~ Negate. Eg. w~l will match weapons that are not launchers.
^ Force. Eg. a^u will match armors that are usable
< and > Less than and Greater than. There are several ways to use these operators
<=$500 Items that cost less than 500 credits
>=#25 Items where there are greater than 25 in the stack. Used when getting items from objects
<=6 Items below level 6
L New in 1.04. Level Constraint. Eg. L:1-5 selects levels between 1 and 5 (inclusive). Replaces above syntax.

F Rarity. Eg. F:cu will only select Common or Uncommon items
http://wiki.kronosaur.com/modding/function/legend
Last edited by gunship256 on Mon Jan 04, 2016 8:31 pm, edited 2 times in total.
PM
Fleet Admiral
Fleet Admiral
Posts: 2570
Joined: Wed Sep 01, 2010 12:54 am

No. You can search for patcher arms and patch spiders by +unid, but there is nothing that selects a category of only armor repair devices.
Download and Play in 1.9 beta 1...
Drake Technologies (Alpha): More hardware for combat in parts 1 and 2!
Star Castle Arcade: Play a classic arcade game adventure, with or without more features (like powerups)!
Playership Drones: Buy or restore exotic ships to command!

Other playable mods from 1.8 and 1.7, waiting to be updated...
Godmode v3 (WIP): Dev/cheat tool compatible with D&O parts 1 or 2.
gunship256
Militia Commander
Militia Commander
Posts: 451
Joined: Sat Jul 25, 2015 11:41 pm
Location: repairing armor

Thanks for the feedback, PM. I can think of three ways to do this:

(1) Over-write the patch spider with a "smart" patch spider.
(2) Create an alternative "smart" patch spider that is available alongside the original patch spider. No overwrite would be necessary, but the new patch spider would not be farmable from Ranx dreadnaughts.
(3) Create a slotless device that tries to guess whether a given device is a patch spider based on its characteristics and name. This is convenient in that settings can be changed in one place for all patch spiders, and mod patch spiders would be contrallable using the same devie and settings.

What do people prefer?
relanat
Militia Captain
Militia Captain
Posts: 941
Joined: Tue Nov 05, 2013 9:56 am

Great idea. Option 2 works for me. Make the smart ones significantly more expensive though and perhaps slightly rarer. I never get many intact ones from Dreadnoughts anyway :( .
Another option might be a ROM which upgrades normal patch spiders.
Stupid code. Do what I want, not what I typed in!
User avatar
Atarlost
Fleet Admiral
Fleet Admiral
Posts: 2391
Joined: Tue Aug 26, 2008 12:02 am

As a UI fix it should be a proper fix, not another item tax. Option 1.
Literally is the new Figuratively
gunship256
Militia Commander
Militia Commander
Posts: 451
Joined: Sat Jul 25, 2015 11:41 pm
Location: repairing armor

Atarlost wrote:As a UI fix it should be a proper fix, not another item tax. Option 1.
One of the reasons I was leaning toward option 3 was the convenience of being able to change settings. For example, one player might want to use only shield status as a criterion, while another might want patch spiders to be automatically installed with shields down but no hostiles visible.

What about option 1 or 2 with the settings manipulable through a settings file in the extension's folder?
User avatar
Atarlost
Fleet Admiral
Fleet Admiral
Posts: 2391
Joined: Tue Aug 26, 2008 12:02 am

You can change settings with it on the spider itself too. It takes an extra keystroke to install or uninstall manually since the menu has to go there, but the whole point is that you will never install or uninstall manually when you can automate.

Settings can be stored globally. Name mangle your global variables and they won't step on anything else. (eg. gunship256_variablename)
Literally is the new Figuratively
gunship256
Militia Commander
Militia Commander
Posts: 451
Joined: Sat Jul 25, 2015 11:41 pm
Location: repairing armor

Here's an alpha for people to take a look at:
d064_SmartPatchSpiders20151226.zip
(5.12 KiB) Downloaded 240 times
What's working: Patcher arm variants work correctly as far as I can tell. I also tested the basic patch spider (a level 4 variant) in actual gameplay up to Dorado, the system after St. Kat's. When a shield is installed, the device works correctly, uninstalling itself when armor is undamaged OR shields are down and hostiles are within 100ls and reinstalling itself when the above condition is not true.

To Do: Clean up code so that I'm not copying and pasting the same detection code every time I create a new variant of the patch spider. Add a settings screen that lets the player determine the criteria that the spiders use to install and uninstall themselves.

What's broken: If there is no shield installed, the basic patch spider does not remove itself when hostiles are present, although it does remove itself when armor is finished healing. I think the code that is used to check shield status doesn't work the way it should when a shield is not installed.

Here's the code that's broken. I need to tell the spider that when a shield is NOT INSTALLED, the spider should act as though shields are DOWN. What's the most effective way to do that?

Code: Select all

		<Events>
			<OnUpdate>
				(block Nil
					
					; Check to see whether ship's armor is damaged
					(if (gr (objGetVisibleDamage gSource) 0)
						(setq armorIsDamaged True)
						(setq armorIsDamaged Nil)
						)
							
					; If shields are DOWN and enemies are nearby, set safe to nil; if shields are DOWN and enemies are not nearby, set safe to True
					; If shields are UP, set safe to True
					(if (eq (objGetShieldLevel gSource) 0)
						(if (sysFindObject gSource "s T A E N:100 P")
							(setq safe Nil)
							(setq safe True)
							)
						(setq safe True)
						)	
						
					; Install patch spider if armor is damaged AND ship's hull is safe from attack
					; Uninstall patch spider otherwise
					; See PM's PSD7 PSDBaseClass.xml, lines 1630-1649 for similar code (accessed on 2015 12 26)
					(if (and armorIsDamaged safe)
						(if (@ (objCanInstallItem gSource gItem) 0)
							(shpInstallDevice gSource gItem)
							)
						
						(if (leq (itmGetMass gItem) (objGetCargoSpaceLeft gSource))
							(shpRemoveDevice gSource gItem)
							)
						)
						
					)
			
			</OnUpdate>
		</Events>
gunship256
Militia Commander
Militia Commander
Posts: 451
Joined: Sat Jul 25, 2015 11:41 pm
Location: repairing armor

Never mind! I fixed the problem, though [edit] the patch spiders still can't tell the different between a "real" shield and something that's installed in the shield slot. For example, if PM's particle autobeamer is installed, the patch spiders think that's a real shield and won't uninstall themselves if enemies are around. I'm not sure how to fix this. Suggestions?

There's an additional problem: The game sometimes crashes when the patch spiders are moving themselves around. It's either happening when I view my inventory or when I use 'S' and 'S' to check my ship's shield and armor status. This crash does NOT happen with the thermo shell nanofac, though, which does something similar; the inventory screen will update live while I'm looking at it instead of crashing the game.

I'll try to replicate the exact problem.

Here's the fixed alpha (version 0.11):
d064_SmartPatchSpiders20151227.zip
(5.13 KiB) Downloaded 231 times
Here's the fixed code:

Code: Select all

		<Events>
			<OnUpdate>
				(block Nil
					
					; Check to see whether ship's armor is damaged
					(if (gr (objGetVisibleDamage gSource) 0)
						(setq armorIsDamaged True)
						(setq armorIsDamaged Nil)
						)
						
					; Check to see if a shield is installed
					(setq shieldIsInstalled Nil)
					(objEnumItems gSource "sI" theItem
						(setq shieldIsInstalled True)
						)

					; Check to see if shield level is at zero (This will return Nil if shield is up OR if a shield is not installed)
					(if (eq (objGetShieldLevel gSource) 0)
						(setq shieldIsZero True)					
						(setq shieldIsZero Nil)				
						)
				
					; Armor is not covered by a shield if either a shield is not installed OR it is at zero
					; Armor is covered by a shield otherwise
					(if (or	(not shieldIsInstalled)
							shieldIsZero
							)
						(setq armorIsCoveredByShield Nil)
						(setq armorIsCoveredByShield True)
						)
							
					; If armor is covered by a shield, it is safe for the patch spider to come out
					; If armor is not covered by a shield and enemies are within 100ls, it is NOT safe for patch spiders to come out
						; But if enemies are not within 100ls, it is safe for patch spiders to come out
					(if armorIsCoveredByShield
						(setq safe True)
						(if (sysFindObject gSource "s T A E N:100 P")
							(setq safe Nil)
							(setq safe True)
							)
						)
						
					; Install patch spider if armor is damaged AND ship's hull is safe from attack
					; Uninstall patch spider otherwise
					; See PM's PSD7 PSDBaseClass.xml, lines 1630-1649 for similar code (accessed on 2015 12 26)
					(if (and armorIsDamaged safe)
						(if (@ (objCanInstallItem gSource gItem) 0)
							(shpInstallDevice gSource gItem)
							)
						
						(if (leq (itmGetMass gItem) (objGetCargoSpaceLeft gSource))
							(shpRemoveDevice gSource gItem)
							)
						)
						
					)
			
			</OnUpdate>
		</Events>
User avatar
AssumedPseudonym
Fleet Officer
Fleet Officer
Posts: 1190
Joined: Thu Aug 29, 2013 5:18 am
Location: On the other side of the screen.

gunship256 wrote:…the patch spiders still can't tell the different between a "real" shield and something that's installed in the shield slot. For example, if PM's particle autobeamer is installed, the patch spiders think that's a real shield and won't uninstall themselves if enemies are around. I'm not sure how to fix this. Suggestions?
 Instead of checking for whether a shield is installed, check to see if damage to a ship’s shield is equal to its shield’s max HP:

Code: Select all

(if (eq (shpGetShieldDamage gSource) (shpGetShieldMaxHitPoints gSource)) «Do stuff here»)
 Non-shields should always always trigger that since both their max HP and damage to them will always be zero.
Image

Mod prefixes: 0xA010 (registered) and 0xDCC8 (miscellaneous)

My mods on Xelerus: Click here!

Of all the things I’ve lost in life, I miss my mind the least. (I’m having a lot more fun without it!)
gunship256
Militia Commander
Militia Commander
Posts: 451
Joined: Sat Jul 25, 2015 11:41 pm
Location: repairing armor

Thanks! That worked beautifully.

Here's the updated alpha (version 0.12):
d064_SmartPatchSpiders 0.12 alpha.zip
(5.54 KiB) Downloaded 246 times
Here's the fixed code:

Code: Select all

		<Events>
			<OnUpdate>
				(block Nil
					
					; Check to see whether ship's armor is damaged
					(if (gr (objGetVisibleDamage gSource) 0)
						(setq armorIsDamaged True)
						(setq armorIsDamaged Nil)
						)
								
					; In order to check if shields are up, check to see whether shield damage is equal to max shield HP
					; This is done to handle the following circumstances correctly:
						; No shield is installed (damage and max HP are both zero)
						; A non-shield device is installed in the shield slot (damage and max HP are both zero)
					; Thanks to AP for suggesting this code. (See forum thread URL in the Read Me file.)
					(if (eq (shpGetShieldDamage gSource) (shpGetShieldMaxHitPoints gSource))
						(setq shieldDamageEqualToMaxHP True)
						(setq shieldDamageEqualToMaxHP Nil)
						)
							
					; If shield damage = max HP and enemies are within 100ls, it is NOT safe for patch spiders to come out
						; But if enemies are not within 100ls, it is safe for patch spiders to come out
					; ELSE If shield damage is NOT equal to max HP, it is safe for patch spiders to come out
					(if shieldDamageEqualToMaxHP
						(if (sysFindObject gSource "s T A E N:100 P")
							(setq safe Nil)
							(setq safe True)
							)
						(setq safe True)
						)
						
					; Install patch spider if armor is damaged AND ship's hull is safe from attack
					; Uninstall patch spider otherwise
					; See PM's PSD7 PSDBaseClass.xml, lines 1630-1649 for similar code (accessed on 2015 12 26)
					(if (and armorIsDamaged safe)
						(if (@ (objCanInstallItem gSource gItem) 0)
							(shpInstallDevice gSource gItem)
							)
						
						(if (leq (itmGetMass gItem) (objGetCargoSpaceLeft gSource))
							(shpRemoveDevice gSource gItem)
							)
						)
						
					)
			
			</OnUpdate>
		</Events>
gunship256
Militia Commander
Militia Commander
Posts: 451
Joined: Sat Jul 25, 2015 11:41 pm
Location: repairing armor

I have some code for changing the settings now, but I'm currently storing the settings inside the spider itself. Besides the fact that this isn't ideal because settings aren't global, this method causes problems because the spider doesn't seem to want to move itself around after this new data is added to it.

Specifically, the error I get is:
Itemd0644144 Event [Raijin-class heavy gunship]: Unable to find specified item in object. ### shipRemoveDevice gSource gItem ###
I assume this problem will fix itself once I store the settings globally instead of inside the spider.

What's the best way to go about this? Should I create a virtual object and put the data in there? Or is there a way to define a global variable that can hold the settings?

Here's the code that's currently generating the error along with a download link to the mod:. [Edit: only the basic patch spider has the new settings code in it. The normal patch spider and nanotech repair spider still use the v0.12 code, and they function properly but are unaffected by settings.]
d064_SmartPatchSpiders 0.13 alpha.zip
(6.15 KiB) Downloaded 244 times

Code: Select all

		<Invoke>
			(block Nil
				; Similar code at PM's Drake Technologies Alpha, Frag.xml, lines 64-75 (accessed 2015 12 27)
				(block (newMode)
					(setq newMode (modulo (add (itmGetProperty gItem 'charges) 1) 2) )

					(objSendMessage gSource Nil (switch
						(eq newMode 1)	"Safe mode: Spider will hide if shields are not up"
						"Default mode: Spider will repair an unshielded ship if no hostiles are nearby"
						))

					(objSetItemProperty gSource gItem 'charges newMode)
					)
				)
			</Invoke>
				
		<Events>
			<OnUpdate>
				(block Nil
					
					; Check to see whether ship's armor is damaged
					(if (gr (objGetVisibleDamage gSource) 0)
						(setq armorIsDamaged True)
						(setq armorIsDamaged Nil)
						)
								
					; In order to check if shields are up, check to see whether shield damage is equal to max shield HP
					; This is done to handle the following circumstances correctly:
						; No shield is installed (damage and max HP are both zero)
						; A non-shield device is installed in the shield slot (damage and max HP are both zero)
					; Thanks to AP for suggesting this code. (See forum thread URL in the Read Me file.)
					(if (eq (shpGetShieldDamage gSource) (shpGetShieldMaxHitPoints gSource))
						(setq shieldDamageEqualToMaxHP True)
						(setq shieldDamageEqualToMaxHP Nil)
						)
					
					;Check settings to see if patch spiders are allowed to come out when shields are down
					; Safe Mode = 1 (patch spiders only come out when shields are up)
					; Default Mode = 0 (patch spiders can come out when shields are down)
					; Similar code at PM's Drake Technologies Alpha, Frag.xml, lines 88-104 (accessed 2015 12 27)
					(if (eq (setq theCharges (itmGetProperty gItem 'charges)) 1)
						(setq safeMode True)
						(setq safeMode Nil)
						)
					
					;Check to see if enemies are within 100ls
					(if (sysFindObject gSource "s T A E N:100 P")
							(setq enemiesNearby True)
							(setq enemiesNearby Nil)
							)
						
							
					; If there are no shields, it is unsafe for spiders to come out if safe mode is on OR there are enemies nearby
					; ELSE it is safe for spiders to come out
					(if shieldDamageEqualToMaxHP
						(if (or safeMode enemiesNearby)
							(setq safeToComeOut Nil)
							(setq safeToComeOut True)
							)
						(setq safeToComeOut True)
						)
						
					; Install patch spider if armor is damaged AND ship's hull is safe from attack
					; Uninstall patch spider otherwise
					; See PM's PSD7 PSDBaseClass.xml, lines 1630-1649 for similar code (accessed on 2015 12 26)
					(if (and armorIsDamaged safeToComeOut)
						(if (@ (objCanInstallItem gSource gItem) 0)
							(shpInstallDevice gSource gItem)
							)
						
						(if (leq (itmGetMass gItem) (objGetCargoSpaceLeft gSource))
							(shpRemoveDevice gSource gItem)
							)
						)
						
					)
			
			</OnUpdate>
				
		</Events>
gunship256
Militia Commander
Militia Commander
Posts: 451
Joined: Sat Jul 25, 2015 11:41 pm
Location: repairing armor

Also, my overwrite of the level 6 patch spider doesn't seem to be working correctly. It works fine when I test the mod out in the first system, but I just bought a patch spider in a real playthrough right before Jiang's Star, and it's the vanilla version that doesn't install and uninstall itself. I'm not sure why yet.

[edit 2015 Dec 28]
This happened because Relief Pack 912 also overwrites the patch spider in order for PM's "Invoke one patch spider for all" functionality to work. When I use both mods, PM's version overwrites mine.

I fixed this by opening up the folder for Relief Pack 912, opening the file Relief912.xml, and replacing the text

Code: Select all

		<Module filename="AllSpider.xml"/>
with this:

Code: Select all

		<!--
		<Module filename="AllSpider.xml"/>
		-->
shanejfilomena
Fleet Officer
Fleet Officer
Posts: 1533
Joined: Tue Mar 22, 2011 8:43 pm
Location: Alaska
Contact:

First of all, I appreciate your efforts in trying to bring to the universe a new device that could most probably over-come the bugs older ones gain as the versions of ships' engines go over time ...

However : take a peek at the original efforts of Bobby and PM's Patch
http://xelerus.de/index.php?s=mod&id=579
http://xelerus.de/index.php?s=mod&id=1243

if you want to call a device : like a Patch Spider : "d +ArmorRepair;" would work, however these devices suffer the same Lag in Modernization as the Molotok did about getting an Attribute declaring it as a blackMarket ship.
( Also the 'bountyHunter' Attrib seems to come & go - or it's just me, I like to make sure it's on there because Paying your debt doesn't always get rid of the Molotoks, so I add my own thing )

So if you are willing to go into the .XML , it's less typing to just add the Attribute to the device

Code: Select all


	<!-- Patch Spider -->

	<ItemType UNID="&itPatchSpider;"
			name=				"patch spider"
			attributes=			"commonwealth, ArmorRepair, majorItem"
			  
			level=				"6"
			frequency=			"rare"

			value=				"7000"
			mass=				"2000"
			  
			description=		"This robotic spider crawls along the ship's hull and repairs armor of up to technology level XII. It does not require a device slot."
			>

		<Image imageID="&rsItems1;" imageX="0" imageY="192" imageWidth="96" imageHeight="96"/>

		<RepairerDevice
				regen=			" 3, 3, 3, 3, 3,  2, 2, 2, 2, 1,  1, 1"
				powerUse=		"50"

				deviceSlots=	"0"
				external=		"true"
				/>

		<Invoke>
			(intAutoInstall gSource gItem)
		</Invoke>
	</ItemType>

Flying Irresponsibly In Eridani......

I don't like to kill pirates in cold blood ..I do it.. but I don't like it..
gunship256
Militia Commander
Militia Commander
Posts: 451
Joined: Sat Jul 25, 2015 11:41 pm
Location: repairing armor

Thanks for the feedback! I didn't think about searching for a similar mod until I was almost done with this one, so I guess I created a lot of work for myself!

Based on what I saw in Bobby's code, I think the mod I made has different features and balance that don't make it an attempt to replace his. I tried to be as true as possible to the original devices in the game, so none of them can do item repair, and they're easier to find in shops than the repair droids are.

The level 3 solar panel array is exactly like the original, except that it is external and can install and uninstall itself, and it has a higher mass to make it harder to loot from Heliotropes. The level 5 and 8 solar panel devices each have a cost and refuel rate that matches a reactor of the same level.

Try it and let me know what I can do to improve the mod:

https://forums.kronosaur.com/viewtopic. ... 82&p=67019
Post Reply