Scripters cove

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

User avatar
maik
Wiki Wizard
Wiki Wizard
Posts: 2028
Joined: Wed Mar 10, 2010 12:30 pm
Location: Ljubljana, Slovenia (mainly industrial, feudal, TL12)

Re: Scripters cove

Post by maik »

I am trying to achieve the following: I want a ship with role abc to be only created if the number of ships with role xyz is greater than n.

After reading through the shipdata.plist and related documentation, I am now playing around with abc's shipdata.plist: I added a launch_actions array where I count the ships with role xyz and set a local variable to YES if it is greater than n. In the shipdata's conditions key I test for this local variable to be YES. In the launch_actions I also added a few <string>debugMessage: aarrrghhh</string> lines.

What I expect to happen is:
  • In the debug console or in latest.log I should see 'aarrrghhh' when I run system.addShips("abc", 1). I don't.
  • The condition in shipdata's conditions key should know the local variable that I set in the launch_actions. I have no idea how to tell it does.
Unfortunately, I haven't found documentation that tells me in what sequence which _actions are executed and when the conditions for creating the ship are evaluated, so I don't even know if the above makes sense in Oolite.

Can someone enlighten me please?
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripters cove

Post by Thargoid »

The conditions key is used to remove the ship from the available pool of ships with the role, if the conditions aren't met. But in your case you are using the launch_action of the ship to make the test, hence the condition cannot stop the spawning as the ship already exists by that point.

I would interpret it as your conditions aren't met (your local variable), hence your addShips fails (and you see no message), so your local variable doesn't get set and so your condition cannot ever be fulfilled. Basically you've got the safe key locked in the safe ;)

What may be easier is to give the ship a short javascript, and use the this.shipSpawned function to trigger doing the count, and if the count isn't sufficient then just remove the ship again (this.ship.remove();).

If you need more elaboration, just holler...
User avatar
maik
Wiki Wizard
Wiki Wizard
Posts: 2028
Joined: Wed Mar 10, 2010 12:30 pm
Location: Ljubljana, Slovenia (mainly industrial, feudal, TL12)

Re: Scripters cove

Post by maik »

Thanks! That works :)
User avatar
maik
Wiki Wizard
Wiki Wizard
Posts: 2028
Joined: Wed Mar 10, 2010 12:30 pm
Location: Ljubljana, Slovenia (mainly industrial, feudal, TL12)

Re: Scripters cove

Post by maik »

New question, this time about the AI: There is a ship that is a Thargoid hunter. It wanders the space lane between witch point and main station and attacks all Thargoids it finds. If its energy is low, it performs evasive maneuvers until it is at least medium, otherwise it attacks the Thargoids until they are destroyed. If it is being attacked by pirates, it just follows the fightOrFlee logic, nothing fancy there.

This is how I put it into an AI, based on what I understood from the documentation:

Code: Select all

{
	GLOBAL = {
		ENTER = ("setStateTo: LOOK_FOR_THARGOIDS");
	};

	LOOK_FOR_THARGOIDS = {
		ENTER = (scanForThargoid);
		TARGET_FOUND = (setTargetToFoundTarget, "setStateTo: ATTACK_THARGOID");
		NOTHING_FOUND = (checkForNormalSpace);
		NORMAL_SPACE = ("setStateTo: HEAD_FOR_WITCHPOINT");
		UPDATE = (scanForThargoid, "pauseAI: 3.0");
	};

	ATTACK_THARGOID = {
		ENTER = (checkEnergy);
		ENERGY_LOW = (performTumble, "pauseAI: 1.0", checkEnergy);
		ENERGY_MEDIUM = (performAttack);
		ENERGY_HIGH = (performAttack);
		ENERGY_FULL = (performAttack);
		TARGET_DESTROYED = ("setStateTo: LOOK_FOR_THARGOIDS");
		UPDATE = (checkEnergy, "pauseAI: 1.0");
	};

	HEAD_FOR_WITCHPOINT = {
		ENTER = (setCourseToWitchpoint, "setDesiredRangeTo: 15000.0", checkCourseToDestination);
		RESTARTED = (setCourseToWitchpoint, "setDesiredRangeTo: 15000.0", checkCourseToDestination);
		COURSE_OK = (setSpeedToCruiseSpeed, performFlyToRangeFromDestination);
		WAYPOINT_SET = ("setAITo: goToWaypointAI.plist");
		DESIRED_RANGE_ACHIEVED = ("pauseAI: 2.0", "setStateTo: HEAD_FOR_PLANET"); 
		ATTACKED = (fightOrFleeHostiles);
		INCOMING_MISSILE = (fightOrFleeMissile);
		UPDATE = (scanForThargoid, "pauseAI: 3.0");
		TARGET_FOUND = (setTargetToFoundTarget, "setThrustFactorTo: 0.8", "setStateTo: ATTACK_THARGOID");
		NOTHING_FOUND = ("pauseAI: 3.0");
	};

	HEAD_FOR_PLANET = {
		ENTER = (setCourseToPlanet, "setDesiredRangeTo: 80000.0", checkCourseToDestination);
		RESTARTED = (setCourseToPlanet, "setDesiredRangeTo: 80000.0", checkCourseToDestination);
		COURSE_OK = (setSpeedToCruiseSpeed, performFlyToRangeFromDestination);
		WAYPOINT_SET = ("setAITo: goToWaypointAI.plist");
		DESIRED_RANGE_ACHIEVED = ("pauseAI: 2.0", "setStateTo: HEAD_FOR_WITCHPOINT");
		ATTACKED = (fightOrFleeHostiles);
		INCOMING_MISSILE = (fightOrFleeMissile);
		UPDATE = (scanForThargoid, "pauseAI: 3.0");
		TARGET_FOUND = (setTargetToFoundTarget, "setThrustFactorTo: 0.8", "setStateTo: ATTACK_THARGOID");
		NOTHING_FOUND = ("pauseAI: 3.0");
	};
}
Does that make sense? Please disregard the goToWaypointAI for the moment. Also, I haven't thought thoroughly about what needs to change when being in witchspace, so please disregard this, too.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripters cove

Post by Thargoid »

I'm not sure I should be answering this ;) :twisted:

I would beware of the update in the ATTACK_THARGOID state. Here you're checking the energy very frequently and unless it's low you're repeating the performAttack command every second. It might be better to only check the energy if the ship is actually attacked whilst in combat (or even just in normal flight as well) rather than doing it so repeatedly.

Also you're making no account of the target becoming lost (other than by it getting destroyed) which might cause the ship to hang if the thing it's fighting just wanders off.

By the way if you want something similar in concept, look at the AI for the Raptors in TCAT.
User avatar
maik
Wiki Wizard
Wiki Wizard
Posts: 2028
Joined: Wed Mar 10, 2010 12:30 pm
Location: Ljubljana, Slovenia (mainly industrial, feudal, TL12)

Re: Scripters cove

Post by maik »

Cool, thanks for the feedback!
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Scripters cove

Post by Eric Walch »

maik wrote:
If its energy is low, it performs evasive maneuvers until it is at least medium,

Code: Select all

		ENERGY_LOW = (performTumble, "pauseAI: 1.0", checkEnergy);
Evasive maneuvers would be more a 'performFlee' not being a sitting duck during a 'performTumble'. This asks for a seperate FLEE state like found in many other AI's
User avatar
Fatleaf
Intergalactic Spam Assassin
Intergalactic Spam Assassin
Posts: 1988
Joined: Tue Jun 08, 2010 5:11 am
Location: In analysis mode on Phaelon
Contact:

Re: Scripters cove

Post by Fatleaf »

http://wiki.alioth.net/index.php/Shipda ... pace_motor

If I use "hyperspace_motor" = yes; would that allow a standard NPC non jump capable ship to jump?
Find out about the early influences of Fatleaf here. Also his OXP's!
Holds the Ooniversal record for "Thread Necromancy"
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2453
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: Scripters cove

Post by Wildeblood »

Fatleaf wrote:
http://wiki.alioth.net/index.php/Shipda ... pace_motor

If I use "hyperspace_motor" = yes; would that allow a standard NPC non jump capable ship to jump?
Yes.
User avatar
Fatleaf
Intergalactic Spam Assassin
Intergalactic Spam Assassin
Posts: 1988
Joined: Tue Jun 08, 2010 5:11 am
Location: In analysis mode on Phaelon
Contact:

Re: Scripters cove

Post by Fatleaf »

.. :D ..
Find out about the early influences of Fatleaf here. Also his OXP's!
Holds the Ooniversal record for "Thread Necromancy"
User avatar
Fatleaf
Intergalactic Spam Assassin
Intergalactic Spam Assassin
Posts: 1988
Joined: Tue Jun 08, 2010 5:11 am
Location: In analysis mode on Phaelon
Contact:

Re: Scripters cove

Post by Fatleaf »

Is there any way by script to stop a player from saving their game at a main station?
Find out about the early influences of Fatleaf here. Also his OXP's!
Holds the Ooniversal record for "Thread Necromancy"
User avatar
Gimi
---- E L I T E ----
---- E L I T E ----
Posts: 2073
Joined: Tue Aug 29, 2006 5:02 pm
Location: Norway

Re: Scripters cove

Post by Gimi »

Ionics does this by expelling you from the station, stating that you are a rebel and unwanted. Not sure if this is what you want, but might be worth a look. This effectively also stops the Save Anywhere OXP from working within the system, as that one transports you to the main station in order to allow you to save.
"A brilliant game of blasting and trading... Truly a mega-game... The game of a lifetime."
(Gold Medal Award, Zzap!64 May 1985).
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post by cim »

Another way of doing it: destroy the main station, and put a secondary station which looks the same (and has the same market, shipyard, etc.) where it was. You might have to add some special handling for escape pods, and I don't think the courier market will be available.
User avatar
Fatleaf
Intergalactic Spam Assassin
Intergalactic Spam Assassin
Posts: 1988
Joined: Tue Jun 08, 2010 5:11 am
Location: In analysis mode on Phaelon
Contact:

Re: Scripters cove

Post by Fatleaf »

Gimi: Tried that. And successfully forced the player to launch. But it isn't what I want. I need the player to do business in the station first.

cim: I was thinking of removing the main station and replacing it with a station of my own. But I then need to add a station to my oxp. A lot of work when I was hoping for a line or two of JS code instead.

Thanks for two good ideas. If there is no way to do it by script them removing the main station is the way to go as far as I can see. Unless someone has another idea!
Find out about the early influences of Fatleaf here. Also his OXP's!
Holds the Ooniversal record for "Thread Necromancy"
User avatar
maik
Wiki Wizard
Wiki Wizard
Posts: 2028
Joined: Wed Mar 10, 2010 12:30 pm
Location: Ljubljana, Slovenia (mainly industrial, feudal, TL12)

Re: Scripters cove

Post by maik »

Eric Walch wrote:
maik wrote:
If its energy is low, it performs evasive maneuvers until it is at least medium,

Code: Select all

		ENERGY_LOW = (performTumble, "pauseAI: 1.0", checkEnergy);
Evasive maneuvers would be more a 'performFlee' not being a sitting duck during a 'performTumble'. This asks for a seperate FLEE state like found in many other AI's
Thanks, Eric. I was following what is written here: [wiki]OXP howto AI[/wiki]
wiki wrote:
performTumble: Performs random pitch and roll, 'evasive maneuvers'.
I guess I misunderstood how to properply use it, what is it I have to do instead?
Post Reply