Modify mission scripts to use populator to add mission ships

This commit is contained in:
cim 2013-07-31 21:29:29 +01:00
parent fd822b2c2b
commit d3ab9e05d7
4 changed files with 102 additions and 73 deletions

View File

@ -40,7 +40,16 @@ this.description = "Cloaking device mission in galaxy 5.";
this.version = "1.77.1";
this.shipWillExitWitchspace = function ()
this.startUp = function ()
{
if (missionVariables.cloak !== null)
{
// save time by deleting unused handlers
delete this.systemWillPopulate;
}
}
this.systemWillPopulate = function ()
{
// If we're in galaxy 5...
if (galaxyNumber === 4)
@ -62,9 +71,17 @@ this.shipWillExitWitchspace = function ()
if (missionVariables.cloakcounter > 6 && system.countShipsWithRole("asp-cloaked") === 0)
{
// Then trigger the ambush!
system.addShips("asp-cloaked", 1);
system.addShips("asp-pirate", 2);
}
system.setPopulator("oolite-cloaking-device-mission",
{
priority: 50,
location: "WITCHPOINT",
callback: function(pos)
{
system.addShips("asp-cloaked", 1, pos, 0);
system.addShips("asp-pirate", 2, pos, 2E3);
}
});
}
}
}
};

View File

@ -45,8 +45,7 @@ this._cleanUp = function ()
// Remove event handlers.
delete this.guiScreenChanged;
delete this.missionScreenOpportunity;
delete this.shipExitedWitchspace;
delete this.shipLaunchedFromStation;
delete this.systemWillPopulate;
};
@ -165,17 +164,24 @@ this.missionScreenOpportunity = function ()
};
this.shipExitedWitchspace = this.shipLaunchedFromStation = function ()
this.systemWillPopulate = function()
{
if (galaxyNumber === 1 &&
system.ID === 193 &&
missionVariables.conhunt === "STAGE_1" &&
system.countShipsWithRole("constrictor") === 0)
missionVariables.conhunt === "STAGE_1")
{
var constrictor = system.addShips("constrictor", 1);
constrictor[0].bounty = 250; // Ensure a bounty, in case it was missing in a custom shipdata.plist.
// Attach script here and not in shipdata, so that like_ship copies of the constrictor have no mission script,
// only the version used for the mission will have the script now.
constrictor[0].setScript("oolite-constrictor.js");
system.setPopulator("oolite-constrictor-mission",
{
priority: 50,
location: "WITCHPOINT",
callback: function(pos)
{
var constrictor = system.addShips("constrictor", 1, pos, 0);
constrictor[0].bounty = 250; // Ensure a bounty, in case it was missing in a custom shipdata.plist.
// Attach script here and not in shipdata, so that like_ship copies of the constrictor have no mission script,
// only the version used for the mission will have the script now.
constrictor[0].setScript("oolite-constrictor.js");
}
});
}
};

View File

@ -48,7 +48,7 @@ this.systemWillPopulate = function()
// in this order.
system.setPopulator("oolite-nav-buoy",
{
priority: 1,
priority: 5,
location: "COORDINATES",
coordinates: system.mainStation.position.add(system.mainStation.vectorForward.multiply(10E3)),
callback: function(pos) {
@ -61,7 +61,7 @@ this.systemWillPopulate = function()
system.setPopulator("oolite-witch-buoy",
{
priority: 2,
priority: 10,
location: "COORDINATES",
coordinates: [0,0,0],
callback: function(pos) {
@ -149,7 +149,7 @@ this.systemWillPopulate = function()
/* Add traders */
system.setPopulator("oolite-route1-traders",
{
priority: 10,
priority: 20,
location: "LANE_WP",
groupCount: traders,
callback: function(pos) {
@ -160,7 +160,7 @@ this.systemWillPopulate = function()
system.setPopulator("oolite-route2-traders",
{
priority: 10,
priority: 20,
location: "LANE_PS",
groupCount: pstraders,
callback: function(pos) {
@ -187,7 +187,7 @@ this.systemWillPopulate = function()
system.setPopulator("oolite-route1-pirates",
{
priority: 10,
priority: 20,
location: "LANE_WP",
groupCount: pirates,
callback: this._addPirates
@ -195,7 +195,7 @@ this.systemWillPopulate = function()
system.setPopulator("oolite-route2-pirates",
{
priority: 10,
priority: 20,
location: "LANE_PS",
groupCount: pspirates,
callback: this._addPirates
@ -226,7 +226,7 @@ this.systemWillPopulate = function()
}
system.setPopulator("oolite-route1-hunters",
{
priority: 10,
priority: 20,
location: "LANE_WP",
groupCount: hunters,
callback: addHunter
@ -234,7 +234,7 @@ this.systemWillPopulate = function()
system.setPopulator("oolite-route2-hunters",
{
priority: 10,
priority: 20,
location: "LANE_PS",
groupCount: hunters,
callback: function(pos) {
@ -247,7 +247,7 @@ this.systemWillPopulate = function()
/* Add thargoids */
system.setPopulator("oolite-route1-thargoids",
{
priority: 10,
priority: 20,
location: "LANE_WP",
groupCount: thargoids,
callback: function(pos) {
@ -274,7 +274,7 @@ this.systemWillPopulate = function()
system.setPopulator("oolite-route1-asteroids",
{
priority: 10,
priority: 20,
location: "LANE_WP",
locationSeed: 51728,
groupCount: clusters,
@ -283,7 +283,7 @@ this.systemWillPopulate = function()
});
system.setPopulator("oolite-route2-asteroids",
{
priority: 10,
priority: 20,
location: "LANE_PS",
locationSeed: 82715,
groupCount: psclusters,
@ -414,9 +414,10 @@ this.systemWillRepopulate = function()
}
// Thargoid invasions
if (Math.random() < 0.01)
// TODO: Need to think more about how new thargoids get added in.
if (Math.random() < 0.001)
{
system.addShips("thargoid",1,[0,0,0],7500);
system.addShips("thargoid",1,system.planet.position.multiply(0.5),7500);
}
}

View File

@ -39,41 +39,6 @@ this.copyright = "© 2008-2013 the Oolite team.";
this.version = "1.77.1";
this._setUpShips = function ()
{
function addThargoids()
{
this._waveCount++; // 5 loops of adding in the legacy script with a script timer.
if (this._waveCount > 5)
{
this._thargoidTimer.stop();
return;
}
if (system.countShipsWithRole("thargoid") < 2)
{
system.addShipsToRoute("thargoid", 1, 0.33);
system.addShipsToRoute("thargoid", 1, 0.66);
}
if (system.countShipsWithRole("thargoid") < 5 && Math.random() < 0.5)
{
system.addShips("thargoid", 1);
}
}
if (missionVariables.thargplans === "RUNNING" && galaxyNumber === 2)
{
if (this._thargoidTimer)
{
this._thargoidTimer.start();
}
else
{
this._thargoidTimer = new Timer(this, addThargoids, 10, 10);
}
}
};
this._cleanUp = function ()
{
/* After the mission is complete, it's good
@ -87,8 +52,8 @@ this._cleanUp = function ()
the gaming experience as smooth as possible.
*/
delete this.missionScreenOpportunity;
delete this.shipLaunchedFromStation;
delete this.shipExitedWitchspace;
delete this.systemWillPopulate;
delete this.systemWillRepopulate;
};
@ -96,7 +61,6 @@ this._cleanUp = function ()
this.startUp = function ()
{
this._waveCount = 0; // should be zero on the first launch after a reset.
if (missionVariables.thargplans === "MISSION_COMPLETE")
{
this._cleanUp();
@ -170,14 +134,55 @@ this.missionScreenOpportunity = function ()
};
this.shipLaunchedFromStation = function ()
this.systemWillPopulate = function()
{
this._setUpShips();
};
if (missionVariables.thargplans === "RUNNING" && galaxyNumber === 2)
{
system.setPopulator("oolite-thargoidplans-mission-a",
{
priority: 50,
location: "LANE_WP",
groupCount: 2,
callback: function(pos)
{
system.addShips("thargoid", 1, pos, 0);
}
});
system.setPopulator("oolite-thargoidplans-mission-b",
{
priority: 50,
location: "WITCHPOINT",
groupCount: 1,
callback: function(pos)
{
system.addShips("thargoid", 1, pos, 0);
}
});
this._waveCount = 0;
this._ambushCount = 0;
// bring a few extra thargoids in shortly after arrival
this.systemWillRepopulate = function()
{
if (this._waveCount <= 4)
{
if (Math.random() < 0.5 && this._ambushCount < 2)
{
this._ambushCount++;
system.addShips("thargoid", 1);
}
}
else
{
delete this.systemWillRepopulate;
}
this._waveCount++;
}
}
else
{
delete this.systemWillRepopulate;
}
}
this.shipExitedWitchspace = function ()
{
this._waveCount = 0;
this._setUpShips();
};