/usr/share/oolite/Scripts/oolite-contracts-helpers.js is in oolite-data 1.77.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | /*
oolite-contracts-helpers.js
Helper functions for various types of contracts
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 galaxyNumber, missionVariables, system*/
"use strict";
this.name = "oolite-contracts-helpers";
this.author = "cim";
this.copyright = "© 2012-2013 the Oolite team.";
this.description = "Helper functions for various contracts.";
this.version = "1.77.1";
// returns a string containing the necessary number of "hair spaces" to
// pad the currentText string to the specified length in 'em'
this._paddingText = function(currentText, desiredLength)
{
var hairSpace = String.fromCharCode(31);
var currentLength = defaultFont.measureString(currentText);
var hairSpaceLength = defaultFont.measureString(hairSpace);
// calculate number needed to fill remaining length
var padsNeeded = Math.floor((desiredLength - currentLength) / hairSpaceLength);
if (padsNeeded < 1)
{
return "";
}
// quick way of generating a repeated string of that number
return new Array(padsNeeded).join(hairSpace);
}
// gives a text description of the time remaining to deliver this contract
this._timeRemaining = function(contract)
{
return this._formatTravelTime(this._timeRemainingSeconds(contract));
}
this._timeRemainingSeconds = function(contract) {
return contract.deadline - clock.seconds;
}
// gives a text description of a reasonable travel time to fulfil contract
this._timeEstimate = function(contract)
{
// allow 30 minutes in each system on the shortest route
return this._formatTravelTime(this._timeEstimateSeconds(contract));
}
this._timeEstimateSeconds = function(contract)
{
return (contract.route.time * 3600) + (contract.route.route.length * 1800);
}
// format the travel time
this._formatTravelTime = function(seconds) {
// this function uses an hours-only format
// but provides enough information to use a days&hours format if
// oolite-contracts-time-format in missiontext.plist is overridden
// extra minutes are discarded
var hours = Math.floor(seconds/3600);
var days = Math.floor(hours/24);
var spareHours = hours % 24;
return expandMissionText("oolite-contracts-time-format",{
"oolite-contracts-time-format-hours": hours,
"oolite-contracts-time-format-days": days,
"oolite-contracts-time-format-spare-hours": spareHours
});
}
// summarises economy and government in system
this._systemName = function(id)
{
var info = System.infoForSystem(galaxyNumber,id);
var name = info.name+" (";
name += String.fromCharCode(info.government); //chr 0-7 are gov icons
name += ",";
name += String.fromCharCode(23-info.economy); //chr 16-23 are eco icons, in reverse order...
return name +")";
}
// sounds
this._soundSuccess = function()
{
var sound = new SoundSource;
sound.sound = "[contract-accepted]";
sound.play();
}
this._soundFailure = function()
{
var sound = new SoundSource;
sound.sound = "[contract-rejected]";
sound.play();
}
|