Checking to see whether shields are enabled

Freeform discussion about anything related to modding Transcendence.
Post Reply
gunship256
Militia Commander
Militia Commander
Posts: 451
Joined: Sat Jul 25, 2015 11:41 pm
Location: repairing armor

I'm trying to check to see if a shield is both installed and enabled. Unfortunately, the code below doesn't seem to work. For some reason, shieldEnabled is always set to Nil, even if I've got a shield installed and it's enabled.

Is there a better way to accomplish what I'm trying to do? Thanks if anyone can help!

Code: Select all

				; shieldEnabled will be set to True if a shield is installed AND enabled
				; Otherwise, it will remain at Nil
				(setq shieldEnabled Nil)
				(objEnumItems gPlayerShip "*sI" theShield
					(if (objGetItemProperty gPlayership theShield 'enabled)
						(setq shieldEnabled True)
						)
					)
User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2620
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

Where are you running this ?
Why don't you try to save the state on the playership using objsetdata ?
gunship256
Militia Commander
Militia Commander
Posts: 451
Joined: Sat Jul 25, 2015 11:41 pm
Location: repairing armor

Why don't you try to save the state on the playership using objsetdata?
To do that, I'd have to have a way to measure whether the shield is enabled, right? The only way I can think of to save the state on the playership without being able to measure whether the shield is enabled is to use an event, but if I remember right, devices can't pick up other devices' events, even if both devices are installed on the same ship.
Where are you running this ?
It's part of a mod that overwrites the Domina Restore power, giving the player the choice to repair either shields or armor. If shields are disabled but armor is damaged, the power should repair armor without having to ask the player.

Here's part of the code along with a link to the current version of the mod:
Restore.xml
(6.16 KiB) Downloaded 172 times

Code: Select all

	<!-- Overwrites the Domina Restore power -->
	
	<Power UNID="&pwHeal;"
			name=		"Restore"
			attributes=	"Domina"
			key=		"B"
			>

		<OnShow>
			(domShowPower 2)
		</OnShow>

		<OnInvokedByPlayer>
			(domInvokePower 2)
		</OnInvokedByPlayer>

		<Invoke>
			(block (shieldLevel)
				(setq shieldLevel (objGetShieldLevel gSource))
				
				<!-- 
				COMMENTED OUT CODE BELOW: DOESN'T SEEM TO WORK
				; shieldEnabled will be set to True if a shield is installed AND enabled
				; Otherwise, it will remain at Nil
				(setq shieldEnabled Nil)
				(objEnumItems gPlayerShip "*sI" theShield
					(if (objGetItemProperty gPlayership theShield 'enabled)
						(setq shieldEnabled True)
						)
					)
				-->
				
				; 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.
				(if (eq (shpGetShieldDamage gSource) (shpGetShieldMaxHitPoints gSource))
					(setq shieldDamageEqualToMaxHP True)
					(setq shieldDamageEqualToMaxHP Nil)
					)
				
				; Check to see whether ship's armor is damaged
				(if (gr (objGetVisibleDamage gSource) 0)
					(setq armorIsDamaged True)
					(setq armorIsDamaged Nil)
					)

				(switch					
					; If shields are enabled (interpret as greater than 0) but damaged AND armor is damaged, show a dockscreen
					; Unfortunately, this is not a great way to check if shields are enabled, since if shields are 
					; DOWN, shieldLevel will be zero, which makes it look like they're not enabled
					(and (gr shieldLevel 0) (ls shieldLevel 100) armorIsDamaged)
						(block Nil
							; Show the dockscreen
							(scrShowScreen gScreen &dsGSpwHeal;)
							
							; For now, just repair armor
							; (gsIntArmorRepairAll gSource 25)
							; (objSendMessage gSource Nil "Dockscreen is not functional yet")
							)
					
					; If shields are enabled (interpret as greater than 0) but damaged AND armor is undamaged, repair shields
					(and (gr shieldLevel 0) (ls shieldLevel 100) (not armorIsDamaged))
						(block Nil
							(shpRechargeShield gSource 1000)
							(objSendMessage gSource Nil "Invoked the restoring powers of Domina!")
							)
						
					; If shields are at 100% OR shield damage is equal to max shield HP but armor is damaged, repair armor
						; Make it possible to repair armor that is at less than 25% health
						; Need to create a replacement function for intArmorRepairAll so that the above can be done
					(and (or (eq shieldLevel 100) shieldDamageEqualToMaxHP) armorIsDamaged)
						(block Nil
							(gsIntArmorRepairAll gSource 25)
							(objSendMessage gSource Nil "Invoked the repairing powers of Domina!")
							)

					; Otherwise, do nothing
					(objSendMessage gSource Nil "\"I cannot help you, child\"")
					)
				)
			</Invoke>
		
		</Power>
gunship256
Militia Commander
Militia Commander
Posts: 451
Joined: Sat Jul 25, 2015 11:41 pm
Location: repairing armor

Ha - never mind. I was being a dum-dum. I must have typed the original code into the debug console incorrectly. After fixing a bug that's somewhat unrelated to the original problem I had (incorrectly using "*sI" with objEnumItems instead of "sI"), the code works now. Here's the working version:

Code: Select all

				; shieldEnabled will be set to True if a shield is installed AND enabled
				; Otherwise, it will remain at Nil
				(setq shieldEnabled Nil)
				(objEnumItems gPlayerShip "sI" theShield
					(if (objGetItemProperty gPlayership theShield 'enabled)
						(setq shieldEnabled True)
						)
					)
Post Reply