Line data Source code
1 0 : /* 2 : 3 : PlayerEntityLegacyScriptEngine.h 4 : 5 : Various utility methods used for scripting. 6 : 7 : Oolite 8 : Copyright (C) 2004-2013 Giles C Williams and contributors 9 : 10 : This program is free software; you can redistribute it and/or 11 : modify it under the terms of the GNU General Public License 12 : as published by the Free Software Foundation; either version 2 13 : of the License, or (at your option) any later version. 14 : 15 : This program is distributed in the hope that it will be useful, 16 : but WITHOUT ANY WARRANTY; without even the implied warranty of 17 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 : GNU General Public License for more details. 19 : 20 : You should have received a copy of the GNU General Public License 21 : along with this program; if not, write to the Free Software 22 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 23 : MA 02110-1301, USA. 24 : 25 : */ 26 : 27 : #import "PlayerEntity.h" 28 : 29 : 30 : @class OOScript; 31 : 32 : 33 0 : typedef enum 34 : { 35 : COMPARISON_EQUAL, 36 : COMPARISON_NOTEQUAL, 37 : COMPARISON_LESSTHAN, 38 : COMPARISON_GREATERTHAN, 39 : COMPARISON_ONEOF, 40 : COMPARISON_UNDEFINED 41 : } OOComparisonType; 42 : 43 : 44 0 : typedef enum 45 : { 46 : OP_STRING, 47 : OP_NUMBER, 48 : OP_BOOL, 49 : OP_MISSION_VAR, 50 : OP_LOCAL_VAR, 51 : OP_FALSE, 52 : 53 : OP_INVALID // Must be last. 54 : } OOOperationType; 55 : 56 : 57 : @interface PlayerEntity (Scripting) 58 : 59 0 : - (void) checkScript; 60 : 61 0 : - (void) setScriptTarget:(ShipEntity *)ship; 62 0 : - (ShipEntity*) scriptTarget; 63 : 64 0 : - (void) runScriptActions:(NSArray *)sanitizedActions withContextName:(NSString *)contextName forTarget:(ShipEntity *)target; 65 0 : - (void) runUnsanitizedScriptActions:(NSArray *)unsanitizedActions allowingAIMethods:(BOOL)allowAIMethods withContextName:(NSString *)contextName forTarget:(ShipEntity *)target; 66 : 67 : // Test (sanitized) legacy script conditions array. 68 0 : - (BOOL) scriptTestConditions:(NSArray *)array; 69 : 70 0 : - (NSDictionary*) missionVariables; 71 : 72 0 : - (NSString *)missionVariableForKey:(NSString *)key; 73 0 : - (void)setMissionVariable:(NSString *)value forKey:(NSString *)key; 74 : 75 0 : - (NSMutableDictionary *)localVariablesForMission:(NSString *)missionKey; 76 0 : - (NSString *)localVariableForKey:(NSString *)variableName andMission:(NSString *)missionKey; 77 0 : - (void)setLocalVariable:(NSString *)value forKey:(NSString *)variableName andMission:(NSString *)missionKey; 78 : 79 : /*-----------------------------------------------------*/ 80 : 81 0 : - (NSString *) mission_string; 82 0 : - (NSString *) status_string; 83 0 : - (NSString *) gui_screen_string; 84 0 : - (NSNumber *) galaxy_number; 85 0 : - (NSNumber *) planet_number; 86 0 : - (NSNumber *) score_number; 87 0 : - (NSNumber *) credits_number; 88 0 : - (NSNumber *) scriptTimer_number; 89 0 : - (NSNumber *) shipsFound_number; 90 : 91 0 : - (NSNumber *) d100_number; 92 0 : - (NSNumber *) pseudoFixedD100_number; 93 0 : - (NSNumber *) d256_number; 94 0 : - (NSNumber *) pseudoFixedD256_number; 95 : 96 0 : - (NSNumber *) clock_number; // returns the game time in seconds 97 0 : - (NSNumber *) clock_secs_number; // returns the game time in seconds 98 0 : - (NSNumber *) clock_mins_number; // returns the game time in minutes 99 0 : - (NSNumber *) clock_hours_number; // returns the game time in hours 100 0 : - (NSNumber *) clock_days_number; // returns the game time in days 101 : 102 0 : - (NSNumber *) fuelLevel_number; // returns the fuel level in LY 103 : 104 0 : - (NSString *) dockedAtMainStation_bool; 105 0 : - (NSString *) foundEquipment_bool; 106 : 107 0 : - (NSString *) sunWillGoNova_bool; // returns whether the sun is going to go nova 108 0 : - (NSString *) sunGoneNova_bool; // returns whether the sun has gone nova 109 : 110 0 : - (NSString *) missionChoice_string; // returns nil or the key for the chosen option 111 0 : - (NSString *) missionKeyPress_string; 112 : 113 0 : - (NSNumber *) dockedTechLevel_number; 114 0 : - (NSString *) dockedStationName_string; // returns 'NONE' if the player isn't docked, [station name] if it is, 'UNKNOWN' otherwise 115 : 116 0 : - (NSNumber *) systemGovernment_number; 117 0 : - (NSString *) systemGovernment_string; 118 0 : - (NSNumber *) systemEconomy_number; 119 0 : - (NSString *) systemEconomy_string; 120 0 : - (NSNumber *) systemTechLevel_number; 121 0 : - (NSNumber *) systemPopulation_number; 122 0 : - (NSNumber *) systemProductivity_number; 123 : 124 0 : - (NSString *) commanderName_string; 125 0 : - (NSString *) commanderRank_string; 126 0 : - (NSString *) commanderShip_string; 127 0 : - (NSString *) commanderShipDisplayName_string; 128 0 : - (NSString *) commanderLegalStatus_string; 129 0 : - (NSNumber *) commanderLegalStatus_number; 130 : 131 : /*-----------------------------------------------------*/ 132 : 133 0 : - (NSArray *) missionsList; 134 : 135 0 : - (void) setMissionDescription:(NSString *)textKey; 136 0 : - (void) clearMissionDescription; 137 0 : - (void) setMissionInstructions:(NSString *)text forMission:(NSString *)key; 138 0 : - (void) setMissionInstructionsList:(NSArray *)list forMission:(NSString *)key; 139 0 : - (void) setMissionDescription:(NSString *)textKey forMission:(NSString *)key; 140 0 : - (void) clearMissionDescriptionForMission:(NSString *)key; 141 : 142 0 : - (void) commsMessage:(NSString *)valueString; 143 0 : - (void) commsMessageByUnpiloted:(NSString *)valueString; // Enabled 02-May-2008 - Nikos. Same as commsMessage, but 144 : // can be used by scripts to have unpiloted ships sending 145 : // commsMessages, if we want to. 146 : 147 0 : - (void) consoleMessage3s:(NSString *)valueString; 148 0 : - (void) consoleMessage6s:(NSString *)valueString; 149 : 150 0 : - (void) setLegalStatus:(NSString *)valueString; 151 0 : - (void) awardCredits:(NSString *)valueString; 152 0 : - (void) awardShipKills:(NSString *)valueString; 153 0 : - (void) awardEquipment:(NSString *)equipString; //eg. EQ_NAVAL_ENERGY_UNIT 154 0 : - (void) removeEquipment:(NSString *)equipString; //eg. EQ_NAVAL_ENERGY_UNIT 155 : 156 0 : - (void) setPlanetinfo:(NSString *)key_valueString; // uses key=value format 157 0 : - (void) setSpecificPlanetInfo:(NSString *)key_valueString; // uses galaxy#=planet#=key=value 158 : 159 0 : - (void) awardCargo:(NSString *)amount_typeString; 160 0 : - (void) removeAllCargo; 161 0 : - (void) removeAllCargo:(BOOL)forceRemoval; 162 : 163 0 : - (void) useSpecialCargo:(NSString *)descriptionString; 164 : 165 0 : - (void) testForEquipment:(NSString *)equipString; //eg. EQ_NAVAL_ENERGY_UNIT 166 : 167 0 : - (void) awardFuel:(NSString *)valueString; // add to fuel up to 7.0 LY 168 : 169 0 : - (void) messageShipAIs:(NSString *)roles_message; 170 0 : - (void) ejectItem:(NSString *)item_key; 171 0 : - (void) addShips:(NSString *)roles_number; 172 0 : - (void) addSystemShips:(NSString *)roles_number_position; 173 0 : - (void) addShipsAt:(NSString *)roles_number_system_x_y_z; 174 0 : - (void) addShipsAtPrecisely:(NSString *)roles_number_system_x_y_z; 175 0 : - (void) addShipsWithinRadius:(NSString *)roles_number_system_x_y_z_r; 176 0 : - (void) spawnShip:(NSString *)ship_key; 177 0 : - (void) set:(NSString *)missionvariable_value; 178 0 : - (void) reset:(NSString *)missionvariable; 179 : /* 180 : set:missionvariable_value 181 : add:missionvariable_value 182 : subtract:missionvariable_value 183 : 184 : the value may be a string constant or one of the above calls 185 : ending in _bool, _number, or _string 186 : 187 : egs. 188 : set: mission_my_mission_status MISSION_START 189 : set: mission_my_mission_value 12.345 190 : set: mission_my_mission_clock clock_number 191 : add: mission_my_mission_clock 86400 192 : subtract: mission_my_mission_clock d100_number 193 : */ 194 : 195 0 : - (void) increment:(NSString *)missionVariableString; 196 0 : - (void) decrement:(NSString *)missionVariableString; 197 : 198 0 : - (void) add:(NSString *)missionVariableString_value; 199 0 : - (void) subtract:(NSString *)missionVariableString_value; 200 : 201 0 : - (void) checkForShips: (NSString *)roleString; 202 0 : - (void) resetScriptTimer; 203 0 : - (void) addMissionText: (NSString *)textKey; 204 0 : - (void) addLiteralMissionText: (NSString *)text; 205 : 206 0 : - (void) setMissionChoiceByTextEntry:(BOOL)enable; 207 0 : - (void) setMissionChoices:(NSString *)choicesKey; // choicesKey is a key for a dictionary of 208 : // choices/choice phrases in missiontext.plist and also.. 209 0 : - (void) setMissionChoicesDictionary:(NSDictionary *)choicesDict; 210 0 : - (void) resetMissionChoice; // resets MissionChoice to nil 211 : 212 0 : - (void) clearMissionScreen; 213 : 214 0 : - (void) addMissionDestination:(NSString *)destinations; // mark a system on the star charts 215 0 : - (void) removeMissionDestination:(NSString *)destinations; // stop a system being marked on star charts 216 : 217 0 : - (void) showShipModel:(NSString *)shipKey; 218 0 : - (void) setMissionMusic:(NSString *)value; 219 : 220 0 : - (NSString *)missionTitle; 221 0 : - (void) setMissionTitle:(NSString *)value; 222 : 223 0 : - (void) setFuelLeak: (NSString *)value; 224 0 : - (NSNumber *)fuelLeakRate_number; 225 0 : - (void) setSunNovaIn: (NSString *)time_value; 226 0 : - (void) launchFromStation; 227 0 : - (void) blowUpStation; 228 0 : - (void) sendAllShipsAway; 229 : 230 0 : - (OOPlanetEntity *) addPlanet: (NSString *)planetKey; 231 0 : - (OOPlanetEntity *) addMoon: (NSString *)moonKey; 232 : 233 0 : - (void) debugOn; 234 0 : - (void) debugOff; 235 0 : - (void) debugMessage:(NSString *)args; 236 : 237 0 : - (NSString*) replaceVariablesInString:(NSString*) args; 238 : 239 0 : - (void) playSound:(NSString *) soundName; 240 : 241 0 : - (BOOL) addEqScriptForKey:(NSString *)eq_key; 242 0 : - (void) removeEqScriptForKey:(NSString *)eq_key; 243 0 : - (NSUInteger) eqScriptIndexForKey:(NSString *)eq_key; 244 : 245 0 : - (void) targetNearestHostile; 246 0 : - (void) targetNearestIncomingMissile; 247 : 248 0 : - (void) setGalacticHyperspaceBehaviourTo:(NSString *) galacticHyperspaceBehaviourString; 249 0 : - (void) setGalacticHyperspaceFixedCoordsTo:(NSString *) galacticHyperspaceFixedCoordsString; 250 : 251 : /*-----------------------------------------------------*/ 252 : 253 0 : - (void) clearMissionScreenID; 254 0 : - (void) setMissionScreenID:(NSString *)msid; 255 0 : - (NSString *) missionScreenID; 256 0 : - (void) setGuiToMissionScreen; 257 0 : - (void) refreshMissionScreenTextEntry; 258 0 : - (void) setGuiToMissionScreenWithCallback:(BOOL) callback; 259 0 : - (void) doMissionCallback; 260 0 : - (void) endMissionScreenAndNoteOpportunity; 261 0 : - (void) setBackgroundFromDescriptionsKey:(NSString*) d_key; 262 0 : - (void) addScene:(NSArray *) items atOffset:(Vector) off; 263 0 : - (BOOL) processSceneDictionary:(NSDictionary *) couplet atOffset:(Vector) off; 264 0 : - (BOOL) processSceneString:(NSString*) item atOffset:(Vector) off; 265 : 266 : @end 267 : 268 0 : NSString *OOComparisonTypeToString(OOComparisonType type) CONST_FUNC;