~harrison-rt/+junk/jaguar_company

« back to all changes in this revision

Viewing changes to trunk/jaguar_company.oxp/Scripts/jaguar_company_attackers.js

  • Committer: Richard Harrison
  • Date: 2013-01-19 23:01:03 UTC
  • Revision ID: harrison.rt@gmail.com-20130119230103-hukuh0h9jorz3hk1
Tags: 2.4
* Bug fix for spawning Jaguar Company. Potential to spawn the base at all times if the Galactic Navy wasn't present.
* Bug fix for checking the safe zone around the base. Wasn't checking to see if it actually existed.
* Main world script saves the last system ID that was visited for interstellar space.
* Timer on start up for the worldscripts has been added to allow each worldscript to be loaded in. Stops a potential dependency error happening.
* Stray commas in the route list arrays removed.
* Welcome code has been cleaned up.
* missiontext.plist and descriptions.plist cleaned up.
* Altered all player consoleMessage's to show messages for the default time limit.
* Changed all player commsMessage's to consoleMessage.
* Changed some of the player consoleMessage's back into commsMessage.
* Only insert news into Snoopers about battle help if more than 10 minutes has passed since the last news item was inserted.
* If you set $alwaysSpawn to true with OXPConfig the base will be spawned if it doesn't exist.
* Patrol ships follow the Galactic Navy.
** If by some freak accident, all of the Galactic Navy is destroyed, the patrol ships will go back to base if it exists. Otherwise they will patrol the witchpoint to planet lane.
* New reputation level. Shows the location of Jaguar Company Bases in the current galaxy.
** Re-implementation of the game random number generators for system.pseudoRandomNumber and system.scrambledPseudoRandomNumber, to allow checking of all the systems in the current galaxy. The system versions only gives back a value for the current system.
** Oolite v1.76.1 or older only show a list of system names. Go to the long range chart then select the status screen (F6, F6, F5). Borrowed some code from Spara's Trophy Collector OXP for this.
** Oolite v1.77 or newer display the locations on the long range chart. Uses the new object method of mission.markSystem so it won't intefere with other OXPs. (Hopefully)

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
    this.copyright = "© 2012 Richard Thomas Harrison (Tricky)";
28
28
    this.license = "CC BY-NC-SA 3.0";
29
29
    this.description = "Script to initialise the Jaguar Company attackers.";
30
 
    this.version = "1.2";
 
30
    this.version = "1.3";
31
31
 
32
32
    /* Private variable. */
33
33
    var p_attackers = {};
43
43
 
44
44
        log(this.name + " " + this.version + " loaded.");
45
45
 
46
 
        /* Setup the private attackers variable. */
47
 
        this.$setUp();
 
46
        /* Setup the private attackers variable + some public variables. Delay it. */
 
47
        this.$setUpTimerReference = new Timer(this, this.$setUp, 0.5, 0.5);
48
48
    };
49
49
 
50
50
    /* Reset everything just before exiting Witchspace. */
51
51
    this.shipWillExitWitchspace = function () {
52
 
        /* Setup the private attackers variable. */
 
52
        /* Setup the private attackers variable + some public variables. */
53
53
        this.$setUp();
54
54
    };
55
55
 
56
 
    /* Remove the attacker mark and reputation mark if the player jumps galaxies. */
57
 
    this.playerEnteredNewGalaxy = function () {
58
 
        delete missionVariables.jaguar_company_attacker;
59
 
        delete missionVariables.jaguar_company_reputation;
60
 
    };
61
 
 
62
56
    /* Player fired a laser at someone and hit.
63
57
     * Check if they are a known hostile of Jaguar Company.
64
58
     *
72
66
        pilotName,
73
67
        reputation,
74
68
        helperLevel = p_attackers.mainScript.$reputationHelper,
75
 
        blackboxLevel = p_attackers.mainScript.$reputationBlackbox;
 
69
        blackboxLevel = p_attackers.mainScript.$reputationBlackbox,
 
70
        locationsLevel = p_attackers.mainScript.$reputationLocations;
76
71
 
77
72
        if (!this.$isHostile(victim)) {
78
73
            /* Ignore victims that are not hostile to Jaguar Company. */
126
121
            player.commsMessage(pilotName + ": " + expandDescription("[jaguar_company_player_help_buoy]"));
127
122
        } else if (reputation === blackboxLevel) {
128
123
            player.commsMessage(pilotName + ": " + expandDescription("[jaguar_company_player_help_blackbox]"));
 
124
        } else if (reputation === locationsLevel) {
 
125
            player.commsMessage(pilotName + ": " + expandDescription("[jaguar_company_player_help_locations]"));
129
126
        }
130
127
    };
131
128
 
143
140
        newsSource,
144
141
        reputation,
145
142
        helperLevel = p_attackers.mainScript.$reputationHelper,
146
 
        blackboxLevel = p_attackers.mainScript.$reputationBlackbox;
 
143
        blackboxLevel = p_attackers.mainScript.$reputationBlackbox,
 
144
        locationsLevel = p_attackers.mainScript.$reputationLocations;
147
145
 
148
146
        if (!this.$isHostile(victim)) {
149
147
            /* Ignore victims that are not hostile to Jaguar Company. */
200
198
        } else if (reputation >= blackboxLevel && reputation < blackboxLevel + 10 &&
201
199
            player.ship.equipmentStatus("EQ_JAGUAR_COMPANY_BLACK_BOX") !== "EQUIPMENT_OK") {
202
200
            player.commsMessage(pilotName + ": " + expandDescription("[jaguar_company_player_help_blackbox]"));
 
201
        } else if (reputation >= locationsLevel && reputation < locationsLevel + 10 &&
 
202
            player.ship.equipmentStatus("EQ_JAGUAR_COMPANY_BLACK_BOX") === "EQUIPMENT_OK") {
 
203
            player.commsMessage(pilotName + ": " + expandDescription("[jaguar_company_player_help_locations]"));
203
204
        }
204
205
 
205
 
        if (!p_attackers.newsSent || clock.seconds - p_attackers.newsSent > 5 * 60) {
206
 
            /* First kill or more than 5 minutes since the last kill. */
 
206
        if (!p_attackers.newsSent || clock.seconds - p_attackers.newsSent > 10 * 60) {
 
207
            /* First kill in the current system or more than 10 minutes since the last kill. */
207
208
            p_attackers.newsSent = clock.seconds;
208
209
            /* Send news to Snoopers. */
209
210
            p_attackers.mainScript.$sendNewsToSnoopers(expandDescription("[jaguar_company_help_news]", {
216
217
 
217
218
    /* Setup the private attackers variable and clear the public friend roles array. */
218
219
    this.$setUp = function () {
 
220
        if (!worldScripts["Jaguar Company"]) {
 
221
            /* Main script not loaded yet. */
 
222
            return;
 
223
        }
 
224
 
 
225
        /* Stop and remove the timer. */
 
226
        if (this.$setUpTimerReference) {
 
227
            if (this.$setUpTimerReference.isRunning) {
 
228
                this.$setUpTimerReference.stop();
 
229
            }
 
230
 
 
231
            delete this.$setUpTimerReference;
 
232
        }
 
233
 
219
234
        /* Initialise the p_attackers variable object.
220
235
         * Encapsulates all private global data.
221
236
         */
962
977
 
963
978
            if (victim.isPiloted) {
964
979
                /* Player hostile message. */
965
 
                player.commsMessage(pilotName + ": " + expandDescription("[jaguar_company_player_hostile_fire]"));
 
980
                player.consoleMessage(pilotName + ": " + expandDescription("[jaguar_company_player_hostile_fire]"));
966
981
            }
967
982
        } else {
968
983
            if (victim.isPiloted) {
969
984
                /* Other ship hostile message. */
970
 
                player.commsMessage(pilotName + ": " + expandDescription("[jaguar_company_hostile_fire]"));
 
985
                player.consoleMessage(pilotName + ": " + expandDescription("[jaguar_company_hostile_fire]"));
971
986
            }
972
987
        }
973
988
    };
1005
1020
        if (this.$friendRoles.indexOf(attacker.entityPersonality) > -1 || attacker.isPolice) {
1006
1021
            if (victim.isPiloted && Math.random() > p_attackers.messageProbability) {
1007
1022
                /* Broadcast a "friendly fire" message. */
1008
 
                player.commsMessage(pilotName + ": " + expandDescription("[jaguar_company_friendly_fire]"));
 
1023
                player.consoleMessage(pilotName + ": " + expandDescription("[jaguar_company_friendly_fire]"));
1009
1024
            }
1010
1025
 
1011
1026
            /* Tell the attacker that we are a friend. */
1027
1042
                /* Show hostile message. */
1028
1043
                if (attacker.isPlayer) {
1029
1044
                    /* Player hostile message. */
1030
 
                    player.commsMessage(pilotName + ": " +
1031
 
                        expandDescription("[jaguar_company_player_hostile_fire]"));
 
1045
                    player.consoleMessage(pilotName + ": " + expandDescription("[jaguar_company_player_hostile_fire]"));
1032
1046
                } else {
1033
1047
                    /* Other ship hostile message. */
1034
 
                    player.commsMessage(pilotName + ": " + expandDescription("[jaguar_company_hostile_fire]"));
 
1048
                    player.consoleMessage(pilotName + ": " + expandDescription("[jaguar_company_hostile_fire]"));
1035
1049
                }
1036
1050
            }
1037
1051
 
1058
1072
                        /* Decrease reputation. */
1059
1073
                        missionVariables.jaguar_company_reputation -= 1;
1060
1074
                        /* Player warning. */
1061
 
                        player.commsMessage(pilotName + ": " +
 
1075
                        player.consoleMessage(pilotName + ": " +
1062
1076
                            expandDescription("[jaguar_company_player_friendly_fire]"));
1063
1077
                    } else {
1064
1078
                        /* Other ship warning. */
1065
 
                        player.commsMessage(pilotName + ": " +
1066
 
                            expandDescription("[jaguar_company_friendly_fire]"));
 
1079
                        player.consoleMessage(pilotName + ": " + expandDescription("[jaguar_company_friendly_fire]"));
1067
1080
                    }
1068
1081
                }
1069
1082
 
1086
1099
 
1087
1100
            if (victim.isPiloted) {
1088
1101
                /* Player hostile message. */
1089
 
                player.commsMessage(pilotName + ": " + expandDescription("[jaguar_company_player_hostile_fire]"));
 
1102
                player.consoleMessage(pilotName + ": " + expandDescription("[jaguar_company_player_hostile_fire]"));
1090
1103
            }
1091
1104
        } else {
1092
1105
            if (victim.isPiloted) {
1093
1106
                /* Other ship hostile message. */
1094
 
                player.commsMessage(pilotName + ": " + expandDescription("[jaguar_company_hostile_fire]"));
 
1107
                player.consoleMessage(pilotName + ": " + expandDescription("[jaguar_company_hostile_fire]"));
1095
1108
            }
1096
1109
        }
1097
1110
 
1143
1156
                }
1144
1157
 
1145
1158
                /* Death message. */
1146
 
                player.commsMessage(pilotName + ": " + expandDescription("[jaguar_company_death]"));
 
1159
                player.consoleMessage(pilotName + ": " + expandDescription("[jaguar_company_death]"));
1147
1160
            }
1148
1161
        }
1149
1162
 
1170
1183
            missionVariables.conhunt = "CONSTRICTOR_DESTROYED";
1171
1184
            player.score += 1;
1172
1185
            player.credits += target.bounty;
1173
 
            player.consoleMessage(whom.ship.displayName + " assisted in the death of " + target.name, 3);
1174
 
            player.consoleMessage(
 
1186
            player.commsMessage(whom.ship.displayName + " assisted in the death of " + target.name);
 
1187
            player.commsMessage(
1175
1188
                whom.ship.displayName + ": Commander " + player.name +
1176
 
                ", you have the kill and bounty of " + target.bounty + "₢.", 3);
 
1189
                ", you have the kill and bounty of " + target.bounty + "₢.");
1177
1190
 
1178
1191
            if (p_attackers.logging && p_attackers.logExtra) {
1179
1192
                log(this.name, "$shipTargetDestroyed::" + this.ship.displayName +
1310
1323
                return true;
1311
1324
            }
1312
1325
 
1313
 
            if (entity.position.distanceTo(p_attackers.mainScript.$jaguarCompanyBase.position) < 30000) {
 
1326
            if (p_attackers.mainScript.$jaguarCompanyBase && p_attackers.mainScript.$jaguarCompanyBase.isValid &&
 
1327
                entity.position.distanceTo(p_attackers.mainScript.$jaguarCompanyBase.position) < 30000) {
1314
1328
                /* All ships not identified as hostile so far are safe within 30km of the base. */
1315
1329
                return false;
1316
1330
            }
1362
1376
                /* Show hostile message. */
1363
1377
                if (target.isPlayer) {
1364
1378
                    /* Player hostile message. */
1365
 
                    player.commsMessage(pilotName + ": " +
1366
 
                        expandDescription("[jaguar_company_player_hostile_fire]"));
 
1379
                    player.consoleMessage(pilotName + ": " + expandDescription("[jaguar_company_player_hostile_fire]"));
1367
1380
                } else {
1368
1381
                    /* Other ship hostile message. */
1369
 
                    player.commsMessage(pilotName + ": " + expandDescription("[jaguar_company_hostile_fire]"));
 
1382
                    player.consoleMessage(pilotName + ": " + expandDescription("[jaguar_company_hostile_fire]"));
1370
1383
                }
1371
1384
            }
1372
1385