Merge branch 'tutorial-scenario': lesson 6

This commit is contained in:
cim 2013-12-18 12:44:29 +00:00
commit cff7ee1dd0
7 changed files with 335 additions and 16 deletions

View File

@ -0,0 +1,64 @@
/*
oolite-tutorialFighterAI.js
AI for the tutorial simulated combat
Oolite
Copyright © 2004-2013 Giles C Williams and contributors
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
*/
"use strict";
this.name = "Oolite Tutorial Fighter AI";
this.version = "1.79";
this.aiStarted = function() {
var ai = new worldScripts["oolite-libPriorityAI"].PriorityAIController(this.ship);
ai.setCommunicationsRole("_tutorial");
ai.setPriorities([
/* Fight */
{
condition: ai.conditionInCombat,
configuration: ai.configurationAcquireCombatTarget,
behaviour: ai.behaviourDestroyCurrentTarget,
reconsider: 30 // makes missiles more distracting
},
/* Stop following me! */
{
condition: ai.conditionPlayerNearby,
configuration: ai.configurationAcquirePlayerAsTarget,
behaviour: ai.behaviourDestroyCurrentTarget,
reconsider: 5
},
/* Chase Player */
{
configuration: function() {
this.ship.destination = player.ship.position;
this.ship.desiredSpeed = 300;
},
behaviour: ai.behaviourApproachDestination,
reconsider: 5
}
],3+Math.random()+Math.random());
}

View File

@ -189,6 +189,7 @@
"oolite-tutorial-no-death" = "If this wasn't a simulator, that would have killed you. Be more careful this time!";
"oolite-tutorial-no-advance" = "Advancing with '[oolite_key_activate_equipment]' is not currently available.";
"oolite-tutorial-0-0-title" = "Flight Training Course";
"oolite-tutorial-0-0-message" = "Welcome to the Cooperative Flight Training Course, pilot. This course will demonstrate the basic functionality of Cooperative ships to you, in a specially-prepared simulator.\n\nThe course is in multiple sections. While in the simulator, you can use the '[oolite_key_activate_equipment]' key to advance to the next entry in the current lesson, and the '[oolite_key_mode_equipment]' key to go to the next lesson, if you wish to skip sections you have previously completed.\n\nOnce the simulation begins, a panel on your screen will display instructions, which you should follow to progress through the course. If you wish to temporarily hide the panel, press the '[oolite_key_cycle_mfd]' key. You can bring it back with the same key, or it will automatically reappear when there are new instructions.\n\nWhere an instruction asks you to press a letter key, press the letter key alone if it is lower case (e.g. 'i'), and press shift and the key together if it is upper case (e.g. 'K').\n\nWhen you are ready, press the Enter key to begin the simulation with the first lesson.";
@ -196,7 +197,7 @@
"oolite-tutorial-0-2" = "Welcome to the pilot's training course. The lesson information will be displayed on this panel.\n\nYou will often need to press '[oolite_key_activate_equipment]' to go to the next step - do this now to start the first lesson.\n\nRemember, you can also press '[oolite_key_mode_equipment]' to skip to the next lesson.";
"oolite-tutorial-1-0" = "Lesson 1: the HUD\nThis lesson introduces the HUD components in turn.\nFor now, the HUD components have all been hidden. As you go through this lesson, they will be made visible and introduced.";
"oolite-tutorial-1-0" = "Lesson 1: the HUD\nThis lesson introduces the HUD components in turn.\nWhen you start, the HUD components will all be hidden. As you go through this lesson, they will be made visible and introduced.";
"oolite-tutorial-1-1" = "Energy banks: 1/3\nThe energy bank gauge shows the stored energy in your ship's capacitors, which are used to power various high-energy systems.\nThey are continually recharged from your ship's power plant, but intensive activity will drain them faster than they can be charged.";
@ -330,12 +331,32 @@
"oolite-tutorial-5-11" = "Here it comes. Good luck!\n\nOnce you have survived the missile, press '[oolite_key_activate_equipment]' to start the next lesson.";
"oolite-tutorial-6-0" = "Lesson 6: Combat practice\nNow it's time to put everything you've learned in the previous lessons together, and fight some more challenging opponents.";
"oolite-tutorial-6-1" = "You'll be fighting simulated Krait fighters. The Krait is an old design, nowadays mostly superseded by the Mamba and Sidewinder, but it's cheap and easy to repair, and the large hull makes it easy to fit extra equipment, so it's still popular with some pilots. Press '[oolite_key_activate_equipment]' to start.";
"oolite-tutorial-6-2" = "This first Krait is unarmed - destroy it as fast as you can. This one should be easy, but if you ever feel out of your depth in later stages, we've also added a marker buoy. Shoot the buoy to end the lesson.\nYou only get three missiles for the entire course, so use them wisely.";
"oolite-tutorial-6-3" = "Now we move on to targets which can fight back. This Krait has a pulse laser like your own. It's not too much of a threat to your ship, but you should finish it quickly.";
"oolite-tutorial-6-4" = "Good work. Here's two more to take on. While fighting one, don't lose track of what the other is up to.\n\nTip: Zoom your scanner in so that you can see where the one you're firing at is going and keep on it. If you split your fire between both, you won't do enough damage.";
"oolite-tutorial-6-5" = "Excellent. That's the basics done. You can either end the lesson now by pressing '[oolite_key_mode_equipment]' or shooting the buoy, or you can continue to face harder targets by pressing '[oolite_key_activate_equipment]'.\nIf you want to wait a little for your shields to recharge, that's okay.";
"oolite-tutorial-6-6" = "This Krait has been upgraded to carry a beam laser. It'll tear up your shields in no time if you let it. Move!\n\nTip: Your weapon is weaker, so dodge and close the range rather than getting into a long-range shooting match.";
"oolite-tutorial-6-7" = "So far, so good. See if you can handle two at once.\n\nTip: when outnumbered like this, use a missile to distract one while you fight the other.";
"oolite-tutorial-6-8" = "You did it! We do have a third stage available if you're feeling up to it - press '[oolite_key_activate_equipment]' to start it. If that last fight was any trouble, though, maybe you'd be better stopping now. Pressing '[oolite_key_mode_equipment]' or shoot the buoy to complete the lesson.";
"oolite-tutorial-6-9" = "As you wish. This Krait is well-armed, well-equipped, and we've got a local escort pilot in the next simulator booth to fly it for us. Your Cobra might still be a superior ship, but you'll have to make every shot count.";
"oolite-tutorial-6-10" = "Very well done! If you fly like that, you might stand a chance when the pirates come for you. That's all we've got for combat training. Press '[oolite_key_activate_equipment]' to start the next lesson.";
"oolite-tutorial-end-mfd" = "You have completed the course. Press '[oolite_key_activate_equipment]' to view your test scores.";
"oolite-tutorial-end-title" = "Course Complete";
"oolite-tutorial-end-message" = "You have now completed the Pilot's Training Course. Your scores:\n\nDeaths: [mission_oolite_tutorial_deaths]\n\nAsteroid navigation: [mission_oolite_tutorial_asteroids_result] ([mission_oolite_tutorial_asteroids] seconds)\n";
"oolite-tutorial-end-message" = "You have now completed the Pilot's Training Course. Your scores:\n\nDeaths: [mission_oolite_tutorial_deaths]\n\nAsteroid navigation: [mission_oolite_tutorial_asteroids_result] ([mission_oolite_tutorial_asteroids] seconds)\nCombat practice: [mission_oolite_tutorial_combat_result] ([mission_oolite_tutorial_combat_duration] seconds)";
"oolite-tutorial-end-choices" = { "1" = "Exit Simulator"; };
"oolite-tutorial-end-notry" = "Incomplete";

View File

@ -2370,6 +2370,19 @@
weapon_position_port = "-45.0 0.0 -13.5";
weapon_position_starboard = "45.0 0.0 -13.5";
};
"oolite_template_tutorial-krait" = {
like_ship = "oolite_template_krait";
is_template = 1;
ai_type = "oolite-tutorialFighterAI.js";
forward_weapon_type = "WEAPON_PULSE_LASER";
has_fuel_injection = 0;
has_scoop = 0;
has_shield_booster = 0;
has_shield_enhancer = 0;
name = "Training Fighter";
roles = "oolite-tutorial-fighter";
script = "oolite-tutorial-fighter.js";
};
"oolite_template_mamba" = {
aft_eject_position = "0.0 -9.26 -35.1";
ai_type = "oolite-pirateAI.js";
@ -4090,6 +4103,10 @@
{
"like_ship" = "oolite_template_tutorial-buoy";
};
"oolite-tutorial-krait" =
{
"like_ship" = "oolite_template_tutorial-krait";
};
"oolite-tutorial-station" =
{
"like_ship" = "oolite_template_tutorial-station";

View File

@ -440,12 +440,19 @@ this.PriorityAIController = function(ship)
parameters[key] = value;
}
this.setPriorities = function(priorities)
this.setPriorities = function(priorities,delay)
{
priorityList = priorities;
this.clearHandlers();
this.applyHandlers({});
_resetReconsideration.call(this,Math.random());
if (delay && delay > 0)
{
_resetReconsideration.call(this,delay);
}
else
{
_resetReconsideration.call(this,Math.random());
}
}

View File

@ -40,7 +40,7 @@ this.version = "1.79";
this.activated = function()
{
worldScripts["oolite-tutorial"]._nextItem();
worldScripts["oolite-tutorial"]._nextItemEquip();
}

View File

@ -0,0 +1,48 @@
/*
oolite-tutorial-fighter.js
Ship script for Tutorial fighters.
Oolite
Copyright © 2004-2013 Giles C Williams and contributors
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
*/
/*jslint white: true, undef: true, eqeqeq: true, bitwise: true, regexp: true, newcap: true, immed: true */
/*global missionVariables, player*/
"use strict";
this.name = "oolite-tutorial-fighter";
this.author = "cim";
this.copyright = "© 2013-2013 the Oolite team.";
this.version = "1.79";
this.shipDied = function (killer)
{
if (killer && killer.isPlayer && (!this.ship.group || this.ship.group.count <= 1))
{
worldScripts["oolite-tutorial"]._nextItem();
}
};

View File

@ -54,6 +54,7 @@ this.startUp = function()
this.$tutorialStage = 0;
this.$tutorialSubstage = 0;
this.$advanceByEquipment = true;
/* Number of substages in each stage */
this.$tutorialStages = [
@ -63,7 +64,8 @@ this.startUp = function()
6, // stage 3: basic flight challenge
8, // stage 4: targeting + lasers
12, // stage 5: missiles + avoidance
0, // stage 6: (not yet started)
11, // stage 6: combat
0, // stage 7: (not yet started)
];
this.$shipList = [];
@ -72,6 +74,9 @@ this.startUp = function()
missionVariables.oolite_tutorial_asteroids = 0;
missionVariables.oolite_tutorial_asteroids_win = 0;
missionVariables.oolite_tutorial_asteroids_result = expandMissionText("oolite-tutorial-end-notry");
missionVariables.oolite_tutorial_combat_stage = 0;
missionVariables.oolite_tutorial_combat_duration = 0;
missionVariables.oolite_tutorial_combat_result = expandMissionText("oolite-tutorial-end-notry");
// alternative populator
this.ooliteTutorialWillPopulate = function()
@ -127,7 +132,7 @@ this.startUp = function()
if (this.$tutorialStage == 0 && this.$tutorialSubstage == 1)
{
station.position = station.position.add([0,0,1E7]);
station.remove();
station.remove(true);
this._nextItem();
}
}
@ -162,6 +167,18 @@ this.startUp = function()
this.$tutorialSound.play();
}
this._nextItemEquip = function()
{
if (this.$advanceByEquipment)
{
this._nextItem();
}
else
{
player.consoleMessage(expandMissionText("oolite-tutorial-no-advance"));
}
}
// move to the next item in the current tutorial
this._nextItem = function()
{
@ -307,6 +324,7 @@ this.startUp = function()
this._resetPlayerShip = function()
{
this.$advanceByEquipment = true;
player.ship.fuel = 2.0;
player.ship.energy = 256;
player.ship.forwardShield = 128;
@ -339,16 +357,38 @@ this.startUp = function()
{
if (this.$shipList[i] && this.$shipList[i].isShip)
{
this.$shipList[i].remove();
this.$shipList[i].remove(true);
}
}
}
// just in case a role has been defined out by OXP
this.$roleFallbacks = {
"asteroid" : "[asteroid]",
"boulder" : "[boulder]",
"splinter" : "[splinter]",
"police" : "[viper]",
"missile" : "[missile]",
"energy-bomb" : "[qbomb]"
};
this._addShips = function(role,num,pos,rad)
{
var arr = system.addShips(role,num,pos,rad);
this.$shipList = this.$shipList.concat(arr);
return arr;
var arr = system.addGroup(role,num,pos,rad);
if (!arr || arr.ships.length == 0)
{
role = this.$roleFallbacks[role];
if (role)
{
arr = system.addGroup(role,num,pos,rad);
}
}
if (!arr || arr.ships.length == 0)
{
return [];
}
this.$shipList = this.$shipList.concat(arr.ships);
return arr.ships;
}
/* Tutorial stages */
@ -362,12 +402,12 @@ this.startUp = function()
this.__stage1sub0 = function()
{
this._hideHUDItems();
this._setInstructions("oolite-tutorial-1-0");
}
this.__stage1sub1 = function()
{
this._hideHUDItems();
this._setInstructions("oolite-tutorial-1-1");
this._showHUDItem("drawEnergyGauge:");
}
@ -657,6 +697,7 @@ this.startUp = function()
}
this._setInstructions("oolite-tutorial-3-3");
this.$advanceByEquipment = false;
var time = 0;
var nexttime = 5;
var atonce = 1;
@ -781,6 +822,7 @@ this.startUp = function()
{
this._setInstructions("oolite-tutorial-3-4");
}
this.$advanceByEquipment = true;
}
this.__stage3sub5 = function()
@ -934,12 +976,132 @@ this.startUp = function()
adder.remove();
}
this.__stage6sub0 = function()
{
this._setInstructions("oolite-tutorial-6-0");
}
this.__stage6sub1 = function()
{
this._setInstructions("oolite-tutorial-6-1");
}
this._stage6scorer = function()
{
missionVariables.oolite_tutorial_combat_stage = this.$tutorialSubstage;
missionVariables.oolite_tutorial_combat_duration = Math.floor(clock.seconds - this.$combatClock);
}
this.__stage6sub2 = function()
{
this.$advanceByEquipment = false;
this._setInstructions("oolite-tutorial-6-2");
var buoy = this._addShips("oolite-tutorial-buoy",1,player.ship.position,3E3)[0];
this.$combatClock = clock.seconds;
buoy.script.shipTakingDamage = function()
{
this._stage6scorer();
this._nextSection();
}.bind(this);
var target = this._addShips("oolite-tutorial-fighter",1,player.ship.position,10E3);
target[0].forwardWeapon = "EQ_WEAPON_NONE";
target[0].accuracy = 5;
}
this.__stage6sub3 = function()
{
this._setInstructions("oolite-tutorial-6-3");
var target = this._addShips("oolite-tutorial-fighter",1,player.ship.position,10E3);
target[0].accuracy = 0;
this._stage6scorer();
}
this.__stage6sub4 = function()
{
this._setInstructions("oolite-tutorial-6-4");
var target = this._addShips("oolite-tutorial-fighter",2,player.ship.position,10E3);
target[0].accuracy = 0;
target[1].accuracy = 0;
this._stage6scorer();
}
this.__stage6sub5 = function()
{
this.$advanceByEquipment = true;
this._setInstructions("oolite-tutorial-6-5");
this._stage6scorer();
}
this.__stage6sub6 = function()
{
this.$advanceByEquipment = false;
this._setInstructions("oolite-tutorial-6-6");
var target = this._addShips("oolite-tutorial-fighter",1,player.ship.position,10E3)
target[0].accuracy = 0;
target[0].forwardWeapon = "EQ_WEAPON_BEAM_LASER";
this._stage6scorer();
}
this.__stage6sub7 = function()
{
this._setInstructions("oolite-tutorial-6-7");
var target = this._addShips("oolite-tutorial-fighter",2,player.ship.position,10E3)
target[0].accuracy = 0;
target[0].forwardWeapon = "EQ_WEAPON_BEAM_LASER";
target[1].accuracy = 0;
target[1].forwardWeapon = "EQ_WEAPON_BEAM_LASER";
this._stage6scorer();
}
this.__stage6sub8 = function()
{
this.$advanceByEquipment = true;
this._setInstructions("oolite-tutorial-6-8");
this._stage6scorer();
}
this.__stage6sub9 = function()
{
this.$advanceByEquipment = false;
this._setInstructions("oolite-tutorial-6-9");
var target = this._addShips("oolite-tutorial-fighter",1,player.ship.position,10E3)
target[0].accuracy = 6;
target[0].forwardWeapon = "EQ_WEAPON_BEAM_LASER";
target[0].awardEquipment("EQ_ECM");
target[0].awardEquipment("EQ_FUEL_INJECTION");
target[0].awardEquipment("EQ_SHIELD_BOOSTER");
this._stage6scorer();
}
this.__stage6sub10 = function()
{
this.$advanceByEquipment = true;
this._setInstructions("oolite-tutorial-6-10");
this._stage6scorer();
}
this.__stage7sub0 = function()
{
if (missionVariables.oolite_tutorial_combat_stage > 0)
{
if (missionVariables.oolite_tutorial_combat_stage > 9)
{
this._scoreBonus("combat_result");
}
else if (missionVariables.oolite_tutorial_combat_stage > 7)
{
this._scoreWin("combat_result");
}
else if (missionVariables.oolite_tutorial_combat_stage > 4)
{
this._scoreTry("combat_result");
}
}
this._setInstructions("oolite-tutorial-end-mfd");
}