Oolite
Loading...
Searching...
No Matches
OOJSShip.m File Reference
Include dependency graph for OOJSShip.m:

Go to the source code of this file.

Macros

#define GET_THIS_SHIP(THISENT)

Enumerations

enum  {
  kShip_accuracy = -128 , kShip_aftWeapon , kShip_AI , kShip_AIScript ,
  kShip_AIScriptWakeTime , kShip_AIState , kShip_AIFoundTarget , kShip_AIPrimaryAggressor ,
  kShip_alertCondition , kShip_autoAI , kShip_autoWeapons , kShip_beaconCode ,
  kShip_beaconLabel , kShip_boundingBox , kShip_bounty , kShip_cargoList ,
  kShip_cargoSpaceAvailable , kShip_cargoSpaceCapacity , kShip_cargoSpaceUsed , kShip_collisionExceptions ,
  kShip_contracts , kShip_commodity , kShip_commodityAmount , kShip_cloakAutomatic ,
  kShip_crew , kShip_cruiseSpeed , kShip_currentWeapon , kShip_dataKey ,
  kShip_defenseTargets , kShip_desiredRange , kShip_desiredSpeed , kShip_destination ,
  kShip_destinationSystem , kShip_displayName , kShip_dockingInstructions , kShip_energyRechargeRate ,
  kShip_entityPersonality , kShip_equipment , kShip_escortGroup , kShip_escorts ,
  kShip_exhaustEmissiveColor , kShip_exhausts , kShip_extraCargo , kShip_flashers ,
  kShip_forwardWeapon , kShip_fuel , kShip_fuelChargeRate , kShip_group ,
  kShip_hasHostileTarget , kShip_hasHyperspaceMotor , kShip_hasSuspendedAI , kShip_heading ,
  kShip_heatInsulation , kShip_homeSystem , kShip_hyperspaceSpinTime , kShip_injectorBurnRate ,
  kShip_injectorSpeedFactor , kShip_isBeacon , kShip_isBoulder , kShip_isCargo ,
  kShip_isCloaked , kShip_isDerelict , kShip_isFrangible , kShip_isFleeing ,
  kShip_isJamming , kShip_isMinable , kShip_isMine , kShip_isMissile ,
  kShip_isPiloted , kShip_isPirate , kShip_isPirateVictim , kShip_isPolice ,
  kShip_isRock , kShip_isThargoid , kShip_isTurret , kShip_isTrader ,
  kShip_isWeapon , kShip_laserHeatLevel , kShip_laserHeatLevelAft , kShip_laserHeatLevelForward ,
  kShip_laserHeatLevelPort , kShip_laserHeatLevelStarboard , kShip_lightsActive , kShip_markedForFines ,
  kShip_maxEscorts , kShip_maxPitch , kShip_maxSpeed , kShip_maxRoll ,
  kShip_maxYaw , kShip_maxThrust , kShip_missileCapacity , kShip_missileLoadTime ,
  kShip_missiles , kShip_name , kShip_parcelCount , kShip_parcels ,
  kShip_passengerCapacity , kShip_passengerCount , kShip_passengers , kShip_pitch ,
  kShip_portWeapon , kShip_potentialCollider , kShip_primaryRole , kShip_reactionTime ,
  kShip_reportAIMessages , kShip_roleWeights , kShip_roles , kShip_roll ,
  kShip_savedCoordinates , kShip_scanDescription , kShip_scannerDisplayColor1 , kShip_scannerDisplayColor2 ,
  kShip_scannerHostileDisplayColor1 , kShip_scannerHostileDisplayColor2 , kShip_scannerRange , kShip_script ,
  kShip_scriptedMisjump , kShip_scriptedMisjumpRange , kShip_scriptInfo , kShip_shipClassName ,
  kShip_shipUniqueName , kShip_speed , kShip_starboardWeapon , kShip_subEntities ,
  kShip_subEntityCapacity , kShip_subEntityRotation , kShip_sunGlareFilter , kShip_target ,
  kShip_temperature , kShip_thrust , kShip_thrustVector , kShip_trackCloseContacts ,
  kShip_vectorForward , kShip_vectorRight , kShip_vectorUp , kShip_velocity ,
  kShip_weaponFacings , kShip_weaponPositionAft , kShip_weaponPositionForward , kShip_weaponPositionPort ,
  kShip_weaponPositionStarboard , kShip_weaponRange , kShip_withinStationAegis , kShip_yaw
}

Functions

static JSValue ShipGetProperty (OOJS_GETTER_ARGS)
static JSValue ShipSetProperty (OOJS_SETTER_ARGS)
static JSValue ShipSetScript (OOJS_NATIVE_ARGS)
static JSValue ShipSetAI (OOJS_NATIVE_ARGS)
static JSValue ShipSwitchAI (OOJS_NATIVE_ARGS)
static JSValue ShipExitAI (OOJS_NATIVE_ARGS)
static JSValue ShipReactToAIMessage (OOJS_NATIVE_ARGS)
static JSValue ShipSendAIMessage (OOJS_NATIVE_ARGS)
static JSValue ShipDeployEscorts (OOJS_NATIVE_ARGS)
static JSValue ShipDockEscorts (OOJS_NATIVE_ARGS)
static JSValue ShipHasRole (OOJS_NATIVE_ARGS)
static JSValue ShipEjectItem (OOJS_NATIVE_ARGS)
static JSValue ShipEjectSpecificItem (OOJS_NATIVE_ARGS)
static JSValue ShipDumpCargo (OOJS_NATIVE_ARGS)
static JSValue ShipAddCargoEntity (OOJS_NATIVE_ARGS)
static JSValue ShipSpawn (OOJS_NATIVE_ARGS)
static JSValue ShipDealEnergyDamage (OOJS_NATIVE_ARGS)
static JSValue ShipExplode (OOJS_NATIVE_ARGS)
static JSValue ShipRemove (OOJS_NATIVE_ARGS)
static JSValue ShipRunLegacyScriptActions (OOJS_NATIVE_ARGS)
static JSValue ShipCommsMessage (OOJS_NATIVE_ARGS)
static JSValue ShipFireECM (OOJS_NATIVE_ARGS)
static JSValue ShipAbandonShip (OOJS_NATIVE_ARGS)
static JSValue ShipCanAwardEquipment (OOJS_NATIVE_ARGS)
static JSValue ShipAwardEquipment (OOJS_NATIVE_ARGS)
static JSValue ShipAdjustCargo (OOJS_NATIVE_ARGS)
static JSValue ShipRequestHelpFromGroup (OOJS_NATIVE_ARGS)
static JSValue ShipPatrolReportIn (OOJS_NATIVE_ARGS)
static JSValue ShipRemoveEquipment (OOJS_NATIVE_ARGS)
static JSValue ShipRestoreSubEntities (OOJS_NATIVE_ARGS)
static JSValue ShipHasEquipmentProviding (OOJS_NATIVE_ARGS)
static JSValue ShipEquipmentStatus (OOJS_NATIVE_ARGS)
static JSValue ShipSetEquipmentStatus (OOJS_NATIVE_ARGS)
static JSValue ShipSelectNewMissile (OOJS_NATIVE_ARGS)
static JSValue ShipFireMissile (OOJS_NATIVE_ARGS)
static JSValue ShipFindNearestStation (OOJS_NATIVE_ARGS)
static JSValue ShipSetBounty (OOJS_NATIVE_ARGS)
static JSValue ShipSetCargo (OOJS_NATIVE_ARGS)
static JSValue ShipSetMaterials (OOJS_NATIVE_ARGS)
static JSValue ShipSetShaders (OOJS_NATIVE_ARGS)
static JSValue ShipExitSystem (OOJS_NATIVE_ARGS)
static JSValue ShipUpdateEscortFormation (OOJS_NATIVE_ARGS)
static JSValue ShipClearDefenseTargets (OOJS_NATIVE_ARGS)
static JSValue ShipAddDefenseTarget (OOJS_NATIVE_ARGS)
static JSValue ShipRemoveDefenseTarget (OOJS_NATIVE_ARGS)
static JSValue ShipAddCollisionException (OOJS_NATIVE_ARGS)
static JSValue ShipRemoveCollisionException (OOJS_NATIVE_ARGS)
static JSValue ShipGetMaterials (OOJS_NATIVE_ARGS)
static JSValue ShipGetShaders (OOJS_NATIVE_ARGS)
static JSValue ShipBecomeCascadeExplosion (OOJS_NATIVE_ARGS)
static JSValue ShipBroadcastCascadeImminent (OOJS_NATIVE_ARGS)
static JSValue ShipBroadcastDistressMessage (OOJS_NATIVE_ARGS)
static JSValue ShipOfferToEscort (OOJS_NATIVE_ARGS)
static JSValue ShipMarkTargetForFines (OOJS_NATIVE_ARGS)
static JSValue ShipEnterWormhole (OOJS_NATIVE_ARGS)
static JSValue ShipNotifyGroupOfWormhole (OOJS_NATIVE_ARGS)
static JSValue ShipThrowSpark (OOJS_NATIVE_ARGS)
static JSValue ShipPerformAttack (OOJS_NATIVE_ARGS)
static JSValue ShipPerformCollect (OOJS_NATIVE_ARGS)
static JSValue ShipPerformEscort (OOJS_NATIVE_ARGS)
static JSValue ShipPerformFaceDestination (OOJS_NATIVE_ARGS)
static JSValue ShipPerformFlee (OOJS_NATIVE_ARGS)
static JSValue ShipPerformFlyToRangeFromDestination (OOJS_NATIVE_ARGS)
static JSValue ShipPerformHold (OOJS_NATIVE_ARGS)
static JSValue ShipPerformIdle (OOJS_NATIVE_ARGS)
static JSValue ShipPerformIntercept (OOJS_NATIVE_ARGS)
static JSValue ShipPerformLandOnPlanet (OOJS_NATIVE_ARGS)
static JSValue ShipPerformMining (OOJS_NATIVE_ARGS)
static JSValue ShipPerformScriptedAI (OOJS_NATIVE_ARGS)
static JSValue ShipPerformScriptedAttackAI (OOJS_NATIVE_ARGS)
static JSValue ShipPerformStop (OOJS_NATIVE_ARGS)
static JSValue ShipPerformTumble (OOJS_NATIVE_ARGS)
static JSValue ShipRequestDockingInstructions (OOJS_NATIVE_ARGS)
static JSValue ShipRecallDockingInstructions (OOJS_NATIVE_ARGS)
static JSValue ShipCheckCourseToDestination (OOJS_NATIVE_ARGS)
static JSValue ShipGetSafeCourseToDestination (OOJS_NATIVE_ARGS)
static JSValue ShipCheckScanner (OOJS_NATIVE_ARGS)
static JSValue ShipThreatAssessment (OOJS_NATIVE_ARGS)
static JSValue ShipDamageAssessment (OOJS_NATIVE_ARGS)
static double ShipThreatAssessmentWeapon (OOWeaponType wt)
static JSValue ShipSetCargoType (OOJS_NATIVE_ARGS)
static JSValue ShipSetCrew (OOJS_NATIVE_ARGS)
static JSValue RemoveOrExplodeShip (OOJS_NATIVE_ARGS, BOOL explode)
static JSValue ShipSetMaterialsInternal (OOJS_NATIVE_ARGS, ShipEntity *thisEnt, BOOL fromShaders)
static JSValue ShipStaticKeysForRole (OOJS_NATIVE_ARGS)
static JSValue ShipStaticKeys (OOJS_NATIVE_ARGS)
static JSValue ShipStaticRoles (OOJS_NATIVE_ARGS)
static JSValue ShipStaticRoleIsInCategory (OOJS_NATIVE_ARGS)
static JSValue ShipStaticShipDataForKey (OOJS_NATIVE_ARGS)
static JSValue ShipStaticSetShipDataForKey (OOJS_NATIVE_ARGS)
void InitOOJSShip (JSContext *context, JSValueConst global)
JSClassID JSShipClassID (void)

Variables

static JSClassID sShipClassID
static JSClassDef sShipClass
static const JSCFunctionListEntry sShipProperties []
static const JSCFunctionListEntry sShipMethods []
static const JSCFunctionListEntry sShipStaticMethods []

Macro Definition Documentation

◆ GET_THIS_SHIP

#define GET_THIS_SHIP ( THISENT)
Value:
do { \
if (EXPECT_NOT(!JSShipGetShipEntity(context, OOJS_THIS, &THISENT))) \
return OOJSNativeFailure(context); /* Exception */ \
if (OOIsStaleEntity(THISENT)) \
} while (0)
#define EXPECT_NOT(x)
OOINLINE BOOL OOIsStaleEntity(Entity *entity)
Definition OOJSEntity.h:69
#define OOJS_THIS
#define OOJS_RETURN_VOID
JSValue OOJSNativeFailure(JSContext *context)

Definition at line 1766 of file OOJSShip.m.

1766#define GET_THIS_SHIP(THISENT) \
1767 do { \
1768 if (EXPECT_NOT(!JSShipGetShipEntity(context, OOJS_THIS, &THISENT))) \
1769 return OOJSNativeFailure(context); /* Exception */ \
1770 if (OOIsStaleEntity(THISENT)) \
1771 OOJS_RETURN_VOID; \
1772 } while (0)

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kShip_accuracy 
kShip_aftWeapon 
kShip_AI 
kShip_AIScript 
kShip_AIScriptWakeTime 
kShip_AIState 
kShip_AIFoundTarget 
kShip_AIPrimaryAggressor 
kShip_alertCondition 
kShip_autoAI 
kShip_autoWeapons 
kShip_beaconCode 
kShip_beaconLabel 
kShip_boundingBox 
kShip_bounty 
kShip_cargoList 
kShip_cargoSpaceAvailable 
kShip_cargoSpaceCapacity 
kShip_cargoSpaceUsed 
kShip_collisionExceptions 
kShip_contracts 
kShip_commodity 
kShip_commodityAmount 
kShip_cloakAutomatic 
kShip_crew 
kShip_cruiseSpeed 
kShip_currentWeapon 
kShip_dataKey 
kShip_defenseTargets 
kShip_desiredRange 
kShip_desiredSpeed 
kShip_destination 
kShip_destinationSystem 
kShip_displayName 
kShip_dockingInstructions 
kShip_energyRechargeRate 
kShip_entityPersonality 
kShip_equipment 
kShip_escortGroup 
kShip_escorts 
kShip_exhaustEmissiveColor 
kShip_exhausts 
kShip_extraCargo 
kShip_flashers 
kShip_forwardWeapon 
kShip_fuel 
kShip_fuelChargeRate 
kShip_group 
kShip_hasHostileTarget 
kShip_hasHyperspaceMotor 
kShip_hasSuspendedAI 
kShip_heading 
kShip_heatInsulation 
kShip_homeSystem 
kShip_hyperspaceSpinTime 
kShip_injectorBurnRate 
kShip_injectorSpeedFactor 
kShip_isBeacon 
kShip_isBoulder 
kShip_isCargo 
kShip_isCloaked 
kShip_isDerelict 
kShip_isFrangible 
kShip_isFleeing 
kShip_isJamming 
kShip_isMinable 
kShip_isMine 
kShip_isMissile 
kShip_isPiloted 
kShip_isPirate 
kShip_isPirateVictim 
kShip_isPolice 
kShip_isRock 
kShip_isThargoid 
kShip_isTurret 
kShip_isTrader 
kShip_isWeapon 
kShip_laserHeatLevel 
kShip_laserHeatLevelAft 
kShip_laserHeatLevelForward 
kShip_laserHeatLevelPort 
kShip_laserHeatLevelStarboard 
kShip_lightsActive 
kShip_markedForFines 
kShip_maxEscorts 
kShip_maxPitch 
kShip_maxSpeed 
kShip_maxRoll 
kShip_maxYaw 
kShip_maxThrust 
kShip_missileCapacity 
kShip_missileLoadTime 
kShip_missiles 
kShip_name 
kShip_parcelCount 
kShip_parcels 
kShip_passengerCapacity 
kShip_passengerCount 
kShip_passengers 
kShip_pitch 
kShip_portWeapon 
kShip_potentialCollider 
kShip_primaryRole 
kShip_reactionTime 
kShip_reportAIMessages 
kShip_roleWeights 
kShip_roles 
kShip_roll 
kShip_savedCoordinates 
kShip_scanDescription 
kShip_scannerDisplayColor1 
kShip_scannerDisplayColor2 
kShip_scannerHostileDisplayColor1 
kShip_scannerHostileDisplayColor2 
kShip_scannerRange 
kShip_script 
kShip_scriptedMisjump 
kShip_scriptedMisjumpRange 
kShip_scriptInfo 
kShip_shipClassName 
kShip_shipUniqueName 
kShip_speed 
kShip_starboardWeapon 
kShip_subEntities 
kShip_subEntityCapacity 
kShip_subEntityRotation 
kShip_sunGlareFilter 
kShip_target 
kShip_temperature 
kShip_thrust 
kShip_thrustVector 
kShip_trackCloseContacts 
kShip_vectorForward 
kShip_vectorRight 
kShip_vectorUp 
kShip_velocity 
kShip_weaponFacings 
kShip_weaponPositionAft 
kShip_weaponPositionForward 
kShip_weaponPositionPort 
kShip_weaponPositionStarboard 
kShip_weaponRange 
kShip_withinStationAegis 
kShip_yaw 

Definition at line 167 of file OOJSShip.m.

167 {
168 // Property IDs
169 kShip_accuracy = -128, // the ship's accuracy, float, read/write
170 kShip_aftWeapon, // the ship's aft weapon, equipmentType, read/write
171 kShip_AI, // AI state machine name, string, read-only
172 kShip_AIScript, // AI script, Script, read-only
173 kShip_AIScriptWakeTime, // next wakeup time, integer, read/write
174 kShip_AIState, // AI state machine state, string, read/write
175 kShip_AIFoundTarget, // AI "found target", entity, read/write
176 kShip_AIPrimaryAggressor, // AI "primary aggressor", entity, read/write
177 kShip_alertCondition, // number 0-3, read-only, combat alert level
178 kShip_autoAI, // bool, read-only, auto_ai from shipdata
179 kShip_autoWeapons, // bool, read-only, auto_weapons from shipdata
180 kShip_beaconCode, // beacon code, string, read/write
181 kShip_beaconLabel, // beacon label, string, read/write
182 kShip_boundingBox, // boundingBox, vector, read-only
183 kShip_bounty, // bounty, unsigned int, read/write
184 kShip_cargoList, // cargo on board, array of objects, read-only
185 kShip_cargoSpaceAvailable, // free cargo space, integer, read-only
186 kShip_cargoSpaceCapacity, // maximum cargo, integer, read/write
187 kShip_cargoSpaceUsed, // cargo on board, integer, read-only
188 kShip_collisionExceptions, // collision exception list, array, read-only
189 kShip_contracts, // cargo contracts contracts, array - strings & whatnot, read only
190 kShip_commodity, // commodity of a ship, read only
191 kShip_commodityAmount, // commodityAmount of a ship, read only
192 kShip_cloakAutomatic, // should cloack start by itself or by script, read/write
193 kShip_crew, // crew, list, read only
194 kShip_cruiseSpeed, // desired cruising speed, number, read only
195 kShip_currentWeapon, // the ship's active weapon, equipmentType, read/write
196 kShip_dataKey, // string, read-only, shipdata.plist key
197 kShip_defenseTargets, // array, read-only, defense targets
198 kShip_desiredRange, // desired Range, double, read/write
199 kShip_desiredSpeed, // AI desired flight speed, double, read/write
200 kShip_destination, // flight destination, Vector, read/write
201 kShip_destinationSystem, // destination system, number, read/write
202 kShip_displayName, // name displayed on screen, string, read/write
203 kShip_dockingInstructions, // name displayed on screen, string, read/write
204 kShip_energyRechargeRate, // energy recharge rate, float, read-only
205 kShip_entityPersonality, // per-ship random number, int, read-only
206 kShip_equipment, // the ship's equipment, array of EquipmentInfo, read only
207 kShip_escortGroup, // group, ShipGroup, read-only
208 kShip_escorts, // deployed escorts, array of Ship, read-only
209 kShip_exhaustEmissiveColor, // exhaust emissive color, array, read/write
210 kShip_exhausts, // exhausts, array, read-only
211 kShip_extraCargo, // cargo space increase granted by large cargo bay, int, read-only
212 kShip_flashers, // flashers, array, read-only
213 kShip_forwardWeapon, // the ship's forward weapon, equipmentType, read/write
214 kShip_fuel, // fuel, float, read/write
215 kShip_fuelChargeRate, // fuel scoop rate & charge multiplier, float, read-only
216 kShip_group, // group, ShipGroup, read/write
217 kShip_hasHostileTarget, // has hostile target, boolean, read-only
218 kShip_hasHyperspaceMotor, // has hyperspace motor, boolean, read-only
219 kShip_hasSuspendedAI, // AI has suspended states, boolean, read-only
220 kShip_heading, // forwardVector of a ship, read-only
221 kShip_heatInsulation, // hull heat insulation, double, read/write
222 kShip_homeSystem, // home system, number, read/write
223 kShip_hyperspaceSpinTime, // hyperspace spin time, float, read/write
224 kShip_injectorBurnRate, // injector burn rate, number, read/write dLY/s
225 kShip_injectorSpeedFactor, // injector speed factor, number, read/write
226 kShip_isBeacon, // is beacon, boolean, read-only
227 kShip_isBoulder, // is a boulder (generates splinters), boolean, read/write
228 kShip_isCargo, // contains cargo, boolean, read-only
229 kShip_isCloaked, // cloaked, boolean, read/write (if cloaking device installed)
230 kShip_isDerelict, // is an abandoned ship, boolean, read-only
231 kShip_isFrangible, // frangible, boolean, read-only
232 kShip_isFleeing, // is fleeing, boolean, read-only
233 kShip_isJamming, // jamming scanners, boolean, read/write (if jammer installed)
234 kShip_isMinable, // is a sensible target for mining, boolean, read-only
235 kShip_isMine, // is mine, boolean, read-only
236 kShip_isMissile, // is missile, boolean, read-only
237 kShip_isPiloted, // is piloted, boolean, read-only (includes stations)
238 kShip_isPirate, // is pirate, boolean, read-only
239 kShip_isPirateVictim, // is pirate victim, boolean, read-only
240 kShip_isPolice, // is police, boolean, read-only
241 kShip_isRock, // is a rock (hermits included), boolean, read-only
242 kShip_isThargoid, // is thargoid, boolean, read-only
243 kShip_isTurret, // is turret, boolean, read-only
244 kShip_isTrader, // is trader, boolean, read-only
245 kShip_isWeapon, // is missile or mine, boolean, read-only
246 kShip_laserHeatLevel, // active laser temperature, float, read-only
247 kShip_laserHeatLevelAft, // aft laser temperature, float, read-only
248 kShip_laserHeatLevelForward, // fore laser temperature, float, read-only
249 kShip_laserHeatLevelPort, // port laser temperature, float, read-only
250 kShip_laserHeatLevelStarboard, // starboard laser temperature, float, read-only
251 kShip_lightsActive, // flasher/shader light flag, boolean, read/write
252 kShip_markedForFines, // has been marked for fines
253 kShip_maxEscorts, // maximum escort count, int, read/write
254 kShip_maxPitch, // maximum flight pitch, double, read-only
255 kShip_maxSpeed, // maximum flight speed, double, read-only
256 kShip_maxRoll, // maximum flight roll, double, read-only
257 kShip_maxYaw, // maximum flight yaw, double, read-only
258 kShip_maxThrust, // maximum thrust, double, read-only
259 kShip_missileCapacity, // max missiles capacity, integer, read-only
260 kShip_missileLoadTime, // missile load time, double, read/write
261 kShip_missiles, // the ship's missiles / external storage, array of equipmentTypes, read only
262 kShip_name, // name, string, read-only
263 kShip_parcelCount, // number of parcels on ship, integer, read-only
264 kShip_parcels, // parcel contracts, array - strings & whatnot, read only
265 kShip_passengerCapacity, // amount of passenger space on ship, integer, read-only
266 kShip_passengerCount, // number of passengers on ship, integer, read-only
267 kShip_passengers, // passengers contracts, array - strings & whatnot, read only
268 kShip_pitch, // pitch level, float, read-only
269 kShip_portWeapon, // the ship's port weapon, equipmentType, read/write
270 kShip_potentialCollider, // "proximity alert" ship, Entity, read-only
271 kShip_primaryRole, // Primary role, string, read/write
272 kShip_reactionTime, // AI reaction time, read/write
273 kShip_reportAIMessages, // report AI messages, boolean, read/write
274 kShip_roleWeights, // roles and weights, dictionary, read-only
275 kShip_roles, // roles, array, read-only
276 kShip_roll, // roll level, float, read-only
277 kShip_savedCoordinates, // coordinates in system space for AI use, Vector, read/write
278 kShip_scanDescription, // STE scan class label, string, read/write
279 kShip_scannerDisplayColor1, // color of lollipop shown on scanner, array, read/write
280 kShip_scannerDisplayColor2, // color of lollipop shown on scanner when flashing, array, read/write
281 kShip_scannerHostileDisplayColor1, // color of lollipop shown on scanner, array, read/write
282 kShip_scannerHostileDisplayColor2, // color of lollipop shown on scanner when flashing, array, read/write
283 kShip_scannerRange, // scanner range, double, read-only
284 kShip_script, // script, Script, read-only
285 kShip_scriptedMisjump, // next jump will miss if set to true, boolean, read/write
286 kShip_scriptedMisjumpRange, // 0..1 range of next misjump, float, read/write
287 kShip_scriptInfo, // arbitrary data for scripts, dictionary, read-only
288 kShip_shipClassName, // ship type name, string, read/write
289 kShip_shipUniqueName, // uniqish name, string, read/write
290 kShip_speed, // current flight speed, double, read-only
291 kShip_starboardWeapon, // the ship's starboard weapon, equipmentType, read/write
292 kShip_subEntities, // subentities, array of Ship, read-only
293 kShip_subEntityCapacity, // max subentities for this ship, int, read-only
294 kShip_subEntityRotation, // subentity rotation velocity, quaternion, read/write
295 kShip_sunGlareFilter, // sun glare filter multiplier, float, read/write
296 kShip_target, // target, Ship, read/write
297 kShip_temperature, // hull temperature, double, read/write
298 kShip_thrust, // the ship's thrust, double, read/write
299 kShip_thrustVector, // thrust-related component of velocity, vector, read-only
300 kShip_trackCloseContacts, // generate close contact events, boolean, read/write
301 kShip_vectorForward, // forwardVector of a ship, read-only
302 kShip_vectorRight, // rightVector of a ship, read-only
303 kShip_vectorUp, // upVector of a ship, read-only
304 kShip_velocity, // velocity, vector, read/write
305 kShip_weaponFacings, // available facings, int, read-only
306 kShip_weaponPositionAft, // weapon offset, vector, read-only
307 kShip_weaponPositionForward, // weapon offset, vector, read-only
308 kShip_weaponPositionPort, // weapon offset, vector, read-only
309 kShip_weaponPositionStarboard, // weapon offset, vector, read-only
310 kShip_weaponRange, // weapon range, double, read-only
311 kShip_withinStationAegis, // within main station aegis, boolean, read/write
312 kShip_yaw, // yaw level, float, read-only
313};
@ kShip_isMissile
Definition OOJSShip.m:246
@ kShip_AIScriptWakeTime
Definition OOJSShip.m:183
@ kShip_weaponPositionPort
Definition OOJSShip.m:318
@ kShip_hyperspaceSpinTime
Definition OOJSShip.m:233
@ kShip_cargoSpaceUsed
Definition OOJSShip.m:197
@ kShip_destination
Definition OOJSShip.m:210
@ kShip_escorts
Definition OOJSShip.m:218
@ kShip_fuelChargeRate
Definition OOJSShip.m:225
@ kShip_missileCapacity
Definition OOJSShip.m:269
@ kShip_collisionExceptions
Definition OOJSShip.m:198
@ kShip_target
Definition OOJSShip.m:306
@ kShip_commodityAmount
Definition OOJSShip.m:201
@ kShip_autoWeapons
Definition OOJSShip.m:189
@ kShip_weaponFacings
Definition OOJSShip.m:315
@ kShip_subEntityCapacity
Definition OOJSShip.m:303
@ kShip_isFleeing
Definition OOJSShip.m:242
@ kShip_group
Definition OOJSShip.m:226
@ kShip_potentialCollider
Definition OOJSShip.m:280
@ kShip_thrustVector
Definition OOJSShip.m:309
@ kShip_AIState
Definition OOJSShip.m:184
@ kShip_accuracy
Definition OOJSShip.m:179
@ kShip_autoAI
Definition OOJSShip.m:188
@ kShip_isFrangible
Definition OOJSShip.m:241
@ kShip_maxPitch
Definition OOJSShip.m:264
@ kShip_alertCondition
Definition OOJSShip.m:187
@ kShip_hasHostileTarget
Definition OOJSShip.m:227
@ kShip_passengers
Definition OOJSShip.m:277
@ kShip_maxEscorts
Definition OOJSShip.m:263
@ kShip_exhaustEmissiveColor
Definition OOJSShip.m:219
@ kShip_weaponRange
Definition OOJSShip.m:320
@ kShip_cloakAutomatic
Definition OOJSShip.m:202
@ kShip_isRock
Definition OOJSShip.m:251
@ kShip_subEntities
Definition OOJSShip.m:302
@ kShip_injectorSpeedFactor
Definition OOJSShip.m:235
@ kShip_laserHeatLevelAft
Definition OOJSShip.m:257
@ kShip_AIPrimaryAggressor
Definition OOJSShip.m:186
@ kShip_escortGroup
Definition OOJSShip.m:217
@ kShip_maxThrust
Definition OOJSShip.m:268
@ kShip_isBoulder
Definition OOJSShip.m:237
@ kShip_displayName
Definition OOJSShip.m:212
@ kShip_scanDescription
Definition OOJSShip.m:288
@ kShip_dataKey
Definition OOJSShip.m:206
@ kShip_reportAIMessages
Definition OOJSShip.m:283
@ kShip_lightsActive
Definition OOJSShip.m:261
@ kShip_desiredSpeed
Definition OOJSShip.m:209
@ kShip_crew
Definition OOJSShip.m:203
@ kShip_isCargo
Definition OOJSShip.m:238
@ kShip_commodity
Definition OOJSShip.m:200
@ kShip_velocity
Definition OOJSShip.m:314
@ kShip_forwardWeapon
Definition OOJSShip.m:223
@ kShip_reactionTime
Definition OOJSShip.m:282
@ kShip_beaconLabel
Definition OOJSShip.m:191
@ kShip_extraCargo
Definition OOJSShip.m:221
@ kShip_heatInsulation
Definition OOJSShip.m:231
@ kShip_vectorForward
Definition OOJSShip.m:311
@ kShip_heading
Definition OOJSShip.m:230
@ kShip_currentWeapon
Definition OOJSShip.m:205
@ kShip_roles
Definition OOJSShip.m:285
@ kShip_weaponPositionForward
Definition OOJSShip.m:317
@ kShip_shipClassName
Definition OOJSShip.m:298
@ kShip_equipment
Definition OOJSShip.m:216
@ kShip_starboardWeapon
Definition OOJSShip.m:301
@ kShip_cargoList
Definition OOJSShip.m:194
@ kShip_name
Definition OOJSShip.m:272
@ kShip_defenseTargets
Definition OOJSShip.m:207
@ kShip_scannerDisplayColor2
Definition OOJSShip.m:290
@ kShip_vectorRight
Definition OOJSShip.m:312
@ kShip_markedForFines
Definition OOJSShip.m:262
@ kShip_AIScript
Definition OOJSShip.m:182
@ kShip_laserHeatLevelPort
Definition OOJSShip.m:259
@ kShip_passengerCount
Definition OOJSShip.m:276
@ kShip_roleWeights
Definition OOJSShip.m:284
@ kShip_weaponPositionAft
Definition OOJSShip.m:316
@ kShip_scriptedMisjump
Definition OOJSShip.m:295
@ kShip_shipUniqueName
Definition OOJSShip.m:299
@ kShip_isBeacon
Definition OOJSShip.m:236
@ kShip_isMine
Definition OOJSShip.m:245
@ kShip_scriptInfo
Definition OOJSShip.m:297
@ kShip_vectorUp
Definition OOJSShip.m:313
@ kShip_isWeapon
Definition OOJSShip.m:255
@ kShip_temperature
Definition OOJSShip.m:307
@ kShip_injectorBurnRate
Definition OOJSShip.m:234
@ kShip_isPirate
Definition OOJSShip.m:248
@ kShip_scannerDisplayColor1
Definition OOJSShip.m:289
@ kShip_bounty
Definition OOJSShip.m:193
@ kShip_hasHyperspaceMotor
Definition OOJSShip.m:228
@ kShip_cargoSpaceCapacity
Definition OOJSShip.m:196
@ kShip_isJamming
Definition OOJSShip.m:243
@ kShip_contracts
Definition OOJSShip.m:199
@ kShip_maxYaw
Definition OOJSShip.m:267
@ kShip_AIFoundTarget
Definition OOJSShip.m:185
@ kShip_isThargoid
Definition OOJSShip.m:252
@ kShip_isTrader
Definition OOJSShip.m:254
@ kShip_portWeapon
Definition OOJSShip.m:279
@ kShip_yaw
Definition OOJSShip.m:322
@ kShip_isPiloted
Definition OOJSShip.m:247
@ kShip_beaconCode
Definition OOJSShip.m:190
@ kShip_savedCoordinates
Definition OOJSShip.m:287
@ kShip_scannerHostileDisplayColor2
Definition OOJSShip.m:292
@ kShip_AI
Definition OOJSShip.m:181
@ kShip_sunGlareFilter
Definition OOJSShip.m:305
@ kShip_weaponPositionStarboard
Definition OOJSShip.m:319
@ kShip_boundingBox
Definition OOJSShip.m:192
@ kShip_scriptedMisjumpRange
Definition OOJSShip.m:296
@ kShip_homeSystem
Definition OOJSShip.m:232
@ kShip_laserHeatLevelStarboard
Definition OOJSShip.m:260
@ kShip_withinStationAegis
Definition OOJSShip.m:321
@ kShip_roll
Definition OOJSShip.m:286
@ kShip_speed
Definition OOJSShip.m:300
@ kShip_cargoSpaceAvailable
Definition OOJSShip.m:195
@ kShip_script
Definition OOJSShip.m:294
@ kShip_laserHeatLevelForward
Definition OOJSShip.m:258
@ kShip_laserHeatLevel
Definition OOJSShip.m:256
@ kShip_aftWeapon
Definition OOJSShip.m:180
@ kShip_exhausts
Definition OOJSShip.m:220
@ kShip_passengerCapacity
Definition OOJSShip.m:275
@ kShip_maxRoll
Definition OOJSShip.m:266
@ kShip_isPirateVictim
Definition OOJSShip.m:249
@ kShip_isDerelict
Definition OOJSShip.m:240
@ kShip_scannerHostileDisplayColor1
Definition OOJSShip.m:291
@ kShip_missileLoadTime
Definition OOJSShip.m:270
@ kShip_energyRechargeRate
Definition OOJSShip.m:214
@ kShip_trackCloseContacts
Definition OOJSShip.m:310
@ kShip_isCloaked
Definition OOJSShip.m:239
@ kShip_missiles
Definition OOJSShip.m:271
@ kShip_destinationSystem
Definition OOJSShip.m:211
@ kShip_isTurret
Definition OOJSShip.m:253
@ kShip_scannerRange
Definition OOJSShip.m:293
@ kShip_isPolice
Definition OOJSShip.m:250
@ kShip_isMinable
Definition OOJSShip.m:244
@ kShip_thrust
Definition OOJSShip.m:308
@ kShip_hasSuspendedAI
Definition OOJSShip.m:229
@ kShip_maxSpeed
Definition OOJSShip.m:265
@ kShip_fuel
Definition OOJSShip.m:224
@ kShip_pitch
Definition OOJSShip.m:278
@ kShip_entityPersonality
Definition OOJSShip.m:215
@ kShip_cruiseSpeed
Definition OOJSShip.m:204
@ kShip_desiredRange
Definition OOJSShip.m:208
@ kShip_dockingInstructions
Definition OOJSShip.m:213
@ kShip_parcels
Definition OOJSShip.m:274
@ kShip_parcelCount
Definition OOJSShip.m:273
@ kShip_flashers
Definition OOJSShip.m:222
@ kShip_subEntityRotation
Definition OOJSShip.m:304
@ kShip_primaryRole
Definition OOJSShip.m:281

Function Documentation

◆ InitOOJSShip()

void InitOOJSShip ( JSContext * context,
JSValueConst global )

Definition at line 562 of file OOJSShip.m.

563{
565
566 JSValue entityPrototype = JS_GetClassProto(context, JSEntityClassID());
567 OOJSInitClass(context, global, sShipClassID, entityPrototype, OOJSUnconstructableConstruct, 0,
570 JS_FreeValue(context, entityPrototype);
571
574}
static JSFunctionSpec sShipStaticMethods[]
Definition OOJSShip.m:562
static JSFunctionSpec sShipMethods[]
Definition OOJSShip.m:476
static JSClass sShipClass
Definition OOJSShip.m:153
static JSPropertySpec sShipProperties[]
Definition OOJSShip.m:325
void OOJSRegisterObjectConverter(JSClass *theClass, OOJSClassConverterCallback converter)
JSBool OOJSUnconstructableConstruct(JSContext *context, uintN argc, jsval *vp)
void OOJSRegisterSubclass(JSClass *subclass, JSClass *superclass)
id OOJSBasicPrivateObjectConverter(JSContext *context, JSObject *object)
JSClassID JSEntityClassID(void)
Definition OOJSEntity.m:115
static JSClassID sShipClassID
Definition OOJSShip.m:53
JSClassID OOJSRegisterClass(JSClassID *ioClassID, const JSClassDef *classDef)
Definition OOJSClasses.m:61
JSValueConst OOJSInitClass(JSContext *context, JSValueConst global, JSClassID classID, JSValueConst parentPrototype, JSCFunction *constructor, int constructorArgCount, const JSCFunctionListEntry *properties, size_t propertyCount, const JSCFunctionListEntry *methods, size_t methodCount, const JSCFunctionListEntry *staticMethods, size_t staticMethodCount)
#define OOJS_COUNT(array)

References InitOOJSShip(), JSEntityClassID(), OOJS_COUNT, OOJSBasicPrivateObjectConverter(), OOJSInitClass(), OOJSRegisterClass(), OOJSRegisterObjectConverter(), OOJSRegisterSubclass(), OOJSUnconstructableConstruct(), sShipClass, sShipClassID, sShipMethods, sShipProperties, and sShipStaticMethods.

Here is the call graph for this function:

◆ JSShipClassID()

JSClassID JSShipClassID ( void )

Definition at line 576 of file OOJSShip.m.

577{
578 return sShipClassID;
579}

References sShipClassID.

Referenced by InitOOJSDock(), InitOOJSPlayerShip(), InitOOJSStation(), and ShipEntity(OOJavaScriptExtensions)::oo_jsClassID.

Here is the caller graph for this function:

◆ RemoveOrExplodeShip()

JSValue RemoveOrExplodeShip ( OOJS_NATIVE_ARGS ,
BOOL explode )
static

Definition at line 3019 of file OOJSShip.m.

3020{
3022
3023 ShipEntity* thisEnt = nil;
3024
3025 GET_THIS_SHIP(thisEnt);
3026
3027 if (EXPECT_NOT([thisEnt isPlayer])) {
3028 NSCAssert(explode, @"RemoveOrExplodeShip(): shouldn't be called for player with !explode."); // player.ship.remove() is blocked by caller.
3029 PlayerEntity* player = (PlayerEntity*)thisEnt;
3030
3031 if ([player isDocked]) {
3032 OOJSReportError(context, @"Cannot explode() player's ship while docked.");
3033 return OOJSNativeFailure(context);
3034 }
3035 }
3036
3037 if (thisEnt == (ShipEntity*)[UNIVERSE station]) {
3038 // Allow exploding of main station (e.g. nova mission)
3039 [UNIVERSE unMagicMainStation];
3040 }
3041
3042 if (EXPECT_NOT([thisEnt status] == STATUS_DOCKED)) {
3043 /* If it's in the launch queue and hasn't yet been added to
3044 * the universe, set the status to DEAD (so it gets removed
3045 * from the launch queue) */
3046 [thisEnt setStatus:STATUS_DEAD];
3047 /* No shipDied event occurs in this place - it never really
3048 * existed. This case is just to prevent an error from the
3049 * usual code branch - removing ships while they're still
3050 * docked is not recommended. */
3051 } else {
3052 [thisEnt setSuppressExplosion:!explode];
3053 [thisEnt setEnergy:1];
3054 [thisEnt takeEnergyDamage:500000000.0 from:nil becauseOf:nil weaponIdentifier:@""];
3055 }
3056
3058
3060}
#define OOJS_PROFILE_EXIT
#define OOJS_PROFILE_ENTER
#define GET_THIS_SHIP(THISENT)
Definition OOJSShip.m:1823
void OOJSReportError(JSContext *context, NSString *format,...)
return nil
#define UNIVERSE
Definition Universe.h:827

References EXPECT_NOT, GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_VOID, OOJSNativeFailure(), OOJSReportError(), and UNIVERSE.

Here is the call graph for this function:

◆ ShipAbandonShip()

JSValue ShipAbandonShip ( OOJS_NATIVE_ARGS )
static

Definition at line 2338 of file OOJSShip.m.

2339{
2340 OOJS_NATIVE_ENTER(context)
2341
2342 ShipEntity* thisEnt = nil;
2343
2344 GET_THIS_SHIP(thisEnt);
2345 OOJS_RETURN_BOOL([thisEnt hasEscapePod] && [thisEnt abandonShip]);
2346
2348}
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
#define OOJS_RETURN_BOOL(v)

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, and OOJS_RETURN_BOOL.

◆ ShipAddCargoEntity()

JSValue ShipAddCargoEntity ( OOJS_NATIVE_ARGS )
static

Definition at line 2032 of file OOJSShip.m.

2033{
2034 OOJS_NATIVE_ENTER(context)
2035 ShipEntity* thisEnt = nil;
2036 ShipEntity* target = nil;
2037 int procEvents = NO;
2038 int procMessages = NO;
2039
2040 GET_THIS_SHIP(thisEnt);
2041
2042 if (EXPECT_NOT([thisEnt isPlayer] && [(PlayerEntity*)thisEnt isDocked])) {
2043 OOJSReportWarningForCaller(context, @"PlayerShip", @"addCargoEntity", @"Can't add cargo entity while docked, ignoring.");
2044 return OOJSNativeFailure(context);
2045 }
2046 if (EXPECT_NOT(argc == 0 || JS_IsNull(OOJS_ARGV[0]) || !JS_IsObject(OOJS_ARGV[0]) || !JSShipGetShipEntity(context, OOJS_ARGV[0], &target))) {
2047 OOJSReportBadArguments(context, @"PlayerShip", @"addCargoEntity", MIN(argc, 1), OOJS_ARGV, nil, @"scoopable entity.");
2048 return OOJSNativeFailure(context);
2049 }
2050 if ([target scanClass] != CLASS_CARGO) {
2051 OOJSReportWarningForCaller(context, @"PlayerShip", @"addCargoEntity", @"Scoopable entity not cargo.");
2052 return OOJSNativeFailure(context);
2053 }
2054 if ([target status] != STATUS_IN_FLIGHT) {
2055 OOJSReportWarningForCaller(context, @"PlayerShip", @"addCargoEntity", @"Scoopable entity not in flight.");
2056 return OOJSNativeFailure(context);
2057 }
2058 if (argc >= 2 && EXPECT_NOT(!((procEvents = JS_ToBool(context, OOJS_ARGV[1])) >= 0))) {
2059 OOJSReportBadArguments(context, @"PlayerShip", @"addCargoEntity", MIN(argc, 2), OOJS_ARGV, nil, @"boolean");
2060 return OOJSNativeFailure(context);
2061 }
2062 if (argc == 3 && EXPECT_NOT(!((procMessages = JS_ToBool(context, OOJS_ARGV[2])) >= 0))) {
2063 OOJSReportBadArguments(context, @"PlayerShip", @"addCargoEntity", MIN(argc, 3), OOJS_ARGV, nil, @"boolean");
2064 return OOJSNativeFailure(context);
2065 }
2066
2067 // scoop the object, but don't process any events/messages unless requested
2068 OOJS_BEGIN_FULL_NATIVE(context)
2069 [thisEnt scoopUpProcess:target processEvents:procEvents processMessages:procMessages];
2071
2072 OOJS_RETURN_BOOL([target status] == STATUS_IN_HOLD);
2073
2075}
#define OOJS_END_FULL_NATIVE
#define OOJS_BEGIN_FULL_NATIVE(context)
void OOJSReportWarningForCaller(JSContext *context, NSString *scriptClass, NSString *function, NSString *format,...)
#define OOJS_ARGV
void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)
#define MIN(A, B)
Definition OOMaths.h:91
void scoopUpProcess:processEvents:processMessages:(ShipEntity *other,[processEvents] BOOL proc_events,[processMessages] BOOL proc_messages)

References EXPECT_NOT, GET_THIS_SHIP, MIN, nil, OOJS_ARGV, OOJS_BEGIN_FULL_NATIVE, OOJS_END_FULL_NATIVE, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJSNativeFailure(), OOJSReportBadArguments(), OOJSReportWarningForCaller(), and ShipEntity::scoopUpProcess:processEvents:processMessages:.

Here is the call graph for this function:

◆ ShipAddCollisionException()

JSValue ShipAddCollisionException ( OOJS_NATIVE_ARGS )
static

Definition at line 3115 of file OOJSShip.m.

3116{
3118
3119 ShipEntity* thisEnt = nil;
3120 ShipEntity* target = nil;
3121
3122 GET_THIS_SHIP(thisEnt);
3123 if (EXPECT_NOT(argc == 0 || (argc > 0 && (JS_IsNull(OOJS_ARGV[0]) || !JS_IsObject(OOJS_ARGV[0]) || !JSShipGetShipEntity(context, OOJS_ARGV[0], &target))))) {
3124 OOJSReportBadArguments(context, @"Ship", @"addCollisionException", 1U, OOJS_ARGV, nil, @"other ship");
3125 return OOJSNativeFailure(context);
3126 }
3127
3128 // have to do it both ways because it's not defined which order
3129 // the collisions get tested in. More efficient to add both ways
3130 // than to test both ways
3131 [thisEnt addCollisionException:target];
3132 [target addCollisionException:thisEnt];
3133
3135
3137}
void addCollisionException:(ShipEntity *ship)

References ShipEntity::addCollisionException:, EXPECT_NOT, GET_THIS_SHIP, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_VOID, OOJSNativeFailure(), and OOJSReportBadArguments().

Here is the call graph for this function:

◆ ShipAddDefenseTarget()

JSValue ShipAddDefenseTarget ( OOJS_NATIVE_ARGS )
static

Definition at line 3075 of file OOJSShip.m.

3076{
3078
3079 ShipEntity* thisEnt = nil;
3080 ShipEntity* target = nil;
3081
3082 GET_THIS_SHIP(thisEnt);
3083 if (EXPECT_NOT(argc == 0 || (argc > 0 && (JS_IsNull(OOJS_ARGV[0]) || !JS_IsObject(OOJS_ARGV[0]) || !JSShipGetShipEntity(context, OOJS_ARGV[0], &target))))) {
3084 OOJSReportBadArguments(context, @"Ship", @"addDefenseTarget", 1U, OOJS_ARGV, nil, @"target");
3085 return OOJSNativeFailure(context);
3086 }
3087
3088 [thisEnt addDefenseTarget:target];
3089
3091
3093}

References EXPECT_NOT, GET_THIS_SHIP, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_VOID, OOJSNativeFailure(), and OOJSReportBadArguments().

Here is the call graph for this function:

◆ ShipAdjustCargo()

JSValue ShipAdjustCargo ( OOJS_NATIVE_ARGS )
static

Definition at line 3657 of file OOJSShip.m.

3658{
3660
3661 ShipEntity* thisEnt = nil;
3662 NSString* commodity = @"";
3663 int32_t adjustment = 0;
3664
3665 GET_THIS_SHIP(thisEnt);
3666
3667 if (argc < 2) {
3668 OOJSReportBadArguments(context, @"Ship", @"adjustCargo", argc, OOJS_ARGV, nil, @"commodity, amount");
3669 return OOJSNativeFailure(context);
3670 }
3671
3672 commodity = OOStringFromJSValue(context, OOJS_ARGV[0]);
3673 if (!OOJSValueToInt32(context, OOJS_ARGV[1], &adjustment)) {
3674 OOJSReportBadArguments(context, @"Ship", @"adjustCargo", argc, OOJS_ARGV, nil, @"commodity, amount");
3675 return OOJSNativeFailure(context);
3676 }
3677
3678 if ([thisEnt cargoType] != CARGO_NOT_CARGO || [thisEnt isPlayer]) {
3679 OOJSReportError(context, @"ship.adjustCargo may only be used on NPC cargo carriers");
3680 return OOJSNativeFailure(context);
3681 }
3682
3683 BOOL ok = YES;
3684
3685 if (adjustment > 0) {
3686 NSArray* cargo = [UNIVERSE getContainersOfCommodity:commodity how_much:adjustment]; // non-reified templates
3687 ok = [thisEnt addCargo:cargo];
3688 } else if (adjustment < 0) {
3689 OOCargoQuantity r = (OOCargoQuantity)(-adjustment);
3690 ok = [thisEnt removeCargo:commodity amount:r];
3691 }
3692
3693 OOJS_RETURN_BOOL(ok);
3694
3696}
OOINLINE BOOL OOJSValueToInt32(JSContext *context, jsval value, int32_t *outValue)
NSString * OOStringFromJSValue(JSContext *context, jsval value)
@ CARGO_NOT_CARGO
Definition OOTypes.h:61
uint32_t OOCargoQuantity
Definition OOTypes.h:155

References CARGO_NOT_CARGO, GET_THIS_SHIP, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_BOOL, OOJSNativeFailure(), OOJSReportBadArguments(), OOJSReportError(), OOJSValueToInt32(), and OOStringFromJSValue().

Here is the call graph for this function:

◆ ShipAwardEquipment()

JSValue ShipAwardEquipment ( OOJS_NATIVE_ARGS )
static

Definition at line 2397 of file OOJSShip.m.

2398{
2399 OOJS_NATIVE_ENTER(context)
2400
2401 ShipEntity* thisEnt = nil;
2402 OOEquipmentType* eqType = nil;
2403 NSString* identifier = nil;
2404 BOOL OK = YES;
2405 BOOL berth;
2406 BOOL isRepair = NO;
2407
2408 GET_THIS_SHIP(thisEnt);
2409
2410 if (argc > 0)
2411 eqType = JSValueToEquipmentType(context, OOJS_ARGV[0]);
2412 if (EXPECT_NOT(eqType == nil)) {
2413 OOJSReportBadArguments(context, @"Ship", @"awardEquipment", MIN(argc, 1), OOJS_ARGV, nil, @"equipment type");
2414 return OOJSNativeFailure(context);
2415 }
2416
2417 // Check that equipment is permitted.
2418 identifier = [eqType identifier];
2419 berth = [identifier isEqualToString:@"EQ_PASSENGER_BERTH"];
2420 if (berth) {
2421 OK = [thisEnt availableCargoSpace] >= [eqType requiredCargoSpace];
2422 } else if ([identifier isEqualToString:@"EQ_FUEL"]) {
2423 OK = NO;
2424 } else {
2425 OK = [eqType canCarryMultiple] || ![thisEnt hasEquipmentItem:identifier];
2426 }
2427
2428 if (OK) {
2429 if ([thisEnt isPlayer]) {
2430 PlayerEntity* player = (PlayerEntity*)thisEnt;
2431
2432 if ([identifier isEqualToString:@"EQ_MISSILE_REMOVAL"]) {
2433 [player removeMissiles];
2434 } else if ([eqType isMissileOrMine]) {
2435 OK = [player mountMissileWithRole:identifier];
2436 } else if (berth) {
2437 OK = [player changePassengerBerths:+1];
2438 } else if ([identifier isEqualToString:@"EQ_PASSENGER_BERTH_REMOVAL"]) {
2439 OK = [player changePassengerBerths:-1];
2440 } else {
2441 isRepair = [thisEnt hasEquipmentItem:[identifier stringByAppendingString:@"_DAMAGED"]];
2442 OK = [player addEquipmentItem:identifier withValidation:YES inContext:@"scripted"];
2443 if (OK && isRepair) {
2444 [player doScriptEvent:OOJSID("equipmentRepaired") withArgument:identifier];
2445 }
2446 }
2447 } else {
2448 if ([identifier isEqualToString:@"EQ_MISSILE_REMOVAL"]) {
2449 [thisEnt removeMissiles];
2450 }
2451 // no passenger handling for NPCs. EQ_CARGO_BAY is dealt with inside addEquipmentItem
2452 else if (!berth && ![identifier isEqualToString:@"EQ_PASSENGER_BERTH_REMOVAL"]) {
2453 OK = [thisEnt addEquipmentItem:identifier withValidation:YES inContext:@"scripted"];
2454 } else {
2455 OK = NO;
2456 }
2457 }
2458 }
2459
2460 OOJS_RETURN_BOOL(OK);
2461
2463}
OOEquipmentType * JSValueToEquipmentType(JSContext *context, jsval value)
OOCargoQuantity requiredCargoSpace()
NSString * identifier()
BOOL addEquipmentItem:withValidation:inContext:(NSString *equipmentKey, [withValidation] BOOL validateAddition, [inContext] NSString *context)
BOOL changePassengerBerths:(int addRemove)
OOCreditsQuantity removeMissiles()
BOOL mountMissileWithRole:(NSString *role)
BOOL addEquipmentItem:withValidation:inContext:(NSString *equipmentKey,[withValidation] BOOL validateAddition,[inContext] NSString *context)
OOCargoQuantity availableCargoSpace()
OOCreditsQuantity removeMissiles()
BOOL hasEquipmentItem:(id equipmentKeys)
void doScriptEvent:withArgument:(OOJSPropID message,[withArgument] id argument)

References PlayerEntity::addEquipmentItem:withValidation:inContext:, ShipEntity::addEquipmentItem:withValidation:inContext:, ShipEntity::availableCargoSpace, OOEquipmentType::canCarryMultiple, PlayerEntity::changePassengerBerths:, ShipEntity::doScriptEvent:withArgument:, EXPECT_NOT, GET_THIS_SHIP, ShipEntity::hasEquipmentItem:, OOEquipmentType::identifier, JSValueToEquipmentType(), MIN, PlayerEntity::mountMissileWithRole:, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJSNativeFailure(), OOJSReportBadArguments(), PlayerEntity::removeMissiles, ShipEntity::removeMissiles, and OOEquipmentType::requiredCargoSpace.

Here is the call graph for this function:

◆ ShipBecomeCascadeExplosion()

JSValue ShipBecomeCascadeExplosion ( OOJS_NATIVE_ARGS )
static

Definition at line 3210 of file OOJSShip.m.

3211{
3213
3214 ShipEntity* thisEnt = nil;
3215 GET_THIS_SHIP(thisEnt);
3216 [thisEnt becomeEnergyBlast];
3217
3219
3221}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_VOID.

◆ ShipBroadcastCascadeImminent()

JSValue ShipBroadcastCascadeImminent ( OOJS_NATIVE_ARGS )
static

Definition at line 3197 of file OOJSShip.m.

3198{
3200
3201 ShipEntity* thisEnt = nil;
3202 GET_THIS_SHIP(thisEnt);
3203 [thisEnt broadcastEnergyBlastImminent];
3204
3206
3208}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_VOID.

◆ ShipBroadcastDistressMessage()

JSValue ShipBroadcastDistressMessage ( OOJS_NATIVE_ARGS )
static

Definition at line 3586 of file OOJSShip.m.

3587{
3589
3590 ShipEntity* thisEnt = nil;
3591 GET_THIS_SHIP(thisEnt);
3592 [thisEnt broadcastDistressMessageWithDumping:NO];
3593
3595
3597}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_VOID.

◆ ShipCanAwardEquipment()

JSValue ShipCanAwardEquipment ( OOJS_NATIVE_ARGS )
static

Definition at line 2351 of file OOJSShip.m.

2352{
2353 OOJS_NATIVE_ENTER(context)
2354
2355 ShipEntity* thisEnt = nil;
2356 NSString* key = nil;
2357 NSString* ctx = @"scripted";
2358 BOOL result;
2359 BOOL exists;
2360
2361 GET_THIS_SHIP(thisEnt);
2362
2363 if (argc > 0)
2364 key = JSValueToEquipmentKeyRelaxed(context, OOJS_ARGV[0], &exists);
2365 if (EXPECT_NOT(key == nil)) {
2366 OOJSReportBadArguments(context, @"Ship", @"canAwardEquipment", MIN(argc, 1), OOJS_ARGV, nil, @"equipment type");
2367 return OOJSNativeFailure(context);
2368 }
2369
2370 if (exists) {
2371 if (argc > 1) {
2372 ctx = OOStringFromJSValue(context, OOJS_ARGV[1]);
2373 if (![ctx isEqualToString:@"scripted"] && ![ctx isEqualToString:@"purchase"] && ![ctx isEqualToString:@"newShip"] && ![ctx isEqualToString:@"npc"]) {
2374 OOJSReportBadArguments(context, @"Ship", @"canAwardEquipment", MIN(argc, 2), OOJS_ARGV, nil, @"context");
2375 return OOJSNativeFailure(context);
2376 }
2377 }
2378 result = YES;
2379
2380 // can't add fuel as equipment.
2381 if ([key isEqualToString:@"EQ_FUEL"])
2382 result = NO;
2383
2384 if (result)
2385 result = [thisEnt canAddEquipment:key inContext:ctx];
2386 } else {
2387 // Unknown type.
2388 result = NO;
2389 }
2390
2391 OOJS_RETURN_BOOL(result);
2392
2394}
NSString * JSValueToEquipmentKeyRelaxed(JSContext *context, jsval value, BOOL *outExists)
BOOL canAddEquipment:inContext:(NSString *equipmentKey,[inContext] NSString *context)

References ShipEntity::canAddEquipment:inContext:, EXPECT_NOT, GET_THIS_SHIP, JSValueToEquipmentKeyRelaxed(), MIN, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJSNativeFailure(), OOJSReportBadArguments(), and OOStringFromJSValue().

Here is the call graph for this function:

◆ ShipCheckCourseToDestination()

JSValue ShipCheckCourseToDestination ( OOJS_NATIVE_ARGS )
static

Definition at line 3599 of file OOJSShip.m.

3600{
3602
3603 ShipEntity* thisEnt = nil;
3604 GET_THIS_SHIP(thisEnt);
3605
3606 Entity* hazard = [UNIVERSE hazardOnRouteFromEntity:thisEnt toDistance:[thisEnt desiredRange] fromPoint:[thisEnt destination]];
3607
3608 OOJS_RETURN_OBJECT(hazard);
3609
3611}
#define OOJS_RETURN_OBJECT(o)

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_OBJECT.

◆ ShipCheckScanner()

JSValue ShipCheckScanner ( OOJS_NATIVE_ARGS )
static

Definition at line 3627 of file OOJSShip.m.

3628{
3630
3631 ShipEntity* thisEnt = nil;
3632 int onlyCheckPowered = NO;
3633
3634 GET_THIS_SHIP(thisEnt);
3635
3636 if (argc > 0 && EXPECT_NOT(!((onlyCheckPowered = JS_ToBool(context, OOJS_ARGV[0])) >= 0))) {
3637 OOJSReportBadArguments(context, @"Ship", @"checkScanner", argc, OOJS_ARGV, nil, @"boolean");
3638 return OOJSNativeFailure(context);
3639 }
3640
3641 if (onlyCheckPowered) {
3642 [thisEnt checkScannerIgnoringUnpowered];
3643 } else {
3644 [thisEnt checkScanner];
3645 }
3646 ShipEntity** scannedShips = [thisEnt scannedShips];
3647 unsigned num = [thisEnt numberOfScannedShips];
3648 NSMutableArray* scanResult = [NSMutableArray array];
3649 for (unsigned i = 0; i < num; i++) {
3650 [scanResult addObject:scannedShips[i]];
3651 }
3652 OOJS_RETURN_OBJECT(scanResult);
3653
3655}

References EXPECT_NOT, GET_THIS_SHIP, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_OBJECT, OOJSNativeFailure(), and OOJSReportBadArguments().

Here is the call graph for this function:

◆ ShipClearDefenseTargets()

JSValue ShipClearDefenseTargets ( OOJS_NATIVE_ARGS )
static

Definition at line 3062 of file OOJSShip.m.

3063{
3065
3066 ShipEntity* thisEnt = nil;
3067 GET_THIS_SHIP(thisEnt);
3068 [thisEnt removeAllDefenseTargets];
3069
3071
3073}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_VOID.

◆ ShipCommsMessage()

JSValue ShipCommsMessage ( OOJS_NATIVE_ARGS )
static

Definition at line 2289 of file OOJSShip.m.

2290{
2291 OOJS_NATIVE_ENTER(context)
2292
2293 ShipEntity* thisEnt = nil;
2294 NSString* message = nil;
2295 ShipEntity* target = nil;
2296
2297 GET_THIS_SHIP(thisEnt);
2298
2299 if (argc > 0)
2300 message = OOStringFromJSValue(context, OOJS_ARGV[0]);
2301 if (EXPECT_NOT(message == nil || (argc > 1 && (JS_IsNull(OOJS_ARGV[1]) || !JS_IsObject(OOJS_ARGV[1]) || !JSShipGetShipEntity(context, OOJS_ARGV[1], &target))))) {
2302 OOJSReportBadArguments(context, @"Ship", @"commsMessage", MIN(argc, 1), OOJS_ARGV, nil, @"message and optional target");
2303 return OOJSNativeFailure(context);
2304 }
2305
2306 if (argc < 2) {
2307 [thisEnt commsMessage:message withUnpilotedOverride:YES]; // generic broadcast
2308 } else if (target != nil) // Not stale reference
2309 {
2310 [thisEnt sendMessage:message toShip:target withUnpilotedOverride:YES]; // ship-to-ship narrowcast
2311 }
2313
2315}
void sendMessage:toShip:withUnpilotedOverride:(NSString *message_text,[toShip] ShipEntity *other_ship,[withUnpilotedOverride] BOOL unpilotedOverride)
void commsMessage:withUnpilotedOverride:(NSString *valueString,[withUnpilotedOverride] BOOL unpilotedOverride)

References ShipEntity::commsMessage:withUnpilotedOverride:, EXPECT_NOT, GET_THIS_SHIP, MIN, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJSNativeFailure(), OOJSReportBadArguments(), OOStringFromJSValue(), and ShipEntity::sendMessage:toShip:withUnpilotedOverride:.

Here is the call graph for this function:

◆ ShipDamageAssessment()

JSValue ShipDamageAssessment ( OOJS_NATIVE_ARGS )
static

Definition at line 3699 of file OOJSShip.m.

3700{
3702
3703 ShipEntity* thisEnt = nil;
3704 int assessment = 0;
3705
3706 GET_THIS_SHIP(thisEnt);
3707
3708 // if could have missiles but doesn't, consumables low
3709 if ([thisEnt missileCapacity] > 0 && [[thisEnt missilesList] count] == 0) {
3710 assessment++;
3711 }
3712 // if has injectors but fuel is low, consumables low
3713 // if no injectors, not a problem
3714 if ([thisEnt hasFuelInjection] && [thisEnt fuel] < 35) {
3715 assessment++;
3716 }
3717
3718 /* TODO: when NPC equipment can be damaged in combat, assess this
3719 * here */
3720
3721 OOJS_RETURN_INT(assessment);
3722
3724}
#define OOJS_RETURN_INT(v)
unsigned count

References count, GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_INT.

◆ ShipDealEnergyDamage()

JSValue ShipDealEnergyDamage ( OOJS_NATIVE_ARGS )
static

Definition at line 2171 of file OOJSShip.m.

2172{
2173 OOJS_NATIVE_ENTER(context)
2174
2175 ShipEntity* thisEnt = nil;
2176 double baseDamage;
2177 double range;
2178 double velocityBias = 0.0;
2179 BOOL gotDamage;
2180 BOOL gotRange;
2181 BOOL gotVBias;
2182 GET_THIS_SHIP(thisEnt);
2183
2184 if (argc < 2) {
2185 OOJSReportBadArguments(context, @"Ship", @"dealEnergyDamage", argc, OOJS_ARGV, nil, @"damage and range needed");
2186 return OOJSNativeFailure(context);
2187 }
2188
2189 gotDamage = (JS_ToFloat64(context, &baseDamage, OOJS_ARGV[0]) == 0);
2190 if (EXPECT_NOT(!gotDamage || baseDamage < 0)) {
2191 OOJSReportBadArguments(context, @"Ship", @"dealEnergyDamage", argc, OOJS_ARGV, nil, @"damage must be positive");
2192 return OOJSNativeFailure(context);
2193 }
2194 gotRange = (JS_ToFloat64(context, &range, OOJS_ARGV[1]) == 0);
2195 if (EXPECT_NOT(!gotRange || range < 0)) {
2196 OOJSReportBadArguments(context, @"Ship", @"dealEnergyDamage", argc, OOJS_ARGV, nil, @"range must be positive");
2197 return OOJSNativeFailure(context);
2198 }
2199 if (argc >= 3) {
2200 gotVBias = (JS_ToFloat64(context, &velocityBias, OOJS_ARGV[2]) == 0);
2201 if (!gotVBias) {
2202 OOJSReportBadArguments(context, @"Ship", @"dealEnergyDamage", argc, OOJS_ARGV, nil, @"velocity bias must be a number");
2203 return OOJSNativeFailure(context);
2204 }
2205 }
2206
2207 [thisEnt dealEnergyDamage:(GLfloat)baseDamage atRange:(GLfloat)range withBias:(GLfloat)velocityBias];
2208
2210
2212}

References ShipEntity::dealEnergyDamage:atRange:withBias:, EXPECT_NOT, GET_THIS_SHIP, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJSNativeFailure(), and OOJSReportBadArguments().

Here is the call graph for this function:

◆ ShipDeployEscorts()

JSValue ShipDeployEscorts ( OOJS_NATIVE_ARGS )
static

Definition at line 1936 of file OOJSShip.m.

1937{
1938 OOJS_NATIVE_ENTER(context)
1939
1940 ShipEntity* thisEnt = nil;
1941
1942 GET_THIS_SHIP(thisEnt);
1943
1944 [thisEnt deployEscorts];
1946
1948}
void deployEscorts()

References ShipEntity::deployEscorts, GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, and OOJS_RETURN_VOID.

Here is the call graph for this function:

◆ ShipDockEscorts()

JSValue ShipDockEscorts ( OOJS_NATIVE_ARGS )
static

Definition at line 1951 of file OOJSShip.m.

1952{
1953 OOJS_NATIVE_ENTER(context)
1954
1955 ShipEntity* thisEnt = nil;
1956
1957 GET_THIS_SHIP(thisEnt);
1958
1959 [thisEnt dockEscorts];
1961
1963}
void dockEscorts()

References ShipEntity::dockEscorts, GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, and OOJS_RETURN_VOID.

Here is the call graph for this function:

◆ ShipDumpCargo()

JSValue ShipDumpCargo ( OOJS_NATIVE_ARGS )
static

Definition at line 2100 of file OOJSShip.m.

2101{
2102 OOJS_NATIVE_ENTER(context)
2103
2104 ShipEntity* thisEnt = nil;
2105 OOCommodityType pref = nil;
2106
2107 GET_THIS_SHIP(thisEnt);
2108
2109 if (EXPECT_NOT([thisEnt isPlayer] && [(PlayerEntity*)thisEnt isDocked])) {
2110 OOJSReportWarningForCaller(context, @"PlayerShip", @"dumpCargo", @"Can't dump cargo while docked, ignoring.");
2112 }
2113
2114 if (argc > 1) {
2115 pref = OOStringFromJSValue(context, OOJS_ARGV[1]);
2116 }
2117
2118 // NPCs can queue multiple items to dump
2119 if (!EXPECT_NOT([thisEnt isPlayer])) {
2120 int32_t i, count = 1;
2121 BOOL gotCount = YES;
2122 if (argc > 0)
2123 gotCount = OOJSValueToInt32(context, OOJS_ARGV[0], &count);
2124 if (EXPECT_NOT(!gotCount || count < 1 || count > 64)) {
2125 OOJSReportBadArguments(context, @"Ship", @"dumpCargo", MIN(argc, 1), OOJS_ARGV, nil, @"optional quantity (1 to 64), optional preferred commodity");
2126 return OOJSNativeFailure(context);
2127 }
2128
2129 for (i = 1; i < count; i++) {
2130 [thisEnt performSelector:@selector(dumpCargo) withObject:nil afterDelay:0.75 * i]; // drop 3 canisters per 2 seconds
2131 }
2132 }
2133
2134 OOJS_RETURN_OBJECT([thisEnt dumpCargoItem:pref]);
2135
2137}
#define OOJS_RETURN_NULL
NSString * OOCommodityType
Definition OOTypes.h:97

References count, EXPECT_NOT, GET_THIS_SHIP, MIN, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_NULL, OOJS_RETURN_OBJECT, OOJSNativeFailure(), OOJSReportBadArguments(), OOJSReportWarningForCaller(), OOJSValueToInt32(), and OOStringFromJSValue().

Here is the call graph for this function:

◆ ShipEjectItem()

JSValue ShipEjectItem ( OOJS_NATIVE_ARGS )
static

Definition at line 2010 of file OOJSShip.m.

2011{
2012 OOJS_NATIVE_ENTER(context)
2013
2014 ShipEntity* thisEnt = nil;
2015 NSString* role = nil;
2016
2017 GET_THIS_SHIP(thisEnt);
2018
2019 if (argc > 0)
2020 role = OOStringFromJSValue(context, OOJS_ARGV[0]);
2021 if (EXPECT_NOT(role == nil)) {
2022 OOJSReportBadArguments(context, @"Ship", @"ejectItem", MIN(argc, 1), OOJS_ARGV, nil, @"string (role)");
2023 return OOJSNativeFailure(context);
2024 }
2025
2026 OOJS_RETURN_OBJECT([thisEnt ejectShipOfRole:role]);
2027
2029}

References EXPECT_NOT, GET_THIS_SHIP, MIN, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, OOJSNativeFailure(), OOJSReportBadArguments(), and OOStringFromJSValue().

Here is the call graph for this function:

◆ ShipEjectSpecificItem()

JSValue ShipEjectSpecificItem ( OOJS_NATIVE_ARGS )
static

Definition at line 2078 of file OOJSShip.m.

2079{
2080 OOJS_NATIVE_ENTER(context)
2081
2082 ShipEntity* thisEnt = nil;
2083 NSString* itemKey = nil;
2084
2085 GET_THIS_SHIP(thisEnt);
2086
2087 if (argc > 0)
2088 itemKey = OOStringFromJSValue(context, OOJS_ARGV[0]);
2089 if (EXPECT_NOT(itemKey == nil)) {
2090 OOJSReportBadArguments(context, @"Ship", @"ejectSpecificItem", MIN(argc, 1), OOJS_ARGV, nil, @"string (ship key)");
2091 return OOJSNativeFailure(context);
2092 }
2093
2094 OOJS_RETURN_OBJECT([thisEnt ejectShipOfType:itemKey]);
2095
2097}

References EXPECT_NOT, GET_THIS_SHIP, MIN, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, OOJSNativeFailure(), OOJSReportBadArguments(), and OOStringFromJSValue().

Here is the call graph for this function:

◆ ShipEnterWormhole()

JSValue ShipEnterWormhole ( OOJS_NATIVE_ARGS )
static

Definition at line 3299 of file OOJSShip.m.

3300{
3302
3303 ShipEntity* thisEnt = nil;
3304 Entity* hole = nil;
3305
3306 if ([PLAYER status] != STATUS_ENTERING_WITCHSPACE) {
3307 OOJSReportError(context, @"Cannot use this function while player's ship not entering witchspace.");
3308 return OOJSNativeFailure(context);
3309 }
3310
3311 GET_THIS_SHIP(thisEnt);
3312 if (EXPECT_NOT(argc == 0 || (argc > 0 && !JS_IsNull(OOJS_ARGV[0]) && (!JS_IsObject(OOJS_ARGV[0]) || !OOJSEntityGetEntity(context, OOJS_ARGV[0], &hole))))) {
3313 [thisEnt enterPlayerWormhole];
3314 } else {
3315 if (![hole isWormhole]) {
3316 OOJSReportBadArguments(context, @"Ship", @"enterWormhole", 1U, OOJS_ARGV, nil, @"[wormhole]");
3317 return OOJSNativeFailure(context);
3318 }
3319
3320 [thisEnt enterWormhole:(WormholeEntity*)hole];
3321 }
3322
3324
3326}
#define PLAYER

References EXPECT_NOT, GET_THIS_SHIP, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_VOID, OOJSNativeFailure(), OOJSReportBadArguments(), OOJSReportError(), and PLAYER.

Here is the call graph for this function:

◆ ShipEquipmentStatus()

JSValue ShipEquipmentStatus ( OOJS_NATIVE_ARGS )
static

Definition at line 2626 of file OOJSShip.m.

2627{
2628 OOJS_NATIVE_ENTER(context)
2629
2630 ShipEntity* thisEnt = nil;
2631 NSString* key = nil;
2632 BOOL asDict = NO;
2633 NSDictionary* dict = nil;
2634
2635 GET_THIS_SHIP(thisEnt);
2636
2637 if (argc > 0)
2638 key = JSValueToEquipmentKey(context, OOJS_ARGV[0]);
2639 if (argc > 1)
2640 asDict = OOJSValueToBOOL(context, OOJS_ARGV[1]);
2641 if (EXPECT_NOT(key == nil)) {
2642 if (argc > 0 && JS_IsString(OOJS_ARGV[0])) {
2643 if (asDict) {
2644 dict = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:1], @"EQUIPMENT_UNKNOWN", nil];
2645 OOJS_RETURN_OBJECT(dict);
2646 } else {
2647 OOJS_RETURN(OOJSSTR("EQUIPMENT_UNKNOWN"));
2648 }
2649 }
2650
2651 OOJSReportBadArguments(context, @"Ship", @"equipmentStatus", MIN(argc, 1), &OOJS_ARGV[0], nil, @"equipment type");
2652 return OOJSNativeFailure(context);
2653 }
2654
2655 if (asDict) {
2656 dict = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInteger:[thisEnt countEquipmentItem:key]], @"EQUIPMENT_OK", [NSNumber numberWithUnsignedInteger:[thisEnt countEquipmentItem:[key stringByAppendingString:@"_DAMAGED"]]], @"EQUIPMENT_DAMAGED", nil];
2657 OOJS_RETURN_OBJECT(dict);
2658 } else {
2659 if ([thisEnt hasEquipmentItem:key includeWeapons:YES whileLoading:NO])
2660 OOJS_RETURN(OOJSSTR("EQUIPMENT_OK"));
2661 else if ([thisEnt hasEquipmentItem:[key stringByAppendingString:@"_DAMAGED"]])
2662 OOJS_RETURN(OOJSSTR("EQUIPMENT_DAMAGED"));
2663
2664 OOJS_RETURN(OOJSSTR("EQUIPMENT_UNAVAILABLE"));
2665 }
2667}
NSString * JSValueToEquipmentKey(JSContext *context, jsval value)
#define OOJS_RETURN(v)
#define OOJSSTR(str)
OOINLINE BOOL OOJSValueToBOOL(JSContext *context, jsval value)
NSUInteger countEquipmentItem:(NSString *eqkey)

References ShipEntity::countEquipmentItem:, EXPECT_NOT, GET_THIS_SHIP, JSValueToEquipmentKey(), MIN, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN, OOJS_RETURN_OBJECT, OOJSNativeFailure(), OOJSReportBadArguments(), OOJSSTR, and OOJSValueToBOOL().

Here is the call graph for this function:

◆ ShipExitAI()

JSValue ShipExitAI ( OOJS_NATIVE_ARGS )
static

Definition at line 1853 of file OOJSShip.m.

1854{
1855 OOJS_NATIVE_ENTER(context)
1856
1857 ShipEntity* thisEnt = nil;
1858 AI* thisAI = nil;
1859 NSString* message = nil;
1860
1861 GET_THIS_SHIP(thisEnt);
1862 if (EXPECT_NOT([thisEnt isPlayer])) {
1863 OOJSReportErrorForCaller(context, @"Ship", @"exitAI", @"Not valid for player ship.");
1864 return OOJSNativeFailure(context);
1865 }
1866 thisAI = [thisEnt getAI];
1867
1868 if ([thisAI hasSuspendedStateMachines]) {
1869 if (argc > 0) {
1870 message = OOStringFromJSValue(context, OOJS_ARGV[0]);
1871 }
1872 // Else AI will default to RESTARTED.
1873
1874 [thisAI exitStateMachineWithMessage:message];
1875 } else {
1876 OOJSReportWarningForCaller(context, @"Ship", @"exitAI()", @"Cannot exit current AI state machine because there are no suspended state machines.");
1877 }
1879
1881}
void OOJSReportErrorForCaller(JSContext *context, NSString *scriptClass, NSString *function, NSString *format,...)
Definition AI.h:35
void exitStateMachineWithMessage:(NSString *message)
Definition AI.m:268

References AI::exitStateMachineWithMessage:, EXPECT_NOT, GET_THIS_SHIP, ShipEntity::getAI, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJSNativeFailure(), OOJSReportErrorForCaller(), OOJSReportWarningForCaller(), and OOStringFromJSValue().

Here is the call graph for this function:

◆ ShipExitSystem()

JSValue ShipExitSystem ( OOJS_NATIVE_ARGS )
static

Definition at line 2978 of file OOJSShip.m.

2979{
2980 OOJS_NATIVE_ENTER(context)
2981
2982 ShipEntity* thisEnt = nil;
2983 int32_t systemID = -1;
2984 BOOL OK = NO;
2985
2986 GET_THIS_SHIP(thisEnt);
2987 if (EXPECT_NOT([thisEnt isPlayer])) {
2988 OOJSReportErrorForCaller(context, @"Ship", @"exitSystem", @"Not valid for player ship.");
2989 return OOJSNativeFailure(context);
2990 }
2991
2992 if (argc > 0) {
2993 if (!OOJSValueToInt32(context, OOJS_ARGV[0], &systemID) || systemID < 0 || 255 < systemID) {
2994 OOJSReportBadArguments(context, @"Ship", @"exitSystem", MIN(argc, 1), OOJS_ARGV, nil, @"system ID");
2995 return OOJSNativeFailure(context);
2996 }
2997 }
2998
2999 OK = [thisEnt performHyperSpaceToSpecificSystem:systemID]; // -1 == random destination system
3000
3001 OOJS_RETURN_BOOL(OK);
3002
3004}
BOOL performHyperSpaceToSpecificSystem:(OOSystemID systemID)

References EXPECT_NOT, GET_THIS_SHIP, MIN, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJSNativeFailure(), OOJSReportBadArguments(), OOJSReportErrorForCaller(), OOJSValueToInt32(), and ShipEntity::performHyperSpaceToSpecificSystem:.

Here is the call graph for this function:

◆ ShipExplode()

JSValue ShipExplode ( OOJS_NATIVE_ARGS )
static

Definition at line 2215 of file OOJSShip.m.

2216{
2217 OOJS_NATIVE_ENTER(context)
2218
2219 return RemoveOrExplodeShip(context, OOJS_THIS, argc, OOJS_ARGV, YES);
2220
2222}
static BOOL RemoveOrExplodeShip(JSContext *context, uintN argc, jsval *vp, BOOL explode)
Definition OOJSShip.m:3090

References OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_THIS, and RemoveOrExplodeShip().

Here is the call graph for this function:

◆ ShipFindNearestStation()

JSValue ShipFindNearestStation ( OOJS_NATIVE_ARGS )
static

Definition at line 2709 of file OOJSShip.m.

2710{
2711 OOJS_NATIVE_ENTER(context)
2712
2713 ShipEntity* thisEnt = nil;
2714 StationEntity* result = nil;
2715
2716 GET_THIS_SHIP(thisEnt);
2717
2718 double sdist, distance = 1E32;
2719
2720 StationEntity* se = nil;
2721 foreach (se, [UNIVERSE stations]) {
2722 sdist = HPdistance2([thisEnt position], [se position]);
2723
2724 if (sdist < distance) {
2725 distance = sdist;
2726 result = se;
2727 }
2728 }
2729
2730 OOJS_RETURN_OBJECT(result);
2731
2733}
OOINLINE OOHPScalar HPdistance2(HPVector v1, HPVector v2) INLINE_CONST_FUNC
Definition OOHPVector.h:293
OOINLINE OOScalar distance(Vector v1, Vector v2) INLINE_CONST_FUNC
Definition OOVector.h:280

References distance(), GET_THIS_SHIP, HPdistance2(), nil, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, and UNIVERSE.

Here is the call graph for this function:

◆ ShipFireECM()

JSValue ShipFireECM ( OOJS_NATIVE_ARGS )
static

Definition at line 2318 of file OOJSShip.m.

2319{
2320 OOJS_NATIVE_ENTER(context)
2321
2322 ShipEntity* thisEnt = nil;
2323 BOOL OK;
2324
2325 GET_THIS_SHIP(thisEnt);
2326
2327 OK = [thisEnt fireECM];
2328 if (!OK) {
2329 OOJSReportWarning(context, @"Ship %@ was requested to fire ECM burst but does not carry ECM equipment.", [thisEnt oo_jsDescription]);
2330 }
2331
2332 OOJS_RETURN_BOOL(OK);
2333
2335}
void OOJSReportWarning(JSContext *context, NSString *format,...)

References ShipEntity::fireECM, GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, and OOJSReportWarning().

Here is the call graph for this function:

◆ ShipFireMissile()

JSValue ShipFireMissile ( OOJS_NATIVE_ARGS )
static

Definition at line 2689 of file OOJSShip.m.

2690{
2691 OOJS_NATIVE_ENTER(context)
2692
2693 ShipEntity* thisEnt = nil;
2694 id result = nil;
2695
2696 GET_THIS_SHIP(thisEnt);
2697
2698 if (argc > 0)
2699 result = [thisEnt fireMissileWithIdentifier:OOStringFromJSValue(context, OOJS_ARGV[0]) andTarget:[thisEnt primaryTarget]];
2700 else
2701 result = [thisEnt fireMissile];
2702
2703 OOJS_RETURN_OBJECT(result);
2704
2706}
ShipEntity * fireMissile()
ShipEntity * fireMissileWithIdentifier:andTarget:(NSString *identifier,[andTarget] Entity *target)

References ShipEntity::fireMissile, ShipEntity::fireMissileWithIdentifier:andTarget:, GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, and ShipEntity::primaryTarget.

Here is the call graph for this function:

◆ ShipGetMaterials()

JSValue ShipGetMaterials ( OOJS_NATIVE_ARGS )
static

Definition at line 3162 of file OOJSShip.m.

3163{
3165
3166 ShipEntity* thisEnt = nil;
3167 NSObject* result = nil;
3168
3169 GET_THIS_SHIP(thisEnt);
3170
3171 result = [[thisEnt mesh] materials];
3172 if (result == nil)
3173 result = [NSDictionary dictionary];
3174 OOJS_RETURN_OBJECT(result);
3175
3177}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_OBJECT.

◆ ShipGetProperty()

JSValue ShipGetProperty ( OOJS_GETTER_ARGS )
static

Definition at line 581 of file OOJSShip.m.

582{
583
584 OOJS_NATIVE_ENTER(context)
585
586 ShipEntity* entity = nil;
587 id result = nil;
588
589 if (EXPECT_NOT(!JSShipGetShipEntity(context, this, &entity)))
590 return OOJSNativeFailure(context);
591 if (OOIsStaleEntity(entity)) {
592 return JS_UNDEFINED;
593 }
594
595 switch (magic) {
596 case kShip_name:
597 result = [entity name];
598 break;
599
601 result = [entity displayName];
602 break;
603
605 result = [entity shipUniqueName];
606 break;
607
609 result = [entity shipClassName];
610 break;
611
613 result = [entity scanDescriptionForScripting];
614 break;
615
616 case kShip_roles:
617 result = [[entity roleSet] sortedRoles];
618 break;
619
621 result = [[entity roleSet] rolesAndProbabilities];
622 break;
623
625 result = [entity primaryRole];
626 break;
627
628 case kShip_AI:
629 result = [[entity getAI] name];
630 break;
631
632 case kShip_AIState:
633 result = [[entity getAI] state];
634 break;
635
637 result = [entity foundTarget];
638 break;
639
641 result = [entity primaryAggressor];
642 break;
643
645 return JS_NewNumber(context, [entity realAlertCondition]);
646
647 case kShip_autoAI:
648 return OOJSValueFromBOOL([entity hasAutoAI]);
649
651 return OOJSValueFromBOOL([entity hasAutoWeapons]);
652
653 case kShip_accuracy:
654 return JS_NewNumber(context, [entity accuracy]);
655
656 case kShip_fuel:
657 return JS_NewNumber(context, [entity fuel] * 0.1);
658
660 return JS_NewNumber(context, [entity fuelChargeRate]);
661
662 case kShip_bounty:
663 return JS_NewNumber(context, [entity bounty]);
664
666 result = [entity subEntitiesForScript];
667 break;
668
669 case kShip_exhausts:
670 result = [[entity exhaustEnumerator] allObjects];
671 break;
672
673 case kShip_flashers:
674 result = [[entity flasherEnumerator] allObjects];
675 break;
676
678 return JS_NewNumber(context, [entity maxShipSubEntities]);
679
681 OOJS_RETURN_QUATERNION([entity subEntityRotationalVelocity]);
682
684 return OOJSValueFromBOOL([[entity getAI] hasSuspendedStateMachines]);
685
686 case kShip_target:
687 result = [entity primaryTarget];
688 break;
689
691 [entity validateDefenseTargets];
692 result = [NSMutableArray arrayWithCapacity:[entity defenseTargetCount]];
693 NSEnumerator* defTargets = [entity defenseTargetEnumerator];
694 Entity* target = nil;
695 while ((target = [[defTargets nextObject] weakRefUnderlyingObject])) {
696 [result addObject:target];
697 }
698 break;
699 }
700
701 case kShip_crew:
702 result = [entity crewForScripting];
703 break;
704
705 case kShip_escorts:
706 result = [[entity escortGroup] memberArrayExcludingLeader];
707 break;
708
709 case kShip_group:
710 result = [entity group];
711 break;
712
714 result = [entity escortGroup];
715 break;
716
718 return JS_NewNumber(context, [entity temperature] / SHIP_MAX_CABIN_TEMP);
719
721 return JS_NewNumber(context, [entity heatInsulation]);
722
723 case kShip_heading:
724 OOJS_RETURN_VECTOR([entity forwardVector]);
725
727 return JS_NewNumber(context, [entity energyRechargeRate]);
728
730 return JS_NewInt32(context, [entity entityPersonalityInt]);
731
732 case kShip_isBeacon:
733 return OOJSValueFromBOOL([entity isBeacon]);
734
735 case kShip_beaconCode:
736 result = [entity beaconCode];
737 break;
738
740 result = [entity beaconLabel];
741 break;
742
744 return OOJSValueFromBOOL([entity isFrangible]);
745
746 case kShip_isCloaked:
747 return OOJSValueFromBOOL([entity isCloaked]);
748
750 return OOJSValueFromBOOL([entity hasAutoCloak]);
751
752 case kShip_isJamming:
753 return OOJSValueFromBOOL([entity isJammingScanning]);
754
756 result = [entity proximityAlert];
757 break;
758
760 return OOJSValueFromBOOL([entity hasHostileTarget]);
761
763 return OOJSValueFromBOOL([entity hasHyperspaceMotor]);
764
766 return JS_NewNumber(context, [entity hyperspaceSpinTime]);
767
769 return JS_NewNumber(context, [entity weaponRange]);
770
772 if ([entity isPlayer]) {
773 PlayerEntity* pent = (PlayerEntity*)entity;
774 return JS_NewNumber(context, [pent availableFacings]);
775 }
776 return JS_NewNumber(context, [entity weaponFacings]);
777
779 result = [entity aftWeaponOffset];
780 break;
781
783 result = [entity forwardWeaponOffset];
784 break;
785 // OOJS_RETURN_VECTOR([entity forwardWeaponOffset]);
786
788 result = [entity portWeaponOffset];
789 break;
790
792 result = [entity starboardWeaponOffset];
793 break;
794
796 return JS_NewNumber(context, [entity scannerRange]);
797
799 return JS_NewNumber(context, [entity reactionTime]);
800
802 return OOJSValueFromBOOL([entity reportAIMessages]);
803
805 return OOJSValueFromBOOL([entity withinStationAegis]);
806
808 return JS_NewInt32(context, [entity maxAvailableCargoSpace]);
809
811 return JS_NewInt32(context, [entity maxAvailableCargoSpace] - [entity availableCargoSpace]);
812
814 return JS_NewInt32(context, [entity availableCargoSpace]);
815
816 case kShip_cargoList:
817 result = [entity cargoListForScripting];
818 break;
819
820 case kShip_extraCargo:
821 return JS_NewNumber(context, [entity extraCargo]);
822
823 case kShip_commodity:
824 if ([entity commodityAmount] > 0) {
825 result = [entity commodityType];
826 }
827 break;
828
830 return JS_NewInt32(context, [entity commodityAmount]);
831
833 result = [entity collisionExceptions];
834 break;
835
836 case kShip_speed:
837 return JS_NewNumber(context, [entity flightSpeed]);
838
840 return JS_NewNumber(context, [entity cruiseSpeed]);
841
842 case kShip_dataKey:
843 result = [entity shipDataKey];
844 break;
845
847 return JS_NewNumber(context, [entity desiredRange]);
848
850 return JS_NewNumber(context, [entity desiredSpeed]);
851
853 OOJS_RETURN_HPVECTOR([entity destination]);
854
856 return OOJSValueFromBOOL([entity markedForFines]);
857
858 case kShip_maxEscorts:
859 return JS_NewNumber(context, [entity maxEscortCount]);
860
861 case kShip_maxPitch:
862 return JS_NewNumber(context, [entity maxFlightPitch]);
863
864 case kShip_maxSpeed:
865 return JS_NewNumber(context, [entity maxFlightSpeed]);
866
867 case kShip_maxRoll:
868 return JS_NewNumber(context, [entity maxFlightRoll]);
869
870 case kShip_maxYaw:
871 return JS_NewNumber(context, [entity maxFlightYaw]);
872
874 return JS_NewNumber(context, [entity afterburnerRate]);
875
877 return JS_NewNumber(context, [entity afterburnerFactor]);
878
879 case kShip_script:
880 result = [entity shipScript];
881 break;
882
883 case kShip_AIScript:
884 result = [entity shipAIScript];
885 break;
886
888 return JS_NewNumber(context, [entity shipAIScriptWakeTime]);
889 break;
890
892 return JS_NewNumber(context, [entity destinationSystem]);
893 break;
894
895 case kShip_homeSystem:
896 return JS_NewNumber(context, [entity homeSystem]);
897 break;
898
899 case kShip_isPirate:
900 return OOJSValueFromBOOL([entity isPirate]);
901
902 case kShip_isPolice:
903 return OOJSValueFromBOOL([entity isPolice]);
904
905 case kShip_isThargoid:
906 return OOJSValueFromBOOL([entity isThargoid]);
907
908 case kShip_isTurret:
909 return OOJSValueFromBOOL([entity isTurret]);
910
911 case kShip_isTrader:
912 return OOJSValueFromBOOL([entity isTrader]);
913
915 return OOJSValueFromBOOL([entity isPirateVictim]);
916
917 case kShip_isMissile:
918 return OOJSValueFromBOOL([entity isMissile]);
919
920 case kShip_isMine:
921 return OOJSValueFromBOOL([entity isMine]);
922
923 case kShip_isWeapon:
924 return OOJSValueFromBOOL([entity isWeapon]);
925
926 case kShip_isRock:
927 return OOJSValueFromBOOL([entity scanClass] == CLASS_ROCK); // hermits and asteroids!
928
929 case kShip_isMinable:
930 return OOJSValueFromBOOL([entity isMinable]);
931
932 case kShip_isBoulder:
933 return OOJSValueFromBOOL([entity isBoulder]);
934
935 case kShip_isFleeing:
936 if ([entity isPlayer]) {
937 return OOJSValueFromBOOL([(PlayerEntity*)entity fleeingStatus] >= PLAYER_FLEEING_CARGO);
938 } else {
939 return OOJSValueFromBOOL([entity behaviour] == BEHAVIOUR_FLEE_TARGET || [entity behaviour] == BEHAVIOUR_FLEE_EVASIVE_ACTION);
940 }
941
942 case kShip_isCargo:
943 return OOJSValueFromBOOL([entity scanClass] == CLASS_CARGO && [entity commodityAmount] > 0);
944
945 case kShip_isDerelict:
946 return OOJSValueFromBOOL([entity isHulk]);
947
948 case kShip_isPiloted:
949 return OOJSValueFromBOOL([entity isPlayer] || [[entity crew] count] > 0);
950
952 return OOJSValueFromBOOL([entity scriptedMisjump]);
953
955 return JS_NewNumber(context, [entity scriptedMisjumpRange]);
956
957 case kShip_scriptInfo:
958 result = [entity scriptInfo];
959 if (result == nil)
960 result = [NSDictionary dictionary]; // empty rather than null
961 break;
962
964 return JS_NewNumber(context, [entity sunGlareFilter]);
965
967 return OOJSValueFromBOOL([entity trackCloseContacts]);
968
970 return JS_NewNumber(context, [entity passengerCount]);
971
973 return JS_NewNumber(context, [entity parcelCount]);
974
976 return JS_NewNumber(context, [entity passengerCapacity]);
977
979 return JS_NewNumber(context, [entity missileCapacity]);
980
982 return JS_NewNumber(context, [entity missileLoadTime]);
983
985 OOJS_RETURN_HPVECTOR([entity coordinates]);
986
987 case kShip_equipment:
988 result = [entity equipmentListForScripting];
989 break;
990
992 result = [entity weaponTypeForFacing:[entity currentWeaponFacing] strict:YES];
993 break;
994
996 result = [entity weaponTypeForFacing:WEAPON_FACING_FORWARD strict:YES];
997 break;
998
999 case kShip_aftWeapon:
1000 result = [entity weaponTypeForFacing:WEAPON_FACING_AFT strict:YES];
1001 break;
1002
1003 case kShip_portWeapon:
1004 result = [entity weaponTypeForFacing:WEAPON_FACING_PORT strict:YES];
1005 break;
1006
1008 result = [entity weaponTypeForFacing:WEAPON_FACING_STARBOARD strict:YES];
1009 break;
1010
1012 return JS_NewNumber(context, [entity laserHeatLevel]);
1013
1015 return JS_NewNumber(context, [entity laserHeatLevelAft]);
1016
1018 return JS_NewNumber(context, [entity laserHeatLevelForward]);
1019
1021 return JS_NewNumber(context, [entity laserHeatLevelPort]);
1022
1024 return JS_NewNumber(context, [entity laserHeatLevelStarboard]);
1025
1026 case kShip_missiles:
1027 result = [entity missilesList];
1028 break;
1029
1030 case kShip_passengers:
1031 result = [entity passengerListForScripting];
1032 break;
1033
1034 case kShip_parcels:
1035 result = [entity parcelListForScripting];
1036 break;
1037
1038 case kShip_contracts:
1039 result = [entity contractListForScripting];
1040 break;
1041
1043 result = [entity dockingInstructions];
1044 break;
1045
1047 result = [[entity scannerDisplayColor1] normalizedArray];
1048 break;
1049
1051 result = [[entity scannerDisplayColor2] normalizedArray];
1052 break;
1053
1055 result = [[entity scannerDisplayColorHostile1] normalizedArray];
1056 break;
1057
1059 result = [[entity scannerDisplayColorHostile2] normalizedArray];
1060 break;
1061
1063 result = [[entity exhaustEmissiveColor] normalizedArray];
1064 break;
1065
1066 case kShip_maxThrust:
1067 return JS_NewNumber(context, [entity maxThrust]);
1068
1069 case kShip_thrust:
1070 return JS_NewNumber(context, [entity thrust]);
1071
1072 case kShip_lightsActive:
1073 return OOJSValueFromBOOL([entity lightsActive]);
1074
1075 case kShip_vectorRight:
1076 OOJS_RETURN_VECTOR([entity rightVector]);
1077
1079 OOJS_RETURN_VECTOR([entity forwardVector]);
1080
1081 case kShip_vectorUp:
1082 OOJS_RETURN_VECTOR([entity upVector]);
1083
1084 case kShip_velocity:
1085 OOJS_RETURN_VECTOR([entity velocity]);
1086
1087 case kShip_thrustVector:
1088 OOJS_RETURN_VECTOR([entity thrustVector]);
1089
1090 case kShip_pitch:
1091 return JS_NewNumber(context, [entity flightPitch]);
1092
1093 case kShip_roll:
1094 return JS_NewNumber(context, [entity flightRoll]);
1095
1096 case kShip_yaw:
1097 return JS_NewNumber(context, [entity flightYaw]);
1098
1099 case kShip_boundingBox: {
1100 Vector bbvect;
1101 BoundingBox box;
1102
1103 if ([entity isSubEntity]) {
1104 box = [entity boundingBox];
1105 } else {
1106 box = [entity totalBoundingBox];
1107 }
1108 bounding_box_get_dimensions(box, &bbvect.x, &bbvect.y, &bbvect.z);
1109 OOJS_RETURN_VECTOR(bbvect);
1110 }
1111
1112 default:
1114 return OOJSNativeFailure(context);
1115 }
1116
1117 return OOJSValueFromNativeObject(context, result);
1118
1120}
OOINLINE void bounding_box_get_dimensions(BoundingBox bb, GLfloat *xSize, GLfloat *ySize, GLfloat *zSize) ALWAYS_INLINE_FUNC
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
#define OOJS_RETURN_QUATERNION(value)
OOINLINE jsval OOJSValueFromBOOL(int b) INLINE_CONST_FUNC
#define OOJS_RETURN_HPVECTOR(value)
#define OOJS_RETURN_VECTOR(value)
@ PLAYER_FLEEING_CARGO
#define SHIP_MAX_CABIN_TEMP
Definition ShipEntity.h:69
NSString * name()
Definition AI.m:329
NSString * state()
Definition AI.m:339
BoundingBox boundingBox
Definition Entity.m:666
NSArray * normalizedArray()
Definition OOColor.m:465
NSArray * sortedRoles()
Definition OORoleSet.m:163
NSDictionary * rolesAndProbabilities()
Definition OORoleSet.m:168
NSArray * memberArrayExcludingLeader()
NSUInteger defenseTargetCount()
NSString * beaconLabel()
NSDictionary * scriptInfo
OOScript * shipScript()
NSArray * contractListForScripting()
OOWeaponFacing currentWeaponFacing
NSDictionary * dockingInstructions
OOShipGroup * escortGroup()
NSString * shipDataKey()
OORoleSet * roleSet
NSString * primaryRole
NSString * beaconCode()
OOShipGroup * group()
OOColor * scannerDisplayColor2()
NSString * name
NSArray * portWeaponOffset
NSString * shipClassName
Entity * primaryAggressor()
void validateDefenseTargets()
NSArray * equipmentListForScripting()
BoundingBox totalBoundingBox
NSEnumerator * defenseTargetEnumerator()
NSArray * starboardWeaponOffset
NSArray * parcelListForScripting()
NSArray * cargoListForScripting()
NSEnumerator * flasherEnumerator()
Entity * proximityAlert()
NSString * shipUniqueName
NSString * scanDescriptionForScripting()
OOColor * scannerDisplayColorHostile2()
NSArray * missilesList()
NSEnumerator * exhaustEnumerator()
NSArray * aftWeaponOffset
NSArray * forwardWeaponOffset
NSArray * passengerListForScripting()
NSArray * collisionExceptions()
OOColor * scannerDisplayColorHostile1()
OOColor * exhaustEmissiveColor()
OOEquipmentType * weaponTypeForFacing:strict:(OOWeaponFacing facing,[strict] BOOL strict)
NSArray * crewForScripting()
OOCommodityType commodityType()
NSString * displayName
Entity * foundTarget()
OOColor * scannerDisplayColor1()
OOScript * shipAIScript()
OOScalar x
Definition OOVector.h:32
OOScalar y
Definition OOVector.h:33
OOScalar z
Definition OOVector.h:34

References ShipEntity::aftWeaponOffset, ShipEntity::beaconCode, ShipEntity::beaconLabel, bounding_box_get_dimensions(), Entity::boundingBox, ShipEntity::cargoListForScripting, ShipEntity::collisionExceptions, ShipEntity::commodityType, ShipEntity::contractListForScripting, count, ShipEntity::crewForScripting, ShipEntity::currentWeaponFacing, ShipEntity::defenseTargetCount, ShipEntity::defenseTargetEnumerator, ShipEntity::displayName, ShipEntity::dockingInstructions, ShipEntity::equipmentListForScripting, ShipEntity::escortGroup, ShipEntity::exhaustEmissiveColor, ShipEntity::exhaustEnumerator, EXPECT_NOT, ShipEntity::flasherEnumerator, ShipEntity::forwardWeaponOffset, ShipEntity::foundTarget, ShipEntity::getAI, ShipEntity::group, kShip_accuracy, kShip_aftWeapon, kShip_AI, kShip_AIFoundTarget, kShip_AIPrimaryAggressor, kShip_AIScript, kShip_AIScriptWakeTime, kShip_AIState, kShip_alertCondition, kShip_autoAI, kShip_autoWeapons, kShip_beaconCode, kShip_beaconLabel, kShip_boundingBox, kShip_bounty, kShip_cargoList, kShip_cargoSpaceAvailable, kShip_cargoSpaceCapacity, kShip_cargoSpaceUsed, kShip_cloakAutomatic, kShip_collisionExceptions, kShip_commodity, kShip_commodityAmount, kShip_contracts, kShip_crew, kShip_cruiseSpeed, kShip_currentWeapon, kShip_dataKey, kShip_defenseTargets, kShip_desiredRange, kShip_desiredSpeed, kShip_destination, kShip_destinationSystem, kShip_displayName, kShip_dockingInstructions, kShip_energyRechargeRate, kShip_entityPersonality, kShip_equipment, kShip_escortGroup, kShip_escorts, kShip_exhaustEmissiveColor, kShip_exhausts, kShip_extraCargo, kShip_flashers, kShip_forwardWeapon, kShip_fuel, kShip_fuelChargeRate, kShip_group, kShip_hasHostileTarget, kShip_hasHyperspaceMotor, kShip_hasSuspendedAI, kShip_heading, kShip_heatInsulation, kShip_homeSystem, kShip_hyperspaceSpinTime, kShip_injectorBurnRate, kShip_injectorSpeedFactor, kShip_isBeacon, kShip_isBoulder, kShip_isCargo, kShip_isCloaked, kShip_isDerelict, kShip_isFleeing, kShip_isFrangible, kShip_isJamming, kShip_isMinable, kShip_isMine, kShip_isMissile, kShip_isPiloted, kShip_isPirate, kShip_isPirateVictim, kShip_isPolice, kShip_isRock, kShip_isThargoid, kShip_isTrader, kShip_isTurret, kShip_isWeapon, kShip_laserHeatLevel, kShip_laserHeatLevelAft, kShip_laserHeatLevelForward, kShip_laserHeatLevelPort, kShip_laserHeatLevelStarboard, kShip_lightsActive, kShip_markedForFines, kShip_maxEscorts, kShip_maxPitch, kShip_maxRoll, kShip_maxSpeed, kShip_maxThrust, kShip_maxYaw, kShip_missileCapacity, kShip_missileLoadTime, kShip_missiles, kShip_name, kShip_parcelCount, kShip_parcels, kShip_passengerCapacity, kShip_passengerCount, kShip_passengers, kShip_pitch, kShip_portWeapon, kShip_potentialCollider, kShip_primaryRole, kShip_reactionTime, kShip_reportAIMessages, kShip_roles, kShip_roleWeights, kShip_roll, kShip_savedCoordinates, kShip_scanDescription, kShip_scannerDisplayColor1, kShip_scannerDisplayColor2, kShip_scannerHostileDisplayColor1, kShip_scannerHostileDisplayColor2, kShip_scannerRange, kShip_script, kShip_scriptedMisjump, kShip_scriptedMisjumpRange, kShip_scriptInfo, kShip_shipClassName, kShip_shipUniqueName, kShip_speed, kShip_starboardWeapon, kShip_subEntities, kShip_subEntityCapacity, kShip_subEntityRotation, kShip_sunGlareFilter, kShip_target, kShip_temperature, kShip_thrust, kShip_thrustVector, kShip_trackCloseContacts, kShip_vectorForward, kShip_vectorRight, kShip_vectorUp, kShip_velocity, kShip_weaponFacings, kShip_weaponPositionAft, kShip_weaponPositionForward, kShip_weaponPositionPort, kShip_weaponPositionStarboard, kShip_weaponRange, kShip_withinStationAegis, kShip_yaw, OOShipGroup::memberArrayExcludingLeader, ShipEntity::missilesList, AI::name, ShipEntity::name, nil, OOColor::normalizedArray, OOIsStaleEntity(), OOJS_COUNT, OOJS_GETTER_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_HPVECTOR, OOJS_RETURN_QUATERNION, OOJS_RETURN_VECTOR, OOJSNativeFailure(), OOJSReportBadPropertySelector(), OOJSValueFromBOOL(), OOJSValueFromNativeObject(), ShipEntity::parcelListForScripting, ShipEntity::passengerListForScripting, PLAYER_FLEEING_CARGO, ShipEntity::portWeaponOffset, ShipEntity::primaryAggressor, ShipEntity::primaryRole, ShipEntity::primaryTarget, ShipEntity::proximityAlert, OORoleSet::rolesAndProbabilities, ShipEntity::roleSet, ShipEntity::scanDescriptionForScripting, ShipEntity::scannerDisplayColor1, ShipEntity::scannerDisplayColor2, ShipEntity::scannerDisplayColorHostile1, ShipEntity::scannerDisplayColorHostile2, ShipEntity::scriptInfo, SHIP_MAX_CABIN_TEMP, ShipEntity::shipAIScript, ShipEntity::shipClassName, ShipEntity::shipDataKey, ShipEntity::shipScript, ShipEntity::shipUniqueName, OORoleSet::sortedRoles, sShipProperties, ShipEntity::starboardWeaponOffset, AI::state, ShipEntity::subEntitiesForScript, ShipEntity::totalBoundingBox, ShipEntity::validateDefenseTargets, ShipEntity::weaponTypeForFacing:strict:, Vector::x, Vector::y, and Vector::z.

Here is the call graph for this function:

◆ ShipGetSafeCourseToDestination()

JSValue ShipGetSafeCourseToDestination ( OOJS_NATIVE_ARGS )
static

Definition at line 3613 of file OOJSShip.m.

3614{
3616
3617 ShipEntity* thisEnt = nil;
3618 GET_THIS_SHIP(thisEnt);
3619
3620 HPVector waypoint = [UNIVERSE getSafeVectorFromEntity:thisEnt toDistance:[thisEnt desiredRange] fromPoint:[thisEnt destination]];
3621
3622 OOJS_RETURN_HPVECTOR(waypoint);
3623
3625}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_HPVECTOR.

◆ ShipGetShaders()

JSValue ShipGetShaders ( OOJS_NATIVE_ARGS )
static

Definition at line 3180 of file OOJSShip.m.

3181{
3183
3184 ShipEntity* thisEnt = nil;
3185 NSObject* result = nil;
3186
3187 GET_THIS_SHIP(thisEnt);
3188
3189 result = [[thisEnt mesh] shaders];
3190 if (result == nil)
3191 result = [NSDictionary dictionary];
3192 OOJS_RETURN_OBJECT(result);
3193
3195}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_OBJECT.

◆ ShipHasEquipmentProviding()

JSValue ShipHasEquipmentProviding ( OOJS_NATIVE_ARGS )
static

Definition at line 1966 of file OOJSShip.m.

1967{
1968 OOJS_NATIVE_ENTER(context)
1969
1970 ShipEntity* thisEnt = nil;
1971 NSString* equipment = nil;
1972
1973 GET_THIS_SHIP(thisEnt);
1974
1975 if (argc > 0)
1976 equipment = OOStringFromJSValue(context, OOJS_ARGV[0]);
1977 if (EXPECT_NOT(equipment == nil)) {
1978 OOJSReportBadArguments(context, @"Ship", @"hasEquipmentProviding", MIN(argc, 1), OOJS_ARGV, nil, @"string (equipment)");
1979 return OOJSNativeFailure(context);
1980 }
1981
1982 OOJS_RETURN_BOOL([thisEnt hasEquipmentItemProviding:equipment]);
1983
1985}

References EXPECT_NOT, GET_THIS_SHIP, MIN, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJSNativeFailure(), OOJSReportBadArguments(), and OOStringFromJSValue().

Here is the call graph for this function:

◆ ShipHasRole()

JSValue ShipHasRole ( OOJS_NATIVE_ARGS )
static

Definition at line 1988 of file OOJSShip.m.

1989{
1990 OOJS_NATIVE_ENTER(context)
1991
1992 ShipEntity* thisEnt = nil;
1993 NSString* role = nil;
1994
1995 GET_THIS_SHIP(thisEnt);
1996
1997 if (argc > 0)
1998 role = OOStringFromJSValue(context, OOJS_ARGV[0]);
1999 if (EXPECT_NOT(role == nil)) {
2000 OOJSReportBadArguments(context, @"Ship", @"hasRole", MIN(argc, 1), OOJS_ARGV, nil, @"string (role)");
2001 return OOJSNativeFailure(context);
2002 }
2003
2004 OOJS_RETURN_BOOL([thisEnt hasRole:role]);
2005
2007}

References EXPECT_NOT, GET_THIS_SHIP, MIN, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJSNativeFailure(), OOJSReportBadArguments(), and OOStringFromJSValue().

Here is the call graph for this function:

◆ ShipMarkTargetForFines()

JSValue ShipMarkTargetForFines ( OOJS_NATIVE_ARGS )
static

Definition at line 3280 of file OOJSShip.m.

3281{
3283
3284 ShipEntity* thisEnt = nil;
3285
3286 GET_THIS_SHIP(thisEnt);
3287
3288 ShipEntity* ship = [thisEnt primaryTarget];
3289 BOOL ok = NO;
3290 if ((ship != nil) && ([ship status] != STATUS_DEAD) && ([ship status] != STATUS_DOCKED)) {
3291 ok = [ship markForFines];
3292 }
3293
3294 OOJS_RETURN_BOOL(ok);
3295
3297}
BOOL markForFines()

References GET_THIS_SHIP, ShipEntity::markForFines, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_BOOL.

Here is the call graph for this function:

◆ ShipNotifyGroupOfWormhole()

JSValue ShipNotifyGroupOfWormhole ( OOJS_NATIVE_ARGS )
static

Definition at line 3328 of file OOJSShip.m.

3329{
3331
3332 ShipEntity* thisEnt = nil;
3333 GET_THIS_SHIP(thisEnt);
3334
3335 [thisEnt wormholeEntireGroup];
3336
3338
3340}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_VOID.

◆ ShipOfferToEscort()

JSValue ShipOfferToEscort ( OOJS_NATIVE_ARGS )
static

Definition at line 3223 of file OOJSShip.m.

3224{
3226
3227 ShipEntity* thisEnt = nil;
3228 ShipEntity* mother = nil;
3229
3230 GET_THIS_SHIP(thisEnt);
3231 if (EXPECT_NOT(argc == 0 || (argc > 0 && (JS_IsNull(OOJS_ARGV[0]) || !JS_IsObject(OOJS_ARGV[0]) || !JSShipGetShipEntity(context, OOJS_ARGV[0], &mother))))) {
3232 OOJSReportBadArguments(context, @"Ship", @"offerToEscort", 1U, OOJS_ARGV, nil, @"target");
3233 return OOJSNativeFailure(context);
3234 }
3235
3236 BOOL result = [thisEnt suggestEscortTo:mother];
3237
3238 OOJS_RETURN_BOOL(result);
3239
3241}

References EXPECT_NOT, GET_THIS_SHIP, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_BOOL, OOJSNativeFailure(), and OOJSReportBadArguments().

Here is the call graph for this function:

◆ ShipPatrolReportIn()

JSValue ShipPatrolReportIn ( OOJS_NATIVE_ARGS )
static

Definition at line 3258 of file OOJSShip.m.

3259{
3261
3262 ShipEntity* thisEnt = nil;
3263 ShipEntity* target = nil;
3264
3265 GET_THIS_SHIP(thisEnt);
3266 if (EXPECT_NOT(argc == 0 || (argc > 0 && (JS_IsNull(OOJS_ARGV[0]) || !JS_IsObject(OOJS_ARGV[0]) || !JSShipGetShipEntity(context, OOJS_ARGV[0], &target))))) {
3267 OOJSReportBadArguments(context, @"Ship", @"addDefenseTarget", 1U, OOJS_ARGV, nil, @"target");
3268 return OOJSNativeFailure(context);
3269 }
3270 if ([target isStation]) {
3271 StationEntity* station = (StationEntity*)target;
3272 [station acceptPatrolReportFrom:thisEnt];
3273 }
3274
3276
3278}
void acceptPatrolReportFrom:(ShipEntity *patrol_ship)

References StationEntity::acceptPatrolReportFrom:, EXPECT_NOT, GET_THIS_SHIP, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_VOID, OOJSNativeFailure(), and OOJSReportBadArguments().

Here is the call graph for this function:

◆ ShipPerformAttack()

JSValue ShipPerformAttack ( OOJS_NATIVE_ARGS )
static

Definition at line 3355 of file OOJSShip.m.

3356{
3358
3359 ShipEntity* thisEnt = nil;
3360 GET_THIS_SHIP(thisEnt);
3361 [thisEnt performAttack];
3362
3364
3366}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_VOID.

◆ ShipPerformCollect()

JSValue ShipPerformCollect ( OOJS_NATIVE_ARGS )
static

Definition at line 3368 of file OOJSShip.m.

3369{
3371
3372 ShipEntity* thisEnt = nil;
3373 GET_THIS_SHIP(thisEnt);
3374 [thisEnt performCollect];
3375
3377
3379}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_VOID.

◆ ShipPerformEscort()

JSValue ShipPerformEscort ( OOJS_NATIVE_ARGS )
static

Definition at line 3381 of file OOJSShip.m.

3382{
3384
3385 ShipEntity* thisEnt = nil;
3386 GET_THIS_SHIP(thisEnt);
3387 [thisEnt performEscort];
3388
3390
3392}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_VOID.

◆ ShipPerformFaceDestination()

JSValue ShipPerformFaceDestination ( OOJS_NATIVE_ARGS )
static

Definition at line 3394 of file OOJSShip.m.

3395{
3397
3398 ShipEntity* thisEnt = nil;
3399 GET_THIS_SHIP(thisEnt);
3400 [thisEnt performFaceDestination];
3401
3403
3405}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_VOID.

◆ ShipPerformFlee()

JSValue ShipPerformFlee ( OOJS_NATIVE_ARGS )
static

Definition at line 3407 of file OOJSShip.m.

3408{
3410
3411 ShipEntity* thisEnt = nil;
3412 GET_THIS_SHIP(thisEnt);
3413 [thisEnt performFlee];
3414
3416
3418}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_VOID.

◆ ShipPerformFlyToRangeFromDestination()

JSValue ShipPerformFlyToRangeFromDestination ( OOJS_NATIVE_ARGS )
static

Definition at line 3420 of file OOJSShip.m.

3421{
3423
3424 ShipEntity* thisEnt = nil;
3425 GET_THIS_SHIP(thisEnt);
3426 [thisEnt performFlyToRangeFromDestination];
3427
3429
3431}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_VOID.

◆ ShipPerformHold()

JSValue ShipPerformHold ( OOJS_NATIVE_ARGS )
static

Definition at line 3433 of file OOJSShip.m.

3434{
3436
3437 ShipEntity* thisEnt = nil;
3438 GET_THIS_SHIP(thisEnt);
3439 [thisEnt performHold];
3440
3442
3444}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_VOID.

◆ ShipPerformIdle()

JSValue ShipPerformIdle ( OOJS_NATIVE_ARGS )
static

Definition at line 3446 of file OOJSShip.m.

3447{
3449
3450 ShipEntity* thisEnt = nil;
3451 GET_THIS_SHIP(thisEnt);
3452 [thisEnt performIdle];
3453
3455
3457}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_VOID.

◆ ShipPerformIntercept()

JSValue ShipPerformIntercept ( OOJS_NATIVE_ARGS )
static

Definition at line 3459 of file OOJSShip.m.

3460{
3462
3463 ShipEntity* thisEnt = nil;
3464 GET_THIS_SHIP(thisEnt);
3465 [thisEnt performIntercept];
3466
3468
3470}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_VOID.

◆ ShipPerformLandOnPlanet()

JSValue ShipPerformLandOnPlanet ( OOJS_NATIVE_ARGS )
static

Definition at line 3472 of file OOJSShip.m.

3473{
3475
3476 ShipEntity* thisEnt = nil;
3477 GET_THIS_SHIP(thisEnt);
3478 [thisEnt performLandOnPlanet];
3479
3481
3483}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_VOID.

◆ ShipPerformMining()

JSValue ShipPerformMining ( OOJS_NATIVE_ARGS )
static

Definition at line 3485 of file OOJSShip.m.

3486{
3488
3489 ShipEntity* thisEnt = nil;
3490 GET_THIS_SHIP(thisEnt);
3491 [thisEnt performMining];
3492
3494
3496}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_VOID.

◆ ShipPerformScriptedAI()

JSValue ShipPerformScriptedAI ( OOJS_NATIVE_ARGS )
static

Definition at line 3498 of file OOJSShip.m.

3499{
3501
3502 ShipEntity* thisEnt = nil;
3503 GET_THIS_SHIP(thisEnt);
3504 [thisEnt performScriptedAI];
3505
3507
3509}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_VOID.

◆ ShipPerformScriptedAttackAI()

JSValue ShipPerformScriptedAttackAI ( OOJS_NATIVE_ARGS )
static

Definition at line 3511 of file OOJSShip.m.

3512{
3514
3515 ShipEntity* thisEnt = nil;
3516 GET_THIS_SHIP(thisEnt);
3517 [thisEnt performScriptedAttackAI];
3518
3520
3522}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_VOID.

◆ ShipPerformStop()

JSValue ShipPerformStop ( OOJS_NATIVE_ARGS )
static

Definition at line 3524 of file OOJSShip.m.

3525{
3527
3528 ShipEntity* thisEnt = nil;
3529 GET_THIS_SHIP(thisEnt);
3530 [thisEnt performStop];
3531
3533
3535}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_VOID.

◆ ShipPerformTumble()

JSValue ShipPerformTumble ( OOJS_NATIVE_ARGS )
static

Definition at line 3537 of file OOJSShip.m.

3538{
3540
3541 ShipEntity* thisEnt = nil;
3542 GET_THIS_SHIP(thisEnt);
3543 [thisEnt performTumble];
3544
3546
3548}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_VOID.

◆ ShipReactToAIMessage()

JSValue ShipReactToAIMessage ( OOJS_NATIVE_ARGS )
static

Definition at line 1884 of file OOJSShip.m.

1885{
1886 OOJS_NATIVE_ENTER(context)
1887
1888 ShipEntity* thisEnt = nil;
1889 NSString* message = nil;
1890
1891 GET_THIS_SHIP(thisEnt);
1892 if (argc > 0)
1893 message = OOStringFromJSValue(context, OOJS_ARGV[0]);
1894 if (EXPECT_NOT(message == nil)) {
1895 OOJSReportBadArguments(context, @"Ship", @"reactToAIMessage", MIN(argc, 1), OOJS_ARGV, nil, @"string");
1896 return OOJSNativeFailure(context);
1897 }
1898 if (EXPECT_NOT([thisEnt isPlayer])) {
1899 OOJSReportErrorForCaller(context, @"Ship", @"reactToAIMessage", @"Not valid for player ship.");
1900 return OOJSNativeFailure(context);
1901 }
1902
1903 [thisEnt reactToAIMessage:message context:@"JavaScript reactToAIMessage()"];
1905
1907}
void reactToAIMessage:context:(NSString *message,[context] NSString *debugContext)

References EXPECT_NOT, GET_THIS_SHIP, MIN, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJSNativeFailure(), OOJSReportBadArguments(), OOJSReportErrorForCaller(), OOStringFromJSValue(), and ShipEntity::reactToAIMessage:context:.

Here is the call graph for this function:

◆ ShipRecallDockingInstructions()

JSValue ShipRecallDockingInstructions ( OOJS_NATIVE_ARGS )
static

Definition at line 3568 of file OOJSShip.m.

3569{
3571
3572 ShipEntity* thisEnt = nil;
3573 GET_THIS_SHIP(thisEnt);
3574 [thisEnt recallDockingInstructions];
3575
3576 NSDictionary* dockingInstructions = [thisEnt dockingInstructions];
3577 if (dockingInstructions != nil) {
3578 OOJS_RETURN_OBJECT(dockingInstructions);
3579 } else {
3581 }
3582
3584}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_NULL, and OOJS_RETURN_OBJECT.

◆ ShipRemove()

JSValue ShipRemove ( OOJS_NATIVE_ARGS )
static

Definition at line 2225 of file OOJSShip.m.

2226{
2227 OOJS_NATIVE_ENTER(context)
2228
2229 ShipEntity* thisEnt = nil;
2230 int suppressDeathEvent = NO;
2231
2232 GET_THIS_SHIP(thisEnt);
2233
2234 if ([thisEnt isPlayer]) {
2235 OOJSReportError(context, @"Cannot remove() player's ship.");
2236 return OOJSNativeFailure(context);
2237 }
2238
2239 if (argc > 0 && EXPECT_NOT(!((suppressDeathEvent = JS_ToBool(context, OOJS_ARGV[0])) >= 0))) {
2240 OOJSReportBadArguments(context, @"Ship", @"remove", argc, OOJS_ARGV, nil, @"boolean");
2241 return OOJSNativeFailure(context);
2242 }
2243
2244 [thisEnt doScriptEvent:OOJSID("shipRemoved") withArgument:[NSNumber numberWithBool:suppressDeathEvent]];
2245
2246 if (suppressDeathEvent) {
2247 [thisEnt removeScript];
2248 }
2249 return RemoveOrExplodeShip(context, OOJS_THIS, argc, OOJS_ARGV, NO);
2250
2252}
void removeScript()

References ShipEntity::doScriptEvent:withArgument:, EXPECT_NOT, GET_THIS_SHIP, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_THIS, OOJSNativeFailure(), OOJSReportBadArguments(), OOJSReportError(), RemoveOrExplodeShip(), and ShipEntity::removeScript.

Here is the call graph for this function:

◆ ShipRemoveCollisionException()

JSValue ShipRemoveCollisionException ( OOJS_NATIVE_ARGS )
static

Definition at line 3139 of file OOJSShip.m.

3140{
3142
3143 ShipEntity* thisEnt = nil;
3144 ShipEntity* target = nil;
3145
3146 GET_THIS_SHIP(thisEnt);
3147 if (EXPECT_NOT(argc == 0 || (argc > 0 && (JS_IsNull(OOJS_ARGV[0]) || !JS_IsObject(OOJS_ARGV[0]) || !JSShipGetShipEntity(context, OOJS_ARGV[0], &target))))) {
3148 OOJSReportBadArguments(context, @"Ship", @"removeCollisionException", 1U, OOJS_ARGV, nil, @"other ship");
3149 return OOJSNativeFailure(context);
3150 }
3151
3152 // doesn't need a check to see if it was already gone
3153 [thisEnt removeCollisionException:target];
3154 [target removeCollisionException:thisEnt];
3155
3157
3159}
void removeCollisionException:(ShipEntity *ship)

References EXPECT_NOT, GET_THIS_SHIP, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_VOID, OOJSNativeFailure(), OOJSReportBadArguments(), and ShipEntity::removeCollisionException:.

Here is the call graph for this function:

◆ ShipRemoveDefenseTarget()

JSValue ShipRemoveDefenseTarget ( OOJS_NATIVE_ARGS )
static

Definition at line 3095 of file OOJSShip.m.

3096{
3098
3099 ShipEntity* thisEnt = nil;
3100 ShipEntity* target = nil;
3101
3102 GET_THIS_SHIP(thisEnt);
3103 if (EXPECT_NOT(argc == 0 || (argc > 0 && (JS_IsNull(OOJS_ARGV[0]) || !JS_IsObject(OOJS_ARGV[0]) || !JSShipGetShipEntity(context, OOJS_ARGV[0], &target))))) {
3104 OOJSReportBadArguments(context, @"Ship", @"removeDefenseTarget", 1U, OOJS_ARGV, nil, @"target");
3105 return OOJSNativeFailure(context);
3106 }
3107
3108 [thisEnt removeDefenseTarget:target];
3109
3111
3113}

References EXPECT_NOT, GET_THIS_SHIP, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_VOID, OOJSNativeFailure(), and OOJSReportBadArguments().

Here is the call graph for this function:

◆ ShipRemoveEquipment()

JSValue ShipRemoveEquipment ( OOJS_NATIVE_ARGS )
static

Definition at line 2466 of file OOJSShip.m.

2467{
2468 OOJS_NATIVE_ENTER(context)
2469
2470 ShipEntity* thisEnt = nil;
2471 NSString* key = nil;
2472 BOOL OK = YES;
2473
2474 GET_THIS_SHIP(thisEnt);
2475
2476 if (argc > 0)
2477 key = JSValueToEquipmentKey(context, OOJS_ARGV[0]);
2478 if (EXPECT_NOT(key == nil)) {
2479 OOJSReportBadArguments(context, @"Ship", @"removeEquipment", MIN(argc, 1), OOJS_ARGV, nil, @"equipment type");
2480 return OOJSNativeFailure(context);
2481 }
2482 // berths are not in hasOneEquipmentItem
2483 OK = [thisEnt hasOneEquipmentItem:key includeMissiles:YES whileLoading:NO] || ([key isEqualToString:@"EQ_PASSENGER_BERTH"] && [thisEnt passengerCapacity] > 0);
2484 if (!OK) {
2485 // Allow removal of damaged equipment.
2486 key = [key stringByAppendingString:@"_DAMAGED"];
2487 OK = [thisEnt hasOneEquipmentItem:key includeMissiles:NO whileLoading:NO];
2488 }
2489 if (OK) {
2490 // exceptions
2491 if ([key isEqualToString:@"EQ_PASSENGER_BERTH"] || [key isEqualToString:@"EQ_CARGO_BAY"]) {
2492 if ([key isEqualToString:@"EQ_PASSENGER_BERTH"]) {
2493 if ([thisEnt passengerCapacity] > [thisEnt passengerCount]) {
2494 // must be the player's ship!
2495 if ([thisEnt isPlayer])
2497 } else
2498 OK = NO;
2499 } else // EQ_CARGO_BAY
2500 {
2501 // player cargo bay removal handled in script
2502 if ([thisEnt isPlayer] || [thisEnt extraCargo] <= [thisEnt availableCargoSpace]) {
2503 [thisEnt removeEquipmentItem:key];
2504 } else
2505 OK = NO;
2506 }
2507 } else
2508 [thisEnt removeEquipmentItem:key];
2509 }
2510
2511 OOJS_RETURN_BOOL(OK);
2512
2514}
void removeEquipmentItem:(NSString *equipmentKey)
NSUInteger passengerCapacity()
BOOL hasOneEquipmentItem:includeMissiles:whileLoading:(NSString *itemKey,[includeMissiles] BOOL includeMissiles,[whileLoading] BOOL loading)

References PlayerEntity::changePassengerBerths:, EXPECT_NOT, GET_THIS_SHIP, ShipEntity::hasOneEquipmentItem:includeMissiles:whileLoading:, JSValueToEquipmentKey(), MIN, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJSNativeFailure(), OOJSReportBadArguments(), ShipEntity::passengerCapacity, and ShipEntity::removeEquipmentItem:.

Here is the call graph for this function:

◆ ShipRequestDockingInstructions()

JSValue ShipRequestDockingInstructions ( OOJS_NATIVE_ARGS )
static

Definition at line 3550 of file OOJSShip.m.

3551{
3553
3554 ShipEntity* thisEnt = nil;
3555 GET_THIS_SHIP(thisEnt);
3556 [thisEnt requestDockingCoordinates];
3557
3558 NSDictionary* dockingInstructions = [thisEnt dockingInstructions];
3559 if (dockingInstructions != nil) {
3560 OOJS_RETURN_OBJECT(dockingInstructions);
3561 } else {
3563 }
3564
3566}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_NULL, and OOJS_RETURN_OBJECT.

◆ ShipRequestHelpFromGroup()

JSValue ShipRequestHelpFromGroup ( OOJS_NATIVE_ARGS )
static

Definition at line 3243 of file OOJSShip.m.

3244{
3246
3247 ShipEntity* thisEnt = nil;
3248
3249 GET_THIS_SHIP(thisEnt);
3250
3251 [thisEnt groupAttackTarget];
3252
3254
3256}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_VOID.

◆ ShipRestoreSubEntities()

JSValue ShipRestoreSubEntities ( OOJS_NATIVE_ARGS )
static

Definition at line 2517 of file OOJSShip.m.

2518{
2519 OOJS_NATIVE_ENTER(context)
2520
2521 ShipEntity* thisEnt = nil;
2522 NSUInteger numSubEntitiesRestored = 0U;
2523
2524 GET_THIS_SHIP(thisEnt);
2525
2526 NSUInteger subCount = [[thisEnt subEntitiesForScript] count];
2527
2528 [thisEnt clearSubEntities];
2529 [thisEnt setUpSubEntities];
2530
2531 if ([[thisEnt subEntitiesForScript] count] - subCount > 0)
2532 numSubEntitiesRestored = [[thisEnt subEntitiesForScript] count] - subCount;
2533
2534 // for each subentity restored, slightly increase the trade-in factor
2535 if ([thisEnt isPlayer]) {
2536 int tradeInFactorChange = (int)MAX(PLAYER_SHIP_SUBENTITY_TRADE_IN_VALUE * numSubEntitiesRestored, 25U);
2537 [(PlayerEntity*)thisEnt adjustTradeInFactorBy:tradeInFactorChange];
2538 }
2539
2540 OOJS_RETURN_BOOL(numSubEntitiesRestored > 0);
2541
2543}
#define MAX(A, B)
Definition OOMaths.h:94
#define PLAYER_SHIP_SUBENTITY_TRADE_IN_VALUE
void adjustTradeInFactorBy:(int value)
void clearSubEntities()
BOOL setUpSubEntities()
Definition ShipEntity.m:790
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque

References PlayerEntity::adjustTradeInFactorBy:, ShipEntity::clearSubEntities, count, GET_THIS_SHIP, int(), MAX, nil, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, PLAYER_SHIP_SUBENTITY_TRADE_IN_VALUE, ShipEntity::setUpSubEntities, and ShipEntity::subEntitiesForScript.

Here is the call graph for this function:

◆ ShipRunLegacyScriptActions()

JSValue ShipRunLegacyScriptActions ( OOJS_NATIVE_ARGS )
static

Definition at line 2255 of file OOJSShip.m.

2256{
2257 OOJS_NATIVE_ENTER(context)
2258
2259 ShipEntity* thisEnt = nil;
2260 PlayerEntity* player = nil;
2261 ShipEntity* target = nil;
2262 NSArray* actions = nil;
2263
2264 player = OOPlayerForScripting();
2265 GET_THIS_SHIP(thisEnt);
2266
2267 if (argc > 1)
2268 actions = OOJSNativeObjectFromJSValue(context, OOJS_ARGV[1]);
2269 if (EXPECT_NOT(argc != 2 || !JS_IsObject(OOJS_ARGV[0]) || !JSShipGetShipEntity(context, OOJS_ARGV[0], &target) || ![actions isKindOfClass:[NSArray class]])) {
2270 OOJSReportBadArguments(context, @"Ship", @"__runLegacyScriptActions", argc, OOJS_ARGV, nil, @"target and array of actions");
2271 return OOJSNativeFailure(context);
2272 }
2273
2274 if (target != nil) // Not stale reference
2275 {
2276 [player setScriptTarget:thisEnt];
2277 [player runUnsanitizedScriptActions:actions
2279 withContextName:[NSString stringWithFormat:@"<ship \"%@\" legacy actions>", [thisEnt name]]
2280 forTarget:target];
2281 }
2282
2284
2286}
PlayerEntity * OOPlayerForScripting(void)
Definition OOJSPlayer.m:175
id OOJSNativeObjectFromJSValue(JSContext *context, jsval value)
void runUnsanitizedScriptActions:allowingAIMethods:withContextName:forTarget:(NSArray *unsanitizedActions,[allowingAIMethods] BOOL allowAIMethods,[withContextName] NSString *contextName,[forTarget] ShipEntity *target)
void setScriptTarget:(ShipEntity *ship)

References EXPECT_NOT, GET_THIS_SHIP, ShipEntity::name, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJSNativeFailure(), OOJSNativeObjectFromJSValue(), OOJSReportBadArguments(), OOPlayerForScripting(), PlayerEntity::runUnsanitizedScriptActions:allowingAIMethods:withContextName:forTarget:, and PlayerEntity::setScriptTarget:.

Here is the call graph for this function:

◆ ShipSelectNewMissile()

JSValue ShipSelectNewMissile ( OOJS_NATIVE_ARGS )
static

Definition at line 2670 of file OOJSShip.m.

2671{
2672 OOJS_NATIVE_ENTER(context)
2673
2674 ShipEntity* thisEnt = nil;
2675
2676 GET_THIS_SHIP(thisEnt);
2677
2678 NSString* result = [[thisEnt selectMissile] identifier];
2679 // if there's a badly defined missile, selectMissile may return nil
2680 if (result == nil)
2681 result = @"EQ_MISSILE";
2682
2683 OOJS_RETURN_OBJECT(result);
2684
2686}
OOEquipmentType * selectMissile()

References GET_THIS_SHIP, OOEquipmentType::identifier, nil, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, and ShipEntity::selectMissile.

Here is the call graph for this function:

◆ ShipSendAIMessage()

JSValue ShipSendAIMessage ( OOJS_NATIVE_ARGS )
static

Definition at line 1910 of file OOJSShip.m.

1911{
1912 OOJS_NATIVE_ENTER(context)
1913
1914 ShipEntity* thisEnt = nil;
1915 NSString* message = nil;
1916
1917 GET_THIS_SHIP(thisEnt);
1918 if (argc > 0)
1919 message = OOStringFromJSValue(context, OOJS_ARGV[0]);
1920 if (EXPECT_NOT(message == nil)) {
1921 OOJSReportBadArguments(context, @"Ship", @"sendAIMessage", MIN(argc, 1), OOJS_ARGV, nil, @"string");
1922 return OOJSNativeFailure(context);
1923 }
1924 if (EXPECT_NOT([thisEnt isPlayer])) {
1925 OOJSReportErrorForCaller(context, @"Ship", @"sendAIMessage", @"Not valid for player ship.");
1926 return OOJSNativeFailure(context);
1927 }
1928
1929 [thisEnt sendAIMessage:message];
1931
1933}
void sendAIMessage:(NSString *message)

References EXPECT_NOT, GET_THIS_SHIP, MIN, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJSNativeFailure(), OOJSReportBadArguments(), OOJSReportErrorForCaller(), OOStringFromJSValue(), and ShipEntity::sendAIMessage:.

Here is the call graph for this function:

◆ ShipSetAI()

JSValue ShipSetAI ( OOJS_NATIVE_ARGS )
static

Definition at line 1801 of file OOJSShip.m.

1802{
1803 OOJS_NATIVE_ENTER(context)
1804
1805 ShipEntity* thisEnt = nil;
1806 NSString* name = nil;
1807
1808 GET_THIS_SHIP(thisEnt);
1809 if (argc > 0)
1810 name = OOStringFromJSValue(context, OOJS_ARGV[0]);
1811 if (EXPECT_NOT(name == nil)) {
1812 OOJSReportBadArguments(context, @"Ship", @"setAI", MIN(argc, 1), OOJS_ARGV, nil, @"string (AI name)");
1813 return OOJSNativeFailure(context);
1814 }
1815 if (EXPECT_NOT([thisEnt isPlayer])) {
1816 OOJSReportErrorForCaller(context, @"Ship", @"setAI", @"Not valid for player ship.");
1817 return OOJSNativeFailure(context);
1818 }
1819
1820 [thisEnt setAITo:name];
1822
1824}
void setAITo:(NSString *aiString)

References EXPECT_NOT, GET_THIS_SHIP, MIN, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJSNativeFailure(), OOJSReportBadArguments(), OOJSReportErrorForCaller(), OOStringFromJSValue(), and ShipEntity::setAITo:.

Here is the call graph for this function:

◆ ShipSetBounty()

JSValue ShipSetBounty ( OOJS_NATIVE_ARGS )
static

Definition at line 2736 of file OOJSShip.m.

2737{
2738 OOJS_NATIVE_ENTER(context)
2739
2740 ShipEntity* thisEnt = nil;
2741 NSString* reason = nil;
2742 int32_t newbounty = 0;
2743 BOOL gotBounty = YES;
2744
2745 GET_THIS_SHIP(thisEnt);
2746
2747 if (argc > 0)
2748 gotBounty = OOJSValueToInt32(context, OOJS_ARGV[0], &newbounty);
2749 if (argc > 1)
2750 reason = OOStringFromJSValue(context, OOJS_ARGV[1]);
2751 if (EXPECT_NOT(reason == nil || !gotBounty || newbounty < 0)) {
2752 OOJSReportBadArguments(context, @"Ship", @"setBounty", argc, OOJS_ARGV, nil, @"new bounty and reason");
2753 return OOJSNativeFailure(context);
2754 }
2755
2756 [thisEnt setBounty:(OOCreditsQuantity)newbounty withReasonAsString:reason];
2757
2759
2761}
void setBounty:withReasonAsString:(OOCreditsQuantity amount,[withReasonAsString] NSString *reason)

References EXPECT_NOT, GET_THIS_SHIP, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJSNativeFailure(), OOJSReportBadArguments(), OOJSValueToInt32(), OOStringFromJSValue(), and ShipEntity::setBounty:withReasonAsString:.

Here is the call graph for this function:

◆ ShipSetCargo()

JSValue ShipSetCargo ( OOJS_NATIVE_ARGS )
static

Definition at line 2764 of file OOJSShip.m.

2765{
2766 OOJS_NATIVE_ENTER(context)
2767
2768 ShipEntity* thisEnt = nil;
2769 OOCommodityType commodity = nil;
2770 int32_t count = 1;
2771 BOOL gotCount = YES;
2772
2773 GET_THIS_SHIP(thisEnt);
2774
2775 if (argc > 0)
2776 commodity = OOStringFromJSValue(context, OOJS_ARGV[0]);
2777 if (argc > 1)
2778 gotCount = OOJSValueToInt32(context, OOJS_ARGV[1], &count);
2779 if (EXPECT_NOT(commodity == nil || !gotCount || count < 1)) {
2780 OOJSReportBadArguments(context, @"Ship", @"setCargo", argc, OOJS_ARGV, nil, @"cargo name and optional positive quantity");
2781 return OOJSNativeFailure(context);
2782 }
2783
2784 if ([[UNIVERSE commodities] goodDefined:commodity]) {
2785 [thisEnt setCommodityForPod:commodity andAmount:count];
2786 }
2787
2788 OOJS_RETURN_BOOL([[UNIVERSE commodities] goodDefined:commodity]);
2789
2791}
void setCommodityForPod:andAmount:(OOCommodityType co_type,[andAmount] OOCargoQuantity co_amount)

References count, EXPECT_NOT, GET_THIS_SHIP, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJSNativeFailure(), OOJSReportBadArguments(), OOJSValueToInt32(), OOStringFromJSValue(), ShipEntity::setCommodityForPod:andAmount:, and UNIVERSE.

Here is the call graph for this function:

◆ ShipSetCargoType()

JSValue ShipSetCargoType ( OOJS_NATIVE_ARGS )
static

Definition at line 2830 of file OOJSShip.m.

2831{
2832 OOJS_NATIVE_ENTER(context)
2833
2834 ShipEntity* thisEnt = nil;
2835 NSString* cargoType = nil;
2836
2837 GET_THIS_SHIP(thisEnt);
2838
2839 if (argc > 0)
2840 cargoType = OOStringFromJSValue(context, OOJS_ARGV[0]);
2841 if (EXPECT_NOT(cargoType == nil)) {
2842 OOJSReportBadArguments(context, @"Ship", @"setCargoType", argc, OOJS_ARGV, nil, @"cargo type name");
2843 return OOJSNativeFailure(context);
2844 }
2845 if ([thisEnt cargoType] != CARGO_NOT_CARGO) {
2846 OOJSReportBadArguments(context, @"Ship", @"setCargoType", argc, OOJS_ARGV, nil, [NSString stringWithFormat:@"Can only be used on cargo pod carriers, not cargo pods (%@)", [thisEnt shipDataKey]]);
2847 return OOJSNativeFailure(context);
2848 }
2849 BOOL ok = YES;
2850 if ([cargoType isEqualToString:@"SCARCE_GOODS"]) {
2851 [thisEnt setCargoFlag:CARGO_FLAG_FULL_SCARCE];
2852 } else if ([cargoType isEqualToString:@"PLENTIFUL_GOODS"]) {
2853 [thisEnt setCargoFlag:CARGO_FLAG_FULL_PLENTIFUL];
2854 } else if ([cargoType isEqualToString:@"MEDICAL_GOODS"]) {
2855 [thisEnt setCargoFlag:CARGO_FLAG_FULL_MEDICAL];
2856 } else if ([cargoType isEqualToString:@"ILLEGAL_GOODS"]) {
2857 [thisEnt setCargoFlag:CARGO_FLAG_FULL_CONTRABAND];
2858 } else if ([cargoType isEqualToString:@"PIRATE_GOODS"]) {
2859 [thisEnt setCargoFlag:CARGO_FLAG_PIRATE];
2860 } else {
2861 ok = NO;
2862 }
2863 OOJS_RETURN_BOOL(ok);
2864
2866}
void setCargoFlag:(OOCargoFlag flag)

References CARGO_NOT_CARGO, EXPECT_NOT, GET_THIS_SHIP, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJSNativeFailure(), OOJSReportBadArguments(), OOStringFromJSValue(), and ShipEntity::setCargoFlag:.

Here is the call graph for this function:

◆ ShipSetCrew()

JSValue ShipSetCrew ( OOJS_NATIVE_ARGS )
static

Definition at line 2794 of file OOJSShip.m.

2795{
2796 /* TODO: ships can in theory have multiple crew, so this could
2797 * allow that to be set. Probably not necessary for now. */
2798 OOJS_NATIVE_ENTER(context)
2799
2800 ShipEntity* thisEnt = nil;
2801 NSDictionary* crewDefinition = nil;
2802
2803 GET_THIS_SHIP(thisEnt);
2804
2805 // SpiderMonkey's JS_ValueToObject() check let primitives through to an invalid object cast; require an object or null.
2806 if (argc < 1 || (!JS_IsNull(OOJS_ARGV[0]) && !JS_IsObject(OOJS_ARGV[0]))) {
2807 OOJSReportBadArguments(context, @"Ship", @"setCrew", MIN(argc, 1), OOJS_ARGV, NULL, @"definition");
2808 return OOJSNativeFailure(context);
2809 }
2810 BOOL success = YES;
2811
2812 if (![thisEnt isExplicitlyUnpiloted]) {
2813 if (JS_IsNull(OOJS_ARGV[0])) {
2814 [thisEnt setCrew:nil];
2815 } else {
2816 crewDefinition = OOJSNativeObjectFromJSObject(context, OOJS_ARGV[0]);
2817 OOCharacter* crew = [OOCharacter characterWithDictionary:crewDefinition];
2818 [thisEnt setCrew:[NSArray arrayWithObject:crew]];
2819 }
2820 } else {
2821 success = NO;
2822 }
2823
2824 OOJS_RETURN_BOOL(success);
2825
2827}
id OOJSNativeObjectFromJSObject(JSContext *context, JSObject *object)
OOCharacter * characterWithDictionary:(NSDictionary *c_dict)
void setCrew:(NSArray *crewArray)

References OOCharacter::characterWithDictionary:, GET_THIS_SHIP, MIN, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJSNativeFailure(), OOJSNativeObjectFromJSObject(), OOJSReportBadArguments(), and ShipEntity::setCrew:.

Here is the call graph for this function:

◆ ShipSetEquipmentStatus()

JSValue ShipSetEquipmentStatus ( OOJS_NATIVE_ARGS )
static

Definition at line 2546 of file OOJSShip.m.

2547{
2548 OOJS_NATIVE_ENTER(context)
2549
2550 // equipment status accepted: @"EQUIPMENT_OK", @"EQUIPMENT_DAMAGED"
2551
2552 ShipEntity* thisEnt = nil;
2553 OOEquipmentType* eqType = nil;
2554 NSString* key = nil;
2555 NSString* damagedKey = nil;
2556 NSString* status = nil;
2557 BOOL hasOK = NO, hasDamaged = NO;
2558
2559 GET_THIS_SHIP(thisEnt);
2560
2561 if (argc < 2) {
2562 OOJSReportBadArguments(context, @"Ship", @"setEquipmentStatus", argc, OOJS_ARGV, nil, @"equipment type and status");
2563 return OOJSNativeFailure(context);
2564 }
2565
2566 eqType = JSValueToEquipmentType(context, OOJS_ARGV[0]);
2567 if (EXPECT_NOT(eqType == nil)) {
2568 OOJSReportBadArguments(context, @"Ship", @"setEquipmentStatus", 1, &OOJS_ARGV[0], nil, @"equipment type");
2569 return OOJSNativeFailure(context);
2570 }
2571
2572 status = OOStringFromJSValue(context, OOJS_ARGV[1]);
2573 if (EXPECT_NOT(status == nil)) {
2574 OOJSReportBadArguments(context, @"Ship", @"setEquipmentStatus", 1, &OOJS_ARGV[1], nil, @"equipment status");
2575 return OOJSNativeFailure(context);
2576 }
2577
2578 // EMMSTRAN: use interned strings.
2579 if (![status isEqualToString:@"EQUIPMENT_OK"] && ![status isEqualToString:@"EQUIPMENT_DAMAGED"]) {
2580 OOJSReportErrorForCaller(context, @"Ship", @"setEquipmentStatus", @"Second parameter for setEquipmentStatus must be either \"EQUIPMENT_OK\" or \"EQUIPMENT_DAMAGED\".");
2581 return OOJSNativeFailure(context);
2582 }
2583
2584 key = [eqType identifier];
2585 hasOK = [thisEnt hasEquipmentItem:key];
2586 BOOL setOK = [status isEqualToString:@"EQUIPMENT_OK"];
2587 BOOL setDamaged = [status isEqualToString:@"EQUIPMENT_DAMAGED"];
2588 if ([eqType canBeDamaged]) {
2589 damagedKey = [key stringByAppendingString:@"_DAMAGED"];
2590 hasDamaged = [thisEnt hasEquipmentItem:damagedKey];
2591
2592 if ((setOK && hasDamaged) || (setDamaged && hasOK)) {
2593 // the implementation is identical between player and ship.
2594 [thisEnt removeEquipmentItem:(setDamaged ? key : damagedKey)];
2595 if ([thisEnt isPlayer]) {
2596 // these player methods are different to the ship ones.
2597 [(PlayerEntity*)thisEnt addEquipmentItem:(setDamaged ? damagedKey : key) withValidation:NO inContext:@"scripted"];
2598 if (setDamaged) {
2599 [(PlayerEntity*)thisEnt doScriptEvent:OOJSID("equipmentDamaged") withArgument:key];
2600 } else if (setOK) {
2601 [(PlayerEntity*)thisEnt doScriptEvent:OOJSID("equipmentRepaired") withArgument:key];
2602 }
2603
2604 // if player's Docking Computers are set to EQUIPMENT_DAMAGED while on, stop them
2605 // this is now done in a different method
2606 // if (hasOK && [key isEqualToString:@"EQ_DOCK_COMP"]) [(PlayerEntity*)thisEnt disengageAutopilot];
2607 } else {
2608 [thisEnt addEquipmentItem:(setDamaged ? damagedKey : key) withValidation:NO inContext:@"scripted"];
2609 if (hasOK)
2610 [thisEnt doScriptEvent:OOJSID("equipmentDamaged") withArgument:key];
2611 }
2612 }
2613 } else {
2614 if (hasOK && ![status isEqualToString:@"EQUIPMENT_OK"]) {
2615 OOJSReportWarningForCaller(context, @"Ship", @"setEquipmentStatus", @"Equipment %@ cannot be damaged.", key);
2616 hasOK = NO;
2617 }
2618 }
2619
2620 OOJS_RETURN_BOOL(hasOK || hasDamaged);
2621
2623}

References PlayerEntity::addEquipmentItem:withValidation:inContext:, ShipEntity::addEquipmentItem:withValidation:inContext:, ShipEntity::doScriptEvent:withArgument:, EXPECT_NOT, GET_THIS_SHIP, ShipEntity::hasEquipmentItem:, OOEquipmentType::identifier, JSValueToEquipmentType(), nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJSNativeFailure(), OOJSReportBadArguments(), OOJSReportErrorForCaller(), OOJSReportWarningForCaller(), OOStringFromJSValue(), and ShipEntity::removeEquipmentItem:.

Here is the call graph for this function:

◆ ShipSetMaterials()

JSValue ShipSetMaterials ( OOJS_NATIVE_ARGS )
static

Definition at line 2869 of file OOJSShip.m.

2870{
2871 OOJS_NATIVE_ENTER(context)
2872
2873 ShipEntity* thisEnt = nil;
2874
2875 if (argc < 1) {
2876 OOJSReportBadArguments(context, @"Ship", @"setMaterials", 0, OOJS_ARGV, nil, @"parameter object");
2877 return OOJSNativeFailure(context);
2878 }
2879
2880 GET_THIS_SHIP(thisEnt);
2881
2882 return ShipSetMaterialsInternal(context, OOJS_THIS, argc, OOJS_ARGV, thisEnt, NO);
2883
2885}
static JSBool ShipSetMaterialsInternal(JSContext *context, uintN argc, jsval *vp, ShipEntity *thisEnt, BOOL fromShaders)
Definition OOJSShip.m:2985

References GET_THIS_SHIP, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_THIS, OOJSNativeFailure(), OOJSReportBadArguments(), and ShipSetMaterialsInternal().

Here is the call graph for this function:

◆ ShipSetMaterialsInternal()

JSValue ShipSetMaterialsInternal ( OOJS_NATIVE_ARGS ,
ShipEntity * thisEnt,
BOOL fromShaders )
static

Definition at line 2914 of file OOJSShip.m.

2915{
2917
2918 JSValueConst params = JS_UNDEFINED;
2919 NSDictionary* materials;
2920 NSDictionary* shaders;
2921 BOOL withShaders = NO;
2922 BOOL success = NO;
2923
2924 GET_THIS_SHIP(thisEnt);
2925
2926 if (JS_IsNull(OOJS_ARGV[0]) || (!JS_IsNull(OOJS_ARGV[0]) && !JS_IsObject(OOJS_ARGV[0]))) {
2927 OOJSReportWarning(context, @"Ship.%@: expected %@ instead of '%@'.", @"setMaterials", @"object", OOStringFromJSValueEvenIfNull(context, OOJS_ARGV[0]));
2928 OOJS_RETURN_BOOL(NO);
2929 }
2930
2931 if (argc > 1) {
2932 withShaders = YES;
2933 if (JS_IsNull(OOJS_ARGV[1]) || (!JS_IsNull(OOJS_ARGV[1]) && !JS_IsObject(OOJS_ARGV[1]))) {
2934 OOJSReportWarning(context, @"Ship.%@: expected %@ instead of '%@'.", @"setMaterials", @"object as second parameter", OOStringFromJSValueEvenIfNull(context, OOJS_ARGV[1]));
2935 withShaders = NO;
2936 }
2937 }
2938
2939 if (fromShaders) {
2940 materials = [[thisEnt mesh] materials];
2941 params = OOJS_ARGV[0];
2942 shaders = OOJSNativeObjectFromJSObject(context, params);
2943 } else {
2944 params = OOJS_ARGV[0];
2945 materials = OOJSNativeObjectFromJSObject(context, params);
2946 if (withShaders) {
2947 params = OOJS_ARGV[1];
2948 shaders = OOJSNativeObjectFromJSObject(context, params);
2949 } else {
2950 shaders = [[thisEnt mesh] shaders];
2951 }
2952 }
2953
2954 OOJS_BEGIN_FULL_NATIVE(context)
2955 NSDictionary* shipDict = [thisEnt shipInfoDictionary];
2956
2957 // First we test to see if we can create the mesh.
2958 OOMesh* mesh = [OOMesh meshWithName:[shipDict oo_stringForKey:@"model"]
2959 cacheKey:nil
2960 materialDictionary:materials
2961 shadersDictionary:shaders
2962 smooth:[shipDict oo_boolForKey:@"smooth" defaultValue:NO]
2963 shaderMacros:[[ResourceManager materialDefaults] oo_dictionaryForKey:@"ship-prefix-macros"]
2964 shaderBindingTarget:thisEnt];
2965
2966 if (mesh != nil) {
2967 [thisEnt setMesh:mesh];
2968 success = YES;
2969 }
2971
2972 OOJS_RETURN_BOOL(success);
2973
2975}
NSString * OOStringFromJSValueEvenIfNull(JSContext *context, jsval value)
NSDictionary * shaders()
Definition OOMesh.m:570
OOMaterial * materials[kOOMeshMaxMaterials]
Definition OOMesh.m:565
instancetype meshWithName:cacheKey:materialDictionary:shadersDictionary:smooth:shaderMacros:shaderBindingTarget:(NSString *name,[cacheKey] NSString *cacheKey,[materialDictionary] NSDictionary *materialDict,[shadersDictionary] NSDictionary *shadersDict,[smooth] BOOL smooth,[shaderMacros] NSDictionary *macros,[shaderBindingTarget] id< OOWeakReferenceSupport > object)
Definition OOMesh.m:223
NSDictionary * materialDefaults()
void setMesh:(OOMesh *mesh)
NSDictionary * shipInfoDictionary()
OOMesh * mesh()

References GET_THIS_SHIP, ResourceManager::materialDefaults, OOMesh::materials, ShipEntity::mesh, OOMesh::meshWithName:cacheKey:materialDictionary:shadersDictionary:smooth:shaderMacros:shaderBindingTarget:, nil, OOJS_ARGV, OOJS_BEGIN_FULL_NATIVE, OOJS_END_FULL_NATIVE, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_BOOL, OOJSNativeObjectFromJSObject(), OOJSReportWarning(), OOStringFromJSValueEvenIfNull(), ShipEntity::setMesh:, OOMesh::shaders, and ShipEntity::shipInfoDictionary.

Here is the call graph for this function:

◆ ShipSetProperty()

JSValue ShipSetProperty ( OOJS_SETTER_ARGS )
static

Definition at line 1122 of file OOJSShip.m.

1123{
1124
1125 OOJS_NATIVE_ENTER(context)
1126
1127 ShipEntity* entity = nil;
1128 ShipEntity* target = nil;
1129 NSString* sValue = nil;
1130 double fValue;
1131 int32_t iValue;
1132 int bValue;
1133 Vector vValue;
1134 Quaternion qValue;
1135 HPVector hpvValue;
1136 OOShipGroup* group = nil;
1137 OOColor* colorForScript = nil;
1138 BOOL exists;
1139
1140 if (EXPECT_NOT(!JSShipGetShipEntity(context, this, &entity)))
1141 return OOJSNativeFailure(context);
1142 if (OOIsStaleEntity(entity))
1143 return JS_UNDEFINED;
1144
1145 NSCAssert(![entity isTemplateCargoPod], @"-OOJSShip: a template cargo pod has become accessible to Javascript");
1146
1147 switch (magic) {
1148 case kShip_name:
1149 if (EXPECT_NOT([entity isPlayer]))
1150 goto playerReadOnly;
1151
1152 sValue = OOStringFromJSValue(context, value);
1153 if (sValue != nil) {
1154 [entity setName:sValue];
1155 return JS_UNDEFINED;
1156 }
1157 break;
1158
1159 case kShip_displayName:
1160 if (EXPECT_NOT([entity isPlayer]))
1161 goto playerReadOnly;
1162
1163 sValue = OOStringFromJSValue(context, value);
1164 if (sValue != nil) {
1165 [entity setDisplayName:sValue];
1166 return JS_UNDEFINED;
1167 }
1168 break;
1169
1171 sValue = OOStringFromJSValue(context, value);
1172 if (sValue != nil) {
1173 [entity setShipUniqueName:sValue];
1174 return JS_UNDEFINED;
1175 }
1176 break;
1177
1179 sValue = OOStringFromJSValue(context, value);
1180 if (sValue != nil) {
1181 [entity setShipClassName:sValue];
1182 return JS_UNDEFINED;
1183 }
1184 break;
1185
1187 sValue = OOStringFromJSValue(context, value);
1188 // can set to nil
1189 [entity setScanDescription:sValue];
1190 return JS_UNDEFINED;
1191
1192 case kShip_primaryRole:
1193 if (EXPECT_NOT([entity isPlayer]))
1194 goto playerReadOnly;
1195
1196 sValue = OOStringFromJSValue(context, value);
1197 if (sValue != nil) {
1198 [entity setPrimaryRole:sValue];
1199 return JS_UNDEFINED;
1200 }
1201 break;
1202
1203 case kShip_AIState:
1204 if (EXPECT_NOT([entity isPlayer]))
1205 goto playerReadOnly;
1206
1207 sValue = OOStringFromJSValue(context, value);
1208 if (sValue != nil) {
1209 [[entity getAI] setState:sValue];
1210 return JS_UNDEFINED;
1211 }
1212 break;
1213
1214 case kShip_beaconCode:
1215 if (EXPECT_NOT([entity isPlayer]))
1216 goto playerReadOnly;
1217
1218 sValue = OOStringFromJSValue(context, value);
1219 if ([sValue length] == 0) {
1220 if ([entity isBeacon]) {
1221 [UNIVERSE clearBeacon:entity];
1222 if ([PLAYER nextBeacon] == entity) {
1223 [PLAYER setCompassMode:COMPASS_MODE_PLANET];
1224 }
1225 }
1226 } else {
1227 if ([entity isBeacon]) {
1228 [entity setBeaconCode:sValue];
1229 } else // Universe needs to update beacon lists in this case only
1230 {
1231 [entity setBeaconCode:sValue];
1232 [UNIVERSE setNextBeacon:entity];
1233 }
1234 }
1235 return JS_UNDEFINED;
1236 break;
1237
1238 case kShip_beaconLabel:
1239 if (EXPECT_NOT([entity isPlayer]))
1240 goto playerReadOnly;
1241 sValue = OOStringFromJSValue(context, value);
1242 if (sValue != nil) {
1243 [entity setBeaconLabel:sValue];
1244 return JS_UNDEFINED;
1245 }
1246 break;
1247
1248 case kShip_accuracy:
1249 if (EXPECT_NOT([entity isPlayer]))
1250 goto playerReadOnly;
1251
1252 if ((JS_ToFloat64(context, &fValue, value) == 0)) {
1253 [entity setAccuracy:fValue];
1254 return JS_UNDEFINED;
1255 }
1256 break;
1257
1258 case kShip_fuel:
1259 if ((JS_ToFloat64(context, &fValue, value) == 0)) {
1260 fValue = OOClamp_0_max_d(fValue, MAX_JUMP_RANGE);
1261 [entity setFuel:lround(fValue * 10.0)];
1262 return JS_UNDEFINED;
1263 }
1264 break;
1265
1267 if (OOJSValueToInt32(context, value, &iValue)) {
1268 if (iValue < 0 || iValue > (int32_t)ENTITY_PERSONALITY_MAX) {
1270 return OOJSNativeFailure(context);
1271 }
1272 [entity setEntityPersonalityInt:iValue];
1273 return JS_UNDEFINED;
1274 }
1275
1277 if ((JS_ToFloat64(context, &fValue, value) == 0)) {
1278 [entity setHyperspaceSpinTime:fValue];
1279 return JS_UNDEFINED;
1280 }
1281 break;
1282
1283 case kShip_bounty:
1284 if (OOJSValueToInt32(context, value, &iValue)) {
1285 if (iValue < 0)
1286 iValue = 0;
1287 [entity setBounty:iValue withReason:kOOLegalStatusReasonByScript];
1288 return JS_UNDEFINED;
1289 }
1290 break;
1291
1293 if (OOJSValueToInt32(context, value, &iValue)) {
1294 if (iValue < 0)
1295 iValue = 0;
1296 // OXPs using equipment with weight requirements may make us end up with more allocated
1297 // cargo space than what we have available. Do not let iValue become negative.
1298 if ([entity maxAvailableCargoSpace] < [entity availableCargoSpace]) {
1299 iValue = 0;
1300 } else if ((OOCargoQuantity)iValue < [entity maxAvailableCargoSpace] - [entity availableCargoSpace]) {
1301 iValue = [entity maxAvailableCargoSpace] - [entity availableCargoSpace];
1302 }
1303 [entity setMaxAvailableCargoSpace:iValue];
1304 return JS_UNDEFINED;
1305 }
1306 break;
1307
1309 if (OOJSValueToInt32(context, value, &iValue)) {
1310 if (iValue < 0)
1311 iValue = 0;
1312 [entity setDestinationSystem:iValue];
1313 return JS_UNDEFINED;
1314 }
1315 break;
1316
1317 case kShip_homeSystem:
1318 if (OOJSValueToInt32(context, value, &iValue)) {
1319 if (iValue < 0)
1320 iValue = 0;
1321 [entity setHomeSystem:iValue];
1322 return JS_UNDEFINED;
1323 }
1324 break;
1325
1326 case kShip_target:
1327 if (JS_IsNull(value)) {
1328 [entity setTargetForScript:nil];
1329 return JS_UNDEFINED;
1330 } else if (JSValueToEntity(context, value, &target) && [target isKindOfClass:[ShipEntity class]]) {
1331 [entity setTargetForScript:target];
1332 return JS_UNDEFINED;
1333 }
1334 break;
1335
1337 if (EXPECT_NOT([entity isPlayer]))
1338 goto playerReadOnly;
1339
1340 if (JS_IsNull(value)) {
1341 [entity setFoundTarget:nil];
1342 return JS_UNDEFINED;
1343 } else if (JSValueToEntity(context, value, &target) && [target isKindOfClass:[ShipEntity class]]) {
1344 [entity setFoundTarget:target];
1345 return JS_UNDEFINED;
1346 }
1347 break;
1348
1350 if (EXPECT_NOT([entity isPlayer]))
1351 goto playerReadOnly;
1352
1353 if (JS_IsNull(value)) {
1354 [entity setPrimaryAggressor:nil];
1355 return JS_UNDEFINED;
1356 } else if (JSValueToEntity(context, value, &target) && [target isKindOfClass:[ShipEntity class]]) {
1357 [entity setPrimaryAggressor:target];
1358 return JS_UNDEFINED;
1359 }
1360 break;
1361
1362 case kShip_group:
1363 group = OOJSNativeObjectOfClassFromJSValue(context, value, [OOShipGroup class]);
1364 if (group != nil || JS_IsNull(value)) {
1365 [entity setGroup:group];
1366 return JS_UNDEFINED;
1367 }
1368 break;
1369
1371 if ((JS_ToFloat64(context, &fValue, value) == 0)) {
1372 [entity setAIScriptWakeTime:fValue];
1373 return JS_UNDEFINED;
1374 }
1375 break;
1376
1377 case kShip_temperature:
1378 if ((JS_ToFloat64(context, &fValue, value) == 0)) {
1379 fValue = fmax(fValue, 0.0);
1380 [entity setTemperature:fValue * SHIP_MAX_CABIN_TEMP];
1381 return JS_UNDEFINED;
1382 }
1383 break;
1384
1386 if ((JS_ToFloat64(context, &fValue, value) == 0)) {
1387 fValue = fmax(fValue, 0.125);
1388 [entity setHeatInsulation:fValue];
1389 return JS_UNDEFINED;
1390 }
1391 break;
1392
1393 case kShip_isCloaked:
1394 if (((bValue = JS_ToBool(context, value)) >= 0)) {
1395 [entity setCloaked:bValue];
1396 return JS_UNDEFINED;
1397 }
1398 break;
1399
1401 if (((bValue = JS_ToBool(context, value)) >= 0)) {
1402 [entity setAutoCloak:bValue];
1403 return JS_UNDEFINED;
1404 }
1405 break;
1406
1408 if ((JS_ToFloat64(context, &fValue, value) == 0)) {
1409 [entity setMissileLoadTime:fmax(0.0, fValue)];
1410 return JS_UNDEFINED;
1411 }
1412 break;
1413
1414 case kShip_reactionTime:
1415 if (EXPECT_NOT([entity isPlayer]))
1416 goto playerReadOnly;
1417
1418 if ((JS_ToFloat64(context, &fValue, value) == 0)) {
1419 [entity setReactionTime:fValue];
1420 return JS_UNDEFINED;
1421 }
1422 break;
1423
1425 if (((bValue = JS_ToBool(context, value)) >= 0)) {
1426 [entity setReportAIMessages:bValue];
1427 return JS_UNDEFINED;
1428 }
1429 break;
1430
1432 if (((bValue = JS_ToBool(context, value)) >= 0)) {
1433 [entity setTrackCloseContacts:bValue];
1434 return JS_UNDEFINED;
1435 }
1436 break;
1437
1438 case kShip_isBoulder:
1439 if (EXPECT_NOT([entity isPlayer]))
1440 goto playerReadOnly;
1441
1442 if (((bValue = JS_ToBool(context, value)) >= 0)) {
1443 [entity setIsBoulder:bValue];
1444 return JS_UNDEFINED;
1445 }
1446 break;
1447
1448 case kShip_destination:
1449 if (EXPECT_NOT([entity isPlayer]))
1450 goto playerReadOnly;
1451
1452 if (JSValueToHPVector(context, value, &hpvValue)) {
1453 // use setEscortDestination rather than setDestination as
1454 // scripted amendments shouldn't necessarily reset frustration
1455 [entity setEscortDestination:hpvValue];
1456 return JS_UNDEFINED;
1457 }
1458 break;
1459
1460 case kShip_desiredSpeed:
1461 if (EXPECT_NOT([entity isPlayer]))
1462 goto playerReadOnly;
1463
1464 if ((JS_ToFloat64(context, &fValue, value) == 0)) {
1465 [entity setDesiredSpeed:fmax(fValue, 0.0)];
1466 return JS_UNDEFINED;
1467 }
1468 break;
1469
1470 case kShip_desiredRange:
1471 if (EXPECT_NOT([entity isPlayer]))
1472 goto playerReadOnly;
1473
1474 if ((JS_ToFloat64(context, &fValue, value) == 0)) {
1475 [entity setDesiredRange:fmax(fValue, 0.0)];
1476 return JS_UNDEFINED;
1477 }
1478 break;
1479
1481 if (JSValueToHPVector(context, value, &hpvValue)) {
1482 [entity setCoordinate:hpvValue];
1483 return JS_UNDEFINED;
1484 }
1485 break;
1486
1488 colorForScript = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, value)];
1489 if (colorForScript != nil || JS_IsNull(value)) {
1490 [entity setScannerDisplayColor1:colorForScript];
1491 return JS_UNDEFINED;
1492 }
1493 break;
1494
1496 colorForScript = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, value)];
1497 if (colorForScript != nil || JS_IsNull(value)) {
1498 [entity setScannerDisplayColor2:colorForScript];
1499 return JS_UNDEFINED;
1500 }
1501 break;
1502
1504 colorForScript = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, value)];
1505 if (colorForScript != nil || JS_IsNull(value)) {
1506 [entity setScannerDisplayColorHostile1:colorForScript];
1507 return JS_UNDEFINED;
1508 }
1509 break;
1510
1512 colorForScript = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, value)];
1513 if (colorForScript != nil || JS_IsNull(value)) {
1514 [entity setScannerDisplayColorHostile2:colorForScript];
1515 return JS_UNDEFINED;
1516 }
1517 break;
1518
1520 colorForScript = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, value)];
1521 if (colorForScript != nil || JS_IsNull(value)) {
1522 [entity setExhaustEmissiveColor:colorForScript];
1523 return JS_UNDEFINED;
1524 }
1525 break;
1526
1528 if (((bValue = JS_ToBool(context, value)) >= 0)) {
1529 [entity setScriptedMisjump:bValue];
1530 return JS_UNDEFINED;
1531 }
1532 break;
1533
1535 if ((JS_ToFloat64(context, &fValue, value) == 0)) {
1536 if (fValue > 0.0 && fValue < 1.0) {
1537 [entity setScriptedMisjumpRange:fValue];
1538 return JS_UNDEFINED;
1539 } else {
1540 OOJSReportError(context, @"ship.%@ must be > 0.0 and < 1.0.", OOStringFromJSPropertyMagic(magic, sShipProperties, OOJS_COUNT(sShipProperties)));
1541 return OOJSNativeFailure(context);
1542 }
1543 }
1544 break;
1545
1547 if (JSValueToQuaternion(context, value, &qValue)) {
1548 [entity setSubEntityRotationalVelocity:qValue];
1549 return JS_UNDEFINED;
1550 }
1551 break;
1552
1554 if ((JS_ToFloat64(context, &fValue, value) == 0)) {
1555 if (fValue >= 0.0f && fValue <= 1.0f) {
1556 [entity setSunGlareFilter:fValue];
1557 return JS_UNDEFINED;
1558 } else {
1559 OOJSReportError(context, @"ship.%@ must be > 0.0 and < 1.0.", OOStringFromJSPropertyMagic(magic, sShipProperties, OOJS_COUNT(sShipProperties)));
1560 return OOJSNativeFailure(context);
1561 }
1562 }
1563 break;
1564
1565 case kShip_thrust:
1566 // if (EXPECT_NOT([entity isPlayer])) goto playerReadOnly;
1567
1568 if ((JS_ToFloat64(context, &fValue, value) == 0)) {
1569 [entity setThrust:OOClamp_0_max_f(fValue, [entity maxThrust])];
1570 return JS_UNDEFINED;
1571 }
1572 break;
1573
1574 case kShip_maxPitch:
1575 if ((JS_ToFloat64(context, &fValue, value) == 0)) {
1576 if (fValue < 0) {
1577 OOJSReportError(context, @"ship.maxPitch cannot be negative.");
1578 return OOJSNativeFailure(context);
1579 }
1580 [entity setMaxFlightPitch:fValue];
1581 return JS_UNDEFINED;
1582 }
1583 break;
1584
1585 case kShip_maxSpeed:
1586 if ((JS_ToFloat64(context, &fValue, value) == 0)) {
1587 if (fValue < 0) {
1588 OOJSReportError(context, @"ship.maxSpeed cannot be negative.");
1589 return OOJSNativeFailure(context);
1590 }
1591 [entity setMaxFlightSpeed:fValue];
1592 return JS_UNDEFINED;
1593 }
1594 break;
1595
1596 case kShip_maxRoll:
1597 if ((JS_ToFloat64(context, &fValue, value) == 0)) {
1598 if (fValue < 0) {
1599 OOJSReportError(context, @"ship.maxRoll cannot be negative.");
1600 return OOJSNativeFailure(context);
1601 }
1602 [entity setMaxFlightRoll:fValue];
1603 return JS_UNDEFINED;
1604 }
1605 break;
1606
1607 case kShip_maxYaw:
1608 if ((JS_ToFloat64(context, &fValue, value) == 0)) {
1609 if (fValue < 0) {
1610 OOJSReportError(context, @"ship.maxYaw cannot be negative.");
1611 return OOJSNativeFailure(context);
1612 }
1613 [entity setMaxFlightYaw:fValue];
1614 return JS_UNDEFINED;
1615 }
1616 break;
1617
1619 if ((JS_ToFloat64(context, &fValue, value) == 0)) {
1620 if (fValue < 0) {
1621 OOJSReportError(context, @"ship.injectorBurnRate cannot be negative.");
1622 return OOJSNativeFailure(context);
1623 }
1624 [entity setAfterburnerRate:fValue];
1625 return JS_UNDEFINED;
1626 }
1627 break;
1628
1630 if ((JS_ToFloat64(context, &fValue, value) == 0)) {
1631 if (fValue < 1) {
1632 OOJSReportError(context, @"ship.injectorSpeedFactor cannot be less than 1.0.");
1633 return OOJSNativeFailure(context);
1634 }
1635#if OO_VARIABLE_TORUS_SPEED
1636 else if (fValue > MIN_HYPERSPEED_FACTOR) {
1637 OOJSReportError(context, @"ship.injectorSpeedFactor cannot be higher than minimum torus speed factor (%f).", MIN_HYPERSPEED_FACTOR);
1638#else
1639 else if (fValue > HYPERSPEED_FACTOR) {
1640 OOJSReportError(context, @"ship.injectorSpeedFactor cannot be higher than torus speed factor (%f).", HYPERSPEED_FACTOR);
1641#endif
1642 return OOJSNativeFailure(context);
1643 }
1644 [entity setAfterburnerFactor:fValue];
1645 return JS_UNDEFINED;
1646 }
1647 break;
1648
1649 case kShip_maxThrust:
1650 if ((JS_ToFloat64(context, &fValue, value) == 0)) {
1651 if (fValue < 0) {
1652 OOJSReportError(context, @"ship.maxThrust cannot be negative.");
1653 return OOJSNativeFailure(context);
1654 }
1655 [entity setMaxThrust:fValue];
1656 return JS_UNDEFINED;
1657 }
1658 break;
1659
1661 if ((JS_ToFloat64(context, &fValue, value) == 0)) {
1662 if (fValue < 0) {
1663 OOJSReportError(context, @"ship.energyRechargeRate cannot be negative.");
1664 return OOJSNativeFailure(context);
1665 }
1666 [entity setEnergyRechargeRate:fValue];
1667 return JS_UNDEFINED;
1668 }
1669 break;
1670
1671 case kShip_lightsActive:
1672 if (((bValue = JS_ToBool(context, value)) >= 0)) {
1673 if (bValue)
1674 [entity switchLightsOn];
1675 else
1676 [entity switchLightsOff];
1677 return JS_UNDEFINED;
1678 }
1679 break;
1680
1681 case kShip_velocity:
1682 if (JSValueToVector(context, value, &vValue)) {
1683 [entity setTotalVelocity:vValue];
1684 return JS_UNDEFINED;
1685 }
1686 break;
1687
1688 case kShip_portWeapon:
1690 case kShip_aftWeapon:
1693 sValue = JSValueToEquipmentKeyRelaxed(context, value, &exists);
1694 if (sValue == nil) {
1695 sValue = @"EQ_WEAPON_NONE";
1696 }
1698 switch (magic) {
1699 case kShip_aftWeapon:
1700 facing = WEAPON_FACING_AFT;
1701 break;
1703 facing = WEAPON_FACING_FORWARD;
1704 break;
1705 case kShip_portWeapon:
1706 facing = WEAPON_FACING_PORT;
1707 break;
1709 facing = WEAPON_FACING_STARBOARD;
1710 break;
1712 facing = [entity currentWeaponFacing];
1713 break;
1714 }
1715 if ([entity isPlayer]) {
1716 PlayerEntity* pent = (PlayerEntity*)entity;
1717 [pent setWeaponMount:facing toWeapon:sValue inContext:@"scripted"];
1718 } else {
1719 [entity setWeaponMount:facing toWeapon:sValue];
1720 }
1721 return JS_UNDEFINED;
1722
1723 case kShip_maxEscorts:
1724 if (EXPECT_NOT([entity isPlayer]))
1725 goto playerReadOnly;
1726
1727 if (OOJSValueToInt32(context, value, &iValue)) {
1728 if ((NSInteger)iValue < (NSInteger)[[entity escortGroup] count] - 1) {
1729 OOJSReportError(context, @"ship.%@ must be >= current escort numbers.", OOStringFromJSPropertyMagic(magic, sShipProperties, OOJS_COUNT(sShipProperties)));
1730 return OOJSNativeFailure(context);
1731 }
1732 if (iValue > MAX_ESCORTS) {
1734 return OOJSNativeFailure(context);
1735 }
1736 [entity setMaxEscortCount:iValue];
1737 return JS_UNDEFINED;
1738 }
1739
1740 break;
1741
1742 default:
1744 return OOJSNativeFailure(context);
1745 }
1746
1748 return OOJSNativeFailure(context);
1749
1750playerReadOnly:
1751 OOJSReportError(context, @"player.ship.%@ is read-only.", OOStringFromJSPropertyMagic(magic, sShipProperties, OOJS_COUNT(sShipProperties)));
1752 return OOJSNativeFailure(context);
1753
1754 // Not used (yet)
1755 /*
1756 npcReadOnly:
1757 OOJSReportError(context, @"npc.ship.%@ is read-only.", OOStringFromJSPropertyMagic(magic, sShipProperties, OOJS_COUNT(sShipProperties)));
1758 return OOJSNativeFailure(context);
1759 */
1760
1762}
OOINLINE double OOClamp_0_max_d(double value, double max) INLINE_CONST_FUNC
BOOL JSValueToEntity(JSContext *context, jsval value, Entity **outEntity)
Definition OOJSEntity.m:133
BOOL JSValueToQuaternion(JSContext *context, jsval value, Quaternion *outQuaternion) NONNULL_FUNC
BOOL JSValueToVector(JSContext *context, jsval value, Vector *outVector) NONNULL_FUNC
Definition OOJSVector.m:341
BOOL JSValueToHPVector(JSContext *context, jsval value, HPVector *outVector) NONNULL_FUNC
Definition OOJSVector.m:333
id OOJSNativeObjectOfClassFromJSValue(JSContext *context, jsval value, Class requiredClass)
void OOJSReportBadPropertyValue(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec, jsval value)
OOWeaponFacing
Definition OOTypes.h:195
@ WEAPON_FACING_FORWARD
Definition OOTypes.h:196
@ WEAPON_FACING_AFT
Definition OOTypes.h:197
@ WEAPON_FACING_PORT
Definition OOTypes.h:198
@ WEAPON_FACING_STARBOARD
Definition OOTypes.h:199
#define HYPERSPEED_FACTOR
#define MIN_HYPERSPEED_FACTOR
NSString * OOStringFromJSPropertyMagic(int magic, const JSCFunctionListEntry *list, size_t count)
#define MAX_JUMP_RANGE
Definition ShipEntity.h:109
#define MAX_ESCORTS
Definition ShipEntity.h:76
#define ENTITY_PERSONALITY_MAX
Definition ShipEntity.h:112
void setState:(NSString *stateName)
Definition AI.m:303
OOColor * colorWithDescription:(id description)
Definition OOColor.m:135
BOOL setWeaponMount:toWeapon:inContext:(OOWeaponFacing facing,[toWeapon] NSString *eqKey,[inContext] NSString *context)
void setMaxFlightYaw:(GLfloat new)
void setScannerDisplayColor1:(OOColor *color1)
void setExhaustEmissiveColor:(OOColor *color)
void setAfterburnerFactor:(GLfloat new)
void setBounty:withReason:(OOCreditsQuantity amount,[withReason] OOLegalStatusReason reason)
float maxThrust()
void setPrimaryAggressor:(Entity *targetEntity)
void setDesiredSpeed:(double amount)
void setEnergyRechargeRate:(GLfloat new)
void setFuel:(OOFuelQuantity amount)
void setCoordinate:(HPVector coord)
void setMaxFlightRoll:(GLfloat new)
void setThrust:(double amount)
void setDestinationSystem:(OOSystemID s)
void setMaxAvailableCargoSpace:(OOCargoQuantity new)
void switchLightsOn()
void setScannerDisplayColorHostile1:(OOColor *color1)
void setAIScriptWakeTime:(OOTimeAbsolute t)
void setGroup:(OOShipGroup *group)
void setEscortDestination:(HPVector dest)
void setDisplayName:(NSString *inName)
void setAccuracy:(GLfloat new_accuracy)
void setAutoCloak:(BOOL automatic)
void setAfterburnerRate:(GLfloat new)
void setPrimaryRole:(NSString *role)
void setHeatInsulation:(GLfloat value)
void setScannerDisplayColor2:(OOColor *color2)
BOOL setWeaponMount:toWeapon:(OOWeaponFacing facing,[toWeapon] NSString *eqKey)
void setTargetForScript:(ShipEntity *target)
void setName:(NSString *inName)
void setBeaconCode:(NSString *bcode)
void setScanDescription:(NSString *inName)
void switchLightsOff()
void setMaxFlightPitch:(GLfloat new)
void setReactionTime:(float newReactionTime)
void setScriptedMisjumpRange:(GLfloat newValue)
void setEntityPersonalityInt:(uint16_t value)
void setReportAIMessages:(BOOL yn)
void setTrackCloseContacts:(BOOL value)
void setSubEntityRotationalVelocity:(Quaternion rv)
void setMaxFlightSpeed:(GLfloat new)
OOCargoQuantity maxAvailableCargoSpace()
void setTemperature:(GLfloat value)
void setScriptedMisjump:(BOOL newValue)
void setTotalVelocity:(Vector vel)
void setSunGlareFilter:(GLfloat newValue)
void setCloaked:(BOOL cloak)
void setIsBoulder:(BOOL flag)
void setMaxEscortCount:(uint8_t newCount)
void setBeaconLabel:(NSString *blabel)
void setFoundTarget:(Entity *targetEntity)
void setScannerDisplayColorHostile2:(OOColor *color2)
void setMissileLoadTime:(OOTimeDelta newMissileLoadTime)
void setDesiredRange:(double amount)
void setHomeSystem:(OOSystemID s)
void setHyperspaceSpinTime:(float new)
void setShipUniqueName:(NSString *inName)
void setMaxThrust:(GLfloat new)
void setShipClassName:(NSString *inName)

References ShipEntity::availableCargoSpace, OOColor::colorWithDescription:, count, ShipEntity::currentWeaponFacing, ENTITY_PERSONALITY_MAX, EXPECT_NOT, ShipEntity::getAI, HYPERSPEED_FACTOR, JSValueToEntity(), JSValueToEquipmentKeyRelaxed(), JSValueToHPVector(), JSValueToQuaternion(), JSValueToVector(), kShip_accuracy, kShip_aftWeapon, kShip_AIFoundTarget, kShip_AIPrimaryAggressor, kShip_AIScriptWakeTime, kShip_AIState, kShip_beaconCode, kShip_beaconLabel, kShip_bounty, kShip_cargoSpaceCapacity, kShip_cloakAutomatic, kShip_currentWeapon, kShip_desiredRange, kShip_desiredSpeed, kShip_destination, kShip_destinationSystem, kShip_displayName, kShip_energyRechargeRate, kShip_entityPersonality, kShip_exhaustEmissiveColor, kShip_forwardWeapon, kShip_fuel, kShip_group, kShip_heatInsulation, kShip_homeSystem, kShip_hyperspaceSpinTime, kShip_injectorBurnRate, kShip_injectorSpeedFactor, kShip_isBoulder, kShip_isCloaked, kShip_lightsActive, kShip_maxEscorts, kShip_maxPitch, kShip_maxRoll, kShip_maxSpeed, kShip_maxThrust, kShip_maxYaw, kShip_missileLoadTime, kShip_name, kShip_portWeapon, kShip_primaryRole, kShip_reactionTime, kShip_reportAIMessages, kShip_savedCoordinates, kShip_scanDescription, kShip_scannerDisplayColor1, kShip_scannerDisplayColor2, kShip_scannerHostileDisplayColor1, kShip_scannerHostileDisplayColor2, kShip_scriptedMisjump, kShip_scriptedMisjumpRange, kShip_shipClassName, kShip_shipUniqueName, kShip_starboardWeapon, kShip_subEntityRotation, kShip_sunGlareFilter, kShip_target, kShip_temperature, kShip_thrust, kShip_trackCloseContacts, kShip_velocity, MAX_ESCORTS, MAX_JUMP_RANGE, ShipEntity::maxAvailableCargoSpace, ShipEntity::maxThrust, MIN_HYPERSPEED_FACTOR, nil, OOClamp_0_max_d(), OOIsStaleEntity(), OOJS_COUNT, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_SETTER_ARGS, OOJSNativeFailure(), OOJSNativeObjectOfClassFromJSValue(), OOJSReportBadPropertySelector(), OOJSReportBadPropertyValue(), OOJSReportError(), OOJSValueToInt32(), OOStringFromJSPropertyMagic(), OOStringFromJSValue(), PLAYER, ShipEntity::setAccuracy:, ShipEntity::setAfterburnerFactor:, ShipEntity::setAfterburnerRate:, ShipEntity::setAIScriptWakeTime:, ShipEntity::setAutoCloak:, ShipEntity::setBeaconCode:, ShipEntity::setBeaconLabel:, ShipEntity::setBounty:withReason:, ShipEntity::setCloaked:, ShipEntity::setCoordinate:, ShipEntity::setDesiredRange:, ShipEntity::setDesiredSpeed:, ShipEntity::setDestinationSystem:, ShipEntity::setDisplayName:, ShipEntity::setEnergyRechargeRate:, ShipEntity::setEntityPersonalityInt:, ShipEntity::setEscortDestination:, ShipEntity::setExhaustEmissiveColor:, ShipEntity::setFoundTarget:, ShipEntity::setFuel:, ShipEntity::setGroup:, ShipEntity::setHeatInsulation:, ShipEntity::setHomeSystem:, ShipEntity::setHyperspaceSpinTime:, ShipEntity::setIsBoulder:, ShipEntity::setMaxAvailableCargoSpace:, ShipEntity::setMaxEscortCount:, ShipEntity::setMaxFlightPitch:, ShipEntity::setMaxFlightRoll:, ShipEntity::setMaxFlightSpeed:, ShipEntity::setMaxFlightYaw:, ShipEntity::setMaxThrust:, ShipEntity::setMissileLoadTime:, ShipEntity::setName:, ShipEntity::setPrimaryAggressor:, ShipEntity::setPrimaryRole:, ShipEntity::setReactionTime:, ShipEntity::setReportAIMessages:, ShipEntity::setScanDescription:, ShipEntity::setScannerDisplayColor1:, ShipEntity::setScannerDisplayColor2:, ShipEntity::setScannerDisplayColorHostile1:, ShipEntity::setScannerDisplayColorHostile2:, ShipEntity::setScriptedMisjump:, ShipEntity::setScriptedMisjumpRange:, ShipEntity::setShipClassName:, ShipEntity::setShipUniqueName:, AI::setState:, ShipEntity::setSubEntityRotationalVelocity:, ShipEntity::setSunGlareFilter:, ShipEntity::setTargetForScript:, ShipEntity::setTemperature:, ShipEntity::setThrust:, ShipEntity::setTotalVelocity:, ShipEntity::setTrackCloseContacts:, ShipEntity::setWeaponMount:toWeapon:, PlayerEntity::setWeaponMount:toWeapon:inContext:, sShipProperties, ShipEntity::switchLightsOff, ShipEntity::switchLightsOn, WEAPON_FACING_AFT, WEAPON_FACING_FORWARD, WEAPON_FACING_PORT, and WEAPON_FACING_STARBOARD.

Here is the call graph for this function:

◆ ShipSetScript()

JSValue ShipSetScript ( OOJS_NATIVE_ARGS )
static

Definition at line 1775 of file OOJSShip.m.

1776{
1777 OOJS_NATIVE_ENTER(context)
1778
1779 ShipEntity* thisEnt = nil;
1780 NSString* name = nil;
1781
1782 GET_THIS_SHIP(thisEnt);
1783 if (argc > 0)
1784 name = OOStringFromJSValue(context, OOJS_ARGV[0]);
1785 if (EXPECT_NOT(name == nil)) {
1786 OOJSReportBadArguments(context, @"Ship", @"setScript", MIN(argc, 1), OOJS_ARGV, nil, @"string (script name)");
1787 return OOJSNativeFailure(context);
1788 }
1789 if (EXPECT_NOT([thisEnt isPlayer])) {
1790 OOJSReportErrorForCaller(context, @"Ship", @"setScript", @"Not valid for player ship.");
1791 return OOJSNativeFailure(context);
1792 }
1793
1794 [thisEnt setShipScript:name];
1796
1798}
void setShipScript:(NSString *script_name)

References EXPECT_NOT, GET_THIS_SHIP, MIN, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJSNativeFailure(), OOJSReportBadArguments(), OOJSReportErrorForCaller(), OOStringFromJSValue(), and ShipEntity::setShipScript:.

Here is the call graph for this function:

◆ ShipSetShaders()

JSValue ShipSetShaders ( OOJS_NATIVE_ARGS )
static

Definition at line 2888 of file OOJSShip.m.

2889{
2890 OOJS_NATIVE_ENTER(context)
2891
2892 ShipEntity* thisEnt = nil;
2893
2894 GET_THIS_SHIP(thisEnt);
2895
2896 if (argc < 1) {
2897 OOJSReportBadArguments(context, @"Ship", @"setShaders", 0, OOJS_ARGV, nil, @"parameter object");
2898 return OOJSNativeFailure(context);
2899 }
2900
2901 if (JS_IsNull(OOJS_ARGV[0]) || (!JS_IsNull(OOJS_ARGV[0]) && !JS_IsObject(OOJS_ARGV[0]))) {
2902 // EMMSTRAN: JS_ValueToObject() and normal error handling here.
2903 OOJSReportWarning(context, @"Ship.%@: expected %@ instead of '%@'.", @"setShaders", @"object", OOStringFromJSValueEvenIfNull(context, OOJS_ARGV[0]));
2904 OOJS_RETURN_BOOL(NO);
2905 }
2906
2907 // SpiderMonkey version: OOJS_ARGV[1] = OOJS_ARGV[0]. QuickJS's argv may be the caller's own stack slots, so copy.
2908 JSValueConst shaderArgv[2] = { OOJS_ARGV[0], OOJS_ARGV[0] };
2909 return ShipSetMaterialsInternal(context, OOJS_THIS, argc, shaderArgv, thisEnt, YES);
2910
2912}

References GET_THIS_SHIP, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJS_THIS, OOJSNativeFailure(), OOJSReportBadArguments(), OOJSReportWarning(), OOStringFromJSValueEvenIfNull(), and ShipSetMaterialsInternal().

Here is the call graph for this function:

◆ ShipSpawn()

JSValue ShipSpawn ( OOJS_NATIVE_ARGS )
static

Definition at line 2140 of file OOJSShip.m.

2141{
2142 OOJS_NATIVE_ENTER(context)
2143
2144 ShipEntity* thisEnt = nil;
2145 NSString* role = nil;
2146 int32_t count = 1;
2147 BOOL gotCount = YES;
2148 NSArray* result = nil;
2149
2150 GET_THIS_SHIP(thisEnt);
2151
2152 if (argc > 0)
2153 role = OOStringFromJSValue(context, OOJS_ARGV[0]);
2154 if (argc > 1)
2155 gotCount = OOJSValueToInt32(context, OOJS_ARGV[1], &count);
2156 if (EXPECT_NOT(role == nil || !gotCount || count < 1 || count > 64)) {
2157 OOJSReportBadArguments(context, @"Ship", @"spawn", MIN(argc, 1), OOJS_ARGV, nil, @"role and optional quantity (1 to 64)");
2158 return OOJSNativeFailure(context);
2159 }
2160
2161 OOJS_BEGIN_FULL_NATIVE(context)
2162 result = [thisEnt spawnShipsWithRole:role count:count];
2164
2165 OOJS_RETURN_OBJECT(result);
2166
2168}
NSArray * spawnShipsWithRole:count:(NSString *role,[count] NSUInteger count)

References count, EXPECT_NOT, GET_THIS_SHIP, MIN, nil, OOJS_ARGV, OOJS_BEGIN_FULL_NATIVE, OOJS_END_FULL_NATIVE, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, OOJSNativeFailure(), OOJSReportBadArguments(), OOJSValueToInt32(), OOStringFromJSValue(), and ShipEntity::spawnShipsWithRole:count:.

Here is the call graph for this function:

◆ ShipStaticKeys()

JSValue ShipStaticKeys ( OOJS_NATIVE_ARGS )
static

Static methods

Definition at line 3857 of file OOJSShip.m.

3858{
3859 OOJS_NATIVE_ENTER(context);
3861
3862 NSArray* keys = [registry shipKeys];
3863 OOJS_RETURN_OBJECT(keys);
3864
3866}
OOShipRegistry * sharedRegistry()
NSArray * shipKeys()

References OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, OOShipRegistry::sharedRegistry, and OOShipRegistry::shipKeys.

Here is the call graph for this function:

◆ ShipStaticKeysForRole()

JSValue ShipStaticKeysForRole ( OOJS_NATIVE_ARGS )
static

Definition at line 3868 of file OOJSShip.m.

3869{
3870 OOJS_NATIVE_ENTER(context);
3872
3873 if (argc > 0) {
3874 NSString* role = OOStringFromJSValue(context, OOJS_ARGV[0]);
3875 NSArray* keys = [registry shipKeysWithRole:role];
3876 OOJS_RETURN_OBJECT(keys);
3877 } else {
3878 OOJSReportBadArguments(context, @"Ship", @"shipKeysForRole", MIN(argc, 1), OOJS_ARGV, nil, @"ship role");
3879 return OOJSNativeFailure(context);
3880 }
3881
3883}
NSArray * shipKeysWithRole:(NSString *role)

References MIN, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, OOJSNativeFailure(), OOJSReportBadArguments(), OOStringFromJSValue(), OOShipRegistry::sharedRegistry, and OOShipRegistry::shipKeysWithRole:.

Here is the call graph for this function:

◆ ShipStaticRoleIsInCategory()

JSValue ShipStaticRoleIsInCategory ( OOJS_NATIVE_ARGS )
static

Definition at line 3885 of file OOJSShip.m.

3886{
3887 OOJS_NATIVE_ENTER(context);
3888
3889 if (argc > 1) {
3890 NSString* role = OOStringFromJSValue(context, OOJS_ARGV[0]);
3891 NSString* category = OOStringFromJSValue(context, OOJS_ARGV[1]);
3892
3893 OOJS_RETURN_BOOL([UNIVERSE role:role isInCategory:category]);
3894 } else {
3895 OOJSReportBadArguments(context, @"Ship", @"roleIsInCategory", MIN(argc, 2), OOJS_ARGV, nil, @"role, category");
3896 return OOJSNativeFailure(context);
3897 }
3898
3900}

References MIN, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJSNativeFailure(), OOJSReportBadArguments(), OOStringFromJSValue(), and UNIVERSE.

Here is the call graph for this function:

◆ ShipStaticRoles()

JSValue ShipStaticRoles ( OOJS_NATIVE_ARGS )
static

Definition at line 3902 of file OOJSShip.m.

3903{
3904 OOJS_NATIVE_ENTER(context);
3906
3907 NSArray* keys = [registry shipRoles];
3908 OOJS_RETURN_OBJECT(keys);
3909
3911}
NSArray * shipRoles()

References OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, OOShipRegistry::sharedRegistry, and OOShipRegistry::shipRoles.

Here is the call graph for this function:

◆ ShipStaticSetShipDataForKey()

JSValue ShipStaticSetShipDataForKey ( OOJS_NATIVE_ARGS )
static

Definition at line 3929 of file OOJSShip.m.

3930{
3931 OOJS_NATIVE_ENTER(context);
3933
3934 if (argc >= 2) {
3935 NSString* key = OOStringFromJSValue(context, OOJS_ARGV[0]);
3936 NSDictionary* newShipData = OOJSNativeObjectFromJSObject(context, OOJS_ARGV[1]);
3937 [registry setShipInfoForKey:key with:newShipData];
3938 OOJS_RETURN_BOOL(YES);
3939 } else {
3940 OOJSReportBadArguments(context, @"Ship", @"setShipInfoForKey", MIN(argc, 2), OOJS_ARGV, nil, @"key shipdata");
3941 return OOJSNativeFailure(context);
3942 }
3944}
void setShipInfoForKey:with:(NSString *key,[with] NSDictionary *newShipData)

References MIN, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJSNativeFailure(), OOJSNativeObjectFromJSObject(), OOJSReportBadArguments(), OOStringFromJSValue(), OOShipRegistry::setShipInfoForKey:with:, and OOShipRegistry::sharedRegistry.

Here is the call graph for this function:

◆ ShipStaticShipDataForKey()

JSValue ShipStaticShipDataForKey ( OOJS_NATIVE_ARGS )
static

Definition at line 3913 of file OOJSShip.m.

3914{
3915 OOJS_NATIVE_ENTER(context);
3917
3918 if (argc > 0) {
3919 NSString* key = OOStringFromJSValue(context, OOJS_ARGV[0]);
3920 NSDictionary* keys = [registry shipInfoForKey:key];
3921 OOJS_RETURN_OBJECT(keys);
3922 } else {
3923 OOJSReportBadArguments(context, @"Ship", @"shipDataForKey", MIN(argc, 1), OOJS_ARGV, nil, @"key");
3924 return OOJSNativeFailure(context);
3925 }
3927}
NSDictionary * shipInfoForKey:(NSString *key)

References MIN, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, OOJSNativeFailure(), OOJSReportBadArguments(), OOStringFromJSValue(), OOShipRegistry::sharedRegistry, and OOShipRegistry::shipInfoForKey:.

Here is the call graph for this function:

◆ ShipSwitchAI()

JSValue ShipSwitchAI ( OOJS_NATIVE_ARGS )
static

Definition at line 1827 of file OOJSShip.m.

1828{
1829 OOJS_NATIVE_ENTER(context)
1830
1831 ShipEntity* thisEnt = nil;
1832 NSString* name = nil;
1833
1834 GET_THIS_SHIP(thisEnt);
1835 if (argc > 0)
1836 name = OOStringFromJSValue(context, OOJS_ARGV[0]);
1837 if (EXPECT_NOT(name == nil)) {
1838 OOJSReportBadArguments(context, @"Ship", @"switchAI", MIN(argc, 1), OOJS_ARGV, nil, @"string (AI name)");
1839 return OOJSNativeFailure(context);
1840 }
1841 if (EXPECT_NOT([thisEnt isPlayer])) {
1842 OOJSReportErrorForCaller(context, @"Ship", @"switchAI", @"Not valid for player ship.");
1843 return OOJSNativeFailure(context);
1844 }
1845
1846 [thisEnt switchAITo:name];
1848
1850}
void switchAITo:(NSString *aiString)

References EXPECT_NOT, GET_THIS_SHIP, MIN, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJSNativeFailure(), OOJSReportBadArguments(), OOJSReportErrorForCaller(), OOStringFromJSValue(), and ShipEntity::switchAITo:.

Here is the call graph for this function:

◆ ShipThreatAssessment()

JSValue ShipThreatAssessment ( OOJS_NATIVE_ARGS )
static

Definition at line 3726 of file OOJSShip.m.

3727{
3729
3730 ShipEntity* thisEnt = nil;
3731 int fullCheck = NO;
3732
3733 GET_THIS_SHIP(thisEnt);
3734
3735 if (argc > 0 && EXPECT_NOT(!((fullCheck = JS_ToBool(context, OOJS_ARGV[0])) >= 0))) {
3736 OOJSReportBadArguments(context, @"Ship", @"threatAssessment", argc, OOJS_ARGV, nil, @"boolean");
3737 return OOJSNativeFailure(context);
3738 }
3739 // start with 2.5 per ship
3740 double assessment = 2.5;
3741 // +/- 0.1 for speed, larger subtraction for very slow ships
3742 GLfloat maxspeed = [thisEnt maxFlightSpeed];
3743 assessment += (maxspeed - 300) / 1000;
3744 if (maxspeed < 200) {
3745 assessment += (maxspeed - 200) / 500;
3746 }
3747
3748 /* FIXME: at the moment this means NPCs can detect other NPCs shield
3749 * boosters, since they're implemented as extra energy */
3750 assessment += ([thisEnt maxEnergy] - 200) / 1000;
3751
3752 // add on some for missiles. Mostly ignore 3rd and subsequent
3753 // missiles: either they can be ECMd or the first two are already
3754 // too many.
3755 if ([thisEnt missileCapacity] > 2) {
3756 assessment += 0.5;
3757 } else {
3758 assessment += ((double)[thisEnt missileCapacity]) / 5.0;
3759 }
3760
3761 /* Turret count is public knowledge */
3762 /* TODO: consider making ship combat behaviour try to
3763 * stay at long range from enemies with turrets. Then
3764 * we could perhaps reduce this bonus a bit. */
3765 assessment += [thisEnt turretCount];
3766
3767 if (fullCheck) {
3768 // consider pilot skill
3769 if ([thisEnt isPlayer]) {
3770 double score = (double)[PLAYER score];
3771 if (score > 6400) {
3772 score = 6400;
3773 }
3774 assessment += pow(score, 0.33) / 10;
3775 // 0 - 1.8
3776 } else {
3777 assessment += [thisEnt accuracy] / 5;
3778 }
3779
3780 // check lasers
3781 OOWeaponType wt = [thisEnt weaponTypeIDForFacing:WEAPON_FACING_FORWARD strict:NO];
3782 /* Not affected by multiple mounts here: they're either just a
3783 * split of the power, or only more dangerous until they
3784 * overheat */
3785 assessment += ShipThreatAssessmentWeapon(wt);
3786 if (isWeaponNone(wt)) {
3787 assessment -= 1.5; // further penalty for ships with no forward laser
3788 }
3789
3790 wt = [thisEnt weaponTypeIDForFacing:WEAPON_FACING_AFT strict:NO];
3791 if (!isWeaponNone(wt)) {
3792 assessment += 1 + ShipThreatAssessmentWeapon(wt);
3793 }
3794 // port and starboard weapons less important
3795 wt = [thisEnt weaponTypeIDForFacing:WEAPON_FACING_PORT strict:NO];
3796 if (!isWeaponNone(wt)) {
3797 assessment += 0.2 + ShipThreatAssessmentWeapon(wt) / 5.0;
3798 }
3799 wt = [thisEnt weaponTypeIDForFacing:WEAPON_FACING_STARBOARD strict:NO];
3800 if (!isWeaponNone(wt)) {
3801 assessment += 0.2 + ShipThreatAssessmentWeapon(wt) / 5.0;
3802 }
3803
3804 // combat-related secondary equipment
3805 if ([thisEnt hasECM]) {
3806 assessment += 0.5;
3807 }
3808 if ([thisEnt hasFuelInjection]) {
3809 assessment += 0.5;
3810 }
3811
3812 } else {
3813 // consider thargoids dangerous
3814 if ([thisEnt isThargoid]) {
3815 assessment *= 1.5;
3816 if ([thisEnt hasRole:@"thargoid-mothership"]) {
3817 assessment += 5;
3818 }
3819 } else {
3820 // consider that armed ships might have a trick or two
3821 if ([thisEnt weaponFacings] == 1) {
3822 assessment += 0.25;
3823 } else {
3824 // and more than one trick if they can mount multiple lasers
3825 assessment += 0.5;
3826 }
3827 }
3828 }
3829
3830 // mostly ignore fleeing ships as threats
3831 if ([thisEnt behaviour] == BEHAVIOUR_FLEE_TARGET || [thisEnt behaviour] == BEHAVIOUR_FLEE_EVASIVE_ACTION) {
3832 assessment *= 0.2;
3833 } else if ([thisEnt isPlayer] && [(PlayerEntity*)thisEnt fleeingStatus] >= PLAYER_FLEEING_CARGO) {
3834 assessment *= 0.2;
3835 }
3836
3837 // don't go too low.
3838 if (assessment < 0.1) {
3839 assessment = 0.1;
3840 }
3841
3842 OOJS_RETURN_DOUBLE(assessment);
3843
3845}
static double ShipThreatAssessmentWeapon(OOWeaponType wt)
Definition OOJSShip.m:3918
#define OOJS_RETURN_DOUBLE(value)
OOEquipmentType * OOWeaponType
Definition ShipEntity.h:164
BOOL isWeaponNone(OOWeaponType weapon)

References EXPECT_NOT, GET_THIS_SHIP, isWeaponNone(), nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_DOUBLE, OOJSNativeFailure(), OOJSReportBadArguments(), PLAYER, PLAYER_FLEEING_CARGO, and ShipThreatAssessmentWeapon().

Here is the call graph for this function:

◆ ShipThreatAssessmentWeapon()

double ShipThreatAssessmentWeapon ( OOWeaponType wt)
static

Definition at line 3847 of file OOJSShip.m.

3848{
3849 if (wt == nil) {
3850 return -1.0;
3851 }
3852 return [wt weaponThreatAssessment];
3853}
GLfloat weaponThreatAssessment()

References nil, and OOEquipmentType::weaponThreatAssessment.

Here is the call graph for this function:

◆ ShipThrowSpark()

JSValue ShipThrowSpark ( OOJS_NATIVE_ARGS )
static

Definition at line 3342 of file OOJSShip.m.

3343{
3345
3346 ShipEntity* thisEnt = nil;
3347 GET_THIS_SHIP(thisEnt);
3348 [thisEnt setThrowSparks:YES];
3349
3351
3353}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_VOID.

◆ ShipUpdateEscortFormation()

JSValue ShipUpdateEscortFormation ( OOJS_NATIVE_ARGS )
static

Definition at line 3006 of file OOJSShip.m.

3007{
3009
3010 ShipEntity* thisEnt = nil;
3011 GET_THIS_SHIP(thisEnt);
3012 [thisEnt updateEscortFormation];
3013
3015
3017}

References GET_THIS_SHIP, nil, OOJS_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and OOJS_RETURN_VOID.

Variable Documentation

◆ sShipClass

JSClassDef sShipClass
static
Initial value:
= {
.class_name = "Ship",
}
void OOJSObjectWrapperFinalize(JSContext *context, JSObject *this)

Definition at line 153 of file OOJSShip.m.

153 {
154 .class_name = "Ship",
155 .finalizer = OOJSObjectWrapperFinalize,
156};

◆ sShipClassID

JSClassID sShipClassID
static

Definition at line 53 of file OOJSShip.m.

Referenced by InitOOJSShip(), and JSShipClassID().

◆ sShipMethods

const JSCFunctionListEntry sShipMethods[]
static

Definition at line 465 of file OOJSShip.m.

465 {
466 // JS name, min args, function
467 JS_CFUNC_DEF("abandonShip", 0, ShipAbandonShip),
468 JS_CFUNC_DEF("addCargoEntity", 1, ShipAddCargoEntity),
469 JS_CFUNC_DEF("addCollisionException", 1, ShipAddCollisionException),
470 JS_CFUNC_DEF("addDefenseTarget", 1, ShipAddDefenseTarget),
471 JS_CFUNC_DEF("adjustCargo", 2, ShipAdjustCargo),
472 JS_CFUNC_DEF("awardEquipment", 1, ShipAwardEquipment),
473 JS_CFUNC_DEF("becomeCascadeExplosion", 0, ShipBecomeCascadeExplosion),
474 JS_CFUNC_DEF("broadcastCascadeImminent", 0, ShipBroadcastCascadeImminent),
475 JS_CFUNC_DEF("broadcastDistressMessage", 0, ShipBroadcastDistressMessage),
476 JS_CFUNC_DEF("canAwardEquipment", 1, ShipCanAwardEquipment),
477 JS_CFUNC_DEF("checkCourseToDestination", 0, ShipCheckCourseToDestination),
478 JS_CFUNC_DEF("checkScanner", 0, ShipCheckScanner),
479 JS_CFUNC_DEF("clearDefenseTargets", 0, ShipClearDefenseTargets),
480 JS_CFUNC_DEF("commsMessage", 1, ShipCommsMessage),
481 JS_CFUNC_DEF("damageAssessment", 0, ShipDamageAssessment),
482 JS_CFUNC_DEF("dealEnergyDamage", 2, ShipDealEnergyDamage),
483 JS_CFUNC_DEF("deployEscorts", 0, ShipDeployEscorts),
484 JS_CFUNC_DEF("dockEscorts", 0, ShipDockEscorts),
485 JS_CFUNC_DEF("dumpCargo", 0, ShipDumpCargo),
486 JS_CFUNC_DEF("ejectItem", 1, ShipEjectItem),
487 JS_CFUNC_DEF("ejectSpecificItem", 1, ShipEjectSpecificItem),
488 JS_CFUNC_DEF("enterWormhole", 0, ShipEnterWormhole),
489 JS_CFUNC_DEF("equipmentStatus", 1, ShipEquipmentStatus),
490 JS_CFUNC_DEF("exitAI", 0, ShipExitAI),
491 JS_CFUNC_DEF("exitSystem", 0, ShipExitSystem),
492 JS_CFUNC_DEF("explode", 0, ShipExplode),
493 JS_CFUNC_DEF("fireECM", 0, ShipFireECM),
494 JS_CFUNC_DEF("fireMissile", 0, ShipFireMissile),
495 JS_CFUNC_DEF("findNearestStation", 0, ShipFindNearestStation),
496 JS_CFUNC_DEF("getMaterials", 0, ShipGetMaterials),
497 JS_CFUNC_DEF("getSafeCourseToDestination", 0, ShipGetSafeCourseToDestination),
498 JS_CFUNC_DEF("getShaders", 0, ShipGetShaders),
499 JS_CFUNC_DEF("hasEquipmentProviding", 1, ShipHasEquipmentProviding),
500 JS_CFUNC_DEF("hasRole", 1, ShipHasRole),
501 JS_CFUNC_DEF("markTargetForFines", 0, ShipMarkTargetForFines),
502 JS_CFUNC_DEF("notifyGroupOfWormhole", 0, ShipNotifyGroupOfWormhole),
503 JS_CFUNC_DEF("offerToEscort", 1, ShipOfferToEscort),
504 JS_CFUNC_DEF("patrolReportIn", 1, ShipPatrolReportIn),
505 JS_CFUNC_DEF("performAttack", 0, ShipPerformAttack),
506 JS_CFUNC_DEF("performCollect", 0, ShipPerformCollect),
507 JS_CFUNC_DEF("performEscort", 0, ShipPerformEscort),
508 JS_CFUNC_DEF("performFaceDestination", 0, ShipPerformFaceDestination),
509 JS_CFUNC_DEF("performFlee", 0, ShipPerformFlee),
510 JS_CFUNC_DEF("performFlyToRangeFromDestination", 0, ShipPerformFlyToRangeFromDestination),
511 JS_CFUNC_DEF("performHold", 0, ShipPerformHold),
512 JS_CFUNC_DEF("performIdle", 0, ShipPerformIdle),
513 JS_CFUNC_DEF("performIntercept", 0, ShipPerformIntercept),
514 JS_CFUNC_DEF("performLandOnPlanet", 0, ShipPerformLandOnPlanet),
515 JS_CFUNC_DEF("performMining", 0, ShipPerformMining),
516 JS_CFUNC_DEF("performScriptedAI", 0, ShipPerformScriptedAI),
517 JS_CFUNC_DEF("performScriptedAttackAI", 0, ShipPerformScriptedAttackAI),
518 JS_CFUNC_DEF("performStop", 0, ShipPerformStop),
519 JS_CFUNC_DEF("performTumble", 0, ShipPerformTumble),
520
521 JS_CFUNC_DEF("reactToAIMessage", 1, ShipReactToAIMessage),
522 JS_CFUNC_DEF("remove", 0, ShipRemove),
523 JS_CFUNC_DEF("removeCollisionException", 1, ShipRemoveCollisionException),
524 JS_CFUNC_DEF("removeDefenseTarget", 1, ShipRemoveDefenseTarget),
525 JS_CFUNC_DEF("removeEquipment", 1, ShipRemoveEquipment),
526 JS_CFUNC_DEF("requestHelpFromGroup", 0, ShipRequestHelpFromGroup),
527 JS_CFUNC_DEF("requestDockingInstructions", 0, ShipRequestDockingInstructions),
528 JS_CFUNC_DEF("recallDockingInstructions", 0, ShipRecallDockingInstructions),
529 JS_CFUNC_DEF("restoreSubEntities", 0, ShipRestoreSubEntities),
530 JS_CFUNC_DEF("__runLegacyScriptActions", 2, ShipRunLegacyScriptActions), // Deliberately not documented
531 JS_CFUNC_DEF("selectNewMissile", 0, ShipSelectNewMissile),
532 JS_CFUNC_DEF("sendAIMessage", 1, ShipSendAIMessage),
533 JS_CFUNC_DEF("setAI", 1, ShipSetAI),
534 JS_CFUNC_DEF("setBounty", 2, ShipSetBounty),
535 JS_CFUNC_DEF("setCargo", 1, ShipSetCargo),
536 JS_CFUNC_DEF("setCargoType", 1, ShipSetCargoType),
537 JS_CFUNC_DEF("setCrew", 1, ShipSetCrew),
538 JS_CFUNC_DEF("setEquipmentStatus", 2, ShipSetEquipmentStatus),
539 JS_CFUNC_DEF("setMaterials", 1, ShipSetMaterials),
540 JS_CFUNC_DEF("setScript", 1, ShipSetScript),
541 JS_CFUNC_DEF("setShaders", 2, ShipSetShaders),
542 JS_CFUNC_DEF("spawn", 1, ShipSpawn),
543 // spawnOne() is defined in the prefix script.
544 JS_CFUNC_DEF("switchAI", 1, ShipSwitchAI),
545 JS_CFUNC_DEF("threatAssessment", 1, ShipThreatAssessment),
546 JS_CFUNC_DEF("throwSpark", 0, ShipThrowSpark),
547 JS_CFUNC_DEF("updateEscortFormation", 0, ShipUpdateEscortFormation),
548};
static JSBool ShipPerformCollect(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3439
static JSBool ShipRemoveDefenseTarget(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3166
static JSBool ShipPatrolReportIn(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3329
static JSBool ShipCheckCourseToDestination(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3670
static JSBool ShipExitSystem(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3049
static JSBool ShipPerformFlyToRangeFromDestination(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3491
static JSBool ShipPerformEscort(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3452
static JSBool ShipSwitchAI(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:1884
static JSBool ShipThreatAssessment(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3797
static JSBool ShipHasRole(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2045
static JSBool ShipAbandonShip(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2395
static JSBool ShipRestoreSubEntities(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2574
static JSBool ShipExitAI(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:1910
static JSBool ShipPerformMining(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3556
static JSBool ShipSelectNewMissile(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2742
static JSBool ShipThrowSpark(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3413
static JSBool ShipUpdateEscortFormation(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3077
static JSBool ShipSetCargo(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2836
static JSBool ShipPerformFaceDestination(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3465
static JSBool ShipSetShaders(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2960
static JSBool ShipSetMaterials(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2941
static JSBool ShipSendAIMessage(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:1967
static JSBool ShipBroadcastCascadeImminent(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3268
static JSBool ShipFindNearestStation(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2781
static JSBool ShipSpawn(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2197
static JSBool ShipGetShaders(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3251
static JSBool ShipPerformScriptedAttackAI(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3582
static JSBool ShipHasEquipmentProviding(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2023
static JSBool ShipExplode(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2272
static JSBool ShipCommsMessage(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2346
static JSBool ShipDamageAssessment(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3770
static JSBool ShipRemove(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2282
static JSBool ShipClearDefenseTargets(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3133
static JSBool ShipDealEnergyDamage(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2228
static JSBool ShipEquipmentStatus(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2683
static JSBool ShipPerformHold(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3504
static JSBool ShipFireMissile(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2761
static JSBool ShipAddCargoEntity(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2089
static JSBool ShipRequestHelpFromGroup(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3314
static JSBool ShipBecomeCascadeExplosion(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3281
static JSBool ShipCanAwardEquipment(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2408
static JSBool ShipNotifyGroupOfWormhole(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3399
static JSBool ShipSetCargoType(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2902
static JSBool ShipDockEscorts(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2008
static JSBool ShipPerformFlee(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3478
static JSBool ShipDumpCargo(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2157
static JSBool ShipMarkTargetForFines(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3351
static JSBool ShipReactToAIMessage(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:1941
static JSBool ShipSetEquipmentStatus(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2603
static JSBool ShipSetScript(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:1832
static JSBool ShipPerformLandOnPlanet(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3543
static JSBool ShipPerformIdle(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3517
static JSBool ShipFireECM(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2375
static JSBool ShipCheckScanner(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3698
static JSBool ShipPerformIntercept(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3530
static JSBool ShipEjectSpecificItem(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2135
static JSBool ShipSetCrew(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2866
static JSBool ShipRemoveCollisionException(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3210
static JSBool ShipAddDefenseTarget(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3146
static JSBool ShipAddCollisionException(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3186
static JSBool ShipAwardEquipment(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2454
static JSBool ShipDeployEscorts(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:1993
static JSBool ShipPerformStop(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3595
static JSBool ShipGetMaterials(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3233
static JSBool ShipRequestDockingInstructions(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3621
static JSBool ShipSetBounty(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2808
static JSBool ShipGetSafeCourseToDestination(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3684
static JSBool ShipSetAI(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:1858
static JSBool ShipEnterWormhole(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3370
static JSBool ShipEjectItem(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2067
static JSBool ShipPerformScriptedAI(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3569
static JSBool ShipPerformAttack(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3426
static JSBool ShipRemoveEquipment(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2523
static JSBool ShipBroadcastDistressMessage(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3657
static JSBool ShipRunLegacyScriptActions(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:2312
static JSBool ShipOfferToEscort(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3294
static JSBool ShipRecallDockingInstructions(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3639
static JSBool ShipPerformTumble(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3608
static JSBool ShipAdjustCargo(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3728

◆ sShipProperties

const JSCFunctionListEntry sShipProperties[]
static

Definition at line 315 of file OOJSShip.m.

315 {
316 // JS name, getter, setter, ID
339 // contracts instead of cargo to distinguish them from the manifest
463};
static JSBool ShipSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
Definition OOJSShip.m:1177
static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
Definition OOJSShip.m:592
#define OOJS_PROPERTY_RW(name, getter, setter, magic)
#define OOJS_PROPERTY_RO(name, getter, magic)

◆ sShipStaticMethods

const JSCFunctionListEntry sShipStaticMethods[]
static
Initial value:
= {
JS_CFUNC_DEF("keys", 0, ShipStaticKeys),
JS_CFUNC_DEF("keysForRole", 1, ShipStaticKeysForRole),
JS_CFUNC_DEF("roleIsInCategory", 2, ShipStaticRoleIsInCategory),
JS_CFUNC_DEF("roles", 0, ShipStaticRoles),
JS_CFUNC_DEF("shipDataForKey", 1, ShipStaticShipDataForKey),
JS_CFUNC_DEF("setShipDataForKey", 2, ShipStaticSetShipDataForKey),
}
static JSBool ShipStaticKeysForRole(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3939
static JSBool ShipStaticKeys(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3928
static JSBool ShipStaticShipDataForKey(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3984
static JSBool ShipStaticRoleIsInCategory(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3956
static JSBool ShipStaticRoles(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:3973
static JSBool ShipStaticSetShipDataForKey(JSContext *context, uintN argc, jsval *vp)
Definition OOJSShip.m:4000

Definition at line 550 of file OOJSShip.m.

550 {
551 // JS name, min args, function
552 JS_CFUNC_DEF("keys", 0, ShipStaticKeys),
553 JS_CFUNC_DEF("keysForRole", 1, ShipStaticKeysForRole),
554 JS_CFUNC_DEF("roleIsInCategory", 2, ShipStaticRoleIsInCategory),
555 JS_CFUNC_DEF("roles", 0, ShipStaticRoles),
556 JS_CFUNC_DEF("shipDataForKey", 1, ShipStaticShipDataForKey),
557 JS_CFUNC_DEF("setShipDataForKey", 2, ShipStaticSetShipDataForKey),
558};