[mod idea+work help] Hive behavior

A place to discuss mods in development and concepts for new mods.
Drako Slyith
Fleet Officer
Fleet Officer
Posts: 1036
Joined: Wed Feb 03, 2010 4:28 am
Location: Researching how to make St. Kats star go supernova.
Contact:

I got an interesting idea today and when I got home, I started typing out some code. My plan was to have a ship that will find the nearest ship like itself, then find out if the other ship is stronger. If it is, it will escort it. If they are equal, it will attack it. When a ship is destroyed, its escorts will escort the other stronger ship. With my very limited experience with scripting, I thought it would be best to get some advice and help.
My ship code is here:

Code: Select all

	<ShipClass UNID="&scAdaptiveAIShip;"
			manufacturer=		""
			class=				""
			type=				"Hive Drone"
			score=				"10"
			abandonedScreen=	"&dsAbandonedStation;"
			dockScreen=			"&dsAbandonedStation;"
			dockingPorts=		"8"
			fuelCapacity=		"3750000"

			mass=				"150"
			reactorPower=		"1000"
			cargoSpace=			"10"
			thrust=				"650"
			maneuver=			"2"
			maxSpeed=			"20"
			rotationCount=			"40"
			cyberDefenseLevel=	"8"
			maxArmor=			"600000"
			maxCargoSpace=		"1500"
			maxDevices=			"20"
			leavesWreck=		"30"		
			
					
	
			>

		<Armor>
			<ArmorSection start="315" span="90" armorID="&itReactiveArmor;" areaSet="0,2" />
			<ArmorSection start="225" span="90" armorID="&itReactiveArmor;" areaSet="3,4" />
			<ArmorSection start="45"  span="90" armorID="&itReactiveArmor;" areaSet="7,13" />
			<ArmorSection start="135" span="90" armorID="&itReactiveArmor;" areaSet="1,6" />
		</Armor>

		<Devices>
						<Device deviceID="&itLaserCannon;"/>
		</Devices>

		<Items>
			<Item count="4d6" item="&itHelium3FuelRod;"/>
			<Item count="1" item="&itEnhanceSRSROM;"/>
			<Item count="1" item="&itTargetingComputerROM;"/>


		</Items>

		<AISettings
			fireRateAdj=		"30"
			fireAccuracy=		"90"
			perception=			"4"
			/>
		<Image imageID="&rsSapphireYacht;" imageX="0" imageY="0" imageWidth="48" imageHeight="48"/>
		<Events>
			<OnDestroy>
				(block nil
					(objSetData gSource	"destroyer" (objGetData gSource "nearShip"))
					(shpOrder (objGetData gSource "fleetShip")  'escort destroyer)
					(objSetData (objGetData gSource "nearShip") "combatScore" (add ((objGetData gSource "combatScore") (objGetData (objGetData gSource "nearShip") "combatScore"))))
				)
			</OnDestroy>
			<OnCreate>
				(block nil
					(objSetData gSource "combatScore" (random 1 3))
						

					
					(sysAddObjRecurringTimerEvent 15 gSource 'hiveFinder)
				)
			</OnCreate>
			<hiveFinder>
				(block nil
					(setq nearShip (sysFindObject gSource "sN"))
					(switch
						(geq (objGetData gSource "combatScore") (objGetData nearShip "combatScore"))
							(block nil
								(shpOrder nearShip 'escort gSource)
								(objSetData gSource "fleetShip" nearShip)
							)
						(eq (objGetData gSource "combatScore") (objGetData nearShip "combatScore"))
							(block nil
								(shpOrder gSource 'attack nearShip)
							) 
						(block nil
							(shpOrder gSource 'escort nearShip)
						)
					)
				)
			</hiveFinder>
		</Events>


	</ShipClass>
Image
Image
Play in over 100 systems in a network. Play the 2011 Mod Of the Year
and the highest rated mod on Xelerus, The Network.
Play the July Mod of the Month, Fellow Pilgrims!
Play My other mods as well
(Drako Slyith)* I am a person
(Eliza chatbot)> Do you believe it is normal to be a person?
Drako Slyith
Fleet Officer
Fleet Officer
Posts: 1036
Joined: Wed Feb 03, 2010 4:28 am
Location: Researching how to make St. Kats star go supernova.
Contact:

I updated the code above with my newest work. The most major issue I see now is that the player is ordered to attack the nearest ship, rather than each ship being ordered to attack each other.
Image
Image
Play in over 100 systems in a network. Play the 2011 Mod Of the Year
and the highest rated mod on Xelerus, The Network.
Play the July Mod of the Month, Fellow Pilgrims!
Play My other mods as well
(Drako Slyith)* I am a person
(Eliza chatbot)> Do you believe it is normal to be a person?
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

A couple of pointers

You should clear orders from ships before assigning them new ones.
Use shpCancelOrders for that.

Running the timer every 15 ticks is quite frequent. If you have a lot
of ships it might slow down things. Every 15 ticks is roughly once every
1/2 second.

You can get a list of ships escorting the current ship using sysFindObject.
(sysFindObject gSource "sO:escort")

You can get the ship the source ship is escorting by using shpGetOrderTarget.
Drako Slyith
Fleet Officer
Fleet Officer
Posts: 1036
Joined: Wed Feb 03, 2010 4:28 am
Location: Researching how to make St. Kats star go supernova.
Contact:

Awesome thanks for the help :D
Image
Image
Play in over 100 systems in a network. Play the 2011 Mod Of the Year
and the highest rated mod on Xelerus, The Network.
Play the July Mod of the Month, Fellow Pilgrims!
Play My other mods as well
(Drako Slyith)* I am a person
(Eliza chatbot)> Do you believe it is normal to be a person?
Drako Slyith
Fleet Officer
Fleet Officer
Posts: 1036
Joined: Wed Feb 03, 2010 4:28 am
Location: Researching how to make St. Kats star go supernova.
Contact:

I got some more work done, and the ships finally swarm together. I added some fail-safe code (such as stopping the event timers once the ship dies. My biggest problem is whenever a ship is destroyed, I get an error message usually ###integer expected (0) ### then that line. I've tried a lot to make it work, but nothing I tried worked. Here's my code:

Code: Select all

	<ShipClass UNID="&scAdaptiveAIShip;"
			manufacturer=		""
			class=				""
			type=				"Hive Drone"
			score=				"10"
			abandonedScreen=	"&dsAbandonedStation;"
			dockScreen=			"&dsAbandonedStation;"
			dockingPorts=		"8"
			fuelCapacity=		"3750000"

			mass=				"150"
			reactorPower=		"1000"
			cargoSpace=			"10"
			thrust=				"650"
			maneuver=			"2"
			maxSpeed=			"20"
			rotationCount=			"40"
			cyberDefenseLevel=	"8"
			maxArmor=			"600000"
			maxCargoSpace=		"1500"
			maxDevices=			"20"
			leavesWreck=		"30"		
			
					
	
			>

		<Armor>
			<ArmorSection start="315" span="90" armorID="&itReactiveArmor;" areaSet="0,2" />
			<ArmorSection start="225" span="90" armorID="&itReactiveArmor;" areaSet="3,4" />
			<ArmorSection start="45"  span="90" armorID="&itReactiveArmor;" areaSet="7,13" />
			<ArmorSection start="135" span="90" armorID="&itReactiveArmor;" areaSet="1,6" />
		</Armor>

		<Devices>
						<Device deviceID="&itLaserCannon;"/>
		</Devices>

		<Items>
			<Item count="4d6" item="&itHelium3FuelRod;"/>
			<Item count="1" item="&itEnhanceSRSROM;"/>
			<Item count="1" item="&itTargetingComputerROM;"/>


		</Items>

		<AISettings
			fireRateAdj=		"30"
			fireAccuracy=		"90"
			perception=			"4"
			/>
		<Image imageID="&rsSapphireYacht;" imageX="0" imageY="0" imageWidth="48" imageHeight="48"/>
		<Events>
			<OnDestroy>
				
			
			
				
				(block (destroyer followers nearShip)
					(setq nearShip (sysFindObject gSource "sN+unid:&scAdaptiveAIShip;"))
					(setq destroyer (objGetData gSource nearShip))
					(setq followers (sysFindObject gSource "sO:escort"))
					(shpCancelOrders destroyer)
					(shpOrder destroyer 'wander)
					(shpCancelOrders followers)
					(shpOrder followers 'escort destroyer)
					(objSetData (objGetData gSource nearShip) "combatScore" (add ((objGetData gSource "combatScore") (objGetData (objGetData gSource "nearShip") "combatScore"))))
					(sysCancelTimerEvent gSource "hiveFinder")
				
				)

			
			
			</OnDestroy>
			<OnCreate>
				(block nil
					(objSetData gSource "combatScore" (random 1 10))
					(sysAddObjRecurringTimerEvent 30 gSource 'hiveFinder)

				)
			</OnCreate>


			<hiveFinder>
			(block nil
					
				(if (leq (objGetDistance gSource (sysFindObject gSource "sN+unid:&scAdaptiveAISHip;")) 100)
					(setq nearShip (sysFindObject gSource "sN+unid:&scAdaptiveAIShip;"))
					(switch
						(geq (objGetData gSource "combatScore") (objGetData nearShip "combatScore"))
							(block nil
									

								(shpCancelOrders nearShip)
								(shpOrder nearShip 'escort gSource)
									(switch
										(eq (objGetOrderGiver gSource) nil)
											(block nil
												(shpOrder gSource 'wander)
												(objSetData gSource "fleetShip" nearShip)
											)
										(block nil
											(shpOrder gSource 'escort (objGetOrderGiver gSource))
											(shpOrder nearShip 'escort (objGetOrderGiver gSource))
										)
									)
							
							
							)
						(eq (objGetData gSource "combatScore") (objGetData nearShip "combatScore"))
							(block nil
								(shpCancelOrders gSource)
								(shpOrder gSource 'attack nearShip)
								
							) 
						(block nil
							(shpCancelOrders gSource)
							(shpOrder gSource 'escort nearShip)
							(shpOrder nearShip 'wander)
						)
					)
				)
			)
			</hiveFinder>
		</Events>


	</ShipClass>
Image
Image
Play in over 100 systems in a network. Play the 2011 Mod Of the Year
and the highest rated mod on Xelerus, The Network.
Play the July Mod of the Month, Fellow Pilgrims!
Play My other mods as well
(Drako Slyith)* I am a person
(Eliza chatbot)> Do you believe it is normal to be a person?
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

I decided to give you code a little makeover... perhaps you can get some
pointers from it... i will comment as I can. There might be things i did
not think of in this, but it is the base of how I would go about it at least.

http://paste.neurohack.com/view/YA62h/


Events running on an object stop running when the object is destroyed, so
there is no need to stop it manually.


In OnDestroy you can access the objId of the ship doing the kill as aDestroyer
See: http://wiki.neurohack.com/transcendence/wiki/events


You need to remember to declare variables you set as local to the block

Eg:

Code: Select all

;; this is bad, nearship becomes a global variable
(block nil
    (setq nearShip "something")
)

;; this is correct, nearship is local
(block (nearship)
    (setq nearShip "something")
)

Hope you can use some of it
Drako Slyith
Fleet Officer
Fleet Officer
Posts: 1036
Joined: Wed Feb 03, 2010 4:28 am
Location: Researching how to make St. Kats star go supernova.
Contact:

Thanks a lot for the help. It works a lot better now. :mrgreen:
Image
Image
Play in over 100 systems in a network. Play the 2011 Mod Of the Year
and the highest rated mod on Xelerus, The Network.
Play the July Mod of the Month, Fellow Pilgrims!
Play My other mods as well
(Drako Slyith)* I am a person
(Eliza chatbot)> Do you believe it is normal to be a person?
Drako Slyith
Fleet Officer
Fleet Officer
Posts: 1036
Joined: Wed Feb 03, 2010 4:28 am
Location: Researching how to make St. Kats star go supernova.
Contact:

I worked some more on it today and got the code here:http://paste.neurohack.com/view/YPrUp/. It seems to work just like I want it to except that every once in a while, a swarm of ships will gate out. It's not really high priority, but I'd prefer not to have them leave.

One more thing I'd like to have ships do is to make them patrol their leaders during a battle, so that they don't have fleets kill each other, and it's much more like a duel.
Image
Image
Play in over 100 systems in a network. Play the 2011 Mod Of the Year
and the highest rated mod on Xelerus, The Network.
Play the July Mod of the Month, Fellow Pilgrims!
Play My other mods as well
(Drako Slyith)* I am a person
(Eliza chatbot)> Do you believe it is normal to be a person?
User avatar
ThePrivateer
Militia Captain
Militia Captain
Posts: 943
Joined: Tue Oct 12, 2010 5:12 am
Location: Starton Australia

Ummm. Did i miss something, or is that new pastebin AWESOME? Sorry to derail the thread, but that's the first time I've seen the new pastebin - I didn't think George went ahead and did that. That's seriously cool - we have a nice Transcendence themed pastebin of our own AND it highlights stuff. Pure awesome! :D :D

*btw* Drako, this sounds really cool, and I can't wait to see the finished result. :mrgreen:
Drako Slyith
Fleet Officer
Fleet Officer
Posts: 1036
Joined: Wed Feb 03, 2010 4:28 am
Location: Researching how to make St. Kats star go supernova.
Contact:

ThePrivateer wrote:
*btw* Drako, this sounds really cool, and I can't wait to see the finished result. :mrgreen:
Thanks. :D My plan with this is to simulate an organic insect behavior: swarming (as discussed here) feeding (asteroids?) and natural selection (getting better weapons on a random chance, then getting them to make another for their offspring, and so on. Not sure this is possible, but worth a shot :wink: )
Image
Image
Play in over 100 systems in a network. Play the 2011 Mod Of the Year
and the highest rated mod on Xelerus, The Network.
Play the July Mod of the Month, Fellow Pilgrims!
Play My other mods as well
(Drako Slyith)* I am a person
(Eliza chatbot)> Do you believe it is normal to be a person?
User avatar
ThePrivateer
Militia Captain
Militia Captain
Posts: 943
Joined: Tue Oct 12, 2010 5:12 am
Location: Starton Australia

Drako Slyith wrote:
ThePrivateer wrote:
*btw* Drako, this sounds really cool, and I can't wait to see the finished result. :mrgreen:
Thanks. :D My plan with this is to simulate an organic insect behavior: swarming (as discussed here) feeding (asteroids?) and natural selection (getting better weapons on a random chance, then getting them to make another for their offspring, and so on. Not sure this is possible, but worth a shot :wink: )
It sounds great if you could get it to work...basically you are creating Evolution and Natural Selection, as well as simulating Behaviour, but in a game world. Sounds like an indie game all of its own! ;)

Edit - BTW, for feeding, remember that one part of evolution and natural selection is dominating other species...the base insects might feed on asteroids yes, but one day, one insect might destroy another ship and 'feed' off of the carcass. Then, it grows stronger than it's asteroid-eating counterparts. Thus begins natural selection as others follow it's lead, or get picked off if they decide to continue their lower-level ways.
Drako Slyith
Fleet Officer
Fleet Officer
Posts: 1036
Joined: Wed Feb 03, 2010 4:28 am
Location: Researching how to make St. Kats star go supernova.
Contact:

What I was thinking is that each ship has a timer that determines its hunger. I.E. It starts out fine, and just wanders around. At stage 2, it will "eat" an asteroid (or ship maybe) if it's very close. At stage 3 is becomes hungry and will extend the range of it's eating search (further than stage 2, still not fully searching. Stage 4 will have it begin looking for food. At stage 5 is becomes hungry enough that it will eat another of its kind. At stage 6 it dies. Therefore, if it can't find an asteroid, and it can't cannibalize, it dies. But if it does cannibalize, it has a chance to gain a "carnivore trait" which has a chance to be passed down. Carnivores will be similar to the asteroid eating insects but they won't eat asteroids; they go right for the cannibalizing with similar urgency, stages 1-4, but then eat any passing ship at stage 5. The timers can be reset by eating, to stage 1.

BTW: I also thought it would be good to have an age timer, similar to hunger but it can't be reset. They just die after so long.
Image
Image
Play in over 100 systems in a network. Play the 2011 Mod Of the Year
and the highest rated mod on Xelerus, The Network.
Play the July Mod of the Month, Fellow Pilgrims!
Play My other mods as well
(Drako Slyith)* I am a person
(Eliza chatbot)> Do you believe it is normal to be a person?
Drako Slyith
Fleet Officer
Fleet Officer
Posts: 1036
Joined: Wed Feb 03, 2010 4:28 am
Location: Researching how to make St. Kats star go supernova.
Contact:

Just did some work on the food system posted above. My code is here:http://paste.neurohack.com/view/YYXk5/
The time scale is for testing convenience and will be changed later. The messages are also for testing.
The problem is that they just wander around like normal, ignoring the behavior I described for them, except for giving me messages constantly about someone eating at level 2, then they all die at once. They don't eat, but their food scale is reset, until they die. :?
Image
Image
Play in over 100 systems in a network. Play the 2011 Mod Of the Year
and the highest rated mod on Xelerus, The Network.
Play the July Mod of the Month, Fellow Pilgrims!
Play My other mods as well
(Drako Slyith)* I am a person
(Eliza chatbot)> Do you believe it is normal to be a person?
User avatar
Ttech
Fleet Admiral
Fleet Admiral
Posts: 2767
Joined: Tue Nov 06, 2007 12:03 am
Location: Traveling in the TARDIS
Contact:

On a random note, ceat random interval a ship should 'think' its self more powerful and try to take over another hive. :P
Image
Image
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

Drako Slyith wrote:My code is here:http://paste.neurohack.com/view/YYXk5/
OK, first of all... your indentation is all messed up. It makes it very hard to read the code (and I don't have time to reformat it). Make sure you only use spaces or tabs, not both (personally i only use spaces).

It seems there is something wrong in your OnDestroy (again, I can not really read it without reformating). It seems you are missing a block somewhere (only the first statement after the case in the switch is run). It might be this that is causing it, since I think the last enum is run every time... but again, hard to read :)
Post Reply