Page 31 of 118
Re: Scripters cove
Posted: Wed Nov 16, 2011 5:31 pm
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?
Re: Scripters cove
Posted: Wed Nov 16, 2011 5:50 pm
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...
Re: Scripters cove
Posted: Wed Nov 16, 2011 6:05 pm
by maik
Thanks! That works
Re: Scripters cove
Posted: Fri Nov 18, 2011 2:19 pm
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.
Re: Scripters cove
Posted: Fri Nov 18, 2011 5:52 pm
by Thargoid
I'm not sure I should be answering this
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.
Re: Scripters cove
Posted: Fri Nov 18, 2011 5:57 pm
by maik
Cool, thanks for the feedback!
Re: Scripters cove
Posted: Sun Nov 20, 2011 9:02 pm
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
Re: Scripters cove
Posted: Tue Nov 22, 2011 1:09 am
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?
Re: Scripters cove
Posted: Tue Nov 22, 2011 1:17 am
by Wildeblood
Re: Scripters cove
Posted: Tue Nov 22, 2011 1:18 am
by Fatleaf
..
..
Re: Scripters cove
Posted: Thu Nov 24, 2011 11:30 pm
by Fatleaf
Is there any way by script to stop a player from saving their game at a main station?
Re: Scripters cove
Posted: Fri Nov 25, 2011 7:59 am
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.
Re: Scripters cove
Posted: Fri Nov 25, 2011 9:10 am
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.
Re: Scripters cove
Posted: Fri Nov 25, 2011 9:54 am
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!
Re: Scripters cove
Posted: Fri Nov 25, 2011 10:46 am
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?