Oolite
Loading...
Searching...
No Matches
ShipEntity Class Reference

#include <ShipEntity.h>

Inheritance diagram for ShipEntity:
Collaboration diagram for ShipEntity:

Instance Methods

(void) - setStateMachine:
(void) - setAI:
(AI *) - getAI
(BOOL) - hasAutoAI
(BOOL) - hasNewAI
(void) - setShipScript:
(void) - removeScript
(OOScript *) - shipScript
(OOScript *) - shipAIScript
(OOTimeAbsolute) - shipAIScriptWakeTime
(void) - setAIScriptWakeTime:
(double) - frustration
(void) - setLaunchDelay:
(void) - interpretAIMessage:
(GLfloat) - accuracy
(void) - setAccuracy:
(OOMesh *) - mesh
(void) - setMesh:
(BoundingBox) - totalBoundingBox
(Vector) - forwardVector
(Vector) - upVector
(Vector) - rightVector
(NSArray *) - subEntities
(NSUInteger) - subEntityCount
(BOOL) - hasSubEntity:
(NSEnumerator *) - subEntityEnumerator
(NSEnumerator *) - shipSubEntityEnumerator
(NSEnumerator *) - flasherEnumerator
(NSEnumerator *) - exhaustEnumerator
(ShipEntity *) - subEntityTakingDamage
(void) - setSubEntityTakingDamage:
(void) - clearSubEntities
(Quaternion) - subEntityRotationalVelocity
(void) - setSubEntityRotationalVelocity:
(NSString *) - serializeShipSubEntities
(void) - deserializeShipSubEntitiesFrom:
(NSUInteger) - maxShipSubEntities
(void) - setSubIdx:
(NSUInteger) - subIdx
(Octree *) - octree
(float) - volume
(GLfloat) - doesHitLine:v1:
(GLfloat) - doesHitLine:v1:hitEntity:
(GLfloat) - doesHitLine:v1:withPosition:i:j:k:
(BoundingBox) - findBoundingBoxRelativeToPosition:i:j:k:
(HPVector) - absoluteTractorPosition
(void) - setIsBoulder:
(BOOL) - isBoulder
(BOOL) - isMinable
(BOOL) - countsAsKill
(void) - setUpEscorts
(void) - updateEscortFormation
(id) - initWithKey:definition:
(BOOL) - setUpFromDictionary:
(BOOL) - setUpShipFromDictionary:
(BOOL) - setUpSubEntities
(BOOL) - setUpOneStandardSubentity:asTurret:
(GLfloat) - frustumRadius
(NSString *) - shipDataKey
(NSString *) - shipDataKeyAutoRole
(void) - setShipDataKey:
(NSDictionary *) - shipInfoDictionary
(NSArray *) - getWeaponOffsetFrom:withKey:inMode:
(NSArray *) - aftWeaponOffset
(NSArray *) - forwardWeaponOffset
(NSArray *) - portWeaponOffset
(NSArray *) - starboardWeaponOffset
(BOOL) - hasAutoWeapons
(BOOL) - isFrangible
(BOOL) - suppressFlightNotifications
(void) - respondToAttackFrom:becauseOf:
(OOWeaponFacingSet) - weaponFacings
(BOOL) - hasEquipmentItem:includeWeapons:whileLoading:
(BOOL) - hasEquipmentItem:
(NSUInteger) - countEquipmentItem:
(NSString *) - equipmentItemProviding:
(BOOL) - hasEquipmentItemProviding:
(BOOL) - hasAllEquipment:includeWeapons:whileLoading:
(BOOL) - hasAllEquipment:
(BOOL) - setWeaponMount:toWeapon:
(BOOL) - canAddEquipment:inContext:
(BOOL) - equipmentValidToAdd:inContext:
(BOOL) - equipmentValidToAdd:whileLoading:inContext:
(BOOL) - addEquipmentItem:inContext:
(BOOL) - addEquipmentItem:withValidation:inContext:
(BOOL) - hasHyperspaceMotor
(float) - hyperspaceSpinTime
(void) - setHyperspaceSpinTime:
(NSEnumerator *) - equipmentEnumerator
(NSUInteger) - equipmentCount
(void) - removeEquipmentItem:
(void) - removeAllEquipment
(OOEquipmentType *) - selectMissile
(OOCreditsQuantity) - removeMissiles
(BOOL) - hasOneEquipmentItem:includeWeapons:whileLoading:
(BOOL) - hasOneEquipmentItem:includeMissiles:whileLoading:
(BOOL) - hasPrimaryWeapon:
(BOOL) - removeExternalStore:
(NSUInteger) - parcelCount
(NSUInteger) - passengerCount
(NSUInteger) - passengerCapacity
(NSUInteger) - missileCount
(NSUInteger) - missileCapacity
(NSUInteger) - extraCargo
(BOOL) - hasScoop
(BOOL) - hasFuelScoop
(BOOL) - hasCargoScoop
(BOOL) - hasECM
(BOOL) - hasCloakingDevice
(BOOL) - hasMilitaryScannerFilter
(BOOL) - hasMilitaryJammer
(BOOL) - hasExpandedCargoBay
(BOOL) - hasShieldBooster
(BOOL) - hasMilitaryShieldEnhancer
(BOOL) - hasHeatShield
(BOOL) - hasFuelInjection
(BOOL) - hasCascadeMine
(BOOL) - hasEscapePod
(BOOL) - hasDockingComputer
(BOOL) - hasGalacticHyperdrive
(float) - shieldBoostFactor
(float) - maxForwardShieldLevel
(float) - maxAftShieldLevel
(float) - shieldRechargeRate
(double) - maxHyperspaceDistance
(float) - afterburnerFactor
(float) - afterburnerRate
(void) - setAfterburnerFactor:
(void) - setAfterburnerRate:
(float) - maxThrust
(float) - thrust
(void) - setMaxThrust:
(void) - setMaxFlightPitch:
(void) - setMaxFlightSpeed:
(void) - setMaxFlightRoll:
(void) - setMaxFlightYaw:
(void) - setEnergyRechargeRate:
(void) - processBehaviour:
(void) - behaviour_stop_still:
(void) - behaviour_idle:
(void) - behaviour_tumble:
(void) - behaviour_tractored:
(void) - behaviour_track_target:
(void) - behaviour_intercept_target:
(void) - behaviour_attack_target:
(void) - behaviour_attack_slow_dogfight:
(void) - behaviour_evasive_action:
(void) - behaviour_attack_break_off_target:
(void) - behaviour_fly_to_target_six:
(void) - behaviour_attack_mining_target:
(void) - behaviour_attack_fly_to_target:
(void) - behaviour_attack_fly_from_target:
(void) - behaviour_running_defense:
(void) - behaviour_flee_target:
(void) - behaviour_attack_broadside:
(void) - behaviour_attack_broadside_left:
(void) - behaviour_attack_broadside_right:
(void) - behaviour_close_to_broadside_range:
(void) - behaviour_close_with_target:
(void) - behaviour_attack_broadside_target:leftside:
(void) - behaviour_attack_sniper:
(void) - behaviour_fly_range_from_destination:
(void) - behaviour_face_destination:
(void) - behaviour_land_on_planet:
(void) - behaviour_formation_form_up:
(void) - behaviour_fly_to_destination:
(void) - behaviour_fly_from_destination:
(void) - behaviour_avoid_collision:
(void) - behaviour_track_as_turret:
(void) - behaviour_fly_thru_navpoints:
(void) - behaviour_scripted_ai:
(float) - reactionTime
(void) - setReactionTime:
(HPVector) - calculateTargetPosition
(void) - startTrackingCurve
(void) - updateTrackingCurve
(void) - calculateTrackingCurve
(GLfloat *) - scannerDisplayColorForShip:isHostile:flash:scannerDisplayColor1:scannerDisplayColor2:scannerDisplayColorH1:scannerDisplayColorH2:
(void) - setScannerDisplayColor1:
(void) - setScannerDisplayColor2:
(OOColor *) - scannerDisplayColor1
(OOColor *) - scannerDisplayColor2
(void) - setScannerDisplayColorHostile1:
(void) - setScannerDisplayColorHostile2:
(OOColor *) - scannerDisplayColorHostile1
(OOColor *) - scannerDisplayColorHostile2
(BOOL) - isCloaked
(void) - setCloaked:
(BOOL) - hasAutoCloak
(void) - setAutoCloak:
(void) - applyThrust:
(void) - applyAttitudeChanges:
(void) - avoidCollision
(void) - resumePostProximityAlert
(double) - messageTime
(void) - setMessageTime:
(OOShipGroup *) - group
(void) - setGroup:
(OOShipGroup *) - escortGroup
(void) - setEscortGroup:
(OOShipGroup *) - stationGroup
(BOOL) - hasEscorts
(NSEnumerator *) - escortEnumerator
(NSArray *) - escortArray
(uint8_t) - escortCount
(uint8_t) - pendingEscortCount
(void) - setPendingEscortCount:
(uint8_t) - maxEscortCount
(void) - setMaxEscortCount:
(NSUInteger) - turretCount
(NSString *) - name
(NSString *) - shipUniqueName
(NSString *) - shipClassName
(NSString *) - displayName
(NSString *) - scanDescription
(NSString *) - scanDescriptionForScripting
(void) - setName:
(void) - setShipUniqueName:
(void) - setShipClassName:
(void) - setDisplayName:
(void) - setScanDescription:
(NSString *) - identFromShip:
(BOOL) - hasRole:
(OORoleSet *) - roleSet
(void) - addRole:
(void) - addRole:withProbability:
(void) - removeRole:
(NSString *) - primaryRole
(void) - setPrimaryRole:
(BOOL) - hasPrimaryRole:
(BOOL) - isPolice
(BOOL) - isThargoid
(BOOL) - isTrader
(BOOL) - isPirate
(BOOL) - isMissile
(BOOL) - isMine
(BOOL) - isWeapon
(BOOL) - isEscort
(BOOL) - isShuttle
(BOOL) - isTurret
(BOOL) - isPirateVictim
(BOOL) - isExplicitlyUnpiloted
(BOOL) - isUnpiloted
(OOAlertCondition) - alertCondition
(OOAlertCondition) - realAlertCondition
(BOOL) - hasHostileTarget
(BOOL) - isHostileTo:
(NSUInteger) - defenseTargetCount
(NSArray *) - allDefenseTargets
(NSEnumerator *) - defenseTargetEnumerator
(void) - validateDefenseTargets
(BOOL) - addDefenseTarget:
(BOOL) - isDefenseTarget:
(void) - removeDefenseTarget:
(void) - removeAllDefenseTargets
(NSArray *) - collisionExceptions
(void) - addCollisionException:
(void) - removeCollisionException:
(BOOL) - collisionExceptedFor:
(GLfloat) - weaponRange
(void) - setWeaponRange:
(void) - setWeaponDataFromType:
(float) - energyRechargeRate
(float) - weaponRechargeRate
(void) - setWeaponRechargeRate:
(void) - setWeaponEnergy:
(OOWeaponFacing) - currentWeaponFacing
(GLfloat) - scannerRange
(void) - setScannerRange:
(Vector) - reference
(void) - setReference:
(BOOL) - reportAIMessages
(void) - setReportAIMessages:
(void) - transitionToAegisNone
(OOPlanetEntity *) - findNearestPlanet
(Entity< OOStellarBody > *) - findNearestStellarBody
(OOPlanetEntity *) - findNearestPlanetExcludingMoons
(OOAegisStatus) - checkForAegis
(void) - forceAegisCheck
(BOOL) - withinStationAegis
(void) - setLastAegisLock:
(OOSystemID) - homeSystem
(OOSystemID) - destinationSystem
(void) - setHomeSystem:
(void) - setDestinationSystem:
(NSArray *) - crew
(NSArray *) - crewForScripting
(void) - setCrew:
(void) - setSingleCrewWithRole:
(OOFuelQuantity) - fuel
(void) - setFuel:
(OOFuelQuantity) - fuelCapacity
(GLfloat) - fuelChargeRate
(void) - setRoll:
(void) - setRawRoll:
(void) - setPitch:
(void) - setYaw:
(void) - setThrust:
(void) - applySticks:
(void) - setThrustForDemo:
(void) - setBounty:
(void) - setBounty:withReason:
(void) - setBounty:withReasonAsString:
(OOCreditsQuantity) - bounty
(int) - legalStatus
(BOOL) - isTemplateCargoPod
(void) - setUpCargoType:
(void) - setCommodity:andAmount:
(void) - setCommodityForPod:andAmount:
(OOCommodityType) - commodityType
(OOCargoQuantity) - commodityAmount
(OOCargoQuantity) - maxAvailableCargoSpace
(void) - setMaxAvailableCargoSpace:
(OOCargoQuantity) - availableCargoSpace
(OOCargoQuantity) - cargoQuantityOnBoard
(OOCargoType) - cargoType
(NSArray *) - cargoListForScripting
(NSMutableArray *) - cargo
(void) - setCargo:
(BOOL) - addCargo:
(BOOL) - removeCargo:amount:
(BOOL) - showScoopMessage
(NSArray *) - passengerListForScripting
(NSArray *) - parcelListForScripting
(NSArray *) - contractListForScripting
(NSArray *) - equipmentListForScripting
(OOWeaponType) - weaponTypeIDForFacing:strict:
(OOEquipmentType *) - weaponTypeForFacing:strict:
(NSArray *) - missilesList
(OOCargoFlag) - cargoFlag
(void) - setCargoFlag:
(void) - setSpeed:
(double) - desiredSpeed
(void) - setDesiredSpeed:
(double) - desiredRange
(void) - setDesiredRange:
(double) - cruiseSpeed
(Vector) - thrustVector
(void) - setTotalVelocity:
(void) - increase_flight_speed:
(void) - decrease_flight_speed:
(void) - increase_flight_roll:
(void) - decrease_flight_roll:
(void) - increase_flight_pitch:
(void) - decrease_flight_pitch:
(void) - increase_flight_yaw:
(void) - decrease_flight_yaw:
(GLfloat) - flightRoll
(GLfloat) - flightPitch
(GLfloat) - flightYaw
(GLfloat) - flightSpeed
(GLfloat) - maxFlightPitch
(GLfloat) - maxFlightSpeed
(GLfloat) - maxFlightRoll
(GLfloat) - maxFlightYaw
(GLfloat) - speedFactor
(GLfloat) - temperature
(void) - setTemperature:
(GLfloat) - heatInsulation
(void) - setHeatInsulation:
(float) - randomEjectaTemperature
(float) - randomEjectaTemperatureWithMaxFactor:
(int) - damage
(void) - dealEnergyDamage:atRange:withBias:
(void) - dealEnergyDamageWithinDesiredRange
(void) - dealMomentumWithinDesiredRange:
(void) - noteTakingDamage:from:type:
(void) - noteKilledBy:damageType:
(void) - getDestroyedBy:damageType:
(void) - becomeExplosion
(void) - becomeLargeExplosion:
(void) - becomeEnergyBlast
(void) - broadcastEnergyBlastImminent
(void) - setIsWreckage:
(BOOL) - showDamage
(Vector) - positionOffsetForAlignment:
(Vector) - positionOffsetForShipInRotationToAlignment
(void) - collectBountyFor:
(BoundingBox) - findSubentityBoundingBox
(Triangle) - absoluteIJKForSubentity
(GLfloat) - weaponRecoveryTime
(GLfloat) - laserHeatLevel
(GLfloat) - laserHeatLevelAft
(GLfloat) - laserHeatLevelForward
(GLfloat) - laserHeatLevelPort
(GLfloat) - laserHeatLevelStarboard
(GLfloat) - hullHeatLevel
(GLfloat) - entityPersonality
(GLint) - entityPersonalityInt
(void) - setEntityPersonalityInt:
(void) - setSuppressExplosion:
(void) - resetExhaustPlumes
(void) - removeExhaust:
(void) - removeFlasher:
(void) - checkScanner
(void) - checkScannerIgnoringUnpowered
(ShipEntity **) - scannedShips
(int) - numberOfScannedShips
(Entity *) - foundTarget
(Entity *) - primaryAggressor
(Entity *) - lastEscortTarget
(Entity *) - thankedShip
(Entity *) - rememberedShip
(Entity *) - proximityAlert
(void) - setFoundTarget:
(void) - setPrimaryAggressor:
(void) - setLastEscortTarget:
(void) - setThankedShip:
(void) - setRememberedShip:
(void) - setProximityAlert:
(void) - setTargetStation:
(BOOL) - isValidTarget:
(void) - addTarget:
(void) - removeTarget:
(BOOL) - canStillTrackPrimaryTarget
(id) - primaryTarget
(id) - primaryTargetWithoutValidityCheck
(StationEntity *) - targetStation
(BOOL) - isFriendlyTo:
(ShipEntity *) - shipHitByLaser
(void) - noteLostTarget
(void) - noteLostTargetAndGoIdle
(void) - noteTargetDestroyed:
(OOBehaviour) - behaviour
(void) - setBehaviour:
(void) - trackOntoTarget:withDForward:
(double) - ballTrackLeadingTarget:atTarget:
(GLfloat) - rollToMatchUp:rotating:
(GLfloat) - rangeToDestination
(double) - trackDestination:retreat:
(void) - setCoordinate:
(HPVector) - coordinates
(HPVector) - destination
(HPVector) - distance_six:
(HPVector) - distance_twelve:withOffset:
(void) - setEvasiveJink:
(void) - evasiveAction:
(double) - trackPrimaryTarget:retreat:
(double) - trackSideTarget:leftside:
(double) - missileTrackPrimaryTarget:
(double) - rangeToPrimaryTarget
(double) - approachAspectToPrimaryTarget
(double) - rangeToSecondaryTarget:
(BOOL) - hasProximityAlertIgnoringTarget:
(GLfloat) - currentAimTolerance
(GLfloat) - lookingAtSunWithThresholdAngleCos:
(BOOL) - onTarget:withWeapon:
(OOTimeDelta) - shotTime
(void) - resetShotTime
(BOOL) - fireMainWeapon:
(BOOL) - fireAftWeapon:
(BOOL) - firePortWeapon:
(BOOL) - fireStarboardWeapon:
(BOOL) - fireTurretCannon:
(void) - setLaserColor:
(void) - setExhaustEmissiveColor:
(OOColor *) - laserColor
(OOColor *) - exhaustEmissiveColor
(BOOL) - fireSubentityLaserShot:
(BOOL) - fireDirectLaserShot:
(BOOL) - fireDirectLaserDefensiveShot
(BOOL) - fireDirectLaserShotAt:
(NSArray *) - laserPortOffset:
(BOOL) - fireLaserShotInDirection:weaponIdentifier:
(void) - adjustMissedShots:
(int) - missedShots
(void) - considerFiringMissile:
(Vector) - missileLaunchPosition
(ShipEntity *) - fireMissile
(ShipEntity *) - fireMissileWithIdentifier:andTarget:
(BOOL) - isMissileFlagSet
(void) - setIsMissileFlag:
(OOTimeDelta) - missileLoadTime
(void) - setMissileLoadTime:
(void) - noticeECM
(BOOL) - fireECM
(BOOL) - cascadeIfAppropriateWithDamageAmount:cascadeOwner:
(BOOL) - activateCloakingDevice
(void) - deactivateCloakingDevice
(BOOL) - launchCascadeMine
(ShipEntity *) - launchEscapeCapsule
(OOCommodityType) - dumpCargo
(ShipEntity *) - dumpCargoItem:
(OOCargoType) - dumpItem:
(void) - manageCollisions
(BOOL) - collideWithShip:
(void) - adjustVelocity:
(void) - addImpactMoment:fraction:
(BOOL) - canScoop:
(void) - getTractoredBy:
(void) - scoopIn:
(void) - scoopUp:
(void) - scoopUpProcess:processEvents:processMessages:
(BOOL) - abandonShip
(void) - takeScrapeDamage:from:
(void) - takeHeatDamage:
(void) - enterDock:
(void) - leaveDock:
(void) - enterWormhole:
(void) - enterWormhole:replacing:
(void) - enterWitchspace
(void) - leaveWitchspace
(BOOL) - witchspaceLeavingEffects
(void) - markAsOffender:
(void) - markAsOffender:withReason:
(void) - switchLightsOn
(void) - switchLightsOff
(BOOL) - lightsActive
(void) - setDestination:
(void) - setEscortDestination:
(BOOL) - canAcceptEscort:
(BOOL) - acceptAsEscort:
(void) - deployEscorts
(void) - dockEscorts
(void) - setTargetToNearestFriendlyStation
(void) - setTargetToNearestStation
(void) - setTargetToSystemStation
(void) - landOnPlanet:
(void) - abortDocking
(NSDictionary *) - dockingInstructions
(void) - broadcastThargoidDestroyed
(void) - broadcastHitByLaserFrom:
(GLfloat) - sunGlareFilter
(void) - setSunGlareFilter:
(void) - sendExpandedMessage:toShip:
(void) - sendMessage:toShip:withUnpilotedOverride:
(void) - broadcastAIMessage:
(void) - broadcastMessage:withUnpilotedOverride:
(void) - setCommsMessageColor
(void) - receiveCommsMessage:from:
(void) - commsMessage:withUnpilotedOverride:
(BOOL) - markedForFines
(BOOL) - markForFines
(BOOL) - isMining
(void) - spawn:
(int) - checkShipsInVicinityForWitchJumpExit
(BOOL) - trackCloseContacts
(void) - setTrackCloseContacts:
(void) - setHulk:
(BOOL) - isHulk
(OOJSScript *) - script
(NSDictionary *) - scriptInfo
(void) - overrideScriptInfo:
(BOOL) - scriptedMisjump
(void) - setScriptedMisjump:
(GLfloat) - scriptedMisjumpRange
(void) - setScriptedMisjumpRange:
(Entity *) - entityForShaderProperties
(void) - setDemoShip:
(BOOL) - isDemoShip
(void) - setDemoStartTime:
(void) - doScriptEvent:
(void) - doScriptEvent:withArgument:
(void) - doScriptEvent:withArgument:andArgument:
(void) - doScriptEvent:withArguments:
(void) - doScriptEvent:withArguments:count:
(void) - doScriptEvent:inContext:withArguments:count:
(void) - reactToAIMessage:context:
(void) - sendAIMessage:
(void) - doScriptEvent:andReactToAIMessage:
(void) - doScriptEvent:withArgument:andReactToAIMessage:
(id) - init [implementation]
(id) - initBypassForPlayer [implementation]
(NSString *) - repeatString:times: [implementation]
(BOOL) - setUpOneSubentity: [implementation]
(BOOL) - setUpOneFlasher: [implementation]
(void) - dealloc [implementation]
(NSString *) - descriptionComponents [implementation]
(NSString *) - shortDescriptionComponents [implementation]
(void) - wasAddedToUniverse [implementation]
(void) - wasRemovedFromUniverse [implementation]
(NSString *) - beaconCode [implementation]
(void) - setBeaconCode: [implementation]
(NSString *) - beaconLabel [implementation]
(void) - setBeaconLabel: [implementation]
(BOOL) - isVisible [implementation]
(BOOL) - isBeacon [implementation]
(id< OOHUDBeaconIcon >) - beaconDrawable [implementation]
(Entity< OOBeaconEntity > *) - prevBeacon [implementation]
(Entity< OOBeaconEntity > *) - nextBeacon [implementation]
(void) - setPrevBeacon: [implementation]
(void) - setNextBeacon: [implementation]
(void) - setUpMixedEscorts [implementation]
(void) - setUpOneEscort:inGroup:withRole:atPosition:andCount: [implementation]
(OOScanClass) - scanClass [implementation]
(BOOL) - canCollide [implementation]
(ShipEntity *) - doOctreesCollide [implementation]
(BOOL) - checkCloseCollisionWith: [implementation]
(void) - addSubentityToCollisionRadius: [implementation]
(ShipEntity *) - launchPodWithCrew: [implementation]
(BOOL) - validForAddToUniverse [implementation]
(void) - update: [implementation]
(void) - noteFrustration: [implementation]
(OOEquipmentType *) - generateMissileEquipmentTypeFrom: [implementation]
(OOEquipmentType *) - verifiedMissileTypeFromRole: [implementation]
(void) - drawImmediate:translucent: [implementation]
(void) - drawSubEntityImmediate:translucent: [implementation]
(BOOL) - isJammingScanning [implementation]
(void) - addSubEntity: [implementation]
(void) - setOwner: [implementation]
(void) - orientationChanged [implementation]
(void) - applyRoll:andClimb: [implementation]
(void) - applyRoll:climb:andYaw: [implementation]
(NSComparisonResult) - ComparePlanetsBySurfaceDistance [implementation]
(Entity< OOStellarBody > *) - lastAegisLock [implementation]
(void) - setStatus: [implementation]
(void) - rescaleBy: [implementation]
(void) - rescaleBy:writeToCache: [implementation]
(void) - releaseCargoPodsDebris [implementation]
(void) - subEntityDied: [implementation]
(void) - subEntityReallyDied: [implementation]
(NSComparisonResult) - compareBeaconCodeWith: [implementation]
(uint32_t) - randomSeedForShaders [implementation]
(void) - setShipHitByLaser: [implementation]
(BOOL) - fireWeapon:direction:range: [implementation]
(void) - throwSparks [implementation]
(Vector) - velocity [implementation]
(void) - suppressTargetLost [implementation]
(void) - takeEnergyDamage:from:becauseOf:weaponIdentifier: [implementation]
(void) - refreshEscortPositions [implementation]
(HPVector) - coordinatesForEscortPosition: [implementation]
(void) - setTargetToNearestStationIncludingHostiles: [implementation]
(BoundingBox) - findBoundingBoxRelativeTo:i:j:k: [implementation]
(OOTimeAbsolute) - getDemoStartTime [implementation]
(void) - doNothing [implementation]
(void) - setAITo:
(void) - setAIScript:
(void) - switchAITo:
(void) - scanForHostiles
(BOOL) - performHyperSpaceToSpecificSystem:
(void) - scanForNearestIncomingMissile
(void) - enterTargetWormhole
(void) - enterPlayerWormhole
(void) - wormholeEscorts
(void) - wormholeEntireGroup
(BOOL) - suggestEscortTo:
(void) - groupAttackTarget
(void) - performAttack
(void) - performCollect
(void) - performEscort
(void) - performFaceDestination
(void) - performFlee
(void) - performFlyToRangeFromDestination
(void) - performHold
(void) - performIdle
(void) - performIntercept
(void) - performLandOnPlanet
(void) - performMining
(void) - performScriptedAI
(void) - performScriptedAttackAI
(void) - performStop
(void) - performTumble
(void) - broadcastDistressMessage
(void) - broadcastDistressMessageWithDumping:
(void) - requestDockingCoordinates
(void) - recallDockingInstructions
(void) - performBuoyTumble [implementation]
(NSDictionary *) - savedShipDictionaryWithContext:
(void) - simplifyShipdata:andGetDeletes: [implementation]
(void) - checkFoundTarget [implementation]
(BOOL) - performHyperSpaceExitReplace: [implementation]
(BOOL) - performHyperSpaceExitReplace:toSystem: [implementation]
(void) - scanForNearestShipWithPredicate:parameter: [implementation]
(void) - scanForNearestShipWithNegatedPredicate:parameter: [implementation]
(void) - acceptDistressMessageFrom: [implementation]
(BOOL) - launchPatrol [implementation]
(NSArray *) - subEntitiesForScript
(NSArray *) - subEntitiesForScript
(void) - setTargetForScript:
(void) - setTargetForScript:
(BOOL) - isVisibleToScripts [implementation]
(void) - getJSClass:andPrototype: [implementation]
(NSString *) - oo_jsClassName [implementation]
(JSClassID) - oo_jsClassID [implementation]
(void) - drawDebugStuff [implementation]
(void) - setStateTo: [implementation]
(void) - pauseAI: [implementation]
(void) - randomPauseAI: [implementation]
(void) - dropMessages: [implementation]
(void) - debugDumpPendingMessages [implementation]
(void) - setDestinationToCurrentLocation [implementation]
(void) - setDesiredRangeTo: [implementation]
(void) - setDesiredRangeForWaypoint [implementation]
(void) - setSpeedTo: [implementation]
(void) - setSpeedFactorTo: [implementation]
(void) - setSpeedToCruiseSpeed [implementation]
(void) - setThrustFactorTo: [implementation]
(void) - setTargetToPrimaryAggressor [implementation]
(void) - scanForNearestMerchantman [implementation]
(void) - scanForRandomMerchantman [implementation]
(void) - scanForLoot [implementation]
(void) - scanForRandomLoot [implementation]
(void) - setTargetToFoundTarget [implementation]
(void) - checkForFullHold [implementation]
(void) - getWitchspaceEntryCoordinates [implementation]
(void) - setDestinationFromCoordinates [implementation]
(void) - setCoordinatesFromPosition [implementation]
(void) - fightOrFleeMissile [implementation]
(void) - setCourseToPlanet [implementation]
(void) - setTakeOffFromPlanet [implementation]
(void) - landOnPlanet [implementation]
(void) - checkTargetLegalStatus [implementation]
(void) - checkOwnLegalStatus [implementation]
(void) - exitAIWithMessage: [implementation]
(void) - setDestinationToTarget [implementation]
(void) - setDestinationWithinTarget [implementation]
(void) - checkCourseToDestination [implementation]
(void) - checkAegis [implementation]
(void) - checkEnergy [implementation]
(void) - checkHeatInsulation [implementation]
(void) - scanForOffenders [implementation]
(void) - setCourseToWitchpoint [implementation]
(void) - setDestinationToWitchpoint [implementation]
(void) - setDestinationToStationBeacon [implementation]
(void) - performHyperSpaceExit [implementation]
(void) - performHyperSpaceExitWithoutReplacing [implementation]
(void) - wormholeGroup [implementation]
(void) - commsMessage: [implementation]
(void) - commsMessageByUnpiloted: [implementation]
(void) - ejectCargo [implementation]
(void) - scanForThargoid [implementation]
(void) - scanForNonThargoid [implementation]
(void) - thargonCheckMother [implementation]
(void) - becomeUncontrolledThargon [implementation]
(void) - checkDistanceTravelled [implementation]
(void) - fightOrFleeHostiles [implementation]
(void) - suggestEscort [implementation]
(void) - escortCheckMother [implementation]
(void) - checkGroupOddsVersusTarget [implementation]
(void) - scanForFormationLeader [implementation]
(void) - messageMother: [implementation]
(void) - setPlanetPatrolCoordinates [implementation]
(void) - setSunSkimStartCoordinates [implementation]
(void) - setSunSkimEndCoordinates [implementation]
(void) - setSunSkimExitCoordinates [implementation]
(void) - patrolReportIn [implementation]
(void) - checkForMotherStation [implementation]
(void) - sendTargetCommsMessage: [implementation]
(void) - markTargetForFines [implementation]
(void) - markTargetForOffence: [implementation]
(void) - storeTarget [implementation]
(void) - recallStoredTarget [implementation]
(void) - scanForRocks [implementation]
(void) - setDestinationToDockingAbort [implementation]
(void) - requestNewTarget [implementation]
(void) - rollD: [implementation]
(void) - scanForNearestShipWithPrimaryRole: [implementation]
(void) - scanForNearestShipHavingRole: [implementation]
(void) - scanForNearestShipWithAnyPrimaryRole: [implementation]
(void) - scanForNearestShipHavingAnyRole: [implementation]
(void) - scanForNearestShipWithScanClass: [implementation]
(void) - scanForNearestShipWithoutPrimaryRole: [implementation]
(void) - scanForNearestShipNotHavingRole: [implementation]
(void) - scanForNearestShipWithoutAnyPrimaryRole: [implementation]
(void) - scanForNearestShipNotHavingAnyRole: [implementation]
(void) - scanForNearestShipWithoutScanClass: [implementation]
(void) - setCoordinates: [implementation]
(void) - checkForNormalSpace [implementation]
(void) - setTargetToRandomStation [implementation]
(void) - setTargetToLastStation [implementation]
(void) - addFuel: [implementation]
(void) - scriptActionOnTarget: [implementation]
(void) - sendScriptMessage: [implementation]
(void) - ai_throwSparks [implementation]
(void) - explodeSelf [implementation]
(void) - ai_debugMessage: [implementation]
(void) - targetFirstBeaconWithCode: [implementation]
(void) - targetNextBeaconWithCode: [implementation]
(void) - setRacepointsFromTarget [implementation]
(void) - performFlyRacepoints [implementation]
(void) - addPrimaryAggressorAsDefenseTarget [implementation]
(void) - addFoundTargetAsDefenseTarget [implementation]
(void) - findNewDefenseTarget [implementation]
(void) - setDestinationToJinkPosition [implementation]
(void) - disengageAutopilot [implementation]
(void) - messageSelf: [implementation]
(void) - scanForNearestShipMatchingPredicate: [implementation]
(void) - safeScriptActionOnTarget: [implementation]
(ShipEntity *) - ejectShipOfType:
(ShipEntity *) - ejectShipOfRole:
(NSArray *) - spawnShipsWithRole:count:
(BOOL) - isShipWithSubEntityShip: [implementation]
Instance Methods inherited from OOEntityWithDrawable
(OODrawable *) - drawable
(void) - setDrawable:
(double) - findCollisionRadius [implementation]
Instance Methods inherited from Entity
(NSUInteger) - sessionID
(BOOL) - isShip
(BOOL) - isDock
(BOOL) - isStation
(BOOL) - isSubEntity
(BOOL) - isPlayer
(BOOL) - isPlanet
(BOOL) - isSun
(BOOL) - isSunlit
(BOOL) - isStellarObject
(BOOL) - isSky
(BOOL) - isWormhole
(BOOL) - isEffect
(BOOL) - isVisualEffect
(BOOL) - isWaypoint
(void) - addToLinkedLists
(void) - removeFromLinkedLists
(void) - updateLinkedLists
(void) - warnAboutHostiles
(CollisionRegion *) - collisionRegion
(void) - setCollisionRegion:
(void) - setUniversalID:
(OOUniversalID) - universalID
(BOOL) - throwingSparks
(void) - setThrowSparks:
(id) - owner
(ShipEntity *) - parentEntity
(ShipEntity *) - rootShipEntity
(void) - setPosition:
(void) - setPositionX:y:z:
(HPVector) - position
(Vector) - cameraRelativePosition
(GLfloat) - cameraRangeFront
(GLfloat) - cameraRangeBack
(void) - updateCameraRelativePosition
(Vector) - vectorTo:
(HPVector) - absolutePositionForSubentity
(HPVector) - absolutePositionForSubentityOffset:
(double) - zeroDistance
(double) - camZeroDistance
(NSComparisonResult) - compareZeroDistance:
(BoundingBox) - boundingBox
(GLfloat) - mass
(Quaternion) - orientation
(void) - setOrientation:
(Quaternion) - normalOrientation
(void) - setNormalOrientation:
(void) - setVelocity:
(double) - speed
(GLfloat) - distanceTravelled
(void) - setDistanceTravelled:
(OOEntityStatus) - status
(void) - setScanClass:
(void) - setEnergy:
(GLfloat) - energy
(void) - setMaxEnergy:
(GLfloat) - maxEnergy
(void) - moveForward:
(OOMatrix) - rotationMatrix
(OOMatrix) - drawRotationMatrix
(OOMatrix) - transformationMatrix
(OOMatrix) - drawTransformationMatrix
(GLfloat) - collisionRadius
(void) - setCollisionRadius:
(NSMutableArray *) - collisionArray
(void) - applyVelocity:
(void) - dumpState
(void) - dumpSelfState
(NSUInteger) - lastDrawCounter
(void) - setLastDrawCounter:
(BOOL) - isInSpace
(BOOL) - isImmuneToBreakPatternHide
(GLfloat) - universalTime
(GLfloat) - spawnTime
(GLfloat) - timeElapsedSinceSpawn
(void) - setAtmosphereFogging:
(OOColor *) - fogUniform
(BOOL) - checkLinkedLists [implementation]
(id< OOWeakReferenceSupport >) - superShaderBindingTarget [implementation]
(Vector) - relativePosition [implementation]
(BOOL) - isBreakPattern
(BOOL) - isECMBlast
(BOOL) - isExhaust
(BOOL) - isFlasher
(void) - deleteJSSelf
(void) - deleteJSSelf
(jsval) - oo_jsValueInContext: [implementation]
(BOOL) - isCascadeWeapon
(BOOL) - isPlayerLikeShip
(GLfloat) - clock [implementation]
(unsigned) - pseudoFixedD100 [implementation]
(unsigned) - pseudoFixedD256 [implementation]
(unsigned) - systemGovernment [implementation]
(unsigned) - systemEconomy [implementation]
(unsigned) - systemTechLevel [implementation]
(unsigned) - systemPopulation [implementation]
(unsigned) - systemProductivity [implementation]
Instance Methods inherited from OOWeakRefObject
(id) - weakSelf
(id) - weakRetain [implementation]
(void) - weakRefDied: [implementation]
Instance Methods inherited from <OOWeakReferenceSupport>
(id) - OO_RETURNS_RETAINED

Class Methods

(static BOOL) + IsBehaviourHostile [implementation]
(static float) + SurfaceDistanceSqaredV [implementation]
(static float) + SurfaceDistanceSqared [implementation]
(static BOOL) + AuthorityPredicate [implementation]
(id) + shipRestoredFromDictionary:useFallback:context:

Public Attributes

OOTimeDelta shot_time
Vector v_forward
Vector v_up
Vector v_right
HPVector _destination
GLfloat desired_range
GLfloat desired_speed
GLfloat stick_roll
GLfloat stick_pitch
GLfloat stick_yaw
OOBehaviour behaviour
BoundingBox totalBoundingBox
Public Attributes inherited from Entity
OOUniversalID universalID
unsigned isShip: 1
unsigned isStation: 1
unsigned isPlayer: 1
unsigned isWormhole: 1
unsigned isSubEntity: 1
unsigned hasMoved: 1
unsigned hasRotated: 1
unsigned hasCollided: 1
unsigned isSunlit: 1
unsigned collisionTestFilter: 2
unsigned throw_sparks: 1
unsigned isImmuneToBreakPatternHide: 1
unsigned isExplicitlyNotMainStation: 1
unsigned isVisualEffect: 1
OOScanClass scanClass
GLfloat zero_distance
GLfloat cam_zero_distance
GLfloat no_draw_distance
GLfloat collision_radius
HPVector position
Vector cameraRelativePosition
Quaternion orientation
OOColor * atmosphereFogging
int zero_index
Entity * x_previous
Entity * x_next
Entity * y_previous
Entity * y_next
Entity * z_previous
Entity * z_next
Entity * collision_chain
OOUniversalID shadingEntityID
Entity * collider
CollisionRegion * collisionRegion

Protected Attributes

NSDictionary * shipinfoDictionary
Quaternion subentityRotationalVelocity
OOJSScript * script
OOJSScript * aiScript
OOTimeAbsolute aiScriptWakeTime
NSDictionary * dockingInstructions
OOColor * laser_color
OOColor * default_laser_color
OOColor * exhaust_emissive_color
OOColor * scanner_display_color1
OOColor * scanner_display_color2
OOColor * scanner_display_color_hostile1
OOColor * scanner_display_color_hostile2
GLfloat maxFlightSpeed
GLfloat max_flight_roll
GLfloat max_flight_pitch
GLfloat max_flight_yaw
GLfloat cruiseSpeed
GLfloat max_thrust
GLfloat thrust
float hyperspaceMotorSpinTime
unsigned military_jammer_active: 1
unsigned docking_match_rotation: 1
unsigned pitching_over: 1
unsigned rolling_over: 1
unsigned reportAIMessages: 1
unsigned being_mined: 1
unsigned being_fined: 1
unsigned isHulk: 1
unsigned trackCloseContacts: 1
unsigned isNearPlanetSurface: 1
unsigned isFrangible: 1
unsigned cloaking_device_active: 1
unsigned cloakPassive: 1
unsigned cloakAutomatic: 1
unsigned canFragment: 1
unsigned isWreckage: 1
unsigned _showDamage: 1
unsigned suppressExplosion: 1
unsigned suppressAegisMessages: 1
unsigned isMissile: 1
unsigned _explicitlyUnpiloted: 1
unsigned hasScoopMessage: 1
unsigned scripted_misjump: 1
unsigned haveExecutedSpawnAction: 1
unsigned haveStartedJSAI: 1
unsigned noRocks: 1
unsigned _lightsActive: 1
GLfloat _scriptedMisjumpRange
GLfloat sunGlareFilter
OOFuelQuantity fuel
GLfloat fuel_accumulator
GLfloat afterburner_rate
GLfloat afterburner_speed_factor
OOCargoQuantity likely_cargo
OOCargoQuantity max_cargo
OOCargoQuantity extra_cargo
OOCargoQuantity equipment_weight
OOCargoType cargo_type
OOCargoFlag cargo_flag
OOCreditsQuantity bounty
GLfloat energy_recharge_rate
OOWeaponFacingSet weapon_facings
OOWeaponType forward_weapon_type
OOWeaponType aft_weapon_type
OOWeaponType port_weapon_type
OOWeaponType starboard_weapon_type
GLfloat weapon_damage
GLfloat weapon_damage_override
GLfloat weaponRange
OOWeaponFacing currentWeaponFacing
GLfloat weapon_energy_use
GLfloat weapon_temp
GLfloat weapon_shot_temperature
GLfloat forward_weapon_temp
GLfloat aft_weapon_temp
GLfloat port_weapon_temp
GLfloat starboard_weapon_temp
GLfloat scannerRange
unsigned missiles
unsigned max_missiles
NSString * _missileRole
OOTimeDelta missile_load_time
OOTimeAbsolute missile_launch_time
AI * shipAI
NSString * name
NSString * shipUniqueName
NSString * shipClassName
NSString * displayName
NSString * scan_description
OORoleSet * roleSet
NSString * primaryRole
NSArray * explosionType
Vector jink
HPVector coordinates
Vector reference
NSUInteger _subIdx
NSUInteger _maxShipSubIdx
double launch_time
double launch_delay
OOUniversalID planetForLanding
GLfloat frustration
GLfloat success_factor
int patrol_counter
NSMutableDictionary * previousCondition
float weapon_recharge_rate
int shot_counter
OOTimeAbsolute cargo_dump_time
OOTimeAbsolute last_shot_time
NSMutableArray * cargo
OOCommodityType commodity_type
OOCargoQuantity commodity_amount
GLfloat flightSpeed
GLfloat flightRoll
GLfloat flightPitch
GLfloat flightYaw
GLfloat accuracy
GLfloat pitch_tolerance
GLfloat aim_tolerance
int _missed_shots
OOAegisStatus aegis_status
OOSystemID home_system
OOSystemID destination_system
double messageTime
double next_spark_time
Vector collision_vector
GLfloat _scaleFactor
BOOL _multiplyWeapons
NSArray * forwardWeaponOffset
NSArray * aftWeaponOffset
NSArray * portWeaponOffset
NSArray * starboardWeaponOffset
NSArray * crew
NSMutableDictionary * closeContactsInfo
NSString * lastRadioMessage
Vector tractor_position
float ship_temperature
ShipEntity * scanned_ships [MAX_SCAN_NUMBER+1]
GLfloat distance2_scanned_ships [MAX_SCAN_NUMBER+1]
unsigned n_scanned_ships
HPVector navpoints [32]
unsigned next_navpoint_index
unsigned number_of_navpoints
Octree * octree
uint16_t entity_personality
NSDictionary * scriptInfo
NSMutableArray * subEntities
OOEquipmentType * missile_list [SHIPENTITY_MAX_MISSILES]
OOWeakReference * _primaryTarget
OOWeakReference * _primaryAggressor
OOWeakReference * _targetStation
OOWeakReference * _foundTarget
OOWeakReference * _lastEscortTarget
OOWeakReference * _thankedShip
OOWeakReference * _rememberedShip
OOWeakReference * _proximityAlert
float reactionTime
HPVector trackingCurvePositions [4]
OOTimeAbsolute trackingCurveTimes [4]
HPVector trackingCurveCoeffs [3]
Protected Attributes inherited from Entity
HPVector lastPosition
Quaternion lastOrientation
GLfloat distanceTravelled
OOMatrix rotMatrix
Vector velocity
GLfloat energy
GLfloat maxEnergy
BoundingBox boundingBox
GLfloat mass
NSMutableArray * collidingEntities
OOTimeAbsolute spawnTime
struct JSObject * _jsSelf
NSUInteger lastDrawCounter
Protected Attributes inherited from OOWeakRefObject
OOWeakReference * weakSelf

Private Attributes

OOWeakReference * _subEntityTakingDamage
NSString * _shipKey
NSMutableArray * _equipment
float _heatInsulation
OOWeakReference * _lastAegisLock
OOShipGroup * _group
OOShipGroup * _escortGroup
uint8_t _maxEscortCount
uint8_t _pendingEscortCount
Vector _escortPositions [MAX_ESCORTS]
BOOL _escortPositionsValid
OOWeakSet * _defenseTargets
OOWeakSet * _collisionExceptions
GLfloat _profileRadius
OOWeakReference * _shipHitByLaser
NSString * _beaconCode
NSString * _beaconLabel
OOWeakReference * _prevBeacon
OOWeakReference * _nextBeacon
id< OOHUDBeaconIcon > _beaconDrawable
double _nextAegisCheck
BOOL isDemoShip
OOScalar demoRate
OOTimeAbsolute demoStartTime
Quaternion demoStartOrientation

Detailed Description

Definition at line 183 of file ShipEntity.h.

Method Documentation

◆ abandonShip

- (BOOL) abandonShip

Definition at line 11585 of file ShipEntity.m.

11586{
11587 BOOL OK = NO;
11588 if ([self isPlayer] && [(PlayerEntity*)self isDocked]) {
11589 OOLog(@"ShipEntity.abandonShip.failed", @"%@", @"Player cannot abandon ship while docked.");
11590 return OK;
11591 }
11592
11593 if (![self hasEscapePod]) {
11594 OOLog(@"ShipEntity.abandonShip.failed", @"Ship abandonment was requested for %@, but this ship does not carry escape pod(s).", self);
11595 return OK;
11596 }
11597
11598 if (EXPECT([self launchEscapeCapsule] != NO_TARGET)) // -launchEscapeCapsule takes care of everything for the player
11599 {
11600 if (![self isPlayer]) {
11601 OK = YES;
11602 // if multiple items providing escape pod, remove all of them (NPC process)
11603 while ([self hasEquipmentItemProviding:@"EQ_ESCAPE_POD"]) {
11604 [self removeEquipmentItem:[self equipmentItemProviding:@"EQ_ESCAPE_POD"]];
11605 }
11606 [self setAITo:@"nullAI.plist"];
11607 behaviour = BEHAVIOUR_IDLE;
11608 frustration = 0.0;
11609 [self setScanClass:CLASS_CARGO]; // we're unmanned now!
11610 thrust = thrust * 0.5;
11611 if (thrust > 5)
11612 thrust = 5; // 5 is the thrust of an escape-capsule
11613 desired_speed = 0.0;
11614 if ([self group])
11615 [self setGroup:nil]; // remove self from group.
11616 if (![self isSubEntity] && [self owner])
11617 [self setOwner:nil]; // unset owner, but not if we are a subent
11618 if ([self hasEscorts]) {
11619 OOShipGroup* escortGroup = [self escortGroup];
11620 NSEnumerator* escortEnum = nil;
11621 ShipEntity* escort = nil;
11622 // Note: works on escortArray rather than escortEnumerator because escorts may be mutated.
11623 for (escortEnum = [[self escortArray] objectEnumerator]; (escort = [escortEnum nextObject]);) {
11624 // act individually now!
11625 if ([escort group] == escortGroup)
11626 [escort setGroup:nil];
11627 if ([escort owner] == self)
11628 [escort setOwner:escort];
11629 }
11630
11631 // We now have no escorts.
11632 [_escortGroup release];
11633 _escortGroup = nil;
11634 }
11635 }
11636 } else if (EXPECT([self isSubEntity])) {
11637 // may still have launched passenger pods even if no crew
11638 // if multiple items providing escape pod, remove all of them (NPC process)
11639 while ([self hasEquipmentItemProviding:@"EQ_ESCAPE_POD"]) {
11640 [self removeEquipmentItem:[self equipmentItemProviding:@"EQ_ESCAPE_POD"]];
11641 }
11642
11643 } else {
11644 // this shouldn't happen any more!
11645 OOLog(@"ShipEntity.abandonShip.notPossible", @"Ship %@ cannot be abandoned at this time.", self);
11646 }
11647 return OK;
11648}
#define EXPECT(x)
#define OOLog(class, format,...)
Definition OOLogging.h:84
return nil
@ NO_TARGET
Definition OOTypes.h:169
unsigned isSubEntity
Definition Entity.m:140
unsigned isPlayer
Definition Entity.m:145
id owner()
Definition Entity.m:548
BOOL hasEscorts()
GLfloat frustration
OOShipGroup * escortGroup()
void setGroup:(OOShipGroup *group)
OOShipGroup * group()
NSArray * escortArray()
BOOL hasEscapePod()
GLfloat thrust
ShipEntity * launchEscapeCapsule()
OOBehaviour behaviour
OOShipGroup * _escortGroup
Definition ShipEntity.h:453
GLfloat desired_speed
Definition ShipEntity.h:195
void setOwner:(Entity *who_owns_entity)

References _escortGroup, abandonShip, behaviour, desired_speed, equipmentItemProviding:, escortArray, escortGroup, EXPECT, frustration, group, hasEscapePod, hasEscorts, Entity::isPlayer, Entity::isSubEntity, launchEscapeCapsule, nil, NO_TARGET, OOLog, Entity::owner, removeEquipmentItem:, setAITo:, setGroup:, setOwner:, Entity::setScanClass:, and thrust.

Referenced by abandonShip, coordinates, and takeEnergyDamage:from:becauseOf:weaponIdentifier:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ abortDocking

- (void) abortDocking

Definition at line 12245 of file ShipEntity.m.

12246{
12247 [[UNIVERSE findEntitiesMatchingPredicate:IsStationPredicate
12248 parameter:nil
12249 inRange:-1
12250 ofEntity:nil]
12251 makeObjectsPerformSelector:@selector(abortDockingForShip:)
12252 withObject:self];
12253}

References abortDocking.

Referenced by abortDocking, coordinates, PlayerEntity::disengageAutopilot, and getDestroyedBy:damageType:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ absoluteIJKForSubentity

- (Triangle) absoluteIJKForSubentity

Definition at line 2007 of file ShipEntity.m.

2008{
2009 Triangle result = { { kBasisXVector, kBasisYVector, kBasisZVector } };
2010 Entity* last = nil;
2011 Entity* father = self;
2012 OOMatrix r_mat;
2013
2014 while ((father) && (father != last) && (father != NO_TARGET)) {
2015 r_mat = [father drawRotationMatrix];
2016 result.v[0] = OOVectorMultiplyMatrix(result.v[0], r_mat);
2017 result.v[1] = OOVectorMultiplyMatrix(result.v[1], r_mat);
2018 result.v[2] = OOVectorMultiplyMatrix(result.v[2], r_mat);
2019
2020 last = father;
2021 if (![last isSubEntity])
2022 break;
2023 father = [father owner];
2024 }
2025 return result;
2026}
Vector OOVectorMultiplyMatrix(Vector v, OOMatrix m) CONST_FUNC
Definition OOMatrix.m:121
struct OOMatrix OOMatrix
const Vector kBasisYVector
Definition OOVector.h:46
const Vector kBasisZVector
Definition OOVector.h:47
const Vector kBasisXVector
Definition OOVector.h:45
OOMatrix drawRotationMatrix()
Definition Entity.m:808
Vector v[3]
Definition OOTriangle.h:29

References absoluteIJKForSubentity, Entity::drawRotationMatrix, Entity::isSubEntity, kBasisXVector, kBasisYVector, kBasisZVector, nil, NO_TARGET, OOVectorMultiplyMatrix(), and Entity::owner.

Referenced by absoluteIJKForSubentity, PlayerEntity::doesHitLine:v1:hitEntity:, doesHitLine:v1:hitEntity:, doOctreesCollide, and maxFlightSpeed.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ absoluteTractorPosition

- (HPVector) absoluteTractorPosition

Definition at line 1400 of file ShipEntity.m.

1401{
1403}
OOINLINE HPVector vectorToHPVector(Vector v) INLINE_CONST_FUNC
Definition OOHPVector.h:166
OOINLINE HPVector HPvector_add(HPVector a, HPVector b) INLINE_CONST_FUNC
Definition OOHPVector.h:213
Vector quaternion_rotate_vector(Quaternion q, Vector vector) CONST_FUNC
HPVector position
Definition Entity.m:576
Quaternion normalOrientation()
Definition Entity.m:687
Vector tractor_position
Definition ShipEntity.h:395

References absoluteTractorPosition, HPvector_add(), Entity::normalOrientation, Entity::position, quaternion_rotate_vector(), tractor_position, and vectorToHPVector().

Referenced by absoluteTractorPosition, behaviour_tractored:, and octree.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ acceptAsEscort:

- (BOOL) acceptAsEscort: (ShipEntity*) other_ship

Definition at line 11935 of file ShipEntity.m.

11935 :(ShipEntity*)other_ship
11936{
11937 // can't pair with self
11938 if (self == other_ship)
11939 return NO;
11940
11941 // no longer in flight, probably entered wormhole without telling escorts.
11942 if ([self status] != STATUS_IN_FLIGHT)
11943 return NO;
11944
11945 // increased stack depth at which it can accept escorts to avoid rejections at this stage.
11946 // doesn't seem to have any adverse effect for now. - Kaks.
11947 if ([shipAI stackDepth] > 3) {
11948 OOLog(@"ship.escort.reject", @"%@ rejecting escort %@ because AI stack depth is %zu.", self, other_ship, [shipAI stackDepth]);
11949 return NO;
11950 }
11951
11952 if ([self canAcceptEscort:other_ship]) {
11953 OOShipGroup* escortGroup = [self escortGroup];
11954
11955 if ([escortGroup containsShip:other_ship])
11956 return YES;
11957
11958 // check total number acceptable
11959 // the system's patrols don't have escorts set inside their dictionary, but accept max escorts.
11960 if (_maxEscortCount == 0 && ([self hasPrimaryRole:@"police"] || [self hasPrimaryRole:@"hunter"] || [self hasRole:@"thargoid-mothership"])) {
11962 }
11963
11964 NSUInteger maxEscorts = _maxEscortCount; // never bigger than MAX_ESCORTS.
11965 NSUInteger escortCount = [escortGroup count] - 1; // always 0 or higher.
11966
11967 if (escortCount < maxEscorts) {
11968 [other_ship setGroup:escortGroup];
11969 if ([self group] == nil) {
11970 [self setGroup:escortGroup];
11971 } else if ([self group] != escortGroup)
11972 [[self group] addShip:other_ship];
11973
11974 if (([other_ship maxFlightSpeed] < cruiseSpeed) && ([other_ship maxFlightSpeed] > cruiseSpeed * 0.3)) {
11975 cruiseSpeed = [other_ship maxFlightSpeed] * 0.99;
11976 }
11977
11978 OOLog(@"ship.escort.accept", @"%@ accepting escort %@.", self, other_ship);
11979
11980 [self doScriptEvent:OOJSID("shipAcceptedEscort") withArgument:other_ship];
11981 [other_ship doScriptEvent:OOJSID("escortAccepted") withArgument:self];
11982 [shipAI message:@"ACCEPTED_ESCORT"];
11983 return YES;
11984 } else {
11985 OOLog(@"ship.escort.reject", @"%@ already got max escorts(%zu). Escort rejected: %@.", self, escortCount, other_ship);
11986 }
11987 } else {
11988 OOLog(@"ship.escort.reject", @"%@ failed canAcceptEscort for escort %@.", self, other_ship);
11989 }
11990
11991 return NO;
11992}
#define MAX_ESCORTS
Definition ShipEntity.h:76
OOEntityStatus status()
Definition Entity.m:733
NSUInteger count()
uint8_t _maxEscortCount
Definition ShipEntity.h:454
uint8_t escortCount()
GLfloat maxFlightSpeed
GLfloat cruiseSpeed

References _maxEscortCount, OOShipGroup::addShip:, OOShipGroup::count, cruiseSpeed, doScriptEvent:withArgument:, escortCount, escortGroup, group, MAX_ESCORTS, maxFlightSpeed, AI::message:, nil, OOLog, setGroup:, shipAI, and Entity::status.

Referenced by ShipGroupAddShip(), and ShipGroupAddShip().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ acceptDistressMessageFrom:

- (void) acceptDistressMessageFrom: (ShipEntity*) other
implementation

Reimplemented in StationEntity.

Provided by category ShipEntity(OOAIPrivate).

Definition at line 2513 of file ShipEntityAI.m.

2513 :(ShipEntity*)other
2514{
2515 [self setFoundTarget:[other primaryTarget]];
2516 if ([self isPolice]) {
2517 [(ShipEntity*)[self foundTarget] markAsOffender:8 withReason:kOOLegalStatusReasonDistressCall]; // you have been warned!!
2518 }
2519
2520 NSString* context = nil;
2521#ifndef NDEBUG
2522 context = [NSString stringWithFormat:@"%@ broadcastDistressMessage", [other shortDescription]];
2523#endif
2524 [shipAI reactToMessage:@"ACCEPT_DISTRESS_CALL"
2525 context:context];
2526}
BOOL isPolice()
void markAsOffender:withReason:(int offence_value,[withReason] OOLegalStatusReason reason)

Referenced by ShipEntity(AI)::broadcastDistressMessageWithDumping:.

Here is the caller graph for this function:

◆ accuracy

- (GLfloat) accuracy

References accuracy, and mesh.

Here is the call graph for this function:

◆ activateCloakingDevice

- (BOOL) activateCloakingDevice

Reimplemented in PlayerEntity.

Definition at line 10744 of file ShipEntity.m.

10745{
10747 return cloaking_device_active; // no changes.
10748
10752 [self doScriptEvent:OOJSID("shipCloakActivated")];
10754}
#define CLOAKING_DEVICE_START_ENERGY
Definition ShipEntity.h:51
GLfloat maxEnergy
Definition Entity.m:763
GLfloat energy
Definition Entity.m:753
unsigned cloaking_device_active
Definition ShipEntity.h:254
BOOL hasCloakingDevice()

References activateCloakingDevice, cloaking_device_active, CLOAKING_DEVICE_START_ENERGY, doScriptEvent:, Entity::energy, hasCloakingDevice, and Entity::maxEnergy.

Referenced by activateCloakingDevice, behaviour_attack_break_off_target:, behaviour_attack_broadside:, behaviour_attack_broadside_target:leftside:, behaviour_attack_fly_from_target:, behaviour_attack_fly_to_target:, behaviour_attack_slow_dogfight:, behaviour_attack_sniper:, behaviour_attack_target:, behaviour_evasive_action:, behaviour_flee_target:, behaviour_fly_to_target_six:, behaviour_running_defense:, coordinates, and setCloaked:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addCargo:

- (BOOL) addCargo: (NSArray*) some_cargo

Definition at line 7284 of file ShipEntity.m.

7284 :(NSArray*)some_cargo
7285{
7286 if ([cargo count] + [some_cargo count] > [self maxAvailableCargoSpace]) {
7287 return NO;
7288 } else {
7289 [cargo addObjectsFromArray:some_cargo];
7290 return YES;
7291 }
7292}
unsigned count
NSMutableArray * cargo
OOCargoQuantity maxAvailableCargoSpace()

References cargo, count, and maxAvailableCargoSpace.

Here is the call graph for this function:

◆ addCollisionException:

- (void) addCollisionException: (ShipEntity*) ship

Definition at line 9639 of file ShipEntity.m.

9639 :(ShipEntity*)ship
9640{
9641 if (_collisionExceptions == nil) {
9642 // Allocate lazily for the benefit of the ships that never need this.
9643 _collisionExceptions = [[OOWeakSet alloc] init];
9644 }
9645 [_collisionExceptions addObject:ship];
9646}
OOWeakSet * _collisionExceptions
Definition ShipEntity.h:463

References _collisionExceptions, OOWeakSet::addObject:, and nil.

Referenced by ShipAddCollisionException(), and ShipAddCollisionException().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addDefenseTarget:

- (BOOL) addDefenseTarget: (Entity*) target

Definition at line 9678 of file ShipEntity.m.

9678 :(Entity*)target
9679{
9680 if ([self defenseTargetCount] >= MAX_TARGETS) {
9681 return NO;
9682 }
9683 // primary target can be a wormhole, defense targets shouldn't be
9684 if (target == nil || [self isDefenseTarget:target] || ![target isShip]) {
9685 return NO;
9686 }
9687 if (_defenseTargets == nil) {
9688 // Allocate lazily for the benefit of the ships that never get in fights.
9689 _defenseTargets = [[OOWeakSet alloc] init];
9690 }
9691
9692 [_defenseTargets addObject:target];
9693 return YES;
9694}
#define MAX_TARGETS
Definition ShipEntity.h:38
unsigned isShip
Definition Entity.m:125
NSUInteger defenseTargetCount()
OOWeakSet * _defenseTargets
Definition ShipEntity.h:460

References _defenseTargets, OOWeakSet::addObject:, defenseTargetCount, Entity::isShip, MAX_TARGETS, and nil.

Referenced by ShipEntity(PureAI)::addFoundTargetAsDefenseTarget, ShipEntity(PureAI)::addPrimaryAggressorAsDefenseTarget, ShipEntity(PureAI)::fightOrFleeHostiles, ShipEntity(PureAI)::fightOrFleeMissile, ShipEntity(PureAI)::findNewDefenseTarget, and ShipEntity(PureAI)::setTargetToPrimaryAggressor.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addEquipmentItem:inContext:

- (BOOL) addEquipmentItem: (NSString*) equipmentKey
inContext: (NSString*) context 

Reimplemented in PlayerEntity.

Definition at line 3169 of file ShipEntity.m.

3169 :(NSString*)equipmentKey inContext:(NSString*)context
3170{
3171 return [self addEquipmentItem:equipmentKey withValidation:YES inContext:context];
3172}

References addEquipmentItem:withValidation:inContext:.

Referenced by setUpShipFromDictionary:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addEquipmentItem:withValidation:inContext:

- (BOOL) addEquipmentItem: (NSString*) equipmentKey
withValidation: (BOOL) validateAddition
inContext: (NSString*) context 

Reimplemented in PlayerEntity.

Definition at line 3174 of file ShipEntity.m.

3174 :(NSString*)equipmentKey withValidation:(BOOL)validateAddition inContext:(NSString*)context
3175{
3176 OOEquipmentType* eqType = nil;
3177 NSString* lcEquipmentKey = [equipmentKey lowercaseString];
3178 NSString* damagedKey;
3179 BOOL isEqThargon = [lcEquipmentKey hasSuffix:@"thargon"] || [lcEquipmentKey hasPrefix:@"thargon"];
3180 BOOL isRepairedEquipment = NO;
3181
3182 if ([lcEquipmentKey isEqualToString:@"thargon"])
3183 equipmentKey = @"EQ_THARGON";
3184
3185 // canAddEquipment always checks if the undamaged version is equipped.
3186 if (validateAddition == YES && ![self canAddEquipment:equipmentKey inContext:context])
3187 return NO;
3188
3189 if ([equipmentKey hasSuffix:@"_DAMAGED"]) {
3190 eqType = [OOEquipmentType equipmentTypeWithIdentifier:[equipmentKey substringToIndex:[equipmentKey length] - [@"_DAMAGED" length]]];
3191 } else {
3192 eqType = [OOEquipmentType equipmentTypeWithIdentifier:equipmentKey];
3193 // in case we have the damaged version!
3194 if (![eqType canCarryMultiple]) {
3195 damagedKey = [equipmentKey stringByAppendingString:@"_DAMAGED"];
3196 if ([_equipment containsObject:damagedKey]) {
3197 [_equipment removeObject:damagedKey];
3198 isRepairedEquipment = YES;
3199 }
3200 }
3201 }
3202
3203 // does this equipment actually exist?
3204 if (eqType == nil)
3205 return NO;
3206
3207 // special cases
3208 if ([eqType isMissileOrMine] || ([self isThargoid] && isEqThargon)) {
3209 if (missiles >= max_missiles)
3210 return NO;
3211
3212 missile_list[missiles] = eqType;
3213 missiles++;
3214 return YES;
3215 }
3216
3217 // don't add any thargons to non-thargoid ships.
3218 if (isEqThargon)
3219 return NO;
3220
3221 // we can theoretically add a damaged weapon, but not a working one.
3222 if ([equipmentKey hasPrefix:@"EQ_WEAPON"] && ![equipmentKey hasSuffix:@"_DAMAGED"]) {
3223 return NO;
3224 }
3225 // end special cases
3226
3227 if (_equipment == nil)
3228 _equipment = [[NSMutableArray alloc] init];
3229
3230 if (![equipmentKey isEqualToString:@"EQ_PASSENGER_BERTH"] && !isRepairedEquipment) {
3231 // Add to equipment_weight with all other equipment.
3232 equipment_weight += [eqType requiredCargoSpace];
3234 // should not even happen with old save games. Reject equipment now.
3235 equipment_weight -= [eqType requiredCargoSpace];
3236 return NO;
3237 }
3238 }
3239
3240 if (!isPlayer) {
3241 if ([equipmentKey isEqual:@"EQ_CARGO_BAY"]) {
3243 } else if ([equipmentKey isEqualToString:@"EQ_SHIELD_BOOSTER"]) {
3244 maxEnergy += 256.0f;
3245 }
3246 if ([equipmentKey isEqualToString:@"EQ_SHIELD_ENHANCER"]) {
3247 maxEnergy += 256.0f;
3248 energy_recharge_rate *= 1.5;
3249 }
3250 }
3251 // add the equipment
3252 [_equipment addObject:equipmentKey];
3253 [self doScriptEvent:OOJSID("equipmentAdded") withArgument:equipmentKey];
3254 return YES;
3255}
OOEquipmentType * equipmentTypeWithIdentifier:(NSString *identifier)
NSMutableArray * _equipment
Definition ShipEntity.h:447
unsigned missiles
Definition ShipEntity.h:308
unsigned max_missiles
Definition ShipEntity.h:309
OOEquipmentType * missile_list[SHIPENTITY_MAX_MISSILES]
Definition ShipEntity.h:422
GLfloat energy_recharge_rate
Definition ShipEntity.h:291
OOCargoQuantity max_cargo
Definition ShipEntity.h:284
OOCargoQuantity extra_cargo
Definition ShipEntity.h:285
OOCargoQuantity equipment_weight
Definition ShipEntity.h:286
BOOL isThargoid()

References _equipment, doScriptEvent:withArgument:, energy_recharge_rate, equipment_weight, OOEquipmentType::equipmentTypeWithIdentifier:, extra_cargo, Entity::isPlayer, isThargoid, max_cargo, max_missiles, Entity::maxEnergy, missile_list, missiles, nil, and OOEquipmentType::requiredCargoSpace.

Referenced by addEquipmentItem:inContext:, PlayerEntity::addEquipmentItem:withValidation:inContext:, ShipAwardEquipment(), ShipAwardEquipment(), ShipEntity(LoadRestore)::shipRestoredFromDictionary:useFallback:context:, ShipSetEquipmentStatus(), and ShipSetEquipmentStatus().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addFoundTargetAsDefenseTarget

- (void) addFoundTargetAsDefenseTarget
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1016 of file ShipEntityAI.m.

1017{
1018 Entity* fTarget = [self foundTarget];
1019 if (fTarget != nil) {
1020 if ([fTarget isShip] && ![(ShipEntity*)fTarget isFriendlyTo:self]) {
1021 [self addDefenseTarget:fTarget];
1022 }
1023 }
1024}

◆ addFuel:

- (void) addFuel: (NSString*) fuel_number
implementation

Provided by category ShipEntity(PureAI).

Definition at line 2237 of file ShipEntityAI.m.

2237 :(NSString*)fuel_number
2238{
2239 [self setFuel:[self fuel] + [fuel_number intValue] * 10];
2240}

◆ addImpactMoment:fraction:

- (void) addImpactMoment: (Vector) moment
fraction: (GLfloat) howmuch 

Definition at line 11187 of file ShipEntity.m.

11187 :(Vector)moment fraction:(GLfloat)howmuch
11188{
11190}
OOINLINE Vector vector_add(Vector a, Vector b) INLINE_CONST_FUNC
Definition OOVector.h:195
struct Vector Vector
OOINLINE Vector vector_multiply_scalar(Vector v, OOScalar s) INLINE_CONST_FUNC
Definition OOVector.h:180
GLfloat mass
Definition Entity.m:671
Vector velocity()

References Entity::mass, vector_add(), vector_multiply_scalar(), and velocity.

Referenced by dealMomentumWithinDesiredRange:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addPrimaryAggressorAsDefenseTarget

- (void) addPrimaryAggressorAsDefenseTarget
implementation

Provided by category ShipEntity(PureAI).

Definition at line 871 of file ShipEntityAI.m.

872{
873 Entity* primeAggressor = [self primaryAggressor];
874 if (!primeAggressor)
875 return;
876 if ([self isDefenseTarget:primeAggressor])
877 return;
878
879 if ([primeAggressor isShip] && ![(ShipEntity*)primeAggressor isFriendlyTo:self]) {
880 [self addDefenseTarget:primeAggressor];
881 }
882}

◆ addRole:

- (void) addRole: (NSString*) role

Definition at line 6283 of file ShipEntity.m.

6283 :(NSString*)role
6284{
6285 [self addRole:role withProbability:0.0f];
6286}

References addRole:withProbability:.

Referenced by setIsBoulder:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addRole:withProbability:

- (void) addRole: (NSString*) role
withProbability: (float) probability 

Definition at line 6288 of file ShipEntity.m.

6288 :(NSString*)role withProbability:(float)probability
6289{
6290 if (![self hasRole:role]) {
6291 OORoleSet* newRoles = nil;
6292 if (roleSet != nil)
6293 newRoles = [roleSet roleSetWithAddedRole:role probability:probability];
6294 else
6295 newRoles = [OORoleSet roleSetWithRole:role probability:probability];
6296 if (newRoles != nil) {
6297 [roleSet release];
6298 roleSet = [newRoles retain];
6299 }
6300 }
6301}
instancetype roleSetWithRole:probability:(NSString *role,[probability] float probability)
Definition OORoleSet.m:47
OORoleSet * roleSet

References nil, roleSet, OORoleSet::roleSetWithAddedRole:probability:, and OORoleSet::roleSetWithRole:probability:.

Referenced by addRole:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addSubEntity:

- (void) addSubEntity: (Entity<OOSubEntity>*) sub
implementation

Provided by category ShipEntity(Private).

Definition at line 5788 of file ShipEntity.m.

5788 :(Entity<OOSubEntity>*)sub
5789{
5790 if (sub == nil)
5791 return;
5792
5793 if (subEntities == nil)
5794 subEntities = [[NSMutableArray alloc] init];
5795 sub->isSubEntity = YES;
5796 // Order matters - need consistent state in setOwner:. -- Ahruman 2008-04-20
5797 [subEntities addObject:sub];
5798 [sub setOwner:self];
5799
5800 [self addSubentityToCollisionRadius:sub];
5801}
void setOwner:(Entity *ent)
Definition Entity.m:542
NSMutableArray * subEntities

References addSubentityToCollisionRadius:, Entity::isSubEntity, nil, and setOwner:.

Referenced by ShipEntity(Private)::setUpOneFlasher:, setUpOneStandardSubentity:asTurret:, and setUpSubEntities.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addSubentityToCollisionRadius:

- (void) addSubentityToCollisionRadius: (Entity<OOSubEntity>*) subent
implementation

Provided by category ShipEntity(Private).

Definition at line 2028 of file ShipEntity.m.

2028 :(Entity<OOSubEntity>*)subent
2029{
2030 if (!subent)
2031 return;
2032
2033 double distance = HPmagnitude([subent position]) + [subent findCollisionRadius];
2034 if ([subent isKindOfClass:[ShipEntity class]]) // Solid subentity
2035 {
2036 if (distance > collision_radius) {
2038 }
2039
2040 mass += [subent mass];
2041 }
2042 if (distance > _profileRadius) {
2044 }
2045}
OOINLINE OOHPScalar HPmagnitude(HPVector vec) INLINE_CONST_FUNC
Definition OOHPVector.h:260
OOINLINE OOScalar distance(Vector v1, Vector v2) INLINE_CONST_FUNC
Definition OOVector.h:280
GLfloat collision_radius
Definition Entity.h:107
double findCollisionRadius()
Definition Entity.m:888
GLfloat _profileRadius
Definition ShipEntity.h:465

References distance(), and HPmagnitude().

Referenced by ShipEntity(Private)::addSubEntity:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addTarget:

- (void) addTarget: (Entity*) targetEntity

Reimplemented in PlayerEntity.

Definition at line 8667 of file ShipEntity.m.

8667 :(Entity*)targetEntity
8668{
8669 if (targetEntity == self)
8670 return;
8671 if (targetEntity != nil) {
8673 _primaryTarget = [targetEntity weakRetain];
8674 [self startTrackingCurve];
8675 }
8676
8677 [[self shipSubEntityEnumerator] makeObjectsPerformSelector:@selector(addTarget:) withObject:targetEntity];
8678 if (![self isSubEntity])
8679 [self doScriptEvent:OOJSID("shipTargetAcquired") withArgument:targetEntity];
8680}
#define DESTROY(x)
OOWeakReference * _primaryTarget
Definition ShipEntity.h:425

References _primaryTarget, DESTROY, doScriptEvent:withArgument:, Entity::isSubEntity, nil, shipSubEntityEnumerator, startTrackingCurve, and OOWeakRefObject::weakRetain.

Referenced by PlayerEntity::addTarget:, deployEscorts, enterWormhole:replacing:, ShipEntity(PureAI)::fightOrFleeHostiles, ShipEntity(PureAI)::fightOrFleeMissile, fireMissileWithIdentifier:andTarget:, getTractoredBy:, launchCascadeMine, StationEntity::launchDefenseShip, StationEntity::launchPirateShip, StationEntity::launchPolice, PlayerEntity::moveTargetMemoryBy:, ShipEntity(AI)::recallDockingInstructions, PlayerEntity::selectNextMissile, ShipEntity(OOJavaScriptExtensions)::setTargetForScript:, ShipEntity(PureAI)::setTargetToFoundTarget, ShipEntity(PureAI)::setTargetToLastStation, setTargetToNearestStationIncludingHostiles:, ShipEntity(PureAI)::setTargetToPrimaryAggressor, ShipEntity(PureAI)::setTargetToRandomStation, setTargetToSystemStation, ShipEntity(ScriptMethods)::spawnShipsWithRole:count:, ShipEntity(PureAI)::targetFirstBeaconWithCode:, ShipEntity(PureAI)::targetNextBeaconWithCode:, ShipEntity(AI)::wormholeEscorts, and ShipEntity(PureAI)::wormholeGroup.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ adjustMissedShots:

- (void) adjustMissedShots: (int) delta

Definition at line 10477 of file ShipEntity.m.

10477 :(int)delta
10478{
10479 if ([self isSubEntity]) {
10480 [[self owner] adjustMissedShots:delta];
10481 } else {
10482 _missed_shots += delta;
10483 if (_missed_shots < 0) {
10484 _missed_shots = 0;
10485 }
10486 }
10487}
int _missed_shots
Definition ShipEntity.h:365
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque

References _missed_shots, adjustMissedShots:, Entity::isSubEntity, and Entity::owner.

Referenced by adjustMissedShots:, fireLaserShotInDirection:weaponIdentifier:, and fireSubentityLaserShot:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ adjustVelocity:

- (void) adjustVelocity: (Vector) xVel

Reimplemented in StationEntity.

Definition at line 11182 of file ShipEntity.m.

11182 :(Vector)xVel
11183{
11184 velocity = vector_add(velocity, xVel);
11185}

References vector_add(), and velocity.

Referenced by StationEntity::adjustVelocity:, behaviour_land_on_planet:, collideWithShip:, and DockEntity::shipIsInDockingCorridor:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ afterburnerFactor

- (float) afterburnerFactor

Definition at line 3661 of file ShipEntity.m.

3662{
3664}
GLfloat afterburner_speed_factor
Definition ShipEntity.h:281

References afterburner_speed_factor, and afterburnerFactor.

Referenced by afterburnerFactor, applyThrust:, behaviour_attack_break_off_target:, behaviour_attack_broadside:, behaviour_attack_broadside_target:leftside:, behaviour_attack_fly_from_target:, behaviour_attack_fly_to_target:, behaviour_attack_sniper:, behaviour_evasive_action:, behaviour_flee_target:, behaviour_fly_to_target_six:, PlayerEntity::doBookkeeping:, increase_flight_speed:, isFrangible, PlayerEntity(OOPrivate)::performInFlightUpdates:, and WormholeEntity::suckInShip:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ afterburnerRate

- (float) afterburnerRate

Definition at line 3666 of file ShipEntity.m.

3667{
3668 return afterburner_rate;
3669}
GLfloat afterburner_rate
Definition ShipEntity.h:280

References afterburner_rate, and afterburnerRate.

Referenced by afterburnerRate, and isFrangible.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ aftWeaponOffset

- (NSArray *) aftWeaponOffset

References aftWeaponOffset.

◆ ai_debugMessage:

- (void) ai_debugMessage: (NSString*) message
implementation

Provided by category ShipEntity(PureAI).

Definition at line 2312 of file ShipEntityAI.m.

2312 :(NSString*)message
2313{
2314 NSString* desc = [NSString stringWithFormat:@"%@ %d", [self name], [self universalID]];
2315 if ([self isPlayer])
2316 desc = @"player autopilot";
2317 OOLog(@"ai.takeAction.debugMessage", @"DEBUG: AI MESSAGE from %@: %@", desc, message);
2318}

◆ ai_throwSparks

- (void) ai_throwSparks
implementation

Provided by category ShipEntity(PureAI).

Definition at line 2302 of file ShipEntityAI.m.

2303{
2304 [self setThrowSparks:YES];
2305}

◆ alertCondition

- (OOAlertCondition) alertCondition

Reimplemented in PlayerEntity, and ProxyPlayerEntity.

Definition at line 12883 of file ShipEntity.m.

12884{
12885 if ([self status] == STATUS_DOCKED) {
12887 }
12888 if ([self hasHostileTarget] || energy < maxEnergy / 4) {
12889 return ALERT_CONDITION_RED;
12890 }
12892}
@ ALERT_CONDITION_RED
Definition ShipEntity.h:172
@ ALERT_CONDITION_YELLOW
Definition ShipEntity.h:171
@ ALERT_CONDITION_DOCKED
Definition ShipEntity.h:169
BOOL hasHostileTarget()

References ALERT_CONDITION_DOCKED, ALERT_CONDITION_RED, ALERT_CONDITION_YELLOW, alertCondition, Entity::energy, hasHostileTarget, Entity::maxEnergy, and Entity::status.

Referenced by alertCondition, and isMissile.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ allDefenseTargets

- (NSArray *) allDefenseTargets

Definition at line 9668 of file ShipEntity.m.

9669{
9670 return [_defenseTargets allObjects];
9671}

References allDefenseTargets, and OOWeakSet::allObjects.

Referenced by allDefenseTargets, isMissile, and validateDefenseTargets.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ applyAttitudeChanges:

- (void) applyAttitudeChanges: (double) delta_t

Reimplemented in PlayerEntity.

Definition at line 5908 of file ShipEntity.m.

5908 :(double)delta_t
5909{
5910 [self applyRoll:flightRoll * delta_t climb:flightPitch * delta_t andYaw:flightYaw * delta_t];
5911}

References applyRoll:climb:andYaw:.

Referenced by processBehaviour:, and update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ applyRoll:andClimb:

- (void) applyRoll: (GLfloat) roll1
andClimb: (GLfloat) climb1 
implementation

Reimplemented from Entity.

Reimplemented in PlayerEntity.

Definition at line 5874 of file ShipEntity.m.

5874 :(GLfloat)roll1 andClimb:(GLfloat)climb1
5875{
5877
5878 if (!roll1 && !climb1 && !hasRotated)
5879 return;
5880
5881 if (roll1)
5882 quaternion_rotate_about_z(&q1, -roll1);
5883 if (climb1)
5884 quaternion_rotate_about_x(&q1, -climb1);
5885
5887 [self orientationChanged];
5888}
void quaternion_rotate_about_x(Quaternion *quat, OOScalar angle) NONNULL_FUNC
struct Quaternion Quaternion
const Quaternion kIdentityQuaternion
void quaternion_rotate_about_z(Quaternion *quat, OOScalar angle) NONNULL_FUNC
Quaternion quaternion_multiply(Quaternion q1, Quaternion q2) CONST_FUNC
unsigned hasRotated
Definition Entity.h:93
Quaternion orientation
Definition Entity.m:682

References Entity::hasRotated, kIdentityQuaternion, Entity::orientation, orientationChanged, quaternion_multiply(), quaternion_rotate_about_x(), and quaternion_rotate_about_z().

Here is the call graph for this function:

◆ applyRoll:climb:andYaw:

- (void) applyRoll: (GLfloat) roll1
climb: (GLfloat) climb1
andYaw: (GLfloat) yaw1 
implementation

Reimplemented from Entity.

Definition at line 5890 of file ShipEntity.m.

5890 :(GLfloat)roll1 climb:(GLfloat)climb1 andYaw:(GLfloat)yaw1
5891{
5892 if ((roll1 == 0.0) && (climb1 == 0.0) && (yaw1 == 0.0) && (!hasRotated))
5893 return;
5894
5896
5897 if (roll1)
5898 quaternion_rotate_about_z(&q1, -roll1);
5899 if (climb1)
5900 quaternion_rotate_about_x(&q1, -climb1);
5901 if (yaw1)
5902 quaternion_rotate_about_y(&q1, -yaw1);
5903
5905 [self orientationChanged];
5906}
void quaternion_rotate_about_y(Quaternion *quat, OOScalar angle) NONNULL_FUNC

References Entity::hasRotated, kIdentityQuaternion, Entity::orientation, orientationChanged, quaternion_multiply(), quaternion_rotate_about_x(), quaternion_rotate_about_y(), and quaternion_rotate_about_z().

Referenced by applyAttitudeChanges:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ applySticks:

- (void) applySticks: (double) delta_t

Definition at line 7027 of file ShipEntity.m.

7027 :(double)delta_t
7028{
7029
7030 double rate1 = 2.0 * delta_t; // roll
7031 double rate2 = 4.0 * delta_t; // pitch
7032 double rate3 = 4.0 * delta_t; // yaw
7033
7034 if (((stick_roll > 0.0) && (flightRoll < 0.0)) || ((stick_roll < 0.0) && (flightRoll > 0.0)))
7035 rate1 *= 4.0; // much faster correction
7036 if (((stick_pitch > 0.0) && (flightPitch < 0.0)) || ((stick_pitch < 0.0) && (flightPitch > 0.0)))
7037 rate2 *= 4.0; // much faster correction
7038 if (((stick_yaw > 0.0) && (flightYaw < 0.0)) || ((stick_yaw < 0.0) && (flightYaw > 0.0)))
7039 rate3 *= 4.0; // much faster correction
7040
7042 if (stick_roll == 0.0)
7043 rate1 *= 2.0; // faster correction
7044 if (stick_pitch == 0.0)
7045 rate2 *= 2.0; // faster correction
7046 if (stick_yaw == 0.0)
7047 rate3 *= 2.0; // faster correction
7048 }
7049
7050 // apply stick movement limits
7051 if (flightRoll < stick_roll - rate1) {
7052 flightRoll = flightRoll + rate1;
7053 } else if (flightRoll > stick_roll + rate1) {
7054 flightRoll = flightRoll - rate1;
7055 } else {
7057 }
7058
7059 if (flightPitch < stick_pitch - rate2) {
7060 flightPitch = flightPitch + rate2;
7061 } else if (flightPitch > stick_pitch + rate2) {
7062 flightPitch = flightPitch - rate2;
7063 } else {
7065 }
7066
7067 if (flightYaw < stick_yaw - rate3) {
7068 flightYaw = flightYaw + rate3;
7069 } else if (flightYaw > stick_yaw + rate3) {
7070 flightYaw = flightYaw - rate3;
7071 } else {
7073 }
7074}
#define COMBAT_AI_TRACKS_CLOSER
Definition ShipEntity.h:132
GLfloat stick_pitch
Definition ShipEntity.h:198
GLfloat stick_yaw
Definition ShipEntity.h:199
GLfloat flightPitch
GLfloat accuracy
GLfloat stick_roll
Definition ShipEntity.h:197
GLfloat flightRoll
GLfloat flightYaw

References accuracy, COMBAT_AI_TRACKS_CLOSER, flightPitch, flightRoll, flightYaw, stick_pitch, stick_roll, and stick_yaw.

Referenced by behaviour_idle:, behaviour_scripted_ai:, behaviour_stop_still:, behaviour_tumble:, evasiveAction:, missileTrackPrimaryTarget:, trackDestination:retreat:, trackPrimaryTarget:retreat:, and trackSideTarget:leftside:.

Here is the caller graph for this function:

◆ applyThrust:

- (void) applyThrust: (double) delta_t

Definition at line 5817 of file ShipEntity.m.

5817 :(double)delta_t
5818{
5819 GLfloat dt_thrust = SHIP_THRUST_FACTOR * thrust * delta_t;
5820 BOOL canBurn = [self hasFuelInjection] && (fuel > MIN_FUEL);
5821 BOOL isUsingAfterburner = (canBurn && (flightSpeed > maxFlightSpeed) && (desired_speed >= flightSpeed));
5822 float max_available_speed = maxFlightSpeed;
5823 if (canBurn)
5824 max_available_speed *= [self afterburnerFactor];
5825
5826 if (thrust) {
5827 // If we have Newtonian (non-thrust) velocity, brake it.
5828 GLfloat velmag = magnitude(velocity);
5829 if (velmag) {
5830 GLfloat vscale = fmaxf((velmag - dt_thrust) / velmag, 0.0f);
5831 scale_vector(&velocity, vscale);
5832 }
5833 }
5834
5835 if (behaviour == BEHAVIOUR_TUMBLE)
5836 return;
5837
5838 // check for speed
5839 if (desired_speed > max_available_speed)
5840 desired_speed = max_available_speed;
5841
5842 if (flightSpeed > desired_speed) {
5843 [self decrease_flight_speed:dt_thrust];
5846 }
5847 if (flightSpeed < desired_speed) {
5848 [self increase_flight_speed:dt_thrust];
5851 }
5852 [self moveForward:delta_t * flightSpeed];
5853
5854 // burn fuel at the appropriate rate
5855 if (isUsingAfterburner) // no fuelconsumption on slowdown
5856 {
5858 while (fuel_accumulator < 0.0) {
5859 fuel--;
5860 fuel_accumulator += 1.0;
5861 }
5862 }
5863}
OOINLINE OOScalar magnitude(Vector vec) INLINE_CONST_FUNC
Definition OOVector.h:242
OOINLINE void scale_vector(Vector *outVector, OOScalar factor) ALWAYS_INLINE_FUNC NONNULL_FUNC
Definition OOVector.h:166
#define MIN_FUEL
Definition ShipEntity.h:104
#define SHIP_THRUST_FACTOR
Definition ShipEntity.h:46
GLfloat flightSpeed
OOFuelQuantity fuel
GLfloat fuel_accumulator
Definition ShipEntity.h:278

References afterburner_rate, afterburnerFactor, behaviour, decrease_flight_speed:, desired_speed, flightSpeed, fuel, fuel_accumulator, hasFuelInjection, increase_flight_speed:, magnitude(), maxFlightSpeed, MIN_FUEL, Entity::moveForward:, scale_vector(), SHIP_THRUST_FACTOR, thrust, and velocity.

Referenced by processBehaviour:, and update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ approachAspectToPrimaryTarget

- (double) approachAspectToPrimaryTarget

Definition at line 9745 of file ShipEntity.m.

9746{
9747 Vector delta;
9748 Entity* target = [self primaryTarget];
9749 if (target == nil || ![target isShip]) // leave now!
9750 {
9751 return 0.0;
9752 }
9753 ShipEntity* ship_target = (ShipEntity*)target;
9754
9756
9757 return dot_product(vector_normal(delta), ship_target->v_forward);
9758}
OOINLINE HPVector HPvector_subtract(HPVector a, HPVector b) INLINE_CONST_FUNC
Definition OOHPVector.h:236
OOINLINE Vector HPVectorToVector(HPVector v) INLINE_CONST_FUNC
Definition OOHPVector.h:175
OOINLINE OOScalar dot_product(Vector first, Vector second) INLINE_CONST_FUNC
Definition OOVector.h:299
OOINLINE Vector vector_normal(Vector vec) INLINE_CONST_FUNC
Definition OOVector.h:270
Vector v_forward
Definition ShipEntity.h:189

References approachAspectToPrimaryTarget, dot_product(), HPvector_subtract(), HPVectorToVector(), Entity::isShip, nil, Entity::position, primaryTarget, v_forward, and vector_normal().

Referenced by approachAspectToPrimaryTarget, behaviour_attack_break_off_target:, behaviour_attack_fly_from_target:, behaviour_attack_fly_to_target:, behaviour_attack_slow_dogfight:, behaviour_attack_target:, behaviour_fly_to_target_six:, and coordinates.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AuthorityPredicate

+ (BOOL) AuthorityPredicate (Entity *) entity
(void *) parameter 
implementation

Definition at line 12270 of file ShipEntity.m.

12271{
12272 ShipEntity* victim = parameter;
12273
12274 // Select main station, if victim is in aegis
12275 if (entity == [UNIVERSE station] && [victim withinStationAegis]) {
12276 return YES;
12277 }
12278
12279 // Select police units in typical scanner range
12280 if ([entity scanClass] == CLASS_POLICE && HPdistance2([victim position], [entity position]) < SCANNER_MAX_RANGE2) {
12281 return YES;
12282 }
12283
12284 // Reject others
12285 return NO;
12286}
#define SCANNER_MAX_RANGE2
Definition Entity.h:54
OOINLINE OOHPScalar HPdistance2(HPVector v1, HPVector v2) INLINE_CONST_FUNC
Definition OOHPVector.h:293
#define UNIVERSE
Definition Universe.h:827
OOScanClass scanClass()
BOOL withinStationAegis()

References HPdistance2(), Entity::position, scanClass, SCANNER_MAX_RANGE2, UNIVERSE, and withinStationAegis.

Here is the call graph for this function:

◆ availableCargoSpace

- (OOCargoQuantity) availableCargoSpace

Definition at line 7217 of file ShipEntity.m.

7218{
7219 // OOCargoQuantity is unsigned, we need to check for underflows.
7221 return 0;
7222 return [self maxAvailableCargoSpace] - [self cargoQuantityOnBoard];
7223}
#define EXPECT_NOT(x)
return self
OOCargoQuantity cargoQuantityOnBoard()

References availableCargoSpace, cargoQuantityOnBoard, equipment_weight, EXPECT_NOT, max_cargo, and maxAvailableCargoSpace.

Referenced by availableCargoSpace, bounty, PlayerEntity::enterWitchspace, equipmentValidToAdd:whileLoading:inContext:, PlayerEntity::setCargoQuantityForType:amount:, ShipAwardEquipment(), ShipAwardEquipment(), ShipSetProperty(), ShipSetProperty(), and PlayerEntity::tryBuyingCommodity:all:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ avoidCollision

- (void) avoidCollision

Definition at line 5913 of file ShipEntity.m.

5914{
5915 if (scanClass == CLASS_MISSILE)
5916 return; // missiles are SUPPOSED to collide!
5917
5918 ShipEntity* prox_ship = (ShipEntity*)[self proximityAlert];
5919
5920 if (prox_ship) {
5921 if (previousCondition) {
5922 [previousCondition release];
5924 }
5925
5926 previousCondition = [[NSMutableDictionary dictionaryWithCapacity:5] retain];
5927
5928 [previousCondition oo_setInteger:behaviour forKey:@"behaviour"];
5929 if ([self primaryTarget] != nil) {
5930 // must use the weak ref here to prevent potential over-retention
5931 [previousCondition setObject:[[self primaryTarget] weakSelf] forKey:@"primaryTarget"];
5932 }
5933 [previousCondition oo_setFloat:desired_range forKey:@"desired_range"];
5934 [previousCondition oo_setFloat:desired_speed forKey:@"desired_speed"];
5935 [previousCondition oo_setHPVector:_destination forKey:@"destination"];
5936
5937 _destination = [prox_ship position];
5938 _destination = OOHPVectorInterpolate(position, [prox_ship position], 0.5); // point between us and them
5939
5941
5942 behaviour = BEHAVIOUR_AVOID_COLLISION;
5943 pitching_over = YES;
5944 }
5945}
OOINLINE HPVector OOHPVectorInterpolate(HPVector a, HPVector b, OOHPScalar where) INLINE_CONST_FUNC
Definition OOHPVector.h:222
#define PROXIMITY_AVOID_DISTANCE_FACTOR
Definition Universe.h:101
HPVector _destination
Definition ShipEntity.h:192
NSMutableDictionary * previousCondition
Definition ShipEntity.h:342
GLfloat desired_range
Definition ShipEntity.h:194
Entity * proximityAlert()
unsigned pitching_over
Definition ShipEntity.h:242

References _destination, avoidCollision, behaviour, Entity::collision_radius, desired_range, nil, OOHPVectorInterpolate(), pitching_over, Entity::position, previousCondition, primaryTarget, PROXIMITY_AVOID_DISTANCE_FACTOR, proximityAlert, and scanClass.

Referenced by avoidCollision, behaviour_attack_break_off_target:, behaviour_attack_broadside_target:leftside:, behaviour_attack_fly_from_target:, behaviour_attack_fly_to_target:, behaviour_attack_mining_target:, behaviour_attack_slow_dogfight:, behaviour_close_to_broadside_range:, behaviour_close_with_target:, behaviour_evasive_action:, behaviour_face_destination:, behaviour_flee_target:, behaviour_fly_from_destination:, behaviour_fly_range_from_destination:, behaviour_fly_to_destination:, behaviour_fly_to_target_six:, behaviour_formation_form_up:, behaviour_intercept_target:, behaviour_land_on_planet:, behaviour_running_defense:, behaviour_track_target:, reactionTime, and trackPrimaryTarget:retreat:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ballTrackLeadingTarget:atTarget:

- (double) ballTrackLeadingTarget: (double) delta_t
atTarget: (Entity*) target 

Definition at line 8916 of file ShipEntity.m.

8916 :(double)delta_t atTarget:(Entity*)target
8917{
8918 if (!target) {
8919 return -2.0; // no target
8920 }
8921
8922 Vector vector_to_target;
8923 Vector axis_to_track_by;
8925 Vector my_ref = reference;
8926 double aim_cos, ref_cos;
8927 Vector leading = [target velocity];
8928
8929 // need to get vector to target in terms of this entities coordinate system
8930 HPVector my_position = [self absolutePositionForSubentity];
8931 vector_to_target = HPVectorToVector(HPvector_subtract([target position], my_position));
8932 // this is in absolute coordinates, so now rotate it
8933
8934 Entity* last = nil;
8935 Entity* father = [self parentEntity];
8936
8938 while ((father) && (father != last) && (father != NO_TARGET)) {
8939 /* Fix orientation */
8940 Quaternion fo = [father normalOrientation];
8941 fo.w = -fo.w;
8942 /* The below code works for player turrets where the
8943 * orientation is different, but not for NPC turrets. Taking
8944 * the normal orientation with -w works: there is probably a
8945 * neater way which someone who understands quaternions can
8946 * find, but this works well enough for 1.82 - CIM */
8948 last = father;
8949 if (![last isSubEntity])
8950 break;
8951 father = [father owner];
8952 }
8953 q = quaternion_conjugate(q);
8954 // q now contains the rotation to the turret's reference system
8955
8956 vector_to_target = quaternion_rotate_vector(q, vector_to_target);
8957
8958 leading = quaternion_rotate_vector(q, leading);
8959 // rotate the vector to target and its velocity
8960
8961 if (magnitude(vector_to_target) > weaponRange * 1.01) {
8962 return -2.0; // out of range
8963 }
8964
8965 float lead = magnitude(vector_to_target) / TURRET_SHOT_SPEED;
8966
8967 vector_to_target = vector_add(vector_to_target, vector_multiply_scalar(leading, lead));
8968 vector_to_target = vector_normal_or_fallback(vector_to_target, kBasisZVector);
8969
8970 // do the tracking!
8971 aim_cos = dot_product(vector_to_target, my_aim);
8972 ref_cos = dot_product(vector_to_target, my_ref);
8973
8974 if (ref_cos > TURRET_MINIMUM_COS) // target is forward of self
8975 {
8976 axis_to_track_by = cross_product(vector_to_target, my_aim);
8977 } else {
8978 return -2.0; // target is out of fire arc
8979 }
8980
8981 quaternion_rotate_about_axis(&orientation, axis_to_track_by, thrust * delta_t);
8982 [self orientationChanged];
8983
8984 [self setStatus:STATUS_ACTIVE];
8985
8986 return aim_cos;
8987}
struct HPVector HPVector
Vector vector_forward_from_quaternion(Quaternion quat) CONST_FUNC
OOINLINE Quaternion quaternion_conjugate(Quaternion q) INLINE_CONST_FUNC
void quaternion_rotate_about_axis(Quaternion *quat, Vector axis, OOScalar angle) NONNULL_FUNC
OOINLINE Vector vector_normal_or_fallback(Vector vec, Vector fallback) INLINE_CONST_FUNC
Definition OOVector.h:247
OOINLINE Vector cross_product(Vector first, Vector second) INLINE_CONST_FUNC
Definition OOVector.h:294
#define TURRET_MINIMUM_COS
Definition ShipEntity.h:44
#define TURRET_SHOT_SPEED
Definition ShipEntity.h:82
Vector velocity
Definition Entity.m:708
GLfloat weaponRange
Vector reference
OOScalar w

References Entity::absolutePositionForSubentity, cross_product(), dot_product(), HPvector_subtract(), HPVectorToVector(), Entity::isSubEntity, kBasisZVector, kIdentityQuaternion, magnitude(), nil, NO_TARGET, Entity::normalOrientation, Entity::orientation, orientationChanged, Entity::owner, Entity::parentEntity, Entity::position, quaternion_conjugate(), quaternion_multiply(), quaternion_rotate_about_axis(), quaternion_rotate_vector(), reference, setStatus:, thrust, TURRET_MINIMUM_COS, TURRET_SHOT_SPEED, vector_add(), vector_forward_from_quaternion(), vector_multiply_scalar(), vector_normal_or_fallback(), Entity::velocity, Quaternion::w, and weaponRange.

Referenced by behaviour_track_as_turret:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ beaconCode

- (NSString *) beaconCode
implementation

Reimplemented from <OOBeaconEntity>.

Definition at line 1405 of file ShipEntity.m.

1406{
1407 return _beaconCode;
1408}
NSString * _beaconCode
Definition ShipEntity.h:470

References _beaconCode, and beaconCode.

Referenced by beaconCode, beaconDrawable, compareBeaconCodeWith:, isBeacon, ShipGetProperty(), ShipGetProperty(), and WormholeEntity::suckInShip:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ beaconDrawable

- (id< OOHUDBeaconIcon >) beaconDrawable
implementation

Reimplemented from <OOBeaconEntity>.

Definition at line 1453 of file ShipEntity.m.

1454{
1455 if (_beaconDrawable == nil) {
1456 NSString* beaconCode = [self beaconCode];
1457 NSUInteger length = [beaconCode length];
1458
1459 if (length > 1) {
1460 NSArray* iconData = [[UNIVERSE descriptions] oo_arrayForKey:beaconCode];
1461 if (iconData != nil)
1462 _beaconDrawable = [[OOPolygonSprite alloc] initWithDataArray:iconData outlineWidth:0.5 name:beaconCode];
1463 }
1464
1465 if (_beaconDrawable == nil) {
1466 if (length > 0)
1467 _beaconDrawable = [[beaconCode substringToIndex:1] retain];
1468 else
1469 _beaconDrawable = @"";
1470 }
1471 }
1472
1473 return _beaconDrawable;
1474}
NSString * beaconCode()
id< OOHUDBeaconIcon > _beaconDrawable
Definition ShipEntity.h:474

References _beaconDrawable, beaconCode, beaconDrawable, and nil.

Referenced by beaconDrawable.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ beaconLabel

- (NSString *) beaconLabel
implementation

Reimplemented from <OOBeaconEntity>.

Definition at line 1427 of file ShipEntity.m.

1428{
1429 return _beaconLabel;
1430}
NSString * _beaconLabel
Definition ShipEntity.h:471

References _beaconLabel, and beaconLabel.

Referenced by beaconLabel, ShipGetProperty(), and ShipGetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ becomeEnergyBlast

- (void) becomeEnergyBlast

Reimplemented in StationEntity.

Definition at line 8155 of file ShipEntity.m.

8156{
8157 [UNIVERSE addEntity:[OOQuiriumCascadeEntity quiriumCascadeFromShip:self]];
8158 [self broadcastEnergyBlastImminent];
8159 [self noteKilledBy:nil damageType:kOODamageTypeCascadeWeapon];
8160 [UNIVERSE removeEntity:self];
8161}
instancetype quiriumCascadeFromShip:(ShipEntity *ship)

References becomeEnergyBlast, broadcastEnergyBlastImminent, noteKilledBy:damageType:, and OOQuiriumCascadeEntity::quiriumCascadeFromShip:.

Referenced by becomeEnergyBlast, StationEntity::becomeEnergyBlast, and maxFlightSpeed.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ becomeExplosion

- (void) becomeExplosion

Reimplemented in StationEntity.

Definition at line 7900 of file ShipEntity.m.

7901{
7902
7903 // check if we're destroying a subentity
7904 ShipEntity* parent = [self parentEntity];
7905 if (parent != nil) {
7906 ShipEntity* this_ship = [self retain];
7907 HPVector this_pos = [self absolutePositionForSubentity];
7908
7909 // remove this ship from its parent's subentity list
7910 [parent subEntityDied:self];
7911 [UNIVERSE addEntity:this_ship];
7912 [this_ship setPosition:this_pos];
7913 [this_ship release];
7914 if ([parent isPlayer]) {
7915 // make the parent ship less reliable.
7916 [(PlayerEntity*)parent adjustTradeInFactorBy:-PLAYER_SHIP_SUBENTITY_TRADE_IN_VALUE];
7917 }
7918 }
7919
7920 HPVector xposition = position;
7921 NSUInteger i;
7922 Vector v;
7923 Quaternion q;
7924 int speed_low = 200;
7925 GLfloat n_alloys = sqrtf(sqrtf(mass / 6000.0f));
7926 NSUInteger numAlloys = 0;
7927 BOOL canReleaseSubWreckage = isWreckage && ([UNIVERSE detailLevel] >= DETAIL_LEVEL_EXTRAS);
7928
7929 if ([self status] == STATUS_DEAD) {
7930 [UNIVERSE removeEntity:self];
7931 return;
7932 }
7933 [self setStatus:STATUS_DEAD];
7934
7935 @try {
7936 if ([self isThargoid] && [roleSet hasRole:@"thargoid-mothership"])
7937 [self broadcastThargoidDestroyed];
7938
7940 if (!isWreckage && mass > 500000.0f && randf() < 0.25f) // big!
7941 {
7942 // draw an expanding ring
7943 OORingEffectEntity* ring = [OORingEffectEntity ringFromEntity:self];
7944 [ring setVelocity:vector_multiply_scalar([self velocity], 0.25f)];
7945 [UNIVERSE addEntity:ring];
7946 }
7947
7948 BOOL add_debris = (UNIVERSE->n_entities < 0.95 * UNIVERSE_MAX_ENTITIES) && ([UNIVERSE getTimeDelta] < 0.125); // FPS > 8
7949
7950 // There are several parts to explosions, show only the main
7951 // explosion effect if UNIVERSE is almost full.
7952
7953 if (add_debris) {
7954 if ([UNIVERSE reducedDetail]) {
7955 // Quick explosion effects for reduced detail mode
7956
7957 // 1. fast sparks
7958 [UNIVERSE addEntity:[OOSmallFragmentBurstEntity fragmentBurstFromEntity:self]];
7959 // 2. slow clouds
7960 [UNIVERSE addEntity:[OOBigFragmentBurstEntity fragmentBurstFromEntity:self]];
7961 // 3. flash
7962 [UNIVERSE addEntity:[OOFlashEffectEntity explosionFlashFromEntity:self]];
7963 /* This mode used to be the default for
7964 * cargo/munitions but this now must be explicitly
7965 * specified. */
7966 } else {
7967 NSString* explosionKey = @"oolite-default-ship-explosion";
7968 NSDictionary* explosion = nil;
7969 if (explosionType == nil) {
7970 explosion = [UNIVERSE explosionSetting:explosionKey];
7971 [UNIVERSE addEntity:[OOExplosionCloudEntity explosionCloudFromEntity:self withSettings:explosion]];
7972 // 3. flash
7973 [UNIVERSE addEntity:[OOFlashEffectEntity explosionFlashFromEntity:self]];
7974 }
7975 for (NSUInteger i = 0; i < [explosionType count]; i++) {
7976 explosionKey = [explosionType oo_stringAtIndex:i defaultValue:nil];
7977 if (explosionKey != nil) {
7978 // three special-case builtins
7979 if ([explosionKey isEqualToString:@"oolite-builtin-flash"]) {
7980 [UNIVERSE addEntity:[OOFlashEffectEntity explosionFlashFromEntity:self]];
7981 } else if ([explosionKey isEqualToString:@"oolite-builtin-slowcloud"]) {
7982 [UNIVERSE addEntity:[OOBigFragmentBurstEntity fragmentBurstFromEntity:self]];
7983 } else if ([explosionKey isEqualToString:@"oolite-builtin-fastspark"]) {
7984 [UNIVERSE addEntity:[OOSmallFragmentBurstEntity fragmentBurstFromEntity:self]];
7985 } else {
7986 explosion = [UNIVERSE explosionSetting:explosionKey];
7987 [UNIVERSE addEntity:[OOExplosionCloudEntity explosionCloudFromEntity:self withSettings:explosion]];
7988 }
7989 }
7990 }
7991 // "fireball" explosion effect
7992 }
7993 }
7994
7995 // If UNIVERSE is nearing limit for entities don't add to it!
7996 if (add_debris) {
7997 // we need to throw out cargo at this point.
7998 [self releaseCargoPodsDebris];
7999
8000 // Throw out rocks and alloys to be scooped up
8001 if ([self hasRole:@"asteroid"] || [self isBoulder]) {
8002 if (!noRocks && (being_mined || randf() < 0.20)) {
8003 NSString* defaultRole = @"boulder";
8004 float defaultSpeed = 50.0;
8005 if ([self isBoulder]) {
8006 defaultRole = @"splinter";
8007 defaultSpeed = 20.0;
8008 if (likely_cargo == 0) {
8009 likely_cargo = 4; // compatibility with older boulders
8010 }
8011 } else if ([[self primaryAggressor] isPlayer]) {
8012 [PLAYER addRoleForMining];
8013 }
8014 NSUInteger n_rocks = 2 + (Ranrot() % (likely_cargo + 1));
8015
8016 NSString* debrisRole = [[self shipInfoDictionary] oo_stringForKey:@"debris_role" defaultValue:defaultRole];
8017 for (i = 0; i < n_rocks; i++) {
8018 ShipEntity* rock = [UNIVERSE newShipWithRole:debrisRole]; // retain count = 1
8019 if (rock) {
8020 float r_speed = [rock maxFlightSpeed] > 0 ? 2.0 * [rock maxFlightSpeed] : defaultSpeed;
8021 float cr = (collision_radius < rock->collision_radius) ? collision_radius : 2 * rock->collision_radius;
8022 v.x = ((randf() * r_speed) - r_speed / 2);
8023 v.y = ((randf() * r_speed) - r_speed / 2);
8024 v.z = ((randf() * r_speed) - r_speed / 2);
8025 [rock setVelocity:vector_add(v, [self velocity])];
8027 [rock setPosition:rpos];
8028
8030 [rock setOrientation:q];
8031
8032 [rock setTemperature:[self randomEjectaTemperature]];
8033 if ([self isBoulder]) {
8034 [rock setScanClass:CLASS_CARGO];
8035 [rock setBounty:0 withReason:kOOLegalStatusReasonSetup];
8036 // only make the rock have minerals if something isn't already defined for the rock
8037 if ([[rock shipInfoDictionary] oo_stringForKey:@"cargo_carried"] == nil)
8038 [rock setCommodity:@"minerals" andAmount:1];
8039 } else {
8040 [rock setScanClass:CLASS_ROCK];
8041 [rock setIsBoulder:YES];
8042 }
8043 [UNIVERSE addEntity:rock]; // STATUS_IN_FLIGHT, AI state GLOBAL
8044 [rock release];
8045 }
8046 }
8047 }
8048 return;
8049 }
8050
8051 // throw out burning chunks of wreckage
8052 //
8053 if ((n_alloys && canFragment) || canReleaseSubWreckage) {
8054 NSUInteger n_wreckage = 0;
8055
8056 if (UNIVERSE->n_entities < 0.50 * UNIVERSE_MAX_ENTITIES) {
8057 // Create wreckage only when UNIVERSE is less than half full.
8058 // (condition set in r906 - was < 0.75 before) --Kaks 2011.10.17
8059 NSUInteger maxWrecks = 3;
8060 if (n_alloys == 0) {
8061 // must be sub-wreckage here
8062 n_wreckage = (mass > 600.0 && randf() < 0.2) ? 2 : 0;
8063 } else {
8064 n_wreckage = (n_alloys < maxWrecks) ? floorf(randf() * (n_alloys + 2)) : maxWrecks;
8065 }
8066 }
8067
8068 for (i = 0; i < n_wreckage; i++) {
8069 Vector r1 = [octree randomPoint];
8071 HPVector rpos = HPvector_add(vectorToHPVector(dir), xposition);
8072 GLfloat lifetime = 750.0 * randf() + 250.0 * i + 100.0;
8073 ShipEntity* wreck = [UNIVERSE addWreckageFrom:self withRole:@"wreckage" at:rpos scale:1.0 lifetime:lifetime / 2];
8074
8075 [wreck setVelocity:vector_add([wreck velocity], vector_multiply_scalar(vector_normal(dir), randf() * [wreck collisionRadius]))];
8076 }
8077 n_alloys = randf() * n_alloys;
8078 }
8079 }
8080
8081 if (!canFragment) {
8082 n_alloys = 0.0;
8083 }
8084 // If UNIVERSE is almost full, don't create more than 1 piece of scrap metal.
8085 else if (!add_debris) {
8086 n_alloys = (n_alloys > 1.0) ? 1.0 : 0.0;
8087 }
8088
8089 // now convert to uint
8090 numAlloys = floorf(n_alloys);
8091
8092 // Throw out scrap metal
8093 //
8094 for (i = 0; i < numAlloys; i++) {
8095 ShipEntity* plate = [UNIVERSE newShipWithRole:@"alloy"]; // retain count = 1
8096 if (plate) {
8097 HPVector rpos = xposition;
8099 rpos.x += rrand.x;
8100 rpos.y += rrand.y;
8101 rpos.z += rrand.z;
8102 rpos.x += (ranrot_rand() % 7) - 3;
8103 rpos.y += (ranrot_rand() % 7) - 3;
8104 rpos.z += (ranrot_rand() % 7) - 3;
8105 [plate setPosition:rpos];
8106 v.x = 0.1 * ((ranrot_rand() % speed_low) - speed_low / 2);
8107 v.y = 0.1 * ((ranrot_rand() % speed_low) - speed_low / 2);
8108 v.z = 0.1 * ((ranrot_rand() % speed_low) - speed_low / 2);
8109 [plate setVelocity:vector_add(v, [self velocity])];
8111 [plate setOrientation:q];
8112
8113 [plate setTemperature:[self randomEjectaTemperature]];
8114 [plate setScanClass:CLASS_CARGO];
8115 [plate setCommodity:@"alloys" andAmount:1];
8116 [UNIVERSE addEntity:plate]; // STATUS_IN_FLIGHT, AI state GLOBAL
8117
8118 [plate release];
8119 }
8120 }
8121 }
8122
8123 // Explode subentities.
8124 ShipEntity* se = nil;
8125 foreach (se, [self shipSubEntityEnumerator]) {
8126 [se setSuppressExplosion:suppressExplosion];
8127 [se becomeExplosion];
8128 }
8129 [self clearSubEntities];
8130
8131 // momentum from explosions
8132 if (!suppressExplosion) {
8134 [self dealMomentumWithinDesiredRange:0.125f * mass];
8135 }
8136
8137 if (self != PLAYER) // was if !isPlayer - but I think this may cause ghosts (Who's "I"? -- Ahruman)
8138 {
8139 if (isPlayer) {
8140#ifndef NDEBUG
8141 OOLog(@"becomeExplosion.suspectedGhost.confirm", @"%@", @"Ship spotted with isPlayer set when not actually the player.");
8142#endif
8143 isPlayer = NO;
8144 }
8145 }
8146 }
8147 @finally {
8148 if (self != PLAYER) {
8149 [UNIVERSE removeEntity:self];
8150 }
8151 }
8152}
Vector OORandomPositionInBoundingBox(BoundingBox bb)
Definition OOVector.m:107
void quaternion_set_random(Quaternion *quat) NONNULL_FUNC
float y
float x
@ UNIVERSE_MAX_ENTITIES
Definition OOTypes.h:168
@ DETAIL_LEVEL_EXTRAS
Definition OOTypes.h:212
#define PLAYER
void setVelocity:(Vector vel)
Definition Entity.m:703
void setOrientation:(Quaternion quat)
Definition Entity.m:676
GLfloat collisionRadius()
Definition Entity.m:830
void setScanClass:(OOScanClass sClass)
Definition Entity.m:738
BoundingBox boundingBox
Definition Entity.m:666
void setPosition:(HPVector posn)
Definition Entity.m:608
id fragmentBurstFromEntity:(Entity *entity)
instancetype explosionCloudFromEntity:withSettings:(Entity *entity,[withSettings] NSDictionary *settings)
instancetype explosionFlashFromEntity:(Entity *entity)
instancetype ringFromEntity:(Entity *sourceEntity)
id fragmentBurstFromEntity:(Entity *entity)
void adjustTradeInFactorBy:(int value)
unsigned suppressExplosion
Definition ShipEntity.h:260
void setSuppressExplosion:(BOOL suppress)
unsigned noRocks
Definition ShipEntity.h:270
void setBounty:withReason:(OOCreditsQuantity amount,[withReason] OOLegalStatusReason reason)
NSDictionary * shipInfoDictionary()
unsigned isWreckage
Definition ShipEntity.h:258
Entity * primaryAggressor()
void subEntityDied:(ShipEntity *sub)
unsigned being_mined
Definition ShipEntity.h:246
OOCargoQuantity likely_cargo
Definition ShipEntity.h:283
NSEnumerator * shipSubEntityEnumerator()
void setTemperature:(GLfloat value)
void setIsBoulder:(BOOL flag)
BOOL isVisible()
BOOL isBoulder()
unsigned canFragment
Definition ShipEntity.h:257
void becomeExplosion()
void setCommodity:andAmount:(OOCommodityType co_type,[andAmount] OOCargoQuantity co_amount)
NSArray * explosionType
Definition ShipEntity.h:324
float randf(void)
unsigned Ranrot(void)
#define ranrot_rand()
OOHPScalar x
Definition OOHPVector.h:36
OOHPScalar y
Definition OOHPVector.h:37
OOHPScalar z
Definition OOHPVector.h:38
OOScalar x
Definition OOVector.h:32
OOScalar y
Definition OOVector.h:33
OOScalar z
Definition OOVector.h:34

References Entity::absolutePositionForSubentity, PlayerEntity::adjustTradeInFactorBy:, becomeExplosion, being_mined, Entity::boundingBox, broadcastThargoidDestroyed, canFragment, clearSubEntities, Entity::collision_radius, Entity::collisionRadius, dealMomentumWithinDesiredRange:, desired_range, DETAIL_LEVEL_EXTRAS, OOExplosionCloudEntity::explosionCloudFromEntity:withSettings:, OOFlashEffectEntity::explosionFlashFromEntity:, explosionType, OOBigFragmentBurstEntity::fragmentBurstFromEntity:, OOSmallFragmentBurstEntity::fragmentBurstFromEntity:, HPdistance2(), HPvector_add(), isBoulder, Entity::isPlayer, isThargoid, isVisible, isWreckage, likely_cargo, Entity::mass, maxFlightSpeed, nil, Entity::normalOrientation, noRocks, OOLog, OORandomPositionInBoundingBox(), Entity::parentEntity, PLAYER, Entity::position, primaryAggressor, quaternion_rotate_vector(), quaternion_set_random(), randf(), randomEjectaTemperature, Octree::randomPoint, Ranrot(), ranrot_rand, releaseCargoPodsDebris, OORingEffectEntity::ringFromEntity:, roleSet, SCANNER_MAX_RANGE2, setBounty:withReason:, setCommodity:andAmount:, setIsBoulder:, Entity::setOrientation:, Entity::setPosition:, Entity::setScanClass:, setStatus:, setSuppressExplosion:, setTemperature:, Entity::setVelocity:, shipInfoDictionary, shipSubEntityEnumerator, Entity::status, subEntityDied:, suppressExplosion, UNIVERSE, UNIVERSE_MAX_ENTITIES, vector_multiply_scalar(), vector_normal(), vectorToHPVector(), velocity, HPVector::x, Vector::x, HPVector::y, Vector::y, HPVector::z, and Vector::z.

Referenced by becomeExplosion, StationEntity::becomeExplosion, becomeLargeExplosion:, PlayerEntity::doBookkeeping:, getDestroyedBy:damageType:, and maxFlightSpeed.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ becomeLargeExplosion:

- (void) becomeLargeExplosion: (double) factor

Reimplemented in StationEntity.

Definition at line 8309 of file ShipEntity.m.

8309 :(double)factor
8310{
8311
8312 if ([self status] == STATUS_DEAD)
8313 return;
8314 [self setStatus:STATUS_DEAD];
8315
8316 @try {
8317 // two parts to the explosion:
8318 // 1. fast sparks
8319 float how_many = factor;
8320 while (how_many > 0.5f) {
8321 [UNIVERSE addEntity:[OOSmallFragmentBurstEntity fragmentBurstFromEntity:self]];
8322 how_many -= 1.0f;
8323 }
8324 // 2. slow clouds
8325 how_many = factor;
8326 while (how_many > 0.5f) {
8327 [UNIVERSE addEntity:[OOBigFragmentBurstEntity fragmentBurstFromEntity:self]];
8328 how_many -= 1.0f;
8329 }
8330
8331 [self releaseCargoPodsDebris];
8332
8333 ShipEntity* se = nil;
8334 foreach (se, [self shipSubEntityEnumerator]) {
8335 [se setSuppressExplosion:suppressExplosion];
8336 [se becomeExplosion];
8337 }
8338 [self clearSubEntities];
8339
8340 }
8341 @finally {
8342 if (!isPlayer)
8343 [UNIVERSE removeEntity:self];
8344 }
8345}

References becomeExplosion, clearSubEntities, OOBigFragmentBurstEntity::fragmentBurstFromEntity:, OOSmallFragmentBurstEntity::fragmentBurstFromEntity:, Entity::isPlayer, nil, releaseCargoPodsDebris, setStatus:, setSuppressExplosion:, shipSubEntityEnumerator, and Entity::status.

Referenced by StationEntity::becomeLargeExplosion:, and PlayerEntity::getDestroyedBy:damageType:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ becomeUncontrolledThargon

- (void) becomeUncontrolledThargon
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1512 of file ShipEntityAI.m.

1513{
1514 int ent_count = UNIVERSE->n_entities;
1515 Entity** uni_entities = UNIVERSE->sortedEntities; // grab the public sorted list
1516 int i;
1517 for (i = 0; i < ent_count; i++)
1518 if (uni_entities[i]->isShip) {
1519 ShipEntity* other = (ShipEntity*)uni_entities[i];
1520 if ([other primaryTarget] == self) {
1521 [other removeTarget:self];
1522 }
1523 if ([other isDefenseTarget:self]) {
1524 [other removeDefenseTarget:self];
1525 }
1526 }
1527 // now we're just a bunch of alien artefacts!
1528 scanClass = CLASS_CARGO;
1529 reportAIMessages = NO;
1530 [self setAITo:@"dumbAI.plist"];
1532 [self setSpeed:0.0];
1533 [self setGroup:nil];
1534}
void removeTarget:(Entity *targetEntity)
unsigned reportAIMessages
void removeDefenseTarget:(Entity *target)

◆ behaviour

References behaviour, and rangeToDestination.

Here is the call graph for this function:

◆ behaviour_attack_break_off_target:

- (void) behaviour_attack_break_off_target: (double) delta_t

Definition at line 3886 of file ShipEntity.m.

3886 :(double)delta_t
3887{
3888 if (![self canStillTrackPrimaryTarget]) {
3889 [self noteLostTargetAndGoIdle];
3890 return;
3891 }
3892 BOOL canBurn = [self hasFuelInjection] && (fuel > MIN_FUEL);
3893 float max_available_speed = maxFlightSpeed;
3894 double range = [self rangeToPrimaryTarget];
3895 if (canBurn)
3896 max_available_speed *= [self afterburnerFactor];
3897
3898 desired_speed = max_available_speed;
3899
3900 Entity* target = [self primaryTarget];
3901
3903 double target_speed = [target speed];
3904 if (desired_speed > target_speed * 3.0) {
3905 desired_speed = maxFlightSpeed; // don't overuse the injectors
3906 }
3907 }
3908
3909 if (cloakAutomatic)
3910 [self activateCloakingDevice];
3911 if ([self hasProximityAlertIgnoringTarget:NO]) {
3912 [self avoidCollision];
3913 return;
3914 }
3915
3916 frustration += delta_t;
3917 if (frustration > 15.0 && accuracy >= COMBAT_AI_DOGFIGHTER && !canBurn) {
3919 }
3920 double aspect = [self approachAspectToPrimaryTarget];
3921 if (range > 3000.0 || ([target isShip] && [(ShipEntity*)target primaryTarget] != self) || frustration - floor(frustration) > fmin(1.6 / max_flight_roll, aspect)) {
3922 [self trackPrimaryTarget:delta_t retreat:YES];
3923 } else {
3924 // less useful at long range if not under direct fire
3925 [self evasiveAction:delta_t];
3926 }
3927
3928 if (range > COMBAT_OUT_RANGE_FACTOR * weaponRange) {
3929 behaviour = BEHAVIOUR_ATTACK_TARGET;
3930 } else if (aspect < -0.75 && accuracy >= COMBAT_AI_DOGFIGHTER) {
3931 behaviour = BEHAVIOUR_ATTACK_SLOW_DOGFIGHT;
3933 frustration = 0.0;
3935 behaviour = BEHAVIOUR_ATTACK_SLOW_DOGFIGHT;
3936 } else {
3937 behaviour = BEHAVIOUR_ATTACK_FLY_TO_TARGET;
3938 }
3939 }
3940
3941 flightYaw = 0.0;
3942}
#define COMBAT_AI_WEAPON_TEMP_READY
Definition ShipEntity.h:119
#define COMBAT_AI_DOGFIGHTER
Definition ShipEntity.h:130
#define COMBAT_OUT_RANGE_FACTOR
Definition ShipEntity.h:58
double speed()
Definition Entity.m:713
BOOL canStillTrackPrimaryTarget()
unsigned cloakAutomatic
Definition ShipEntity.h:256
GLfloat forward_weapon_temp
Definition ShipEntity.h:304
double approachAspectToPrimaryTarget()
GLfloat max_flight_roll
Definition ShipEntity.h:229

References accuracy, activateCloakingDevice, afterburnerFactor, approachAspectToPrimaryTarget, avoidCollision, behaviour, canStillTrackPrimaryTarget, cloakAutomatic, COMBAT_AI_DOGFIGHTER, COMBAT_AI_WEAPON_TEMP_READY, COMBAT_OUT_RANGE_FACTOR, desired_speed, evasiveAction:, flightYaw, forward_weapon_temp, frustration, fuel, hasFuelInjection, Entity::isShip, max_flight_roll, maxFlightSpeed, MIN_FUEL, noteLostTargetAndGoIdle, primaryTarget, rangeToPrimaryTarget, Entity::speed, trackPrimaryTarget:retreat:, and weaponRange.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_attack_broadside:

- (void) behaviour_attack_broadside: (double) delta_t

Definition at line 4187 of file ShipEntity.m.

4187 :(double)delta_t
4188{
4189 BOOL canBurn = [self hasFuelInjection] && (fuel > MIN_FUEL);
4190 float max_available_speed = maxFlightSpeed;
4191 double range = [self rangeToPrimaryTarget];
4192 if (canBurn)
4193 max_available_speed *= [self afterburnerFactor];
4194
4195 if (cloakAutomatic)
4196 [self activateCloakingDevice];
4197
4198 if (![self canStillTrackPrimaryTarget]) {
4199 [self noteLostTargetAndGoIdle];
4200 return;
4201 }
4202
4203 desired_speed = max_available_speed;
4205 behaviour = BEHAVIOUR_ATTACK_TARGET;
4206 } else {
4209 behaviour = BEHAVIOUR_ATTACK_BROADSIDE_RIGHT;
4210 [self setWeaponDataFromType:starboard_weapon_type];
4211 } else {
4212 behaviour = BEHAVIOUR_ATTACK_BROADSIDE_LEFT;
4213 [self setWeaponDataFromType:port_weapon_type];
4214 }
4215 } else {
4217 behaviour = BEHAVIOUR_ATTACK_BROADSIDE_RIGHT;
4218 [self setWeaponDataFromType:starboard_weapon_type];
4219 } else {
4220 behaviour = BEHAVIOUR_ATTACK_BROADSIDE_LEFT;
4221 [self setWeaponDataFromType:port_weapon_type];
4222 }
4223 }
4224 jink = kZeroVector;
4225 if (weapon_damage == 0.0) { // safety in case side lasers no longer exist
4226 behaviour = BEHAVIOUR_ATTACK_TARGET;
4227 } else if (range > 0.9 * weaponRange) {
4228 behaviour = BEHAVIOUR_CLOSE_TO_BROADSIDE_RANGE;
4229 }
4230 }
4231
4232 frustration = 0.0; // behaviour changed, so reset frustration
4233}
const Vector kZeroVector
Definition OOVector.m:27
#define COMBAT_BROADSIDE_IN_RANGE_FACTOR
Definition ShipEntity.h:57
BOOL isWeaponNone(OOWeaponType weapon)
GLfloat weapon_damage
Definition ShipEntity.h:298
Vector jink
Definition ShipEntity.h:327
GLfloat port_weapon_temp
Definition ShipEntity.h:304
GLfloat starboard_weapon_temp
Definition ShipEntity.h:304
OOWeaponType starboard_weapon_type
Definition ShipEntity.h:297
OOWeaponType port_weapon_type
Definition ShipEntity.h:296

References activateCloakingDevice, afterburnerFactor, behaviour, canStillTrackPrimaryTarget, cloakAutomatic, COMBAT_BROADSIDE_IN_RANGE_FACTOR, desired_speed, frustration, fuel, hasFuelInjection, isWeaponNone(), jink, kZeroVector, maxFlightSpeed, MIN_FUEL, noteLostTargetAndGoIdle, port_weapon_temp, port_weapon_type, rangeToPrimaryTarget, setWeaponDataFromType:, starboard_weapon_temp, starboard_weapon_type, weapon_damage, and weaponRange.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_attack_broadside_left:

- (void) behaviour_attack_broadside_left: (double) delta_t

Definition at line 4235 of file ShipEntity.m.

4235 :(double)delta_t
4236{
4237 [self behaviour_attack_broadside_target:delta_t leftside:YES];
4238}

References behaviour_attack_broadside_target:leftside:.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_attack_broadside_right:

- (void) behaviour_attack_broadside_right: (double) delta_t

Definition at line 4240 of file ShipEntity.m.

4240 :(double)delta_t
4241{
4242 [self behaviour_attack_broadside_target:delta_t leftside:NO];
4243}

References behaviour_attack_broadside_target:leftside:.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_attack_broadside_target:leftside:

- (void) behaviour_attack_broadside_target: (double) delta_t
leftside: (BOOL) leftside 

Definition at line 4245 of file ShipEntity.m.

4245 :(double)delta_t leftside:(BOOL)leftside
4246{
4247 BOOL canBurn = [self hasFuelInjection] && (fuel > MIN_FUEL);
4248 float max_available_speed = maxFlightSpeed;
4249 double range = [self rangeToPrimaryTarget];
4250 if (canBurn)
4251 max_available_speed *= [self afterburnerFactor];
4252 if ([self primaryTarget] == nil) {
4253 [self noteLostTargetAndGoIdle];
4254 return;
4255 }
4256 GLfloat currentWeaponRange = getWeaponRangeFromType(leftside ? port_weapon_type : starboard_weapon_type);
4257 if (range > COMBAT_BROADSIDE_RANGE_FACTOR * currentWeaponRange) {
4258 behaviour = BEHAVIOUR_CLOSE_TO_BROADSIDE_RANGE;
4259 return;
4260 }
4261
4262 // can get closer on broadsides since there's less risk of a collision
4263 if ((range < COMBAT_BROADSIDE_IN_RANGE_FACTOR * currentWeaponRange) || ([self proximityAlert] != nil)) {
4264 if (![self hasProximityAlertIgnoringTarget:YES]) {
4265 behaviour = BEHAVIOUR_ATTACK_TARGET;
4266 } else {
4267 [self avoidCollision];
4268 return;
4269 }
4270 } else {
4271 if (![self canStillTrackPrimaryTarget]) {
4272 [self noteLostTargetAndGoIdle];
4273 return;
4274 }
4275 }
4276 // control speed
4277 //
4278 BOOL isUsingAfterburner = canBurn && (flightSpeed > maxFlightSpeed);
4279 double slow_down_range = currentWeaponRange * COMBAT_WEAPON_RANGE_FACTOR * ((isUsingAfterburner) ? 3.0 * [self afterburnerFactor] : 1.0);
4280 // double target_speed = [target speed];
4281 if (range <= slow_down_range)
4282 desired_speed = fmin(0.8 * maxFlightSpeed, fmax((2.0 - frustration) * maxFlightSpeed, 0.1 * maxFlightSpeed)); // within the weapon's range slow down to aim
4283 else
4284 desired_speed = max_available_speed; // use afterburner to approach
4285
4286 double last_success_factor = success_factor;
4287 success_factor = [self trackSideTarget:delta_t leftside:leftside]; // do the actual piloting
4288 if (weapon_temp > COMBAT_AI_WEAPON_TEMP_USABLE) { // will probably have more luck with the other laser or picking a different attack method
4289 if (leftside) {
4291 behaviour = BEHAVIOUR_ATTACK_BROADSIDE_RIGHT;
4292 } else {
4293 behaviour = BEHAVIOUR_ATTACK_TARGET;
4294 }
4295 } else {
4297 behaviour = BEHAVIOUR_ATTACK_BROADSIDE_LEFT;
4298 } else {
4299 behaviour = BEHAVIOUR_ATTACK_TARGET;
4300 }
4301 }
4302 }
4303
4304 /* FIXME: again, basically all of this next bit common with standard attack */
4305 if ((success_factor > 0.999) || (success_factor > last_success_factor)) {
4306 frustration -= delta_t;
4307 if (frustration < 0.0)
4308 frustration = 0.0;
4309 } else {
4310 frustration += delta_t;
4311 if (frustration > 3.0) // 3s of frustration
4312 {
4313
4314 [self noteFrustration:@"BEHAVIOUR_ATTACK_BROADSIDE"];
4315 [self setEvasiveJink:1000.0];
4316 behaviour = BEHAVIOUR_ATTACK_FLY_FROM_TARGET;
4317 frustration = 0.0;
4319 }
4320 }
4321
4322 if (missiles)
4323 [self considerFiringMissile:delta_t];
4324
4325 if (cloakAutomatic)
4326 [self activateCloakingDevice];
4327 if (leftside) {
4328 [self firePortWeapon:range];
4329 } else {
4330 [self fireStarboardWeapon:range];
4331 }
4332
4334 behaviour = BEHAVIOUR_ATTACK_TARGET;
4335 }
4336}
#define COMBAT_BROADSIDE_RANGE_FACTOR
Definition ShipEntity.h:59
#define COMBAT_AI_WEAPON_TEMP_USABLE
Definition ShipEntity.h:120
GLfloat getWeaponRangeFromType(OOWeaponType weapon_type)
#define COMBAT_WEAPON_RANGE_FACTOR
Definition ShipEntity.h:60
GLfloat weapon_temp
Definition ShipEntity.h:303
float afterburnerFactor()
GLfloat success_factor
Definition ShipEntity.h:338

References activateCloakingDevice, afterburnerFactor, avoidCollision, behaviour, canStillTrackPrimaryTarget, cloakAutomatic, COMBAT_AI_WEAPON_TEMP_USABLE, COMBAT_BROADSIDE_IN_RANGE_FACTOR, COMBAT_BROADSIDE_RANGE_FACTOR, COMBAT_WEAPON_RANGE_FACTOR, considerFiringMissile:, desired_speed, firePortWeapon:, fireStarboardWeapon:, flightSpeed, frustration, fuel, getWeaponRangeFromType(), hasFuelInjection, isWeaponNone(), maxFlightSpeed, MIN_FUEL, missiles, nil, noteFrustration:, noteLostTargetAndGoIdle, port_weapon_type, primaryTarget, proximityAlert, rangeToPrimaryTarget, setEvasiveJink:, starboard_weapon_type, success_factor, trackSideTarget:leftside:, and weapon_temp.

Referenced by behaviour_attack_broadside_left:, and behaviour_attack_broadside_right:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_attack_fly_from_target:

- (void) behaviour_attack_fly_from_target: (double) delta_t

Definition at line 4733 of file ShipEntity.m.

4733 :(double)delta_t
4734{
4735 double range = [self rangeToPrimaryTarget];
4736 double last_success_factor = success_factor;
4737 success_factor = range;
4738
4739 if ([self primaryTarget] == nil) {
4740 [self noteLostTargetAndGoIdle];
4741 return;
4742 }
4743 if (last_success_factor > success_factor) // our target is closing in.
4744 {
4745 frustration += delta_t;
4746 } else { // not getting away fast enough?
4747 frustration += delta_t / 4.0;
4748 }
4749
4750 if (frustration > 10.0) {
4751 if (randf() < 0.3) {
4752 desired_speed = maxFlightSpeed * (([self hasFuelInjection] && (fuel > MIN_FUEL)) ? [self afterburnerFactor] : 1);
4753 } else if (range > COMBAT_IN_RANGE_FACTOR * weaponRange && randf() < 0.3) {
4754 behaviour = BEHAVIOUR_ATTACK_TARGET;
4755 }
4756 GLfloat z = jink.z;
4757 if (randf() < 0.3) {
4758 z /= 2; // move the z-offset closer to the target to let him fly away from the target.
4759 desired_speed = flightSpeed * 2; // increase speed a bit.
4760 }
4761 [self setEvasiveJink:z];
4762
4763 frustration /= 2.0;
4764 }
4766 ShipEntity* target = [self primaryTarget];
4767 double target_speed = [target speed];
4768 if (desired_speed > target_speed * 2.0) {
4769 desired_speed = maxFlightSpeed; // don't overuse the injectors
4770 }
4771 } else if (desired_speed < maxFlightSpeed * 0.5) {
4773 }
4774
4775 if (range > COMBAT_OUT_RANGE_FACTOR * weaponRange + 15.0 * jink.x || flightSpeed > (scannerRange - range) * max_flight_pitch / 6.28) {
4776 jink = kZeroVector;
4777 behaviour = BEHAVIOUR_ATTACK_TARGET;
4778 frustration = 0.0;
4779 }
4780 [self trackPrimaryTarget:delta_t retreat:YES];
4781
4782 if (missiles)
4783 [self considerFiringMissile:delta_t];
4784
4785 if (cloakAutomatic)
4786 [self activateCloakingDevice];
4787 if ([self hasProximityAlertIgnoringTarget:YES])
4788 [self avoidCollision];
4789
4791 double aspect = [self approachAspectToPrimaryTarget];
4792 // if we're right in their gunsights, dodge!
4793 // need to dodge sooner if in aft sights
4794 if (aspect > 0.99999 || aspect < -0.999) {
4795 frustration = 0.0;
4796 behaviour = BEHAVIOUR_EVASIVE_ACTION;
4797 }
4798 }
4799}
#define COMBAT_AI_FLEES_BETTER_2
Definition ShipEntity.h:135
#define COMBAT_IN_RANGE_FACTOR
Definition ShipEntity.h:56
GLfloat max_flight_pitch
Definition ShipEntity.h:230
GLfloat scannerRange

References accuracy, activateCloakingDevice, afterburnerFactor, approachAspectToPrimaryTarget, avoidCollision, behaviour, cloakAutomatic, COMBAT_AI_FLEES_BETTER_2, COMBAT_IN_RANGE_FACTOR, COMBAT_OUT_RANGE_FACTOR, considerFiringMissile:, desired_speed, flightSpeed, frustration, fuel, hasFuelInjection, jink, kZeroVector, max_flight_pitch, maxFlightSpeed, MIN_FUEL, missiles, nil, noteLostTargetAndGoIdle, primaryTarget, randf(), rangeToPrimaryTarget, scannerRange, setEvasiveJink:, Entity::speed, success_factor, trackPrimaryTarget:retreat:, and weaponRange.

Referenced by behaviour_close_to_broadside_range:, behaviour_close_with_target:, behaviour_fly_to_target_six:, and processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_attack_fly_to_target:

- (void) behaviour_attack_fly_to_target: (double) delta_t

Definition at line 4611 of file ShipEntity.m.

4611 :(double)delta_t
4612{
4613 BOOL canBurn = [self hasFuelInjection] && (fuel > MIN_FUEL);
4614 float max_available_speed = maxFlightSpeed;
4615 double range = [self rangeToPrimaryTarget];
4616 if (canBurn)
4617 max_available_speed *= [self afterburnerFactor];
4618 if ([self primaryTarget] == nil) {
4619 [self noteLostTargetAndGoIdle];
4620 return;
4621 }
4622 Entity* rawTarget = [self primaryTarget];
4623 if (![rawTarget isShip]) {
4624 // can't attack a wormhole
4625 [self noteLostTargetAndGoIdle];
4626 return;
4627 }
4628
4629 ShipEntity* target = (ShipEntity*)rawTarget;
4630 if ((range < COMBAT_IN_RANGE_FACTOR * weaponRange) || ([self proximityAlert] != nil)) {
4631 if (![self hasProximityAlertIgnoringTarget:YES]) {
4632 behaviour = BEHAVIOUR_ATTACK_TARGET;
4633 } else {
4634 [self avoidCollision];
4635 return;
4636 }
4637 } else {
4638 if (![self canStillTrackPrimaryTarget]) {
4639 [self noteLostTargetAndGoIdle];
4640 return;
4641 }
4642 }
4643
4644 // control speed
4645 //
4646 BOOL isUsingAfterburner = canBurn && (flightSpeed > maxFlightSpeed);
4647 BOOL closeQuickly = (canBurn && [target weaponRange] > weaponRange && range > weaponRange);
4648 double slow_down_range = weaponRange * COMBAT_WEAPON_RANGE_FACTOR * ((isUsingAfterburner) ? 3.0 * [self afterburnerFactor] : 1.0);
4649 if (closeQuickly) {
4650 slow_down_range = weaponRange * COMBAT_OUT_RANGE_FACTOR;
4651 }
4652 double back_off_range = 10000 * COMBAT_OUT_RANGE_FACTOR * ((isUsingAfterburner) ? 3.0 * [self afterburnerFactor] : 1.0);
4653 double target_speed = [target speed];
4654 double aspect = [self approachAspectToPrimaryTarget];
4655
4656 if (range <= slow_down_range) {
4657 if (range < back_off_range) {
4658 if (accuracy < COMBAT_AI_IS_SMART || ([target primaryTarget] == self && aspect > 0.8) || aim_tolerance * range > COMBAT_AI_CONFIDENCE_FACTOR) {
4659 if (accuracy >= COMBAT_AI_FLEES_BETTER && aspect > 0.8) {
4660 desired_speed = fmax(target_speed * 1.25, 0.8 * maxFlightSpeed);
4661 // stay at high speed if might be taking return fire
4662 } else {
4663 desired_speed = fmax(target_speed * 1.05, 0.25 * maxFlightSpeed); // within the weapon's range match speed
4664 }
4665 } else { // smart, and not being shot at right now - slow down to attack
4666 desired_speed = fmax(0.1 * target_speed, 0.1 * maxFlightSpeed);
4667 }
4668 } else {
4669 if (accuracy < COMBAT_AI_IS_SMART || ([target isShip] && [(ShipEntity*)target primaryTarget] == self) || range > weaponRange / 2.0) {
4670 desired_speed = fmax(target_speed * 1.5, maxFlightSpeed);
4671 } else { // smart, and not being shot at right now - slow down to attack
4672 if (aspect > -0.25) {
4673 desired_speed = fmax(0.5 * target_speed, 0.5 * maxFlightSpeed);
4674 } else {
4675 desired_speed = fmax(1.25 * target_speed, 0.5 * maxFlightSpeed);
4676 }
4677 }
4678 }
4679 } else {
4680 if (closeQuickly) {
4681 desired_speed = max_available_speed; // use afterburner to approach
4682 } else {
4683 desired_speed = fmax(maxFlightSpeed, fmin(3.0 * target_speed, max_available_speed)); // possibly use afterburner to approach
4684 }
4685 }
4686
4687 double last_success_factor = success_factor;
4688 success_factor = [self trackPrimaryTarget:delta_t retreat:NO]; // do the actual piloting
4689
4690 if ((success_factor > 0.999) || (success_factor > last_success_factor)) {
4691 frustration -= delta_t;
4692 if (frustration < 0.0)
4693 frustration = 0.0;
4694 } else {
4695 frustration += delta_t;
4696 if (frustration > 3.0) // 3s of frustration
4697 {
4698 [self noteFrustration:@"BEHAVIOUR_ATTACK_FLY_TO_TARGET"];
4699 [self setEvasiveJink:1000.0];
4700 behaviour = BEHAVIOUR_ATTACK_TARGET;
4701 frustration = 0.0;
4703 }
4704 }
4705
4706 if (missiles)
4707 [self considerFiringMissile:delta_t];
4708
4709 if (cloakAutomatic)
4710 [self activateCloakingDevice];
4711 [self fireMainWeapon:range];
4712
4714 // don't do this if the target is fleeing and the front laser is
4715 // the only weapon, or if we're too far away to use non-front
4716 // lasers effectively
4718 frustration = 0.0;
4719 behaviour = BEHAVIOUR_ATTACK_TARGET;
4720 }
4721 } else if (accuracy >= COMBAT_AI_FLEES_BETTER_2) {
4722 // if we're right in their gunsights, dodge!
4723 // need to dodge sooner if in aft sights
4724 if ([target behaviour] != BEHAVIOUR_FLEE_TARGET && [target behaviour] != BEHAVIOUR_FLEE_EVASIVE_ACTION) {
4725 if ((aspect > 0.99999 && !isWeaponNone([target weaponTypeForFacing:WEAPON_FACING_FORWARD strict:NO])) || (aspect < -0.999 && !isWeaponNone([target weaponTypeForFacing:WEAPON_FACING_AFT strict:NO]))) {
4726 frustration = 0.0;
4727 behaviour = BEHAVIOUR_EVASIVE_ACTION;
4728 }
4729 }
4730 }
4731}
@ WEAPON_FACING_FORWARD
Definition OOTypes.h:196
@ WEAPON_FACING_AFT
Definition OOTypes.h:197
#define COMBAT_AI_ISNT_AWFUL
Definition ShipEntity.h:124
#define COMBAT_AI_FLEES_BETTER
Definition ShipEntity.h:128
#define COMBAT_AI_CONFIDENCE_FACTOR
Definition ShipEntity.h:123
#define COMBAT_AI_IS_SMART
Definition ShipEntity.h:126
OOWeaponType aft_weapon_type
Definition ShipEntity.h:295
GLfloat aim_tolerance
Definition ShipEntity.h:364

References accuracy, activateCloakingDevice, aft_weapon_type, afterburnerFactor, aim_tolerance, approachAspectToPrimaryTarget, avoidCollision, behaviour, canStillTrackPrimaryTarget, cloakAutomatic, COMBAT_AI_CONFIDENCE_FACTOR, COMBAT_AI_FLEES_BETTER, COMBAT_AI_FLEES_BETTER_2, COMBAT_AI_IS_SMART, COMBAT_AI_ISNT_AWFUL, COMBAT_AI_WEAPON_TEMP_USABLE, COMBAT_IN_RANGE_FACTOR, COMBAT_OUT_RANGE_FACTOR, COMBAT_WEAPON_RANGE_FACTOR, considerFiringMissile:, desired_speed, fireMainWeapon:, flightSpeed, frustration, fuel, hasFuelInjection, Entity::isShip, isWeaponNone(), maxFlightSpeed, MIN_FUEL, missiles, nil, noteFrustration:, noteLostTargetAndGoIdle, port_weapon_type, primaryTarget, proximityAlert, rangeToPrimaryTarget, setEvasiveJink:, Entity::speed, starboard_weapon_type, success_factor, trackPrimaryTarget:retreat:, WEAPON_FACING_AFT, WEAPON_FACING_FORWARD, weapon_temp, and weaponRange.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_attack_mining_target:

- (void) behaviour_attack_mining_target: (double) delta_t

Definition at line 4582 of file ShipEntity.m.

4582 :(double)delta_t
4583{
4584 double range = [self rangeToPrimaryTarget];
4585 if (![self canStillTrackPrimaryTarget]) {
4586 [self noteLostTargetAndGoIdle];
4587 desired_speed = maxFlightSpeed * 0.375;
4588 return;
4589 } else if ((range < 650) || ([self proximityAlert] != nil)) {
4590 if ([self proximityAlert] == NO_TARGET) {
4591 desired_speed = range * maxFlightSpeed / (650.0 * 16.0);
4592 } else {
4593 [self avoidCollision];
4594 }
4595 } else {
4596 // we have a target, its within scanner range, and outside 650
4597 desired_speed = maxFlightSpeed * 0.875;
4598 }
4599
4600 [self trackPrimaryTarget:delta_t retreat:NO];
4601
4602 /* Don't open fire until within 3km - it doesn't take many mining
4603 * laser shots to destroy an asteroid, but some of these mining
4604 * ships are way too slow to effectively chase down the debris:
4605 * wait until reasonably close before trying to split it. */
4606 if (range < 3000) {
4607 [self fireMainWeapon:range];
4608 }
4609}

References avoidCollision, canStillTrackPrimaryTarget, desired_speed, fireMainWeapon:, maxFlightSpeed, nil, NO_TARGET, noteLostTargetAndGoIdle, proximityAlert, rangeToPrimaryTarget, and trackPrimaryTarget:retreat:.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_attack_slow_dogfight:

- (void) behaviour_attack_slow_dogfight: (double) delta_t

Definition at line 3944 of file ShipEntity.m.

3944 :(double)delta_t
3945{
3946 if (![self canStillTrackPrimaryTarget]) {
3947 [self noteLostTargetAndGoIdle];
3948 return;
3949 }
3950 if ([self hasProximityAlertIgnoringTarget:YES]) {
3951 [self avoidCollision];
3952 return;
3953 }
3954 double range = [self rangeToPrimaryTarget];
3955 ShipEntity* target = [self primaryTarget];
3956 double aspect = [self approachAspectToPrimaryTarget];
3957 if (range < 2.5 * (collision_radius + target->collision_radius) && [self proximityAlert] == target && aspect > 0) {
3959 [self avoidCollision];
3960 return;
3961 }
3962 if (aspect < -0.5 && range > COMBAT_IN_RANGE_FACTOR * weaponRange * 2.0) {
3963 behaviour = BEHAVIOUR_ATTACK_TARGET;
3964 } else if (aspect < -0.5) {
3965 // mostly behind target - try to stay there and keep up
3966 desired_speed = fmin(maxFlightSpeed * 0.5, [target speed] * 0.5);
3967 } else if (aspect < 0.3) {
3968 // to side of target - slow right down
3970 } else {
3971 // coming to front of target - accelerate for a quick getaway
3972 desired_speed = maxFlightSpeed * fmin(aspect * 2.5, 1.0);
3973 }
3974 if (aspect > 0.85) {
3975 behaviour = BEHAVIOUR_ATTACK_BREAK_OFF_TARGET;
3976 }
3977 if (aspect > 0.0) {
3978 frustration += delta_t;
3979 } else {
3980 frustration -= delta_t;
3981 }
3982 if (frustration > 10.0) {
3983 desired_speed /= 2.0;
3984 } else if (frustration < 0.0)
3985 frustration = 0.0;
3986
3987 [self trackPrimaryTarget:delta_t retreat:NO];
3988
3989 if (missiles)
3990 [self considerFiringMissile:delta_t];
3991
3992 if (cloakAutomatic)
3993 [self activateCloakingDevice];
3994}

References activateCloakingDevice, approachAspectToPrimaryTarget, avoidCollision, behaviour, canStillTrackPrimaryTarget, cloakAutomatic, Entity::collision_radius, COMBAT_IN_RANGE_FACTOR, considerFiringMissile:, desired_speed, frustration, maxFlightSpeed, missiles, noteLostTargetAndGoIdle, primaryTarget, proximityAlert, rangeToPrimaryTarget, Entity::speed, trackPrimaryTarget:retreat:, and weaponRange.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_attack_sniper:

- (void) behaviour_attack_sniper: (double) delta_t

Definition at line 4397 of file ShipEntity.m.

4397 :(double)delta_t
4398{
4399 if (![self canStillTrackPrimaryTarget]) {
4400 [self noteLostTargetAndGoIdle];
4401 return;
4402 }
4403 Entity* rawTarget = [self primaryTarget];
4404 if (![rawTarget isShip]) {
4405 // can't attack a wormhole
4406 [self noteLostTargetAndGoIdle];
4407 return;
4408 }
4409 ShipEntity* target = (ShipEntity*)rawTarget;
4410
4411 double range = [self rangeToPrimaryTarget];
4412 float max_available_speed = maxFlightSpeed;
4413
4414 if (range < 15000) {
4415 behaviour = BEHAVIOUR_ATTACK_TARGET;
4416 } else {
4417 if (range > weaponRange || range > scannerRange * 0.8) {
4418 BOOL canBurn = [self hasFuelInjection] && (fuel > MIN_FUEL);
4419 if (canBurn && [target weaponRange] > weaponRange && range > weaponRange) {
4420 // if outside maximum weapon range, but inside target weapon range
4421 // close to fight ASAP!
4422 max_available_speed *= [self afterburnerFactor];
4423 }
4424 desired_speed = max_available_speed;
4425 } else {
4426 desired_speed = max_available_speed / 10.0f;
4427 }
4428
4429 double last_success_factor = success_factor;
4430 success_factor = [self trackPrimaryTarget:delta_t retreat:NO];
4431
4432 if ((success_factor > 0.999) || (success_factor > last_success_factor)) {
4433 frustration -= delta_t;
4434 if (frustration < 0.0)
4435 frustration = 0.0;
4436 } else {
4437 frustration += delta_t;
4438 if (frustration > 3.0) // 3s of frustration
4439 {
4440 [self noteFrustration:@"BEHAVIOUR_ATTACK_SNIPER"];
4441 [self setEvasiveJink:1000.0];
4442 behaviour = BEHAVIOUR_ATTACK_TARGET;
4443 frustration = 0.0;
4445 }
4446 }
4447 }
4448
4449 if (missiles)
4450 [self considerFiringMissile:delta_t];
4451
4452 if (cloakAutomatic)
4453 [self activateCloakingDevice];
4454 [self fireMainWeapon:range];
4455
4457 behaviour = BEHAVIOUR_ATTACK_TARGET;
4458 }
4459}

References accuracy, activateCloakingDevice, afterburnerFactor, behaviour, canStillTrackPrimaryTarget, cloakAutomatic, COMBAT_AI_ISNT_AWFUL, COMBAT_AI_WEAPON_TEMP_USABLE, considerFiringMissile:, desired_speed, fireMainWeapon:, frustration, fuel, hasFuelInjection, Entity::isShip, maxFlightSpeed, MIN_FUEL, missiles, noteFrustration:, noteLostTargetAndGoIdle, primaryTarget, rangeToPrimaryTarget, scannerRange, setEvasiveJink:, success_factor, trackPrimaryTarget:retreat:, weapon_temp, and weaponRange.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_attack_target:

- (void) behaviour_attack_target: (double) delta_t

Definition at line 4038 of file ShipEntity.m.

4038 :(double)delta_t
4039{
4040 double range = [self rangeToPrimaryTarget];
4041
4042 if (cloakAutomatic)
4043 [self activateCloakingDevice];
4044
4045 /* Start of behaviour selection:
4046 * Anything beyond the basics should require accuracy >= COMBAT_AI_ISNT_AWFUL
4047 * Anything fancy should require accuracy >= COMBAT_AI_IS_SMART
4048 * If precise aim is required, behaviour should have accuracy >= COMBAT_AI_TRACKS_CLOSER
4049 * - CIM
4050 */
4051
4052 OOWeaponType forward_weapon_real_type = forward_weapon_type;
4053 GLfloat forward_weapon_real_temp = forward_weapon_temp;
4054
4055 // if forward weapon is actually on a subent
4056 if (isWeaponNone(forward_weapon_real_type)) {
4057 BOOL hasTurrets = NO;
4058 NSEnumerator* subEnum = [self shipSubEntityEnumerator];
4059 ShipEntity* se = nil;
4060 while (isWeaponNone(forward_weapon_real_type) && (se = [subEnum nextObject])) {
4061 forward_weapon_real_type = se->forward_weapon_type;
4062 forward_weapon_real_temp = se->forward_weapon_temp;
4063 if (se->behaviour == BEHAVIOUR_TRACK_AS_TURRET) {
4064 hasTurrets = YES;
4065 }
4066 }
4067 if (isWeaponNone(forward_weapon_real_type) && hasTurrets) { // safety for ships only equipped with turrets
4068 forward_weapon_real_type = OOWeaponTypeFromEquipmentIdentifierSloppy(@"EQ_WEAPON_PULSE_LASER");
4069 forward_weapon_real_temp = COMBAT_AI_WEAPON_TEMP_USABLE * 0.9;
4070 }
4071 }
4072
4073 if ([forward_weapon_real_type isTurretLaser]) {
4074 behaviour = BEHAVIOUR_ATTACK_FLY_TO_TARGET_TWELVE;
4075 } else {
4076 BOOL in_good_range = aim_tolerance * range < COMBAT_AI_CONFIDENCE_FACTOR;
4077
4078 BOOL aft_weapon_ready = !isWeaponNone(aft_weapon_type) && (aft_weapon_temp < COMBAT_AI_WEAPON_TEMP_READY) && in_good_range;
4079 BOOL forward_weapon_ready = !isWeaponNone(forward_weapon_real_type) && (forward_weapon_real_temp < COMBAT_AI_WEAPON_TEMP_READY); // does not require in_good_range
4080 BOOL port_weapon_ready = !isWeaponNone(port_weapon_type) && (port_weapon_temp < COMBAT_AI_WEAPON_TEMP_READY) && in_good_range;
4081 BOOL starboard_weapon_ready = !isWeaponNone(starboard_weapon_type) && (starboard_weapon_temp < COMBAT_AI_WEAPON_TEMP_READY) && in_good_range;
4082 // if no weapons cool enough to be good choices, be less picky
4083 BOOL weapons_heating = NO;
4084 if (!forward_weapon_ready && !aft_weapon_ready && !port_weapon_ready && !starboard_weapon_ready) {
4085 weapons_heating = YES;
4086 aft_weapon_ready = !isWeaponNone(aft_weapon_type) && (aft_weapon_temp < COMBAT_AI_WEAPON_TEMP_USABLE) && in_good_range;
4087 forward_weapon_ready = !isWeaponNone(forward_weapon_real_type) && (forward_weapon_real_temp < COMBAT_AI_WEAPON_TEMP_USABLE); // does not require in_good_range
4088 port_weapon_ready = !isWeaponNone(port_weapon_type) && (port_weapon_temp < COMBAT_AI_WEAPON_TEMP_USABLE) && in_good_range;
4089 starboard_weapon_ready = !isWeaponNone(starboard_weapon_type) && (starboard_weapon_temp < COMBAT_AI_WEAPON_TEMP_USABLE) && in_good_range;
4090 }
4091
4092 Entity* target = [self primaryTarget];
4093 double aspect = [self approachAspectToPrimaryTarget];
4094
4095 if (!forward_weapon_ready && !aft_weapon_ready && !port_weapon_ready && !starboard_weapon_ready) { // no usable weapons! Either not fitted or overheated
4096
4097 // if unarmed
4099 behaviour = BEHAVIOUR_ATTACK_FLY_FROM_TARGET;
4100 } else if (aspect > 0) {
4101 if (in_good_range) {
4102 if (accuracy >= COMBAT_AI_IS_SMART && randf() < 0.75) {
4103 behaviour = BEHAVIOUR_EVASIVE_ACTION;
4104 } else {
4105 behaviour = BEHAVIOUR_ATTACK_FLY_FROM_TARGET;
4106 }
4107 } else {
4108 // ready to get more accurate shots later
4109 behaviour = BEHAVIOUR_ATTACK_FLY_TO_TARGET;
4110 }
4111 } else {
4112 // if target is running away, stay on target
4113 // unless too close for safety
4114 if (range < COMBAT_IN_RANGE_FACTOR * weaponRange) {
4115 behaviour = BEHAVIOUR_ATTACK_FLY_FROM_TARGET;
4116 } else {
4117 behaviour = BEHAVIOUR_ATTACK_FLY_TO_TARGET;
4118 }
4119 }
4120 }
4121 // if our current target isn't targeting us, and we have some idea of how to fight, and our weapons are running hot, and we're fairly nearby
4122 else if (weapons_heating && accuracy >= COMBAT_AI_ISNT_AWFUL && [target isShip] && [(ShipEntity*)target primaryTarget] != self && range < COMBAT_OUT_RANGE_FACTOR * weaponRange) {
4123 // then back off a bit for weapons to cool so we get a good attack run later, rather than weaving closer
4124 float relativeSpeed = magnitude(vector_subtract([self velocity], [target velocity]));
4125 [self setEvasiveJink:(range + COMBAT_JINK_OFFSET - relativeSpeed / max_flight_pitch)];
4126 behaviour = BEHAVIOUR_ATTACK_FLY_FROM_TARGET;
4127 } else {
4130
4131 if (nearby && aft_weapon_ready) {
4132 jink = kZeroVector; // almost all behaviours
4133 behaviour = BEHAVIOUR_RUNNING_DEFENSE;
4134 } else if (nearby && (port_weapon_ready || starboard_weapon_ready)) {
4135 jink = kZeroVector; // almost all behaviours
4136 behaviour = BEHAVIOUR_ATTACK_BROADSIDE;
4137 } else if (nearby) {
4138 if (!pitching_over) // don't change jink in the middle of a sharp turn.
4139 {
4140 /*
4141 For most AIs, is behaviour_attack_target called as starting behaviour on every hit.
4142 Target can both fly towards or away from ourselves here. Both situations
4143 need a different jink.z for optimal collision avoidance at high speed approach and low speed dogfighting.
4144 The COMBAT_JINK_OFFSET intentionally over-compensates the range for collision radii to send ships towards
4145 the target at low speeds.
4146 */
4147 float relativeSpeed = magnitude(vector_subtract([self velocity], [target velocity]));
4148 [self setEvasiveJink:(range + COMBAT_JINK_OFFSET - relativeSpeed / max_flight_pitch)];
4149 }
4150 // good pilots use behaviour_attack_break_off_target instead
4152 behaviour = BEHAVIOUR_ATTACK_BREAK_OFF_TARGET;
4153 } else {
4154 behaviour = BEHAVIOUR_ATTACK_FLY_FROM_TARGET;
4155 }
4156 } else if (forward_weapon_ready) {
4157 jink = kZeroVector; // almost all behaviours
4158
4159 // TODO: good pilots use behaviour_attack_sniper sometimes
4160 if (getWeaponRangeFromType(forward_weapon_real_type) > 12500 && range > 12500) {
4161 behaviour = BEHAVIOUR_ATTACK_SNIPER;
4162 }
4163 // generally not good tactics the next two
4164 else if (accuracy < COMBAT_AI_ISNT_AWFUL && aspect < 0) {
4165 behaviour = BEHAVIOUR_ATTACK_FLY_TO_TARGET_SIX;
4166 } else if (accuracy < COMBAT_AI_ISNT_AWFUL) {
4167 behaviour = BEHAVIOUR_ATTACK_FLY_TO_TARGET_TWELVE;
4168 } else {
4169 behaviour = BEHAVIOUR_ATTACK_FLY_TO_TARGET;
4170 }
4171 } else if (port_weapon_ready || starboard_weapon_ready) {
4172 jink = kZeroVector; // almost all behaviours
4173 behaviour = BEHAVIOUR_ATTACK_BROADSIDE;
4174 } else if (aft_weapon_ready && midrange) {
4175 jink = kZeroVector; // almost all behaviours
4176 behaviour = BEHAVIOUR_RUNNING_DEFENSE;
4177 } else {
4178 jink = kZeroVector; // almost all behaviours
4179 behaviour = BEHAVIOUR_ATTACK_FLY_TO_TARGET;
4180 }
4181 }
4182 }
4183
4184 frustration = 0.0; // behaviour changed, so reset frustration
4185}
OOINLINE Vector vector_subtract(Vector a, Vector b) INLINE_CONST_FUNC
Definition OOVector.h:218
OOEquipmentType * OOWeaponType
Definition ShipEntity.h:164
OOWeaponType OOWeaponTypeFromEquipmentIdentifierSloppy(NSString *string) PURE_FUNC
GLfloat aft_weapon_temp
Definition ShipEntity.h:304
OOWeaponType forward_weapon_type
Definition ShipEntity.h:294

References accuracy, activateCloakingDevice, aft_weapon_temp, aft_weapon_type, aim_tolerance, approachAspectToPrimaryTarget, behaviour, cloakAutomatic, COMBAT_AI_CONFIDENCE_FACTOR, COMBAT_AI_FLEES_BETTER, COMBAT_AI_IS_SMART, COMBAT_AI_ISNT_AWFUL, COMBAT_AI_WEAPON_TEMP_READY, COMBAT_AI_WEAPON_TEMP_USABLE, COMBAT_IN_RANGE_FACTOR, COMBAT_OUT_RANGE_FACTOR, forward_weapon_temp, forward_weapon_type, frustration, getWeaponRangeFromType(), Entity::isShip, isWeaponNone(), jink, kZeroVector, magnitude(), nil, OOWeaponTypeFromEquipmentIdentifierSloppy(), pitching_over, port_weapon_temp, port_weapon_type, primaryTarget, randf(), rangeToPrimaryTarget, setEvasiveJink:, shipSubEntityEnumerator, starboard_weapon_temp, starboard_weapon_type, vector_subtract(), velocity, and weaponRange.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_avoid_collision:

- (void) behaviour_avoid_collision: (double) delta_t

Definition at line 5155 of file ShipEntity.m.

5155 :(double)delta_t
5156{
5157 double distance = [self rangeToDestination];
5158 if (distance > desired_range) {
5159 [self resumePostProximityAlert];
5160 } else {
5161 ShipEntity* prox_ship = (ShipEntity*)[self proximityAlert];
5162 if (prox_ship) {
5164 _destination = prox_ship->position;
5165 }
5166 double dq = [self trackDestination:delta_t retreat:YES]; // returns 0 when heading towards prox_ship
5167 // Heading towards target with desired_speed > 0, avoids collisions better than setting desired_speed to zero.
5168 // (tested with boa class cruiser on collisioncourse with buoy)
5169 desired_speed = maxFlightSpeed * (0.5 * dq + 0.5);
5170 }
5171}

References _destination, Entity::collision_radius, desired_range, desired_speed, distance(), maxFlightSpeed, Entity::position, PROXIMITY_AVOID_DISTANCE_FACTOR, proximityAlert, rangeToDestination, resumePostProximityAlert, and trackDestination:retreat:.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_close_to_broadside_range:

- (void) behaviour_close_to_broadside_range: (double) delta_t

Definition at line 4338 of file ShipEntity.m.

4338 :(double)delta_t
4339{
4340 double range = [self rangeToPrimaryTarget];
4341 if ([self proximityAlert] != nil) {
4342 if ([self proximityAlert] == [self primaryTarget]) {
4343 behaviour = BEHAVIOUR_ATTACK_FLY_TO_TARGET; // this behaviour will handle proximity_alert.
4344 [self behaviour_attack_fly_from_target:delta_t]; // do it now.
4345 } else {
4346 [self avoidCollision];
4347 }
4348 return;
4349 }
4350 if (![self canStillTrackPrimaryTarget]) {
4351 [self noteLostTargetAndGoIdle];
4352 return;
4353 }
4354
4355 behaviour = BEHAVIOUR_ATTACK_FLY_TO_TARGET_TWELVE;
4356 [self behaviour_fly_to_target_six:delta_t];
4358 [self setWeaponDataFromType:port_weapon_type];
4359 } else {
4360 [self setWeaponDataFromType:starboard_weapon_type];
4361 }
4363 behaviour = BEHAVIOUR_ATTACK_BROADSIDE;
4364 } else {
4365 behaviour = BEHAVIOUR_CLOSE_TO_BROADSIDE_RANGE;
4366 }
4367}

References avoidCollision, behaviour, behaviour_attack_fly_from_target:, behaviour_fly_to_target_six:, canStillTrackPrimaryTarget, COMBAT_BROADSIDE_RANGE_FACTOR, isWeaponNone(), nil, noteLostTargetAndGoIdle, port_weapon_type, primaryTarget, proximityAlert, rangeToPrimaryTarget, setWeaponDataFromType:, and weaponRange.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_close_with_target:

- (void) behaviour_close_with_target: (double) delta_t

Definition at line 4369 of file ShipEntity.m.

4369 :(double)delta_t
4370{
4371 double range = [self rangeToPrimaryTarget];
4372 if ([self proximityAlert] != nil) {
4373 if ([self proximityAlert] == [self primaryTarget]) {
4374 behaviour = BEHAVIOUR_ATTACK_FLY_TO_TARGET; // this behaviour will handle proximity_alert.
4375 [self behaviour_attack_fly_from_target:delta_t]; // do it now.
4376 } else {
4377 [self avoidCollision];
4378 }
4379 return;
4380 }
4381 if (![self canStillTrackPrimaryTarget]) {
4382 [self noteLostTargetAndGoIdle];
4383 return;
4384 }
4385 behaviour = BEHAVIOUR_ATTACK_FLY_TO_TARGET_TWELVE;
4386 double saved_frustration = frustration;
4387 [self behaviour_fly_to_target_six:delta_t];
4388 frustration = saved_frustration; // ignore fly-to-12 frustration
4389 frustration += delta_t;
4390 if (range <= COMBAT_IN_RANGE_FACTOR * weaponRange || frustration > 5.0) {
4391 behaviour = BEHAVIOUR_ATTACK_TARGET;
4392 } else {
4393 behaviour = BEHAVIOUR_CLOSE_WITH_TARGET;
4394 }
4395}

References avoidCollision, behaviour, behaviour_attack_fly_from_target:, behaviour_fly_to_target_six:, canStillTrackPrimaryTarget, frustration, nil, noteLostTargetAndGoIdle, primaryTarget, proximityAlert, and rangeToPrimaryTarget.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_evasive_action:

- (void) behaviour_evasive_action: (double) delta_t

Definition at line 3996 of file ShipEntity.m.

3996 :(double)delta_t
3997{
3998 BOOL canBurn = [self hasFuelInjection] && (fuel > MIN_FUEL);
3999 float max_available_speed = maxFlightSpeed;
4000 // double range = [self rangeToPrimaryTarget];
4001 if (canBurn)
4002 max_available_speed *= [self afterburnerFactor];
4003 desired_speed = max_available_speed;
4005 ShipEntity* target = [self primaryTarget];
4006 double target_speed = [target speed];
4007 if (desired_speed > target_speed) {
4008 desired_speed = maxFlightSpeed; // don't overuse the injectors
4009 }
4010 }
4011
4012 if (cloakAutomatic)
4013 [self activateCloakingDevice];
4014 if ([self proximityAlert] != nil) {
4015 [self avoidCollision];
4016 return;
4017 }
4018
4019 [self evasiveAction:delta_t];
4020
4021 frustration += delta_t;
4022
4023 if (frustration > 0.5) {
4024 if (behaviour == BEHAVIOUR_FLEE_EVASIVE_ACTION) {
4025 [self setEvasiveJink:400.0];
4026 behaviour = BEHAVIOUR_FLEE_TARGET;
4027 } else {
4028 behaviour = BEHAVIOUR_ATTACK_TARGET;
4029 }
4030 }
4031
4032 flightYaw = 0.0;
4033
4034 // probably only useful for Thargoids, except for the occasional opportunist
4035 [self fireMainWeapon:[self rangeToPrimaryTarget]];
4036}

References activateCloakingDevice, afterburnerFactor, avoidCollision, behaviour, cloakAutomatic, desired_speed, evasiveAction:, fireMainWeapon:, flightYaw, frustration, fuel, hasFuelInjection, maxFlightSpeed, MIN_FUEL, nil, primaryTarget, proximityAlert, rangeToPrimaryTarget, setEvasiveJink:, and Entity::speed.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_face_destination:

- (void) behaviour_face_destination: (double) delta_t

Definition at line 4920 of file ShipEntity.m.

4920 :(double)delta_t
4921{
4922 double max_cos = MAX_COS;
4923 double distance = [self rangeToDestination];
4924 double old_pitch = flightPitch;
4925 desired_speed = 0.0;
4926 if (desired_range > 1.0 && distance > desired_range) {
4927 max_cos = sqrt(1 - 0.90 * desired_range * desired_range / (distance * distance)); // Head for a point within 95% of desired_range (must match the value in trackDestination)
4928 }
4929 double confidenceFactor = [self trackDestination:delta_t retreat:NO];
4930 if (confidenceFactor >= max_cos && flightPitch == 0.0) {
4931 // desired facing achieved and movement stabilised.
4932 [shipAI message:@"FACING_DESTINATION"];
4933 [self doScriptEvent:OOJSID("shipNowFacingDestination")];
4934 frustration = 0.0;
4935 if (docking_match_rotation) // IDLE stops rotating while docking
4936 {
4937 behaviour = BEHAVIOUR_FLY_TO_DESTINATION;
4938 } else {
4939 behaviour = BEHAVIOUR_IDLE;
4940 }
4941 }
4942
4943 if (flightSpeed == 0)
4944 frustration += delta_t;
4945 if (frustration > 15.0 / max_flight_pitch) // allow more time for slow ships.
4946 {
4947 frustration = 0.0;
4948 [self noteFrustration:@"BEHAVIOUR_FACE_DESTINATION"];
4949 if (flightPitch == old_pitch)
4950 flightPitch = 0.5 * max_flight_pitch; // hack to get out of frustration.
4951 }
4952
4953 /* 2009-7-18 Eric: the condition check below is intended to eliminate the flippering between two positions for fast turning ships
4954 during low FPS conditions. This flippering is particular frustrating on slow computers during docking. But with my current computer I can't
4955 induce those low FPS conditions so I can't properly test if it helps.
4956 I did try with the TAF time acceleration that also generated larger frame jumps and than it seemed to help.
4957 */
4958 if (flightSpeed == 0 && frustration > 5 && confidenceFactor > 0.5 && ((flightPitch > 0 && old_pitch < 0) || (flightPitch < 0 && old_pitch > 0))) {
4959 flightPitch += 0.5 * old_pitch; // damping with last pitch value.
4960 }
4961
4962 if ([self hasProximityAlertIgnoringTarget:YES]) {
4963 [self avoidCollision];
4964 }
4965}
#define MAX_COS
Definition ShipEntity.h:142
unsigned docking_match_rotation
Definition ShipEntity.h:240

References avoidCollision, behaviour, desired_range, desired_speed, distance(), docking_match_rotation, doScriptEvent:, flightPitch, flightSpeed, frustration, MAX_COS, max_flight_pitch, AI::message:, noteFrustration:, rangeToDestination, and trackDestination:retreat:.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_flee_target:

- (void) behaviour_flee_target: (double) delta_t

Definition at line 4840 of file ShipEntity.m.

4840 :(double)delta_t
4841{
4842 BOOL canBurn = [self hasFuelInjection] && (fuel > MIN_FUEL);
4843 float max_available_speed = maxFlightSpeed;
4844 double range = [self rangeToPrimaryTarget];
4845 if ([self primaryTarget] == nil) {
4846 [self noteLostTargetAndGoIdle];
4847 return;
4848 }
4849 if (canBurn)
4850 max_available_speed *= [self afterburnerFactor];
4851
4852 double last_range = success_factor;
4853 success_factor = range;
4854
4855 if (range > desired_range || range == 0)
4856 [shipAI message:@"REACHED_SAFETY"];
4857 else
4858 desired_speed = max_available_speed;
4859
4860 if (range > last_range) // improvement
4861 {
4862 frustration -= 0.25 * delta_t;
4863 if (frustration < 0.0)
4864 frustration = 0.0;
4865 } else {
4866 frustration += delta_t;
4867 if (frustration > 15.0) // 15s of frustration
4868 {
4869 [self noteFrustration:@"BEHAVIOUR_FLEE_TARGET"];
4870 frustration = 0.0;
4871 }
4872 }
4873
4874 [self trackPrimaryTarget:delta_t retreat:YES];
4875
4876 Entity* target = [self primaryTarget];
4877
4878 if (missiles && [target isShip] && [(ShipEntity*)target primaryTarget] == self) {
4879 [self considerFiringMissile:delta_t];
4880 }
4881
4882 if (([self hasCascadeMine]) && (range < 10000.0) && canBurn) {
4883 float qbomb_chance = 0.01 * delta_t;
4884 if (randf() < qbomb_chance) {
4885 [self launchCascadeMine];
4886 }
4887 }
4888
4889 // thargoids won't normally be fleeing, but if they do, they can still shoot
4890 if ([forward_weapon_type isTurretLaser]) {
4891 [self fireMainWeapon:range];
4892 }
4893
4894 if (cloakAutomatic)
4895 [self activateCloakingDevice];
4896
4897 // remember to look where you're going?
4898 if (accuracy >= COMBAT_AI_ISNT_AWFUL && [self hasProximityAlertIgnoringTarget:YES]) {
4899 [self avoidCollision];
4900 }
4901}
BOOL hasCascadeMine()

References accuracy, activateCloakingDevice, afterburnerFactor, avoidCollision, cloakAutomatic, COMBAT_AI_ISNT_AWFUL, considerFiringMissile:, desired_range, desired_speed, fireMainWeapon:, forward_weapon_type, frustration, fuel, hasCascadeMine, hasFuelInjection, Entity::isShip, launchCascadeMine, maxFlightSpeed, AI::message:, MIN_FUEL, missiles, nil, noteFrustration:, noteLostTargetAndGoIdle, primaryTarget, randf(), rangeToPrimaryTarget, success_factor, and trackPrimaryTarget:retreat:.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_fly_from_destination:

- (void) behaviour_fly_from_destination: (double) delta_t

Definition at line 5136 of file ShipEntity.m.

5136 :(double)delta_t
5137{
5138 double distance = [self rangeToDestination];
5139 if (distance > desired_range) {
5140 // desired range achieved
5141 [shipAI message:@"DESIRED_RANGE_ACHIEVED"];
5142 [self doScriptEvent:OOJSID("shipAchievedDesiredRange")];
5143
5144 behaviour = BEHAVIOUR_IDLE;
5145 frustration = 0.0;
5146 desired_speed = 0.0;
5147 }
5148
5149 [self trackDestination:delta_t retreat:YES];
5150 if ([self hasProximityAlertIgnoringTarget:YES]) {
5151 [self avoidCollision];
5152 }
5153}

References avoidCollision, behaviour, desired_range, desired_speed, distance(), doScriptEvent:, frustration, AI::message:, rangeToDestination, and trackDestination:retreat:.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_fly_range_from_destination:

- (void) behaviour_fly_range_from_destination: (double) delta_t

Definition at line 4903 of file ShipEntity.m.

4903 :(double)delta_t
4904{
4905 double distance = [self rangeToDestination];
4906 if (distance < desired_range) {
4907 behaviour = BEHAVIOUR_FLY_FROM_DESTINATION;
4909 desired_speed = maxFlightSpeed; // Not all AI define speed when flying away. Start with max speed to stay compatible with such AI's, but allow faster flight if it's (e.g.) used to flee from coordinates rather than entity
4910 }
4911 } else {
4912 behaviour = BEHAVIOUR_FLY_TO_DESTINATION;
4913 }
4914 if ([self hasProximityAlertIgnoringTarget:YES]) {
4915 [self avoidCollision];
4916 }
4917 frustration = 0.0;
4918}

References avoidCollision, behaviour, desired_range, desired_speed, distance(), frustration, maxFlightSpeed, and rangeToDestination.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_fly_thru_navpoints:

- (void) behaviour_fly_thru_navpoints: (double) delta_t

Definition at line 5223 of file ShipEntity.m.

5223 :(double)delta_t
5224{
5225 int navpoint_plus_index = (next_navpoint_index + 1) % number_of_navpoints;
5226 HPVector d1 = navpoints[next_navpoint_index]; // head for this one
5227 HPVector d2 = navpoints[navpoint_plus_index]; // but be facing this one
5228
5229 HPVector rel = HPvector_between(d1, position); // vector from d1 to position
5230 HPVector ref = HPvector_between(d2, d1); // vector from d2 to d1
5231 ref = HPvector_normal(ref);
5232
5233 HPVector xp = make_HPvector(ref.y * rel.z - ref.z * rel.y, ref.z * rel.x - ref.x * rel.z, ref.x * rel.y - ref.y * rel.x);
5234
5235 GLfloat v0 = 0.0;
5236
5237 GLfloat r0 = HPdot_product(rel, ref); // proportion of rel in direction ref
5238
5239 // if r0 is negative then we're the wrong side of things
5240
5241 GLfloat r1 = HPmagnitude(xp); // distance of position from line
5242
5243 BOOL in_cone = (r0 > 0.5 * r1);
5244
5245 if (!in_cone) // are we in the approach cone ?
5246 r1 = 25.0 * flightSpeed; // aim a few km out!
5247 else
5248 r1 *= 2.0;
5249
5250 GLfloat dist2 = HPmagnitude2(rel);
5251
5252 if (dist2 < desired_range * desired_range) {
5253 // desired range achieved
5254 [self doScriptEvent:OOJSID("shipReachedNavPoint") andReactToAIMessage:@"NAVPOINT_REACHED"];
5255 if (navpoint_plus_index == 0) {
5256 [self doScriptEvent:OOJSID("shipReachedEndPoint") andReactToAIMessage:@"ENDPOINT_REACHED"];
5257 behaviour = BEHAVIOUR_IDLE;
5258 }
5259 next_navpoint_index = navpoint_plus_index; // loop as required
5260 } else {
5261 double last_success_factor = success_factor;
5262 double last_dist2 = last_success_factor;
5263 success_factor = dist2;
5264
5265 // set destination spline point from r1 and ref
5266 _destination = make_HPvector(d1.x + r1 * ref.x, d1.y + r1 * ref.y, d1.z + r1 * ref.z);
5267
5268 // do the actual piloting!!
5269 //
5270 // aim to within 1m
5271 GLfloat temp = desired_range;
5272 if (in_cone)
5273 desired_range = 1.0;
5274 else
5275 desired_range = 100.0;
5276 v0 = [self trackDestination:delta_t retreat:NO];
5277 desired_range = temp;
5278
5279 if (dist2 < last_dist2) // improvement
5280 {
5281 frustration -= 0.25 * delta_t;
5282 if (frustration < 0.0)
5283 frustration = 0.0;
5284 } else {
5285 frustration += delta_t;
5286 if (frustration > 15.0) // 15s of frustration
5287 {
5288 [self noteFrustration:@"BEHAVIOUR_FLY_THRU_NAVPOINTS"];
5289 frustration -= 15.0; // repeat after another 15s of frustration
5290 }
5291 }
5292 }
5293
5294 GLfloat temp = desired_speed;
5295 desired_speed *= v0 * v0;
5296
5297 desired_speed = temp;
5298}
OOINLINE OOHPScalar HPdot_product(HPVector first, HPVector second) INLINE_CONST_FUNC
Definition OOHPVector.h:317
OOINLINE HPVector make_HPvector(OOHPScalar vx, OOHPScalar vy, OOHPScalar vz) INLINE_CONST_FUNC
Definition OOHPVector.h:149
OOINLINE HPVector HPvector_normal(HPVector vec) INLINE_CONST_FUNC
Definition OOHPVector.h:288
#define HPvector_between(a, b)
Definition OOHPVector.h:83
OOINLINE OOHPScalar HPmagnitude2(HPVector vec) INLINE_CONST_FUNC
Definition OOHPVector.h:255
unsigned number_of_navpoints
Definition ShipEntity.h:408
HPVector navpoints[32]
Definition ShipEntity.h:406
unsigned next_navpoint_index
Definition ShipEntity.h:407

References _destination, behaviour, desired_range, desired_speed, doScriptEvent:andReactToAIMessage:, flightSpeed, frustration, HPdot_product(), HPmagnitude(), HPmagnitude2(), HPvector_between, HPvector_normal(), make_HPvector(), navpoints, next_navpoint_index, noteFrustration:, number_of_navpoints, Entity::position, success_factor, trackDestination:retreat:, HPVector::x, HPVector::y, and HPVector::z.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_fly_to_destination:

- (void) behaviour_fly_to_destination: (double) delta_t

Definition at line 5049 of file ShipEntity.m.

5049 :(double)delta_t
5050{
5051 double distance = [self rangeToDestination];
5052 // double desiredRange = (dockingInstructions != nil) ? 1.2 * desired_range : desired_range; // stop a bit earlyer when docking.
5053 if (distance < desired_range) // + collision_radius)
5054 {
5055 // desired range achieved
5056 [shipAI message:@"DESIRED_RANGE_ACHIEVED"];
5057 [self doScriptEvent:OOJSID("shipAchievedDesiredRange")];
5058
5059 if (!docking_match_rotation) // IDLE stops rotating while docking
5060 {
5061 behaviour = BEHAVIOUR_IDLE;
5062 desired_speed = 0.0;
5063 }
5064 frustration = 0.0;
5065 } else {
5066 double last_distance = success_factor;
5068
5069 // do the actual piloting!!
5070 double confidenceFactor = [self trackDestination:delta_t retreat:NO];
5071 if (confidenceFactor < 0.2)
5072 confidenceFactor = 0.2; // don't allow small or negative values.
5073
5074 /* 2009-07-19 Eric: Estimated Time of Arrival (eta) should also take the "angle to target" into account (confidenceFactor = cos(angle to target))
5075 and should not fuss about that last meter and use "distance + 1" instead of just "distance".
5076 trackDestination already did pitch regulation, use confidence here only for cutting down to high speeds.
5077 This should prevent ships crawling to their destination when they try to pull up close to their destination.
5078
5079 To prevent ships circling around their target without reaching destination I added a limitation based on turnrate,
5080 speed and distance to target. Formula based on satelite orbit:
5081 orbitspeed = turnrate (rad/sec) * radius (m) or flightSpeed = max_flight_pitch * 2 Pi * distance
5082 Speed must be significant lower when not flying in direction of target (low confidenceFactor) or it can never approach its destination
5083 and the ships runs the risk flying in circles around the target. (exclude active escorts)
5084 */
5085 GLfloat eta = ((distance + 1) - desired_range) / (0.51 * flightSpeed * confidenceFactor); // 2% safety margin assuming an average of half current speed
5086 GLfloat slowdownTime = (thrust > 0.0) ? flightSpeed / (thrust) : 4.0;
5087 GLfloat minTurnSpeedFactor = 0.05 * max_flight_pitch * max_flight_roll; // faster turning implies higher speeds
5088 if (dockingInstructions != nil) {
5089 minTurnSpeedFactor /= 10.0;
5090 if (minTurnSpeedFactor * maxFlightSpeed > 20.0) {
5091 minTurnSpeedFactor /= 10.0;
5092 }
5093 }
5094
5095 if (((eta < slowdownTime) && (flightSpeed > maxFlightSpeed * minTurnSpeedFactor)) || (flightSpeed > max_flight_pitch * 5 * confidenceFactor * distance)) {
5096 desired_speed = flightSpeed * 0.50; // cut speed by 50% to a minimum minTurnSpeedFactor of speed
5097 }
5098
5099 /* Flight correction block to prevent one possible form of
5100 * crashes in late docking process */
5101 if (docking_match_rotation && confidenceFactor >= MAX_COS && dockingInstructions != nil && [dockingInstructions oo_intForKey:@"docking_stage"] >= 7) {
5102 // then at this point should be rotating to match the station
5103 StationEntity* station_for_docking = (StationEntity*)[self targetStation];
5104
5105 if ((station_for_docking) && (station_for_docking->isStation)) {
5106 float rollMatch = dot_product([station_for_docking portUpVectorForShip:self], [self upVector]);
5107 if (rollMatch < MAX_COS && rollMatch > -MAX_COS) {
5108 // not matching rotating - stop until corrected
5109 desired_speed = 0.1;
5110 } else if (desired_speed <= 0.2) {
5111 // had previously paused, so return to normal speed
5112 desired_speed = [dockingInstructions oo_floatForKey:@"speed"];
5113 }
5114 }
5115 }
5116
5117 if (distance < last_distance) // improvement
5118 {
5119 frustration -= 0.25 * delta_t;
5120 if (frustration < 0.0)
5121 frustration = 0.0;
5122 } else {
5123 frustration += delta_t;
5124 if ((frustration > slowdownTime * 10.0 && slowdownTime > 0) || (frustration > 15.0)) // 10x slowdownTime or 15s of frustration
5125 {
5126 [self noteFrustration:@"BEHAVIOUR_FLY_TO_DESTINATION"];
5127 frustration -= slowdownTime * 5.0; // repeat after another five units of frustration
5128 }
5129 }
5130 }
5131 if ([self hasProximityAlertIgnoringTarget:YES]) {
5132 [self avoidCollision];
5133 }
5134}
unsigned isStation
Definition Entity.m:135
Vector upVector()
NSDictionary * dockingInstructions
StationEntity * targetStation()

References avoidCollision, behaviour, desired_range, desired_speed, distance(), docking_match_rotation, dockingInstructions, doScriptEvent:, dot_product(), flightSpeed, frustration, Entity::isStation, MAX_COS, max_flight_pitch, max_flight_roll, maxFlightSpeed, AI::message:, nil, noteFrustration:, rangeToDestination, success_factor, targetStation, thrust, trackDestination:retreat:, and upVector.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_fly_to_target_six:

- (void) behaviour_fly_to_target_six: (double) delta_t

Definition at line 4461 of file ShipEntity.m.

4461 :(double)delta_t
4462{
4463 BOOL canBurn = [self hasFuelInjection] && (fuel > MIN_FUEL);
4464 float max_available_speed = maxFlightSpeed;
4465 double range = [self rangeToPrimaryTarget];
4466 if (canBurn)
4467 max_available_speed *= [self afterburnerFactor];
4468
4469 // deal with collisions and lost targets
4470 if ([self proximityAlert] != nil) {
4471 if ([self proximityAlert] == [self primaryTarget]) {
4472 behaviour = BEHAVIOUR_ATTACK_FLY_TO_TARGET; // this behaviour will handle proximity_alert.
4473 [self behaviour_attack_fly_from_target:delta_t]; // do it now.
4474 } else {
4475 [self avoidCollision];
4476 }
4477 return;
4478 }
4479 if (![self canStillTrackPrimaryTarget]) {
4480 [self noteLostTargetAndGoIdle];
4481 return;
4482 }
4483
4484 // control speed
4485 BOOL isUsingAfterburner = canBurn && (flightSpeed > maxFlightSpeed);
4486 BOOL closeQuickly = (canBurn && range > weaponRange);
4487 double slow_down_range = weaponRange * COMBAT_WEAPON_RANGE_FACTOR * ((isUsingAfterburner) ? 3.0 * [self afterburnerFactor] : 1.0);
4488 if (closeQuickly) {
4489 slow_down_range = weaponRange * COMBAT_OUT_RANGE_FACTOR;
4490 }
4491 double back_off_range = weaponRange * COMBAT_OUT_RANGE_FACTOR * ((isUsingAfterburner) ? 3.0 * [self afterburnerFactor] : 1.0);
4492 Entity* rawTarget = [self primaryTarget];
4493 if (![rawTarget isShip]) {
4494 [self noteLostTargetAndGoIdle];
4495 return;
4496 }
4497 ShipEntity* target = (ShipEntity*)rawTarget;
4498 double target_speed = [target speed];
4499 double last_success_factor = success_factor;
4500 double distance = [self rangeToDestination];
4502
4503 if (range < slow_down_range && (behaviour == BEHAVIOUR_ATTACK_FLY_TO_TARGET_SIX)) {
4504 if (range < back_off_range) {
4505 desired_speed = fmax(0.9 * target_speed, 0.4 * maxFlightSpeed);
4506 } else {
4507 desired_speed = fmax(target_speed * 1.2, maxFlightSpeed);
4508 }
4509
4510 // avoid head-on collision
4511 if ((range < 0.5 * distance) && (behaviour == BEHAVIOUR_ATTACK_FLY_TO_TARGET_SIX))
4512 behaviour = BEHAVIOUR_ATTACK_FLY_TO_TARGET_TWELVE;
4513 } else {
4514 if (range < back_off_range) {
4515 desired_speed = fmax(0.9 * target_speed, 0.8 * maxFlightSpeed);
4516 } else {
4517 desired_speed = max_available_speed; // use afterburner to approach
4518 }
4519 }
4520
4521 // if within 0.75km of the target's six or twelve, or if target almost at standstill for 62.5% of non-thargoid ships (!),
4522 // then vector in attack.
4523 if (distance < 750.0 || (target_speed < 0.2 && ![self isThargoid] && ([self universalID] & 14) > 4)) {
4524 behaviour = BEHAVIOUR_ATTACK_FLY_TO_TARGET;
4525 frustration = 0.0;
4526 desired_speed = fmax(target_speed, 0.4 * maxFlightSpeed); // within the weapon's range don't use afterburner
4527 }
4528
4529 // target-six
4530 if (behaviour == BEHAVIOUR_ATTACK_FLY_TO_TARGET_SIX) {
4531 // head for a point weapon-range * 0.5 to the six of the target
4532 //
4533 _destination = [target distance_six:0.5 * weaponRange];
4534 }
4535 // target-twelve
4536 if (behaviour == BEHAVIOUR_ATTACK_FLY_TO_TARGET_TWELVE) {
4537 if ([forward_weapon_type isTurretLaser]) {
4538 // head for a point near the target, avoiding common Galcop weapon mount locations
4539 // TODO: this should account for weapon ranges
4540 GLfloat offset = 1000.0;
4541 GLfloat spacing = 2000.0;
4542 if (accuracy > 0.0) {
4543 offset = accuracy * 750.0;
4544 spacing = 2000.0 + (accuracy * 500.0);
4545 }
4546 if (entity_personality & 1) { // half at random
4547 offset = -offset;
4548 }
4549 _destination = [target distance_twelve:spacing withOffset:offset];
4550 } else {
4551 // head for a point 1.25km above the target
4552 _destination = [target distance_twelve:1250 withOffset:0];
4553 }
4554 }
4555
4556 pitching_over = NO; // in case it's set from elsewhere
4557 double confidenceFactor = [self trackDestination:delta_t retreat:NO];
4558
4559 if (success_factor > last_success_factor || confidenceFactor < 0.85)
4560 frustration += delta_t;
4561 else if (frustration > 0.0)
4562 frustration -= delta_t * 0.75;
4563
4564 double aspect = [self approachAspectToPrimaryTarget];
4565 if (![forward_weapon_type isTurretLaser] && (frustration > 10 || aspect > 0.75)) {
4566 behaviour = BEHAVIOUR_ATTACK_FLY_TO_TARGET;
4567 }
4568
4569 // use weaponry
4570 if (missiles)
4571 [self considerFiringMissile:delta_t];
4572
4573 if (cloakAutomatic)
4574 [self activateCloakingDevice];
4575 [self fireMainWeapon:range];
4576
4578 behaviour = BEHAVIOUR_ATTACK_TARGET;
4579 }
4580}
OOUniversalID universalID
Definition Entity.m:522
HPVector distance_twelve:withOffset:(GLfloat dist,[withOffset] GLfloat offset)
uint16_t entity_personality
Definition ShipEntity.h:418
HPVector distance_six:(GLfloat dist)
voidpf uLong offset
Definition ioapi.h:132

References _destination, accuracy, activateCloakingDevice, afterburnerFactor, approachAspectToPrimaryTarget, avoidCollision, behaviour, behaviour_attack_fly_from_target:, canStillTrackPrimaryTarget, cloakAutomatic, COMBAT_AI_WEAPON_TEMP_USABLE, COMBAT_OUT_RANGE_FACTOR, COMBAT_WEAPON_RANGE_FACTOR, considerFiringMissile:, desired_speed, distance(), entity_personality, fireMainWeapon:, flightSpeed, forward_weapon_type, frustration, fuel, hasFuelInjection, Entity::isShip, isThargoid, maxFlightSpeed, MIN_FUEL, missiles, nil, noteLostTargetAndGoIdle, pitching_over, primaryTarget, proximityAlert, rangeToDestination, rangeToPrimaryTarget, Entity::speed, success_factor, trackDestination:retreat:, Entity::universalID, weapon_temp, and weaponRange.

Referenced by behaviour_close_to_broadside_range:, behaviour_close_with_target:, and processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_formation_form_up:

- (void) behaviour_formation_form_up: (double) delta_t

Definition at line 5002 of file ShipEntity.m.

5002 :(double)delta_t
5003{
5004 // destination for each escort is set in update() from owner.
5005 ShipEntity* leadShip = [self owner];
5006 double distance = [self rangeToDestination];
5007 double eta = (distance - desired_range) / flightSpeed;
5008 if (eta < 0)
5009 eta = 0;
5010 if ((eta < 5.0) && (leadShip) && (leadShip->isShip))
5011 desired_speed = [leadShip flightSpeed] * (1 + eta * 0.05);
5012 else
5014
5015 double last_distance = success_factor;
5017
5018 // do the actual piloting!!
5019 [self trackDestination:delta_t retreat:NO];
5020
5021 eta = eta / 0.51; // 2% safety margin assuming an average of half current speed
5022 GLfloat slowdownTime = (thrust > 0.0) ? flightSpeed / (thrust) : 4.0;
5023 GLfloat minTurnSpeedFactor = 0.05 * max_flight_pitch * max_flight_roll; // faster turning implies higher speeds
5024
5025 if ((eta < slowdownTime) && (flightSpeed > maxFlightSpeed * minTurnSpeedFactor))
5026 desired_speed = flightSpeed * 0.50; // cut speed by 50% to a minimum minTurnSpeedFactor of speed
5027
5028 if (distance < last_distance) // improvement
5029 {
5030 frustration -= 0.25 * delta_t;
5031 if (frustration < 0.0)
5032 frustration = 0.0;
5033 } else {
5034 frustration += delta_t;
5035 if (frustration > 15.0) {
5036 if (!leadShip)
5037 [self noteFrustration:@"BEHAVIOUR_FORMATION_FORM_UP"]; // escorts never reach their destination when following leader.
5038 else if (distance > 0.5 * scannerRange && !pitching_over) {
5039 pitching_over = YES; // Force the ship in a 180 degree turn. Do it here to allow escorts to break out formation for some seconds.
5040 }
5041 frustration = 0;
5042 }
5043 }
5044 if ([self hasProximityAlertIgnoringTarget:YES]) {
5045 [self avoidCollision];
5046 }
5047}

References avoidCollision, desired_range, desired_speed, distance(), flightSpeed, frustration, Entity::isShip, max_flight_pitch, max_flight_roll, maxFlightSpeed, noteFrustration:, Entity::owner, pitching_over, rangeToDestination, scannerRange, success_factor, thrust, and trackDestination:retreat:.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_idle:

- (void) behaviour_idle: (double) delta_t

Definition at line 3708 of file ShipEntity.m.

3708 :(double)delta_t
3709{
3710 stick_yaw = 0.0;
3711 if ((!isStation) && (scanClass != CLASS_BUOY)) {
3712 stick_roll = 0.0;
3713 } else {
3715 }
3716 if (scanClass != CLASS_BUOY) {
3717 stick_pitch = 0.0;
3718 } else {
3720 }
3721 [self applySticks:delta_t];
3722}

References applySticks:, flightPitch, flightRoll, Entity::isStation, scanClass, stick_pitch, stick_roll, and stick_yaw.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_intercept_target:

- (void) behaviour_intercept_target: (double) delta_t

Definition at line 3817 of file ShipEntity.m.

3817 :(double)delta_t
3818{
3819 double range = [self rangeToPrimaryTarget];
3820 if (behaviour == BEHAVIOUR_INTERCEPT_TARGET) {
3822 if (range < desired_range) {
3823 [shipAI reactToMessage:@"DESIRED_RANGE_ACHIEVED" context:@"BEHAVIOUR_INTERCEPT_TARGET"];
3824 [self doScriptEvent:OOJSID("shipAchievedDesiredRange")];
3825 }
3826 desired_speed = maxFlightSpeed * [self trackPrimaryTarget:delta_t retreat:NO];
3827 } else {
3828 // = BEHAVIOUR_COLLECT_TARGET
3829 ShipEntity* target = [self primaryTarget];
3830 // if somehow ended up in this state but target is not cargo, stop
3831 // trying to scoop it
3832 if (!target || [target scanClass] != CLASS_CARGO || [target cargoType] == CARGO_NOT_CARGO) {
3833 [self noteLostTargetAndGoIdle];
3834 return;
3835 }
3836 double target_speed = [target speed];
3837 double eta = range / (flightSpeed - target_speed);
3838 double last_success_factor = success_factor;
3839 double last_distance = last_success_factor;
3840 double distance = [self rangeToDestination];
3842 //
3843 double slowdownTime = 96.0 / (thrust * SHIP_THRUST_FACTOR); // more thrust implies better slowing
3844 double minTurnSpeedFactor = 0.005 * max_flight_pitch * max_flight_roll; // faster turning implies higher speeds
3845
3846 if ((eta < slowdownTime) && (flightSpeed > maxFlightSpeed * minTurnSpeedFactor))
3847 desired_speed = flightSpeed * 0.75; // cut speed by 50% to a minimum minTurnSpeedFactor of speed
3848 else
3850
3851 if (desired_speed < target_speed) {
3852 desired_speed += target_speed;
3853 if (target_speed > maxFlightSpeed) {
3854 [self noteLostTargetAndGoIdle];
3855 return;
3856 }
3857 }
3858 if (desired_speed > maxFlightSpeed) { // never use injectors for scooping
3860 }
3861
3862 _destination = target->position;
3863 desired_range = 0.5 * target->collision_radius;
3864 [self trackDestination:delta_t retreat:NO];
3865
3866 //
3867 if (distance < last_distance) // improvement
3868 {
3869 frustration -= delta_t;
3870 if (frustration < 0.0)
3871 frustration = 0.0;
3872 } else {
3873 frustration += delta_t * 0.9;
3874 if (frustration > 10.0) // 10s of frustration
3875 {
3876 [self noteFrustration:@"BEHAVIOUR_INTERCEPT_TARGET"];
3877 frustration -= 5.0; // repeat after another five seconds' frustration
3878 }
3879 }
3880 }
3881 if ([self hasProximityAlertIgnoringTarget:YES]) {
3882 [self avoidCollision];
3883 }
3884}
@ CARGO_NOT_CARGO
Definition OOTypes.h:61
OOCargoType cargoType()

References _destination, avoidCollision, behaviour, CARGO_NOT_CARGO, cargoType, Entity::collision_radius, desired_range, desired_speed, distance(), doScriptEvent:, flightSpeed, frustration, max_flight_pitch, max_flight_roll, maxFlightSpeed, noteFrustration:, noteLostTargetAndGoIdle, Entity::position, primaryTarget, rangeToDestination, rangeToPrimaryTarget, AI::reactToMessage:context:, scanClass, SHIP_THRUST_FACTOR, Entity::speed, success_factor, thrust, trackDestination:retreat:, and trackPrimaryTarget:retreat:.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_land_on_planet:

- (void) behaviour_land_on_planet: (double) delta_t

Definition at line 4967 of file ShipEntity.m.

4967 :(double)delta_t
4968{
4969 double max_cos = MAX_COS2; // trackDestination returns the squared confidence in reverse mode.
4970 desired_speed = 0.0;
4971
4972 OOPlanetEntity* planet = [UNIVERSE entityForUniversalID:planetForLanding];
4973
4974 if (![planet isPlanet]) {
4975 behaviour = BEHAVIOUR_IDLE;
4976 aiScriptWakeTime = 1; // reconsider JSAI
4977 [shipAI message:@"NO_PLANET_NEARBY"];
4978 return;
4979 }
4980
4981 if (HPdistance(position, [planet position]) + [self collisionRadius] < [planet radius]) {
4982 // we have landed. (completely disappeared inside planet)
4983 [self landOnPlanet:planet];
4984 return;
4985 }
4986
4987 double confidenceFactor = [self trackDestination:delta_t retreat:YES]; // turn away from destination
4988
4989 if (confidenceFactor >= max_cos && flightSpeed == 0.0) {
4990 // We are now turned away from planet. Start landing by flying backward.
4991 thrust = 0.0; // stop forward acceleration.
4993 [self adjustVelocity:vector_multiply_scalar([self forwardVector], -max_thrust * delta_t)];
4994 }
4995 }
4996
4997 if ([self hasProximityAlertIgnoringTarget:YES]) {
4998 [self avoidCollision];
4999 }
5000}
OOINLINE OOHPScalar HPdistance(HPVector v1, HPVector v2) INLINE_CONST_FUNC
Definition OOHPVector.h:298
OOINLINE OOScalar magnitude2(Vector vec) INLINE_CONST_FUNC
Definition OOVector.h:237
#define MAX_COS2
Definition ShipEntity.h:143
#define MAX_LANDING_SPEED2
Definition ShipEntity.h:140
BOOL isPlanet()
Definition Entity.m:150
OOTimeAbsolute aiScriptWakeTime
Definition ShipEntity.h:213

References adjustVelocity:, aiScriptWakeTime, avoidCollision, behaviour, Entity::collisionRadius, desired_speed, flightSpeed, forwardVector, HPdistance(), Entity::isPlanet, landOnPlanet:, magnitude2(), MAX_COS2, MAX_LANDING_SPEED2, AI::message:, Entity::position, thrust, trackDestination:retreat:, and velocity.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_running_defense:

- (void) behaviour_running_defense: (double) delta_t

Definition at line 4801 of file ShipEntity.m.

4801 :(double)delta_t
4802{
4803 if (![self canStillTrackPrimaryTarget]) {
4804 [self noteLostTargetAndGoIdle];
4805 return;
4806 }
4807
4808 double range = [self rangeToPrimaryTarget];
4809 desired_speed = maxFlightSpeed; // not injectors
4810 jink = kZeroVector;
4811 if (range > weaponRange || range > 0.8 * scannerRange || range == 0) {
4812 behaviour = BEHAVIOUR_CLOSE_WITH_TARGET;
4813 if ([forward_weapon_type isTurretLaser]) {
4814 behaviour = BEHAVIOUR_ATTACK_FLY_TO_TARGET_TWELVE;
4815 }
4816 frustration = 0.0;
4817 }
4818 [self trackPrimaryTarget:delta_t retreat:YES];
4819 if ([forward_weapon_type isTurretLaser]) {
4820 // most Thargoids will only have the forward weapon
4821 [self fireMainWeapon:range];
4822 } else {
4823 [self fireAftWeapon:range];
4824 }
4825 if (cloakAutomatic)
4826 [self activateCloakingDevice];
4827 if ([self hasProximityAlertIgnoringTarget:YES])
4828 [self avoidCollision];
4829
4830 if (behaviour != BEHAVIOUR_CLOSE_WITH_TARGET && weapon_temp > COMBAT_AI_WEAPON_TEMP_USABLE) {
4831 behaviour = BEHAVIOUR_ATTACK_TARGET;
4832 }
4833
4834 // remember to look where you're going?
4835 if (accuracy >= COMBAT_AI_ISNT_AWFUL && [self hasProximityAlertIgnoringTarget:YES]) {
4836 [self avoidCollision];
4837 }
4838}

References accuracy, activateCloakingDevice, avoidCollision, behaviour, canStillTrackPrimaryTarget, cloakAutomatic, COMBAT_AI_ISNT_AWFUL, COMBAT_AI_WEAPON_TEMP_USABLE, desired_speed, fireAftWeapon:, fireMainWeapon:, forward_weapon_type, frustration, jink, kZeroVector, maxFlightSpeed, noteLostTargetAndGoIdle, rangeToPrimaryTarget, scannerRange, trackPrimaryTarget:retreat:, weapon_temp, and weaponRange.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_scripted_ai:

- (void) behaviour_scripted_ai: (double) delta_t

Definition at line 5300 of file ShipEntity.m.

5300 :(double)delta_t
5301{
5302
5303 JSContext* context = OOJSAcquireContext();
5304 OOJSVal rval = OOJSUndefinedValue();
5305 OOJSVal deltaJS = OOJSValueFromDouble(context, delta_t);
5306 NSDictionary* result = nil;
5307
5308 BOOL OK = [[self script] callMethod:OOJSID("scriptedAI")
5309 inContext:context
5310 withArguments:&deltaJS
5311 count:1
5312 result:&rval];
5313 OOJSFreeValue(context, deltaJS);
5314
5315 if (!OK) {
5316 OOLog(@"ai.error", @"Could not call scriptedAI in ship script of %@, reverting to idle", self);
5317 behaviour = BEHAVIOUR_IDLE;
5318 OOJSFreeValue(context, rval);
5319 OOJSRelinquishContext(context);
5320 return;
5321 }
5322
5323#if OOJS_QUICKJS
5324 // SpiderMonkey's JSVAL_IS_OBJECT() is also true for null.
5325 if (!JS_IsObject(rval) && !JS_IsNull(rval)) {
5326#else
5327 if (!JSVAL_IS_OBJECT(rval)) {
5328#endif
5329 OOLog(@"ai.error", @"Invalid return value of scriptedAI in ship script of %@, reverting to idle", self);
5330 behaviour = BEHAVIOUR_IDLE;
5331 OOJSFreeValue(context, rval);
5332 OOJSRelinquishContext(context);
5333 return;
5334 }
5335
5336#if OOJS_QUICKJS
5337 result = OOJSNativeObjectFromJSObject(context, rval);
5338#else
5339 result = OOJSNativeObjectFromJSObject(context, JSVAL_TO_OBJECT(rval));
5340#endif
5341 OOJSFreeValue(context, rval);
5342 OOJSRelinquishContext(context);
5343
5344 // roll or roll factor
5345 if ([result objectForKey:@"stickRollFactor"] != nil) {
5346 stick_roll = [result oo_floatForKey:@"stickRollFactor"] * max_flight_roll;
5347 } else {
5348 stick_roll = [result oo_floatForKey:@"stickRoll"];
5349 }
5352 } else if (stick_roll < -max_flight_roll) {
5354 }
5355
5356 // pitch or pitch factor
5357 if ([result objectForKey:@"stickPitchFactor"] != nil) {
5358 stick_pitch = [result oo_floatForKey:@"stickPitchFactor"] * max_flight_pitch;
5359 } else {
5360 stick_pitch = [result oo_floatForKey:@"stickPitch"];
5361 }
5364 } else if (stick_pitch < -max_flight_pitch) {
5366 }
5367
5368 // yaw or yaw factor
5369 if ([result objectForKey:@"stickYawFactor"] != nil) {
5370 stick_yaw = [result oo_floatForKey:@"stickYawFactor"] * max_flight_yaw;
5371 } else {
5372 stick_yaw = [result oo_floatForKey:@"stickYaw"];
5373 }
5374 if (stick_yaw > max_flight_yaw) {
5376 } else if (stick_yaw < -max_flight_yaw) {
5378 }
5379
5380 // apply sticks to current flight profile
5381 [self applySticks:delta_t];
5382
5383 // desired speed
5384 if ([result objectForKey:@"desiredSpeedFactor"] != nil) {
5385 desired_speed = [result oo_floatForKey:@"desiredSpeedFactor"] * maxFlightSpeed;
5386 } else {
5387 desired_speed = [result oo_floatForKey:@"desiredSpeed"];
5388 }
5389
5390 if (desired_speed < 0.0) {
5391 desired_speed = 0.0;
5392 }
5393 // overspeed and injector use is handled by applyThrust
5394
5395 if (behaviour == BEHAVIOUR_SCRIPTED_ATTACK_AI) {
5396 NSString* chosen_weapon = [result oo_stringForKey:@"chosenWeapon" defaultValue:@"FORWARD"];
5397 double range = [self rangeToPrimaryTarget];
5398
5399 if ([chosen_weapon isEqualToString:@"FORWARD"]) {
5400 [self fireMainWeapon:range];
5401 } else if ([chosen_weapon isEqualToString:@"AFT"]) {
5402 [self fireAftWeapon:range];
5403 } else if ([chosen_weapon isEqualToString:@"PORT"]) {
5404 [self firePortWeapon:range];
5405 } else if ([chosen_weapon isEqualToString:@"STARBOARD"]) {
5406 [self fireStarboardWeapon:range];
5407 }
5408 }
5409}
OOINLINE jsval OOJSValueFromDouble(JSContext *context, double value)
jsval OOJSVal
#define OOJSFreeValue(context, value)
#define OOJSUndefinedValue()
id OOJSNativeObjectFromJSObject(JSContext *context, JSObject *object)
OOINLINE JSContext * OOJSAcquireContext(void)
OOINLINE void OOJSRelinquishContext(JSContext *context)
GLfloat max_flight_yaw
Definition ShipEntity.h:231

References applySticks:, behaviour, OOJSScript::callMethod:inContext:withArguments:count:result:, desired_speed, fireAftWeapon:, fireMainWeapon:, firePortWeapon:, fireStarboardWeapon:, max_flight_pitch, max_flight_roll, max_flight_yaw, maxFlightSpeed, nil, OOJSAcquireContext(), OOJSFreeValue, OOJSNativeObjectFromJSObject(), OOJSRelinquishContext(), OOJSUndefinedValue, OOJSValueFromDouble(), OOLog, rangeToPrimaryTarget, script, stick_pitch, stick_roll, and stick_yaw.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_stop_still:

- (void) behaviour_stop_still: (double) delta_t

Definition at line 3700 of file ShipEntity.m.

3700 :(double)delta_t
3701{
3702 stick_roll = 0.0;
3703 stick_pitch = 0.0;
3704 stick_yaw = 0.0;
3705 [self applySticks:delta_t];
3706}

References applySticks:, stick_pitch, stick_roll, and stick_yaw.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_track_as_turret:

- (void) behaviour_track_as_turret: (double) delta_t

Definition at line 5173 of file ShipEntity.m.

5173 :(double)delta_t
5174{
5175 double aim = -2.0;
5176 ShipEntity* turret_owner = (ShipEntity*)[self owner];
5177 ShipEntity* turret_target = (ShipEntity*)[turret_owner primaryTarget];
5178 if (turret_owner && turret_target && [turret_owner hasHostileTarget]) {
5179 aim = [self ballTrackLeadingTarget:delta_t atTarget:turret_target];
5180 if (aim > -1.0) // potential target
5181 {
5182 HPVector p = HPvector_subtract([turret_target position], [turret_owner position]);
5183 double cr = [turret_owner collisionRadius];
5184
5185 if (aim > .95) {
5186 [self fireTurretCannon:HPmagnitude(p) - cr];
5187 }
5188 return;
5189 }
5190 }
5191
5192 // can't fire on primary target; track secondary targets instead
5193 NSEnumerator* targetEnum = [turret_owner defenseTargetEnumerator];
5194 Entity* target = nil;
5195 while ((target = [[targetEnum nextObject] weakRefUnderlyingObject])) {
5196 // defense targets cannot be tracked while cloaked
5197 if ([target scanClass] == CLASS_NO_DRAW || [(ShipEntity*)target isCloaked] || [target energy] <= 0.0) {
5198 [turret_owner removeDefenseTarget:target];
5199 } else {
5200 double range = [turret_owner rangeToSecondaryTarget:target];
5201 if (range < weaponRange) {
5202 aim = [self ballTrackLeadingTarget:delta_t atTarget:target];
5203 if (aim > -1.0) { // tracking...
5204 HPVector p = HPvector_subtract([target position], [turret_owner position]);
5205 double cr = [turret_owner collisionRadius];
5206
5207 if (aim > .95) { // fire!
5208 [self fireTurretCannon:HPmagnitude(p) - cr];
5209 }
5210 return;
5211 }
5212 // else that target is out of range, try the next priority defense target
5213 } else if (range > scannerRange) {
5214 [turret_owner removeDefenseTarget:target];
5215 }
5216 }
5217 }
5218
5219 // turrets now don't return to neutral facing if no suitable target
5220 // better for shooting at targets that are on edge of fire arc
5221}
double rangeToSecondaryTarget:(Entity *target)
NSEnumerator * defenseTargetEnumerator()
BOOL isCloaked()

References ballTrackLeadingTarget:atTarget:, Entity::collisionRadius, defenseTargetEnumerator, Entity::energy, fireTurretCannon:, hasHostileTarget, HPvector_subtract(), isCloaked, nil, Entity::owner, Entity::position, primaryTarget, rangeToSecondaryTarget:, removeDefenseTarget:, scanClass, scannerRange, and weaponRange.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_track_target:

- (void) behaviour_track_target: (double) delta_t

Definition at line 3805 of file ShipEntity.m.

3805 :(double)delta_t
3806{
3807 if ([self primaryTarget] == nil) {
3808 [self noteLostTargetAndGoIdle];
3809 return;
3810 }
3811 [self trackPrimaryTarget:delta_t retreat:NO]; // applies sticks
3812 if ([self hasProximityAlertIgnoringTarget:YES]) {
3813 [self avoidCollision];
3814 }
3815}

References avoidCollision, nil, noteLostTargetAndGoIdle, primaryTarget, and trackPrimaryTarget:retreat:.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_tractored:

- (void) behaviour_tractored: (double) delta_t

Definition at line 3729 of file ShipEntity.m.

3729 :(double)delta_t
3730{
3732 ShipEntity* hauler = (ShipEntity*)[self owner];
3733 if ((hauler) && ([hauler isShip])) {
3735 double distance = [self rangeToDestination];
3736 if (distance < desired_range) {
3737 [self performTumble];
3738 [self setStatus:STATUS_IN_FLIGHT];
3739 [hauler scoopUp:self];
3740 return;
3741 }
3742 GLfloat tf = TRACTOR_FORCE / mass;
3743 // adjust for difference in velocity (spring rule)
3744 Vector dv = vector_between([self velocity], [hauler velocity]);
3745 GLfloat moment = delta_t * 0.25 * tf;
3746 velocity.x += moment * dv.x;
3747 velocity.y += moment * dv.y;
3748 velocity.z += moment * dv.z;
3749 // acceleration = force / mass
3750 // force proportional to distance (spring rule)
3752 moment = delta_t * 0.5 * tf;
3753 velocity.x += moment * dp.x;
3754 velocity.y += moment * dp.y;
3755 velocity.z += moment * dp.z;
3756 // force inversely proportional to distance
3757 GLfloat d2 = HPmagnitude2(dp);
3758 moment = (d2 > 0.0) ? delta_t * 5.0 * tf / d2 : 0.0;
3759 if (d2 > 0.0) {
3760 velocity.x += moment * dp.x;
3761 velocity.y += moment * dp.y;
3762 velocity.z += moment * dp.z;
3763 }
3764 //
3765 if ([self status] == STATUS_BEING_SCOOPED) {
3766 BOOL lost_contact = (distance > hauler->collision_radius + collision_radius + 250.0f); // 250m range for tractor beam
3767 if ([hauler isPlayer]) {
3768 switch ([(PlayerEntity*)hauler dialFuelScoopStatus]) {
3771 lost_contact = YES; // don't draw
3772 break;
3773
3774 case SCOOP_STATUS_OKAY:
3776 break;
3777 }
3778 }
3779
3780 if (lost_contact) // 250m range for tractor beam
3781 {
3782 // escaped tractor beam
3783 [self setStatus:STATUS_IN_FLIGHT];
3784 behaviour = BEHAVIOUR_IDLE;
3785 [self setThrust:[self maxThrust]]; // restore old thrust.
3786 frustration = 0.0;
3787 [self setOwner:self];
3788 [shipAI exitStateMachineWithMessage:nil]; // exit nullAI.plist
3789 return;
3790 } else if ([hauler isPlayer]) {
3792 }
3793 }
3794 }
3795
3796 // being tractored; sticks ignored - CIM
3797 flightYaw = 0.0;
3798
3799 desired_speed = 0.0;
3800 thrust = 25.0; // used to damp velocity (must be less than hauler thrust)
3801
3802 thrust = 0.0; // must reset thrust now
3803}
#define vector_between(a, b)
Definition OOVector.h:74
@ SCOOP_STATUS_FULL_HOLD
@ SCOOP_STATUS_NOT_INSTALLED
@ SCOOP_STATUS_ACTIVE
@ SCOOP_STATUS_OKAY
#define TRACTOR_FORCE
Definition ShipEntity.h:94
HPVector absoluteTractorPosition()
void scoopUp:(ShipEntity *other)

References _destination, absoluteTractorPosition, behaviour, Entity::collision_radius, desired_range, desired_speed, distance(), AI::exitStateMachineWithMessage:, flightYaw, frustration, HPmagnitude2(), HPvector_between, Entity::isPlayer, Entity::isShip, Entity::mass, maxThrust, Entity::owner, performTumble, Entity::position, rangeToDestination, SCOOP_STATUS_ACTIVE, SCOOP_STATUS_FULL_HOLD, SCOOP_STATUS_NOT_INSTALLED, SCOOP_STATUS_OKAY, scoopUp:, setOwner:, PlayerEntity::setScoopsActive, setStatus:, setThrust:, Entity::status, thrust, TRACTOR_FORCE, vector_between, velocity, HPVector::x, Vector::x, HPVector::y, Vector::y, HPVector::z, and Vector::z.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ behaviour_tumble:

- (void) behaviour_tumble: (double) delta_t

Definition at line 3724 of file ShipEntity.m.

3724 :(double)delta_t
3725{
3726 [self applySticks:delta_t];
3727}

References applySticks:.

Referenced by processBehaviour:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bounty

Reimplemented in PlayerEntity.

References availableCargoSpace, bounty, cargoListForScripting, cargoQuantityOnBoard, cargoType, commodityAmount, commodityType, int(), isTemplateCargoPod, legalStatus, and maxAvailableCargoSpace.

Here is the call graph for this function:

◆ broadcastAIMessage:

- (void) broadcastAIMessage: (NSString*) ai_message

Definition at line 12370 of file ShipEntity.m.

12370 :(NSString*)ai_message
12371{
12372 NSString* expandedMessage = OOExpand(ai_message);
12373
12374 [self checkScanner];
12375 unsigned i;
12376 for (i = 0; i < n_scanned_ships; i++) {
12377 ShipEntity* ship = scanned_ships[i];
12378 [[ship getAI] message:expandedMessage];
12379 }
12380}
#define OOExpand(string,...)
void message:(NSString *ms)
Definition AI.m:536
ShipEntity * scanned_ships[MAX_SCAN_NUMBER+1]
Definition ShipEntity.h:401
unsigned n_scanned_ships
Definition ShipEntity.h:403

References checkScanner, getAI, AI::message:, n_scanned_ships, OOExpand, and scanned_ships.

Referenced by dumpCargoItem:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ broadcastDistressMessage

- (void) broadcastDistressMessage

Provided by category ShipEntity(AI).

Definition at line 677 of file ShipEntityAI.m.

678{
679 /*-- Locates all the stations, bounty hunters and police ships in range and tells them that you are under attack --*/
680 [self broadcastDistressMessageWithDumping:YES];
681}

◆ broadcastDistressMessageWithDumping:

- (void) broadcastDistressMessageWithDumping: (BOOL) dumpCargo

Provided by category ShipEntity(AI).

Definition at line 683 of file ShipEntityAI.m.

683 :(BOOL)dumpCargo
684{
685 [self checkScannerIgnoringUnpowered];
687
688 ShipEntity* aggressor_ship = (ShipEntity*)[self primaryAggressor];
689 if (aggressor_ship == nil)
690 return;
691
692 // don't send too many distress messages at once, space them out semi-randomly
693 if (messageTime > 2.0 * randf())
694 return;
695
696 NSString* distress_message = nil;
697 BOOL is_buoy = (scanClass == CLASS_BUOY);
698 if (is_buoy)
699 distress_message = @"[buoy-distress-call]";
700 else
701 distress_message = @"[distress-call]";
702
703 unsigned i;
704 for (i = 0; i < n_scanned_ships; i++) {
705 ShipEntity* ship = scanned_ships[i];
706
707 // dump cargo if energy is low
708 if (dumpCargo && !is_buoy && [self primaryAggressor] == ship && energy < 0.375 * maxEnergy) {
709 [self ejectCargo];
710 [self performFlee];
711 }
712
713 // tell it! (only plist AIs send comms here; JS AIs are
714 // expected to handle their own)
715 if (ship->isPlayer && ![self hasNewAI]) {
716 [ship doScriptEvent:OOJSID("distressMessageReceived") withArgument:aggressor_ship andArgument:self];
717
718 if (!is_buoy && [self primaryAggressor] == ship && energy < 0.375 * maxEnergy) {
719 [self sendExpandedMessage:@"[beg-for-mercy]" toShip:ship];
720 } else if ([self bounty] == 0) {
721 // only send distress message to player if plausibly sending
722 // one more generally
723 [self sendExpandedMessage:distress_message toShip:ship];
724 }
725
726 // reset the thanked_ship_id
728 } else if ([self bounty] == 0 && [ship crew]) // Only clean ships can have their distress calls accepted
729 {
730 [ship doScriptEvent:OOJSID("distressMessageReceived") withArgument:aggressor_ship andArgument:self];
731
732 // we only can send distressMessages to ships that are known to have a "ACCEPT_DISTRESS_CALL" reaction
733 // in their AI, or they might react wrong on the added found_target.
734
735 // ship must have a plist AI for this next bit. JS AIs
736 // should already have done something sensible on
737 // distressMessageReceived
738 if (![self hasNewAI]) {
739 // FIXME: this test only works with core AIs
740 if (ship->isStation || [ship hasPrimaryRole:@"police"] || [ship hasPrimaryRole:@"hunter"]) {
741 [ship acceptDistressMessageFrom:self];
742 }
743 }
744 }
745 }
746}
OOWeakReference * _thankedShip
Definition ShipEntity.h:430
BOOL hasNewAI()
OOCreditsQuantity bounty
void doScriptEvent:withArgument:andArgument:(OOJSPropID message,[withArgument] id argument1,[andArgument] id argument2)
OOCommodityType dumpCargo()
double messageTime
void acceptDistressMessageFrom:(ShipEntity *other)
NSArray * crew
OOWeakReference * _foundTarget
Definition ShipEntity.h:428

Referenced by ShipEntity(AI)::broadcastDistressMessage.

Here is the caller graph for this function:

◆ broadcastEnergyBlastImminent

- (void) broadcastEnergyBlastImminent

Definition at line 8164 of file ShipEntity.m.

8165{
8166 // anyone further away than typical scanner range probably doesn't need to hear
8167 NSArray* targets = [UNIVERSE entitiesWithinRange:SCANNER_MAX_RANGE ofEntity:self];
8168 if ([targets count] > 0) {
8169 unsigned i;
8170 for (i = 0; i < [targets count]; i++) {
8171 Entity* e2 = [targets objectAtIndex:i];
8172 if ([e2 isShip]) {
8173 ShipEntity* se = (ShipEntity*)e2;
8174 [se setFoundTarget:self];
8175 [se reactToAIMessage:@"CASCADE_WEAPON_DETECTED" context:@"nearby Q-mine"];
8176 [se doScriptEvent:OOJSID("cascadeWeaponDetected") withArgument:self];
8177 }
8178 }
8179 }
8180}
void doScriptEvent:withArgument:(OOJSPropID message,[withArgument] id argument)
void reactToAIMessage:context:(NSString *message,[context] NSString *debugContext)
void setFoundTarget:(Entity *targetEntity)

References broadcastEnergyBlastImminent, count, doScriptEvent:withArgument:, Entity::isShip, reactToAIMessage:context:, and setFoundTarget:.

Referenced by becomeEnergyBlast, broadcastEnergyBlastImminent, and maxFlightSpeed.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ broadcastHitByLaserFrom:

- (void) broadcastHitByLaserFrom: (ShipEntity*) aggressor_ship

Definition at line 12288 of file ShipEntity.m.

12288 :(ShipEntity*)aggressor_ship
12289{
12290 /*-- If you're clean, locates all police and stations in range and tells them OFFENCE_COMMITTED --*/
12291 if (!UNIVERSE)
12292 return;
12293 if ([self bounty])
12294 return;
12295 if (!aggressor_ship)
12296 return;
12297
12298 if ((scanClass == CLASS_NEUTRAL) || (scanClass == CLASS_STATION) || (scanClass == CLASS_BUOY) || (scanClass == CLASS_POLICE) || (scanClass == CLASS_MILITARY) || (scanClass == CLASS_PLAYER)) // only for active ships...
12299 {
12300 NSArray* authorities = nil;
12301 ShipEntity* auth = nil;
12302
12303 authorities = [UNIVERSE findShipsMatchingPredicate:AuthorityPredicate
12304 parameter:self
12305 inRange:-1
12306 ofEntity:nil];
12307 foreach (auth, authorities) {
12308 [auth setFoundTarget:aggressor_ship];
12309 [auth doScriptEvent:OOJSID("offenceCommittedNearby") withArgument:aggressor_ship andArgument:self];
12310 [auth reactToAIMessage:@"OFFENCE_COMMITTED" context:@"combat update"];
12311 }
12312 }
12313}

References bounty, doScriptEvent:withArgument:andArgument:, nil, reactToAIMessage:context:, scanClass, setFoundTarget:, and UNIVERSE.

Referenced by PlayerEntity::takeEnergyDamage:from:becauseOf:weaponIdentifier:, and takeEnergyDamage:from:becauseOf:weaponIdentifier:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ broadcastMessage:withUnpilotedOverride:

- (void) broadcastMessage: (NSString*) message_text
withUnpilotedOverride: (BOOL) unpilotedOverride 

Definition at line 12382 of file ShipEntity.m.

12382 :(NSString*)message_text withUnpilotedOverride:(BOOL)unpilotedOverride
12383{
12384 NSString* expandedMessage = OOExpand(message_text); // consistent with broadcast message.
12385
12386 if (!crew && !unpilotedOverride)
12387 return; // nobody to send the signal and no override for unpiloted craft is set
12388
12389 [self checkScanner];
12390 unsigned i;
12391 for (i = 0; i < n_scanned_ships; i++) {
12392 ShipEntity* ship = scanned_ships[i];
12393 if (![ship isPlayer])
12394 [ship receiveCommsMessage:expandedMessage from:self];
12395 }
12396
12397 PlayerEntity* player = PLAYER; // make sure that the player always receives a message when in range
12398 // SCANNER_MAX_RANGE2 because it's the player's scanner range
12399 // which is important
12401 [self setCommsMessageColor];
12402 [player receiveCommsMessage:expandedMessage from:self];
12403 messageTime = 6.0;
12404 [UNIVERSE resetCommsLogColor];
12405 }
12406}
void receiveCommsMessage:from:(NSString *message_text, [from] ShipEntity *other)

References checkScanner, crew, HPdistance2(), Entity::isPlayer, messageTime, n_scanned_ships, OOExpand, PLAYER, Entity::position, PlayerEntity::receiveCommsMessage:from:, receiveCommsMessage:from:, scanned_ships, SCANNER_MAX_RANGE2, and setCommsMessageColor.

Referenced by commsMessage:withUnpilotedOverride:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ broadcastThargoidDestroyed

- (void) broadcastThargoidDestroyed

Definition at line 12260 of file ShipEntity.m.

12261{
12262 [[UNIVERSE findShipsMatchingPredicate:HasRolePredicate
12263 parameter:@"tharglet"
12264 inRange:SCANNER_MAX_RANGE
12265 ofEntity:self]
12266 makeObjectsPerformSelector:@selector(sendAIMessage:)
12267 withObject:@"THARGOID_DESTROYED"];
12268}

References broadcastThargoidDestroyed.

Referenced by becomeExplosion, broadcastThargoidDestroyed, and dockingInstructions.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculateTargetPosition

- (HPVector) calculateTargetPosition

Definition at line 5421 of file ShipEntity.m.

5422{
5423 Entity* target = [self primaryTarget];
5424 if (target == nil) {
5425 return kZeroHPVector;
5426 }
5427 if (reactionTime <= 0.0) {
5428 return [target position];
5429 }
5430 double t = [UNIVERSE getTime] - trackingCurveTimes[1];
5432}
OOINLINE HPVector HPvector_multiply_scalar(HPVector v, OOHPScalar s) INLINE_CONST_FUNC
Definition OOHPVector.h:198
const HPVector kZeroHPVector
Definition OOHPVector.m:27
OOTimeAbsolute trackingCurveTimes[4]
Definition ShipEntity.h:439
float reactionTime
HPVector trackingCurveCoeffs[3]
Definition ShipEntity.h:440

References calculateTargetPosition, HPvector_add(), HPvector_multiply_scalar(), kZeroHPVector, nil, Entity::position, primaryTarget, reactionTime, trackingCurveCoeffs, and trackingCurveTimes.

Referenced by calculateTargetPosition, onTarget:withWeapon:, reactionTime, trackPrimaryTarget:retreat:, and trackSideTarget:leftside:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculateTrackingCurve

- (void) calculateTrackingCurve

Definition at line 5478 of file ShipEntity.m.

5479{
5480 if (reactionTime <= 0.0) {
5484 return;
5485 }
5486 double t1 = trackingCurveTimes[2] - trackingCurveTimes[1],
5490 HPvector_multiply_scalar(trackingCurvePositions[1], -(t1 + t2) / (t1 * t2)),
5491 HPvector_multiply_scalar(trackingCurvePositions[2], -t2 / (t1 * (t1 - t2)))),
5492 HPvector_multiply_scalar(trackingCurvePositions[3], t1 / (t2 * (t1 - t2))));
5495 HPvector_multiply_scalar(trackingCurvePositions[2], 1 / (t1 * (t1 - t2)))),
5496 HPvector_multiply_scalar(trackingCurvePositions[3], -1 / (t2 * (t1 - t2))));
5497 return;
5498}
HPVector trackingCurvePositions[4]
Definition ShipEntity.h:438

References calculateTrackingCurve, HPvector_add(), HPvector_multiply_scalar(), kZeroHPVector, reactionTime, trackingCurveCoeffs, trackingCurvePositions, and trackingCurveTimes.

Referenced by calculateTrackingCurve, reactionTime, startTrackingCurve, and updateTrackingCurve.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ canAcceptEscort:

- (BOOL) canAcceptEscort: (ShipEntity*) potentialEscort

Definition at line 11914 of file ShipEntity.m.

11914 :(ShipEntity*)potentialEscort
11915{
11916 if (dockingInstructions) // we are busy with docking.
11917 {
11918 return NO;
11919 }
11920 if (scanClass != [potentialEscort scanClass]) // this makes sure that wingman can only select police, thargons only thargoids.
11921 {
11922 return NO;
11923 }
11924 if ([self bounty] == 0 && [potentialEscort bounty] != 0) // clean mothers can only accept clean escorts
11925 {
11926 return NO;
11927 }
11928 if (![self isEscort]) // self is NOT wingman or escort or thargon
11929 {
11930 return [potentialEscort isEscort]; // is wingman or escort or thargon
11931 }
11932 return NO;
11933}
BOOL isEscort()

References bounty, dockingInstructions, isEscort, and scanClass.

Here is the call graph for this function:

◆ canAddEquipment:inContext:

- (BOOL) canAddEquipment: (NSString*) equipmentKey
inContext: (NSString*) context 

Reimplemented in PlayerEntity.

Definition at line 2879 of file ShipEntity.m.

2879 :(NSString*)equipmentKey inContext:(NSString*)context
2880{
2881 if ([equipmentKey hasSuffix:@"_DAMAGED"]) {
2882 equipmentKey = [equipmentKey substringToIndex:[equipmentKey length] - [@"_DAMAGED" length]];
2883 }
2884
2885 NSString* lcEquipmentKey = [equipmentKey lowercaseString];
2886 if ([equipmentKey hasSuffix:@"MISSILE"] || [equipmentKey hasSuffix:@"MINE"] || ([self isThargoid] && ([lcEquipmentKey hasPrefix:@"thargon"] || [lcEquipmentKey hasSuffix:@"thargon"]))) {
2887 if (missiles >= max_missiles)
2888 return NO;
2889 }
2890
2891 OOEquipmentType* eqType = [OOEquipmentType equipmentTypeWithIdentifier:equipmentKey];
2892
2893 if (![eqType canCarryMultiple] && [self hasEquipmentItem:equipmentKey])
2894 return NO;
2895 if (![self equipmentValidToAdd:equipmentKey inContext:context])
2896 return NO;
2897
2898 return YES;
2899}

References OOEquipmentType::equipmentTypeWithIdentifier:, isThargoid, max_missiles, and missiles.

Referenced by ShipCanAwardEquipment(), and ShipCanAwardEquipment().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ canCollide

- (BOOL) canCollide
implementation

Reimplemented from Entity.

Reimplemented in PlayerEntity.

Definition at line 1858 of file ShipEntity.m.

1859{
1860 int status = [self status];
1861 if (status == STATUS_COCKPIT_DISPLAY || status == STATUS_DEAD || status == STATUS_BEING_SCOOPED) {
1862 return NO;
1863 }
1864
1865 if (isWreckage) {
1866 // wreckage won't collide
1867 return NO;
1868 }
1869
1870 if (isMissile && [self shotTime] < 0.25) // not yet fused
1871 {
1872 return NO;
1873 }
1874
1875 return YES;
1876}
unsigned isMissile
OOTimeDelta shotTime()

References canCollide, isMissile, isWreckage, shotTime, and Entity::status.

Referenced by canCollide, and doOctreesCollide.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ canScoop:

- (BOOL) canScoop: (ShipEntity*) other

Reimplemented in PlayerEntity.

Definition at line 11192 of file ShipEntity.m.

11192 :(ShipEntity*)other
11193{
11194 if (other == nil)
11195 return NO;
11196 if (![self hasCargoScoop])
11197 return NO;
11198 if ([cargo count] >= [self maxAvailableCargoSpace])
11199 return NO;
11200 if (scanClass == CLASS_CARGO)
11201 return NO; // we have no power so we can't scoop
11202 if ([other scanClass] != CLASS_CARGO)
11203 return NO;
11204 if ([other cargoType] == CARGO_NOT_CARGO)
11205 return NO;
11206
11207 if ([other isStation])
11208 return NO;
11209
11211
11212 if (dot_product(v_forward, HPVectorToVector(loc)) < 0.0f)
11213 return NO; // Must be in front of us
11214 if ([self isPlayer] && dot_product(v_up, HPVectorToVector(loc)) > 0.0f)
11215 return NO; // player has to scoop on underside, give more flexibility to NPCs
11216
11217 return YES;
11218}
Vector v_up
Definition ShipEntity.h:189
BOOL hasCargoScoop()

References cargo, CARGO_NOT_CARGO, cargoType, count, dot_product(), hasCargoScoop, HPvector_between, HPVectorToVector(), Entity::isPlayer, Entity::isStation, maxAvailableCargoSpace, nil, Entity::position, scanClass, v_forward, and v_up.

Referenced by PlayerEntity::canScoop:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ canStillTrackPrimaryTarget

- (BOOL) canStillTrackPrimaryTarget

Definition at line 8705 of file ShipEntity.m.

8706{
8707 Entity* target = (Entity*)[self primaryTargetWithoutValidityCheck];
8708 if (target == nil) {
8709 return NO;
8710 }
8711 if (![self isValidTarget:target]) {
8712 return NO;
8713 }
8714 double range2 = HPmagnitude2(HPvector_subtract([target position], position));
8715 if (range2 > scannerRange * scannerRange * 1.5625) {
8716 // 1.5625 = 1.25*1.25
8717 return NO;
8718 }
8719 // 1.81: can retain cloaked ships as a *primary* target now
8720 /* if ([target isShip] && [(ShipEntity*)target isCloaked])
8721 {
8722 return NO;
8723 } */
8724 return YES;
8725}
id primaryTargetWithoutValidityCheck()

References canStillTrackPrimaryTarget, HPmagnitude2(), HPvector_subtract(), nil, Entity::position, primaryTargetWithoutValidityCheck, and scannerRange.

Referenced by behaviour_attack_break_off_target:, behaviour_attack_broadside:, behaviour_attack_broadside_target:leftside:, behaviour_attack_fly_to_target:, behaviour_attack_mining_target:, behaviour_attack_slow_dogfight:, behaviour_attack_sniper:, behaviour_close_to_broadside_range:, behaviour_close_with_target:, behaviour_fly_to_target_six:, behaviour_running_defense:, canStillTrackPrimaryTarget, maxFlightSpeed, trackPrimaryTarget:retreat:, and trackSideTarget:leftside:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cargo

- (NSMutableArray *) cargo

References cargo, cargoFlag, contractListForScripting, desiredRange, desiredSpeed, equipmentListForScripting, missilesList, parcelListForScripting, passengerListForScripting, and showScoopMessage.

Here is the call graph for this function:

◆ cargoFlag

- (OOCargoFlag) cargoFlag

Definition at line 7327 of file ShipEntity.m.

7328{
7329 return cargo_flag;
7330}
OOCargoFlag cargo_flag
Definition ShipEntity.h:288

References cargo_flag, and cargoFlag.

Referenced by cargo, and cargoFlag.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cargoListForScripting

- (NSArray *) cargoListForScripting

Reimplemented in PlayerEntity.

Definition at line 7244 of file ShipEntity.m.

7245{
7246 NSMutableArray* list = [NSMutableArray array];
7247
7248 OOCommodityType good = nil;
7249 NSArray* goods = [[UNIVERSE commodityMarket] goods];
7250 NSUInteger i, j, commodityCount = [goods count];
7251 OOCargoQuantity quantityInHold[commodityCount];
7252
7253 for (i = 0; i < commodityCount; i++) {
7254 quantityInHold[i] = 0;
7255 }
7256 for (i = 0; i < [cargo count]; i++) {
7257 ShipEntity* container = [cargo objectAtIndex:i];
7258 j = [goods indexOfObject:[container commodityType]];
7259 quantityInHold[j] += [container commodityAmount];
7260 }
7261
7262 for (i = 0; i < commodityCount; i++) {
7263 if (quantityInHold[i] > 0) {
7264 NSMutableDictionary* commodity = [NSMutableDictionary dictionaryWithCapacity:4];
7265 good = [goods objectAtIndex:i];
7266 // commodity, quantity - keep consistency between .manifest and .contracts
7267 [commodity setObject:good forKey:@"commodity"];
7268 [commodity setObject:[NSNumber numberWithUnsignedInt:quantityInHold[i]] forKey:@"quantity"];
7269 [commodity setObject:[[UNIVERSE commodityMarket] nameForGood:good] forKey:@"displayName"];
7270 [commodity setObject:DisplayStringForMassUnitForCommodity(good) forKey:@"unit"];
7271 [list addObject:commodity];
7272 }
7273 }
7274
7275 return [[list copy] autorelease]; // return an immutable copy
7276}
NSString * OOCommodityType
Definition OOTypes.h:97
uint32_t OOCargoQuantity
Definition OOTypes.h:155
OOCargoQuantity commodityAmount()
OOCommodityType commodityType()

References cargoListForScripting, commodityAmount, commodityType, and nil.

Referenced by bounty, cargoListForScripting, ShipGetProperty(), and ShipGetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cargoQuantityOnBoard

- (OOCargoQuantity) cargoQuantityOnBoard

Reimplemented in PlayerEntity.

Definition at line 7225 of file ShipEntity.m.

7226{
7227 NSUInteger result = [[self cargo] count];
7228 NSAssert(result < UINT32_MAX, @"Cargo quantity out of bounds.");
7229 return (OOCargoQuantity)result;
7230}

References cargo, and cargoQuantityOnBoard.

Referenced by availableCargoSpace, bounty, and cargoQuantityOnBoard.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cargoType

- (OOCargoType) cargoType

Definition at line 7232 of file ShipEntity.m.

7233{
7234 return cargo_type;
7235}
OOCargoType cargo_type
Definition ShipEntity.h:287

References cargo_type, and cargoType.

Referenced by behaviour_intercept_target:, bounty, canScoop:, cargoType, dumpItem:, and scoopUpProcess:processEvents:processMessages:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cascadeIfAppropriateWithDamageAmount:cascadeOwner:

- (BOOL) cascadeIfAppropriateWithDamageAmount: (double) amount
cascadeOwner: (Entity*) owner 

Definition at line 11390 of file ShipEntity.m.

11390 :(double)amount cascadeOwner:(Entity*)owner
11391{
11392 BOOL cascade = NO;
11393 switch ([self scanClass]) {
11394 case CLASS_WORMHOLE:
11395 case CLASS_ROCK:
11396 case CLASS_CARGO:
11397 case CLASS_VISUAL_EFFECT:
11398 case CLASS_BUOY:
11399 // does not normally cascade
11400 if ((fuel > MIN_FUEL) || isStation) {
11401 // we have fuel onboard so we can still go pop, or we are a station which can
11402 } else
11403 break;
11404
11405 case CLASS_STATION:
11406 case CLASS_MINE:
11407 case CLASS_PLAYER:
11408 case CLASS_POLICE:
11409 case CLASS_MILITARY:
11410 case CLASS_THARGOID:
11411 case CLASS_MISSILE:
11412 case CLASS_NOT_SET:
11413 case CLASS_NO_DRAW:
11414 case CLASS_NEUTRAL:
11415 case CLASS_TARGET:
11416 // ...start a chain reaction, if we're dying and have a non-trivial amount of energy.
11417 if (energy < amount && energy > 10 && [self countsAsKill]) {
11418 cascade = YES; // confirm we're cascading, then try to add our cascade to UNIVERSE.
11419 [UNIVERSE addEntity:[OOQuiriumCascadeEntity quiriumCascadeFromShip:self]];
11420 }
11421 break;
11422 // no default thanks, we want the compiler to tell us if we missed a case.
11423 }
11424 return cascade;
11425}
BOOL countsAsKill()

References countsAsKill, fuel, Entity::isStation, MIN_FUEL, OOQuiriumCascadeEntity::quiriumCascadeFromShip:, and scanClass.

Referenced by PlayerEntity::takeEnergyDamage:from:becauseOf:weaponIdentifier:, and takeEnergyDamage:from:becauseOf:weaponIdentifier:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkAegis

- (void) checkAegis
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1272 of file ShipEntityAI.m.

1273{
1274 switch (aegis_status) {
1276 [shipAI message:@"AEGIS_CLOSE_TO_MAIN_PLANET"];
1277 // It's been a few years since 1.71 - it should be safe enough to comment out the line below for 1.77/1.78 -- Kaks 20120917
1278 //[shipAI message:@"AEGIS_CLOSE_TO_PLANET"]; // fires only for main planets, kept for compatibility with pre-1.72 AI plists.
1279 return;
1281 Entity<OOStellarBody>* nearest = [self findNearestStellarBody];
1282
1283 if ([nearest isSun]) {
1284 [shipAI message:@"CLOSE_TO_SUN"];
1285 } else {
1286 [shipAI message:@"CLOSE_TO_PLANET"];
1287 if ([nearest planetType] == STELLAR_TYPE_MOON) {
1288 [shipAI message:@"CLOSE_TO_MOON"];
1289 } else {
1290 [shipAI message:@"CLOSE_TO_SECONDARY_PLANET"];
1291 }
1292 }
1293 return;
1294 }
1296 [shipAI message:@"AEGIS_IN_DOCKING_RANGE"];
1297 return;
1298 case AEGIS_NONE:
1299 [shipAI message:@"AEGIS_NONE"];
1300 return;
1301 }
1302
1303 NSLog(@"Aegis status for %@ has taken on invalid value %i. This is an internal error, please report it.", self, aegis_status);
1305 [shipAI message:@"AEGIS_NONE"];
1306}
#define NSLog(format,...)
Definition OOLogging.h:148
@ STELLAR_TYPE_MOON
@ AEGIS_IN_DOCKING_RANGE
Definition OOTypes.h:57
@ AEGIS_CLOSE_TO_MAIN_PLANET
Definition OOTypes.h:56
@ AEGIS_CLOSE_TO_ANY_PLANET
Definition OOTypes.h:55
@ AEGIS_NONE
Definition OOTypes.h:54
BOOL isSun()
Definition Entity.m:155
OOAegisStatus aegis_status
Definition ShipEntity.h:367

◆ checkCloseCollisionWith:

- (BOOL) checkCloseCollisionWith: (Entity*) other
implementation

Reimplemented from Entity.

Definition at line 1944 of file ShipEntity.m.

1944 :(Entity*)other
1945{
1946 if (other == nil)
1947 return NO;
1948 if ([collidingEntities containsObject:other])
1949 return NO; // we know about this already!
1950
1951 ShipEntity* otherShip = nil;
1952 if ([other isShip])
1953 otherShip = (ShipEntity*)other;
1954
1955 if ([self canScoop:otherShip])
1956 return YES; // quick test - could this improve scooping for small ships? I think so!
1957
1958 if (otherShip != nil && trackCloseContacts) {
1959 // in update we check if close contacts have gone out of touch range (origin within our collision_radius)
1960 // here we check if something has come within that range
1961 HPVector otherPos = [otherShip position];
1962 OOUniversalID otherID = [otherShip universalID];
1963 NSString* other_key = [NSString stringWithFormat:@"%d", otherID];
1964
1965 if (![closeContactsInfo objectForKey:other_key] && HPdistance2(position, otherPos) < collision_radius * collision_radius) {
1966 // calculate position with respect to our own position and orientation
1969 [closeContactsInfo setObject:[NSString stringWithFormat:@"%f %f %f", rpos.x, rpos.y, rpos.z] forKey:other_key];
1970
1971 // send AI a message about the touch
1972 OOWeakReference* temp = _primaryTarget;
1973 _primaryTarget = [otherShip weakRetain];
1974 [self doScriptEvent:OOJSID("shipCloseContact") withArgument:otherShip andReactToAIMessage:@"CLOSE CONTACT"];
1975 _primaryTarget = temp;
1976 }
1977 }
1978
1979 /* This does not appear to save a significant amount of time in
1980 * most situations. No significant change in frame rate with a
1981 * 350-segment planetary ring at 1400 collision candidates, even
1982 * on old hardware. There are perhaps situations in which it could
1983 * be a significant optimisation, but those are likely to also be
1984 * the situations where the effect of adding hundreds of extra
1985 * false-positive collisions leaves the player returning to a
1986 * mess... So, commented out: CIM 21 Jan 2014
1987 if (zero_distance > CLOSE_COLLISION_CHECK_MAX_RANGE2) // don't work too hard on entities that are far from the player
1988 return YES;
1989 */
1990
1991 if (otherShip != nil) {
1992 // check hull octree versus other hull octree
1993 collider = doOctreesCollide(self, otherShip);
1994 return (collider != nil);
1995 }
1996
1997 // default at this stage is to say YES they've collided!
1998 collider = other;
1999 return YES;
2000}
uint16_t OOUniversalID
Definition OOTypes.h:165
OOINLINE Vector make_vector(OOScalar vx, OOScalar vy, OOScalar vz) INLINE_CONST_FUNC
Definition OOVector.h:149
NSMutableArray * collidingEntities
Definition Entity.h:144
Entity * collider
Definition Entity.h:124
unsigned trackCloseContacts
ShipEntity * doOctreesCollide(ShipEntity *prime, ShipEntity *other)
NSMutableDictionary * closeContactsInfo
Definition ShipEntity.h:390
Vector v_right
Definition ShipEntity.h:189

References _primaryTarget, closeContactsInfo, Entity::collider, Entity::collidingEntities, Entity::collision_radius, doOctreesCollide(), doScriptEvent:withArgument:andReactToAIMessage:, dot_product(), HPdistance2(), HPvector_between, HPVectorToVector(), Entity::isShip, make_vector(), nil, Entity::position, trackCloseContacts, Entity::universalID, v_forward, v_right, v_up, and OOWeakRefObject::weakRetain.

Referenced by CollisionRegion::findCollisions.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkCourseToDestination

- (void) checkCourseToDestination
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1256 of file ShipEntityAI.m.

1257{
1258 Entity* hazard = [UNIVERSE hazardOnRouteFromEntity:self toDistance:desired_range fromPoint:_destination];
1259
1260 if (hazard == nil || ([hazard isShip] && HPdistance(position, [hazard position]) > scannerRange) || ([hazard isPlanet] && aegis_status == AEGIS_NONE))
1261 [shipAI message:@"COURSE_OK"]; // Avoid going into a waypoint.plist for far away objects, it cripples the main AI a bit in its funtionality.
1262 else {
1263 if ([hazard isShip] && (weapon_damage * 24.0 > [hazard energy])) {
1264 [shipAI reactToMessage:@"HAZARD_CAN_BE_DESTROYED" context:@"checkCourseToDestination"];
1265 }
1266
1267 _destination = [UNIVERSE getSafeVectorFromEntity:self toDistance:desired_range fromPoint:_destination];
1268 [shipAI message:@"WAYPOINT_SET"];
1269 }
1270}

◆ checkDistanceTravelled

- (void) checkDistanceTravelled
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1536 of file ShipEntityAI.m.

1537{
1539 [shipAI message:@"GONE_BEYOND_RANGE"];
1540}
GLfloat distanceTravelled
Definition Entity.m:718

◆ checkEnergy

- (void) checkEnergy
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1308 of file ShipEntityAI.m.

1309{
1310 if (energy == maxEnergy) {
1311 [shipAI message:@"ENERGY_FULL"];
1312 return;
1313 }
1314 if (energy >= maxEnergy * 0.75) {
1315 [shipAI message:@"ENERGY_HIGH"];
1316 return;
1317 }
1318 if (energy <= maxEnergy * 0.25) {
1319 [shipAI message:@"ENERGY_LOW"];
1320 return;
1321 }
1322 [shipAI message:@"ENERGY_MEDIUM"];
1323}

◆ checkForAegis

- (OOAegisStatus) checkForAegis

Definition at line 6668 of file ShipEntity.m.

6669{
6670 Entity<OOStellarBody>* nearest = [self findNearestStellarBody];
6671 BOOL sunGoneNova = [[UNIVERSE sun] goneNova];
6672
6673 if (nearest == nil) {
6674 if (aegis_status != AEGIS_NONE) {
6675 // Planet disappeared!
6676 [self transitionToAegisNone];
6677 }
6678 return AEGIS_NONE;
6679 }
6680 // check planet
6681 float cr = [nearest radius];
6682 float cr2 = cr * cr;
6683 OOAegisStatus result = AEGIS_NONE;
6684 float d2 = HPmagnitude2(HPvector_subtract([nearest position], [self position]));
6685 // not scannerRange: aegis shouldn't depend on that
6686 float sd2 = SCANNER_MAX_RANGE2 * 10.0f;
6687
6688 // check if nearing a surface
6689 unsigned wasNearPlanetSurface = isNearPlanetSurface; // isNearPlanetSurface is a bit flag, not an actual BOOL
6690 isNearPlanetSurface = (d2 - cr2) < (250000.0f + 1000.0f * cr); // less than 500m from the surface: (a+b)*(a+b) = a*a+b*b +2*a*b
6691
6692 if (EXPECT_NOT((wasNearPlanetSurface != isNearPlanetSurface) && !suppressAegisMessages)) {
6693 if (isNearPlanetSurface) {
6694 [self doScriptEvent:OOJSID("shipApproachingPlanetSurface") withArgument:nearest];
6695 [shipAI reactToMessage:@"APPROACHING_SURFACE" context:@"flight update"];
6696 } else {
6697 [self doScriptEvent:OOJSID("shipLeavingPlanetSurface") withArgument:nearest];
6698 [shipAI reactToMessage:@"LEAVING_SURFACE" context:@"flight update"];
6699 }
6700 }
6701
6702 // being close to the station takes precedence over planets
6703 StationEntity* the_station = [UNIVERSE station];
6704 if (the_station) {
6705 sd2 = HPmagnitude2(HPvector_subtract([the_station position], [self position]));
6706 }
6707 // again, notional scanner range is intentional
6708 if (sd2 < SCANNER_MAX_RANGE2 * 4.0f) // double scanner range
6709 {
6710 result = AEGIS_IN_DOCKING_RANGE;
6711 } else if (EXPECT_NOT(isNearPlanetSurface || d2 < cr2 * 9.0f)) // to 3x radius of any planet/moon - or 500m of tiny ones,
6712 {
6714 if (EXPECT((OOPlanetEntity*)nearest == [UNIVERSE planet])) {
6716 }
6717 }
6718 // need to do this check separately from above case to avoid oddity where
6719 // main planet and small moon are at just the wrong distance. - CIM
6720 if (result != AEGIS_CLOSE_TO_MAIN_PLANET && result != AEGIS_IN_DOCKING_RANGE && !sunGoneNova) {
6721 // are we also close to the main planet?
6722 OOPlanetEntity* mainPlanet = [UNIVERSE planet];
6723 d2 = HPmagnitude2(HPvector_subtract([mainPlanet position], [self position]));
6724 cr2 = [mainPlanet radius];
6725 cr2 *= cr2;
6726 if (d2 < cr2 * 9.0f) {
6727 nearest = mainPlanet;
6729 }
6730 }
6731
6732 /* Rewrote aegis stuff and tested it against redux.oxp that adds multiple planets and moons.
6733 Made sure AI scripts can differentiate between MAIN and NON-MAIN planets so they can decide
6734 if they can dock at the systemStation or just any station.
6735 Added sun detection so route2Patrol can turn before they heat up in the sun.
6736 -- Eric 2009-07-11
6737
6738 More rewriting of the aegis stuff, it's now a bit faster and works properly when moving
6739 from one secondary planet/moon vicinity to another one. -- Kaks 20120917
6740 */
6742 // script/AI messages on change in status
6744 [self doScriptEvent:OOJSID("shipExitedStationAegis") withArgument:the_station];
6745 [shipAI message:@"AEGIS_LEAVING_DOCKING_RANGE"];
6746 }
6747
6748 if (EXPECT_NOT(result == AEGIS_IN_DOCKING_RANGE && aegis_status != result)) {
6749 [self doScriptEvent:OOJSID("shipEnteredStationAegis") withArgument:the_station];
6750 [shipAI message:@"AEGIS_IN_DOCKING_RANGE"];
6751
6752 if ([self lastAegisLock] == nil && !sunGoneNova) // With small main planets the station aegis can come before planet aegis
6753 {
6754 [self doScriptEvent:OOJSID("shipEnteredPlanetaryVicinity") withArgument:[UNIVERSE planet]];
6755 [self setLastAegisLock:[UNIVERSE planet]];
6756 }
6757 } else if (EXPECT_NOT(result == AEGIS_NONE && aegis_status != result)) {
6758 if ([self lastAegisLock] == nil && !sunGoneNova) {
6759 [self setLastAegisLock:[UNIVERSE planet]]; // in case of a first launch from a near-planet station.
6760 }
6761 [self transitionToAegisNone];
6762 }
6763 // approaching..
6764 else if (EXPECT_NOT((result == AEGIS_CLOSE_TO_ANY_PLANET || result == AEGIS_CLOSE_TO_MAIN_PLANET) && [self lastAegisLock] != nearest)) {
6765 if (aegis_status != AEGIS_NONE && [self lastAegisLock] != nil) // we were close to another stellar body
6766 {
6767 [self doScriptEvent:OOJSID("shipExitedPlanetaryVicinity") withArgument:[self lastAegisLock]];
6768 [shipAI message:@"AWAY_FROM_PLANET"]; // fires for suns, planets and moons.
6769 }
6770 [self doScriptEvent:OOJSID("shipEnteredPlanetaryVicinity") withArgument:nearest];
6771 [self setLastAegisLock:nearest];
6772
6773 if (EXPECT_NOT([nearest isSun])) {
6774 [shipAI message:@"CLOSE_TO_SUN"];
6775 } else {
6776 [shipAI message:@"CLOSE_TO_PLANET"];
6777
6778 if (EXPECT(result == AEGIS_CLOSE_TO_MAIN_PLANET)) {
6779 // It's been years since 1.71 - it should be safe enough to comment out the line below for 1.77/1.78 -- Kaks 20120917
6780 //[shipAI message:@"AEGIS_CLOSE_TO_PLANET"]; // fires only for main planets, kept for compatibility with pre-1.72 AI plists.
6781 [shipAI message:@"AEGIS_CLOSE_TO_MAIN_PLANET"]; // fires only for main planet.
6782 } else if (EXPECT_NOT([nearest planetType] == STELLAR_TYPE_MOON)) {
6783 [shipAI message:@"CLOSE_TO_MOON"];
6784 } else {
6785 [shipAI message:@"CLOSE_TO_SECONDARY_PLANET"];
6786 }
6787 }
6788 }
6789 }
6790 if (result == AEGIS_NONE) {
6791 [self setLastAegisLock:nil];
6792 }
6793
6794 aegis_status = result; // put this here
6795 return result;
6796}
OOAegisStatus
Definition OOTypes.h:53
unsigned isNearPlanetSurface
Definition ShipEntity.h:252
unsigned suppressAegisMessages
Definition ShipEntity.h:261
Entity< OOStellarBody > * lastAegisLock()

References AEGIS_CLOSE_TO_ANY_PLANET, AEGIS_CLOSE_TO_MAIN_PLANET, AEGIS_IN_DOCKING_RANGE, AEGIS_NONE, aegis_status, checkForAegis, doScriptEvent:withArgument:, EXPECT, EXPECT_NOT, findNearestStellarBody, HPmagnitude2(), HPvector_subtract(), isNearPlanetSurface, Entity::isSun, lastAegisLock, AI::message:, nil, Entity::position, AI::reactToMessage:context:, SCANNER_MAX_RANGE2, setLastAegisLock:, STELLAR_TYPE_MOON, suppressAegisMessages, transitionToAegisNone, and UNIVERSE.

Referenced by checkForAegis, PlayerEntity::leaveDock:, reportAIMessages, PlayerEntity::setNextCompassMode, PlayerEntity::setPrevCompassMode, update:, and PlayerEntity::validateCompassTarget.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkForFullHold

- (void) checkForFullHold
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1026 of file ShipEntityAI.m.

1027{
1028 if (!max_cargo) {
1029 [shipAI message:@"NO_CARGO_BAY"];
1030 } else if ([cargo count] >= [self maxAvailableCargoSpace]) {
1031 [shipAI message:@"HOLD_FULL"];
1032 } else {
1033 [shipAI message:@"HOLD_NOT_FULL"];
1034 }
1035}

◆ checkForMotherStation

- (void) checkForMotherStation
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1788 of file ShipEntityAI.m.

1789{
1790 ShipEntity* motherStation = [[self group] leader];
1791 if ((!motherStation) || (!(motherStation->isStation))) {
1792 [shipAI message:@"NOTHING_FOUND"];
1793 return;
1794 }
1795 double found_d2 = scannerRange * scannerRange;
1796 HPVector v0 = motherStation->position;
1797 if (HPdistance2(v0, position) > found_d2) {
1798 [shipAI message:@"NOTHING_FOUND"];
1799 return;
1800 }
1801 [shipAI message:@"STATION_FOUND"];
1802}

◆ checkForNormalSpace

- (void) checkForNormalSpace
implementation

Provided by category ShipEntity(PureAI).

Definition at line 2173 of file ShipEntityAI.m.

2174{
2175 if ([UNIVERSE sun] && [UNIVERSE planet])
2176 [shipAI message:@"NORMAL_SPACE"];
2177 else
2178 [shipAI message:@"INTERSTELLAR_SPACE"];
2179}

◆ checkFoundTarget

- (void) checkFoundTarget
implementation

Provided by category ShipEntity(OOAIPrivate).

Definition at line 2393 of file ShipEntityAI.m.

2394{
2395 if ([self foundTarget] != nil) {
2396 [shipAI message:@"TARGET_FOUND"];
2397 } else {
2398 [shipAI message:@"NOTHING_FOUND"];
2399 }
2400}
Entity * foundTarget()

Referenced by ShipEntity(PureAI)::requestNewTarget, ShipEntity(AI)::scanForHostiles, ShipEntity(PureAI)::scanForLoot, ShipEntity(PureAI)::scanForNearestMerchantman, ShipEntity(OOAIPrivate)::scanForNearestShipWithPredicate:parameter:, ShipEntity(PureAI)::scanForNonThargoid, ShipEntity(PureAI)::scanForOffenders, and ShipEntity(PureAI)::scanForRocks.

Here is the caller graph for this function:

◆ checkGroupOddsVersusTarget

- (void) checkGroupOddsVersusTarget
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1607 of file ShipEntityAI.m.

1608{
1609 NSUInteger ownGroupCount = [[self group] count] + (ranrot_rand() & 3); // add a random fudge factor
1610 NSUInteger targetGroupCount = [[[self primaryTarget] group] count] + (ranrot_rand() & 3); // add a random fudge factor
1611
1612 if (ownGroupCount == targetGroupCount) {
1613 [shipAI message:@"ODDS_LEVEL"];
1614 } else if (ownGroupCount > targetGroupCount) {
1615 [shipAI message:@"ODDS_GOOD"];
1616 } else {
1617 [shipAI message:@"ODDS_BAD"];
1618 }
1619}

◆ checkHeatInsulation

- (void) checkHeatInsulation
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1325 of file ShipEntityAI.m.

1326{
1327 float minInsulation = 1000 / [self maxFlightSpeed] + 1;
1328
1329 if ([self heatInsulation] < minInsulation) {
1330 [shipAI message:@"INSULATION_POOR"];
1331 return;
1332 }
1333 [shipAI message:@"INSULATION_OK"];
1334}
GLfloat heatInsulation()

◆ checkOwnLegalStatus

- (void) checkOwnLegalStatus
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1207 of file ShipEntityAI.m.

1208{
1209 if (scanClass == CLASS_THARGOID) {
1210 [shipAI message:@"SELF_THARGOID"];
1211 return;
1212 }
1213 int ls = [self legalStatus];
1214 if (ls > 50) {
1215 [shipAI message:@"SELF_FUGITIVE"];
1216 return;
1217 }
1218 if (ls > 20) {
1219 [shipAI message:@"SELF_OFFENDER"];
1220 return;
1221 }
1222 if (ls > 0) {
1223 [shipAI message:@"SELF_MINOR_OFFENDER"];
1224 return;
1225 }
1226 [shipAI message:@"SELF_CLEAN"];
1227}

◆ checkScanner

- (void) checkScanner

Definition at line 8457 of file ShipEntity.m.

8458{
8459 Entity* scan;
8460 n_scanned_ships = 0;
8461 //
8462 scan = z_previous;
8463 while ((scan) && (scan->isShip == NO))
8464 scan = scan->z_previous; // skip non-ships
8465 GLfloat scannerRange2 = scannerRange * scannerRange;
8466 while ((scan) && (scan->position.z > position.z - scannerRange) && (n_scanned_ships < MAX_SCAN_NUMBER)) {
8467 // can't scan cloaked ships
8468 if (scan->isShip && ![(ShipEntity*)scan isCloaked] && [self isValidTarget:scan]) {
8469 distance2_scanned_ships[n_scanned_ships] = HPdistance2(position, scan->position);
8470 if (distance2_scanned_ships[n_scanned_ships] < scannerRange2)
8471 scanned_ships[n_scanned_ships++] = (ShipEntity*)scan;
8472 }
8473 scan = scan->z_previous;
8474 while ((scan) && (scan->isShip == NO))
8475 scan = scan->z_previous;
8476 }
8477 //
8478 scan = z_next;
8479 while ((scan) && (scan->isShip == NO))
8480 scan = scan->z_next; // skip non-ships
8481 while ((scan) && (scan->position.z < position.z + scannerRange) && (n_scanned_ships < MAX_SCAN_NUMBER)) {
8482 if (scan->isShip && ![(ShipEntity*)scan isCloaked] && [self isValidTarget:scan]) {
8483 distance2_scanned_ships[n_scanned_ships] = HPdistance2(position, scan->position);
8484 if (distance2_scanned_ships[n_scanned_ships] < scannerRange2)
8485 scanned_ships[n_scanned_ships++] = (ShipEntity*)scan;
8486 }
8487 scan = scan->z_next;
8488 while ((scan) && (scan->isShip == NO))
8489 scan = scan->z_next; // skip non-ships
8490 }
8491 //
8492 scanned_ships[n_scanned_ships] = nil; // terminate array
8493}
#define MAX_SCAN_NUMBER
Definition ShipEntity.h:99
Entity * z_next
Definition Entity.h:118
Entity * z_previous
Definition Entity.h:118
GLfloat distance2_scanned_ships[MAX_SCAN_NUMBER+1]
Definition ShipEntity.h:402

References checkScanner, distance2_scanned_ships, HPdistance2(), isCloaked, Entity::isShip, MAX_SCAN_NUMBER, n_scanned_ships, nil, Entity::position, scanned_ships, scannerRange, HPVector::z, Entity::z_next, and Entity::z_previous.

Referenced by broadcastAIMessage:, broadcastMessage:withUnpilotedOverride:, checkScanner, ShipEntity(PureAI)::findNewDefenseTarget, maxFlightSpeed, ShipEntity(PureAI)::requestNewTarget, ShipEntity(AI)::scanForHostiles, ShipEntity(PureAI)::scanForLoot, ShipEntity(OOAIPrivate)::scanForNearestShipWithPredicate:parameter:, ShipEntity(PureAI)::scanForNonThargoid, ShipEntity(PureAI)::scanForOffenders, ShipEntity(PureAI)::scanForRandomLoot, and ShipEntity(PureAI)::scanForRocks.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkScannerIgnoringUnpowered

- (void) checkScannerIgnoringUnpowered

Definition at line 8495 of file ShipEntity.m.

8496{
8497 Entity* scan;
8498 n_scanned_ships = 0;
8499 //
8500 GLfloat scannerRange2 = scannerRange * scannerRange;
8501 scan = z_previous;
8502 while ((scan) && ((scan->isShip == NO) || (scan->scanClass == CLASS_ROCK) || (scan->scanClass == CLASS_CARGO))) {
8503 scan = scan->z_previous; // skip non-ships
8504 }
8505 while ((scan) && (scan->position.z > position.z - scannerRange) && (n_scanned_ships < MAX_SCAN_NUMBER)) {
8506 if (scan->isShip && ![(ShipEntity*)scan isCloaked]) {
8507 distance2_scanned_ships[n_scanned_ships] = HPdistance2(position, scan->position);
8508 if (distance2_scanned_ships[n_scanned_ships] < scannerRange2)
8509 scanned_ships[n_scanned_ships++] = (ShipEntity*)scan;
8510 }
8511 scan = scan->z_previous;
8512 while ((scan) && ((scan->isShip == NO) || (scan->scanClass == CLASS_ROCK) || (scan->scanClass == CLASS_CARGO))) {
8513 scan = scan->z_previous; // skip non-ships
8514 }
8515 }
8516 //
8517 scan = z_next;
8518 while ((scan) && ((scan->isShip == NO) || (scan->scanClass == CLASS_ROCK) || (scan->scanClass == CLASS_CARGO))) {
8519 scan = scan->z_next; // skip non-ships
8520 }
8521
8522 while ((scan) && (scan->position.z < position.z + scannerRange) && (n_scanned_ships < MAX_SCAN_NUMBER)) {
8523 if (scan->isShip && ![(ShipEntity*)scan isCloaked]) {
8524 distance2_scanned_ships[n_scanned_ships] = HPdistance2(position, scan->position);
8525 if (distance2_scanned_ships[n_scanned_ships] < scannerRange2)
8526 scanned_ships[n_scanned_ships++] = (ShipEntity*)scan;
8527 }
8528 scan = scan->z_next;
8529 while ((scan) && ((scan->isShip == NO) || (scan->scanClass == CLASS_ROCK) || (scan->scanClass == CLASS_CARGO))) {
8530 scan = scan->z_next; // skip non-ships
8531 }
8532 }
8533 //
8534 scanned_ships[n_scanned_ships] = nil; // terminate array
8535}
OOScanClass scanClass
Definition Entity.m:743

References checkScannerIgnoringUnpowered, distance2_scanned_ships, HPdistance2(), isCloaked, Entity::isShip, MAX_SCAN_NUMBER, n_scanned_ships, nil, Entity::position, Entity::scanClass, scanned_ships, scannerRange, HPVector::z, Entity::z_next, and Entity::z_previous.

Referenced by ShipEntity(AI)::broadcastDistressMessageWithDumping:, checkScannerIgnoringUnpowered, dumpCargoItem:, ShipEntity(PureAI)::fightOrFleeMissile, getTractoredBy:, maxFlightSpeed, ShipEntity(PureAI)::scanForFormationLeader, ShipEntity(PureAI)::scanForNearestMerchantman, ShipEntity(PureAI)::scanForRandomMerchantman, and scoopUpProcess:processEvents:processMessages:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkShipsInVicinityForWitchJumpExit

- (int) checkShipsInVicinityForWitchJumpExit

Definition at line 12507 of file ShipEntity.m.

12508{
12509 // checks if there are any large masses close by
12510 // since we want to place the space station at least 10km away
12511 // the formula we'll use is K x m / d2 < 1.0
12512 // (m = mass, d2 = distance squared)
12513 // coriolis station is mass 455,223,200
12514 // 10km is 10,000m,
12515 // 10km squared is 100,000,000
12516 // therefore K is 0.22 (approx)
12517
12518 int result = NO_TARGET;
12519
12520 GLfloat k = 0.1;
12521
12522 int ent_count = UNIVERSE->n_entities;
12523 Entity** uni_entities = UNIVERSE->sortedEntities; // grab the public sorted list
12524 ShipEntity* my_entities[ent_count];
12525 int i;
12526
12527 int ship_count = 0;
12528 for (i = 0; i < ent_count; i++)
12529 if ((uni_entities[i]->isShip) && (uni_entities[i] != self))
12530 my_entities[ship_count++] = (ShipEntity*)[uni_entities[i] retain]; // retained
12531 //
12532 for (i = 0; (i < ship_count) && (result == NO_TARGET); i++) {
12533 ShipEntity* ship = my_entities[i];
12535 GLfloat d2 = HPmagnitude2(delta);
12536 if (![ship isPlayer] || ![PLAYER isDocked]) { // player doesn't block if docked
12537 if ((k * [ship mass] > d2) && (d2 < SCANNER_MAX_RANGE2)) // if you go off (typical) scanner from a blocker - it ceases to block
12538 result = [ship universalID];
12539 }
12540 }
12541 for (i = 0; i < ship_count; i++)
12542 [my_entities[i] release]; // released
12543
12544 return result;
12545}

References checkShipsInVicinityForWitchJumpExit, HPmagnitude2(), HPvector_between, int(), Entity::isPlayer, Entity::isShip, Entity::mass, NO_TARGET, PLAYER, Entity::position, SCANNER_MAX_RANGE2, Entity::universalID, and UNIVERSE.

Referenced by checkShipsInVicinityForWitchJumpExit, ShipEntity(OOAIPrivate)::performHyperSpaceExitReplace:toSystem:, sunGlareFilter, and PlayerEntity::witchJumpChecklist:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkTargetLegalStatus

- (void) checkTargetLegalStatus
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1183 of file ShipEntityAI.m.

1184{
1185 ShipEntity* other_ship = [self primaryTarget];
1186 if (!other_ship) {
1187 [shipAI message:@"NO_TARGET"];
1188 return;
1189 } else {
1190 int ls = [other_ship legalStatus];
1191 if (ls > 50) {
1192 [shipAI message:@"TARGET_FUGITIVE"];
1193 return;
1194 }
1195 if (ls > 20) {
1196 [shipAI message:@"TARGET_OFFENDER"];
1197 return;
1198 }
1199 if (ls > 0) {
1200 [shipAI message:@"TARGET_MINOR_OFFENDER"];
1201 return;
1202 }
1203 [shipAI message:@"TARGET_CLEAN"];
1204 }
1205}
int legalStatus()

◆ clearSubEntities

- (void) clearSubEntities

Definition at line 1066 of file ShipEntity.m.

1067{
1068 [subEntities makeObjectsPerformSelector:@selector(setOwner:) withObject:nil]; // Ensure backlinks are broken
1069 [subEntities release];
1070 subEntities = nil;
1071
1072 // reset size & mass!
1073 collision_radius = [self findCollisionRadius];
1075 float density = [[self shipInfoDictionary] oo_floatForKey:@"density" defaultValue:1.0f];
1076 if (octree)
1077 mass = (GLfloat)(density * 20.0f * [octree volume]);
1078}
float volume()
Octree * octree

References _profileRadius, clearSubEntities, Entity::collision_radius, OOEntityWithDrawable::findCollisionRadius, Entity::mass, nil, octree, shipInfoDictionary, subEntities, and volume.

Referenced by becomeExplosion, becomeLargeExplosion:, clearSubEntities, dealloc, PlayerEntity(Contracts)::newShipCommonSetup:yardInfo:baseInfo:, PlayerEntity::setUpAndConfirmOK:saveGame:, ShipRestoreSubEntities(), ShipRestoreSubEntities(), subEntities, and PlayerEntity(OOPrivate)::tryBuyingItem:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ collectBountyFor:

- (void) collectBountyFor: (ShipEntity*) other

Reimplemented in PlayerEntity.

Definition at line 8347 of file ShipEntity.m.

8347 :(ShipEntity*)other
8348{
8349 if ([other isPolice]) // oops, we shot a copper!
8350 {
8351 [self markAsOffender:64 withReason:kOOLegalStatusReasonAttackedPolice];
8352 }
8353}

References isPolice, and markAsOffender:withReason:.

Referenced by noteTargetDestroyed:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ collideWithShip:

- (BOOL) collideWithShip: (ShipEntity*) other

Reimplemented in StationEntity.

Definition at line 11029 of file ShipEntity.m.

11029 :(ShipEntity*)other
11030{
11031 HPVector hploc;
11032 Vector loc;
11033 double dam1, dam2;
11034
11035 if (!other)
11036 return NO;
11037
11038 ShipEntity* otherParent = [other parentEntity];
11039 BOOL otherIsStation = other == [UNIVERSE station];
11040 // calculate line of centers using centres
11042 loc = HPVectorToVector(hploc);
11043
11044 if ([self canScoop:other]) {
11045 [self scoopIn:other];
11046 return NO;
11047 }
11048 if ([other canScoop:self]) {
11049 [other scoopIn:self];
11050 return NO;
11051 }
11052 if (universalID == NO_TARGET)
11053 return NO;
11054 if (other->universalID == NO_TARGET)
11055 return NO;
11056
11057 // find velocity along line of centers
11058 //
11059 // momentum = mass x velocity
11060 // ke = mass x velocity x velocity
11061 //
11062 GLfloat m1 = mass; // mass of self
11063 GLfloat m2 = [other mass]; // mass of other
11064
11065 // starting velocities:
11066 Vector v, vel1b = [self velocity];
11067
11068 if (otherParent != nil) {
11069 // Subentity
11070 /* TODO: if the subentity is rotating (subentityRotationalVelocity is
11071 not 1 0 0 0) we should calculate the tangential velocity from the
11072 other's position relative to our absolute position and add that in.
11073 */
11074 v = [otherParent velocity];
11075 } else {
11076 v = [other velocity];
11077 }
11078
11079 v = vector_subtract(vel1b, v);
11080
11081 GLfloat v2b = dot_product(v, loc); // velocity of other along loc before collision
11082
11083 GLfloat v1a = sqrt(v2b * v2b * m2 / m1); // velocity of self along loc after elastic collision
11084 if (v2b < 0.0f)
11085 v1a = -v1a; // in same direction as v2b
11086
11087 // are they moving apart at over 1m/s already?
11088 if (v2b < 0.0f) {
11089 if (v2b < -1.0f)
11090 return NO;
11091 else {
11092 position = HPvector_subtract(position, hploc); // adjust self position
11093 v = kZeroVector; // go for the 1m/s solution
11094 }
11095 }
11096
11097 // convert change in velocity into damage energy (KE)
11098 dam1 = m2 * v2b * v2b / 50000000;
11099 dam2 = m1 * v2b * v2b / 50000000;
11100
11101 // calculate adjustments to velocity after collision
11102 Vector vel1a = vector_multiply_scalar(loc, -v1a);
11103 Vector vel2a = vector_multiply_scalar(loc, v2b);
11104
11105 if (magnitude2(v) <= 0.1) // virtually no relative velocity - we must provide at least 1m/s to avoid conjoined objects
11106 {
11107 vel1a = vector_multiply_scalar(loc, -1);
11108 vel2a = loc;
11109 }
11110
11111 // apply change in velocity
11112 if (otherParent != nil) {
11113 [otherParent adjustVelocity:vel2a]; // move the otherParent not the subentity
11114 } else {
11115 [other adjustVelocity:vel2a];
11116 }
11117
11118 [self adjustVelocity:vel1a];
11119
11120 BOOL selfDestroyed = (dam1 > energy);
11121 BOOL otherDestroyed = (dam2 > [other energy]) && !otherIsStation;
11122
11123 if (dam1 > 0.05) {
11124 [self takeScrapeDamage:dam1 from:other];
11125 if (selfDestroyed) // inelastic! - take xplosion velocity damage instead
11126 {
11127 vel2a = vector_multiply_scalar(vel2a, -1);
11128 [other adjustVelocity:vel2a];
11129 }
11130 }
11131
11132 if (dam2 > 0.05) {
11133 if (otherParent != nil && ![otherParent isFrangible]) {
11134 [otherParent takeScrapeDamage:dam2 from:self];
11135 } else {
11136 [other takeScrapeDamage:dam2 from:self];
11137 }
11138
11139 if (otherDestroyed) // inelastic! - take explosion velocity damage instead
11140 {
11141 vel1a = vector_multiply_scalar(vel1a, -1);
11142 [self adjustVelocity:vel1a];
11143 }
11144 }
11145
11146 if (!selfDestroyed && !otherDestroyed) {
11147 float t = 10.0 * [UNIVERSE getTimeDelta]; // 10 ticks
11148
11150 [self setPosition:pos1a];
11151
11152 if (!otherIsStation) {
11153 HPVector pos2a = HPvector_add([other position], vectorToHPVector(vector_multiply_scalar(loc, t * v2b)));
11154 [other setPosition:pos2a];
11155 }
11156 }
11157
11158 // remove self from other's collision list
11159 [[other collisionArray] removeObject:self];
11160
11161 [self doScriptEvent:OOJSID("shipCollided") withArgument:other andReactToAIMessage:@"COLLISION"];
11162 [other doScriptEvent:OOJSID("shipCollided") withArgument:self andReactToAIMessage:@"COLLISION"];
11163
11164 return YES;
11165}
OOINLINE HPVector HPvector_normal_or_zbasis(HPVector vec) INLINE_CONST_FUNC
Definition OOHPVector.h:283
HPVector absolutePositionForSubentity()
Definition Entity.m:627
ShipEntity * parentEntity()
Definition Entity.m:553
unsigned isFrangible
void takeScrapeDamage:from:(double amount,[from] Entity *ent)
void adjustVelocity:(Vector xVel)

References Entity::absolutePositionForSubentity, adjustVelocity:, Entity::collisionArray, doScriptEvent:withArgument:andReactToAIMessage:, dot_product(), Entity::energy, HPvector_add(), HPvector_normal_or_zbasis(), HPvector_subtract(), HPVectorToVector(), isFrangible, kZeroVector, magnitude2(), Entity::mass, nil, NO_TARGET, Entity::parentEntity, Entity::position, scoopIn:, Entity::setPosition:, takeScrapeDamage:from:, Entity::universalID, vector_multiply_scalar(), vector_subtract(), vectorToHPVector(), velocity, and Entity::velocity.

Referenced by StationEntity::collideWithShip:, and manageCollisions.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ collisionExceptedFor:

- (BOOL) collisionExceptedFor: (ShipEntity*) ship

Definition at line 9655 of file ShipEntity.m.

9655 :(ShipEntity*)ship
9656{
9657 if (_collisionExceptions == nil) {
9658 return NO;
9659 }
9660 return [_collisionExceptions containsObject:ship];
9661}

References _collisionExceptions, OOWeakSet::containsObject:, and nil.

Here is the call graph for this function:

◆ collisionExceptions

- (NSArray *) collisionExceptions

Definition at line 9631 of file ShipEntity.m.

9632{
9633 if (_collisionExceptions == nil) {
9634 return [NSArray array];
9635 }
9636 return [_collisionExceptions allObjects];
9637}

References _collisionExceptions, OOWeakSet::allObjects, collisionExceptions, and nil.

Referenced by collisionExceptions, isMissile, ShipGetProperty(), and ShipGetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ commodityAmount

- (OOCargoQuantity) commodityAmount

Definition at line 7202 of file ShipEntity.m.

7203{
7204 return commodity_amount;
7205}
OOCargoQuantity commodity_amount
Definition ShipEntity.h:353

References commodity_amount, and commodityAmount.

Referenced by bounty, PlayerEntity::cargoListForScripting, cargoListForScripting, PlayerEntity::cargoQuantityForType:, PlayerEntity::collectBountyFor:, commodityAmount, PlayerEntity::setGuiToMarketInfoScreen, PlayerEntity::setGuiToMarketScreen, PlayerEntity::unloadAllCargoPodsForType:toManifest:, and PlayerEntity::unloadCargoPodsForType:amount:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ commodityType

- (OOCommodityType) commodityType

Definition at line 7197 of file ShipEntity.m.

7198{
7199 return commodity_type;
7200}
OOCommodityType commodity_type
Definition ShipEntity.h:352

References commodity_type, and commodityType.

Referenced by bounty, PlayerEntity::cargoListForScripting, cargoListForScripting, Universe::cargoPodFromTemplate:, PlayerEntity::cargoQuantityForType:, commodityType, dumpCargo, dumpCargoItem:, removeCargo:amount:, PlayerEntity::rotateCargo, scoopUpProcess:processEvents:processMessages:, PlayerEntity::setGuiToMarketInfoScreen, PlayerEntity::setGuiToMarketScreen, ShipGetProperty(), ShipGetProperty(), PlayerEntity::takeInternalDamage, PlayerEntity::unloadAllCargoPodsForType:toManifest:, PlayerEntity::unloadCargoPodsForType:amount:, and OOTrumble::updateTrumble:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ commsMessage:

- (void) commsMessage: (NSString*) valueString
implementation

Reimplemented in PlayerEntity.

Provided by category ShipEntity(PureAI).

Definition at line 1439 of file ShipEntityAI.m.

1439 :(NSString*)valueString
1440{
1441 [self commsMessage:valueString withUnpilotedOverride:NO];
1442}

◆ commsMessage:withUnpilotedOverride:

- (void) commsMessage: (NSString*) valueString
withUnpilotedOverride: (BOOL) unpilotedOverride 

Definition at line 12424 of file ShipEntity.m.

12424 :(NSString*)valueString withUnpilotedOverride:(BOOL)unpilotedOverride
12425{
12426 Random_Seed very_random_seed;
12427 very_random_seed.a = rand() & 255;
12428 very_random_seed.b = rand() & 255;
12429 very_random_seed.c = rand() & 255;
12430 very_random_seed.d = rand() & 255;
12431 very_random_seed.e = rand() & 255;
12432 very_random_seed.f = rand() & 255;
12433 seed_RNG_only_for_planet_description(very_random_seed);
12434
12435 [self broadcastMessage:valueString withUnpilotedOverride:unpilotedOverride];
12436}
void seed_RNG_only_for_planet_description(Random_Seed s_seed)
struct Random_Seed Random_Seed

References Random_Seed::a, Random_Seed::b, broadcastMessage:withUnpilotedOverride:, Random_Seed::c, Random_Seed::d, Random_Seed::e, Random_Seed::f, and seed_RNG_only_for_planet_description().

Referenced by ShipEntity(PureAI)::commsMessage:, ShipEntity(PureAI)::commsMessageByUnpiloted:, ShipCommsMessage(), and ShipCommsMessage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ commsMessageByUnpiloted:

- (void) commsMessageByUnpiloted: (NSString*) valueString
implementation

Reimplemented in PlayerEntity.

Provided by category ShipEntity(PureAI).

Definition at line 1444 of file ShipEntityAI.m.

1444 :(NSString*)valueString
1445{
1446 [self commsMessage:valueString withUnpilotedOverride:YES];
1447}

◆ compareBeaconCodeWith:

- (NSComparisonResult) compareBeaconCodeWith: (Entity<OOBeaconEntity>*) other
implementation

Reimplemented from <OOBeaconEntity>.

Definition at line 8355 of file ShipEntity.m.

8355 :(Entity<OOBeaconEntity>*)other
8356{
8357 return [[self beaconCode] compare:[other beaconCode] options:NSCaseInsensitiveSearch];
8358}

References beaconCode.

Here is the call graph for this function:

◆ ComparePlanetsBySurfaceDistance

- (NSComparisonResult) ComparePlanetsBySurfaceDistance (id) i1
(id) i2
(void *) context 
implementation

Definition at line 6582 of file ShipEntity.m.

6583{
6585 OOPlanetEntity* e1 = i1;
6586 OOPlanetEntity* e2 = i2;
6587
6588 float p1 = SurfaceDistanceSqaredV(p, e1);
6589 float p2 = SurfaceDistanceSqaredV(p, e2);
6590
6591 if (p1 < p2)
6592 return NSOrderedAscending;
6593 if (p1 > p2)
6594 return NSOrderedDescending;
6595
6596 return NSOrderedSame;
6597}
static float SurfaceDistanceSqaredV(HPVector reference, Entity< OOStellarBody > *stellar)

References Entity::position, and SurfaceDistanceSqaredV.

Here is the call graph for this function:

◆ considerFiringMissile:

- (void) considerFiringMissile: (double) delta_t

Definition at line 10530 of file ShipEntity.m.

10530 :(double)delta_t
10531{
10532 int missile_chance = 0;
10533 int rhs = 3.2 / delta_t;
10534 if (rhs)
10535 missile_chance = 1 + (ranrot_rand() % rhs);
10536
10537 double hurt_factor = 16 * pow(energy / maxEnergy, 4.0);
10538 if (missiles > missile_chance * hurt_factor) {
10539 [self fireMissile];
10540 }
10541}

References Entity::energy, fireMissile, Entity::maxEnergy, missiles, and ranrot_rand.

Referenced by behaviour_attack_broadside_target:leftside:, behaviour_attack_fly_from_target:, behaviour_attack_fly_to_target:, behaviour_attack_slow_dogfight:, behaviour_attack_sniper:, behaviour_flee_target:, and behaviour_fly_to_target_six:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ contractListForScripting

- (NSArray *) contractListForScripting

Reimplemented in PlayerEntity.

Definition at line 2966 of file ShipEntity.m.

2967{
2968 return [NSArray array];
2969}

References contractListForScripting.

Referenced by cargo, contractListForScripting, ShipGetProperty(), and ShipGetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ coordinates

◆ coordinatesForEscortPosition:

- (HPVector) coordinatesForEscortPosition: (unsigned) idx
implementation

Provided by category ShipEntity(Private).

Definition at line 12038 of file ShipEntity.m.

12038 :(unsigned)idx
12039{
12040 /*
12041 This function causes problems with Thargoids: their missiles (aka Thargons) are automatically
12042 added to the escorts group, and when a mother ship dies all thargons will attach themselves
12043 as escorts to the surviving battleships. This can lead to huge escort groups.
12044 TODO: better handling of Thargoid groups:
12045 - put thargons (& all other thargon missiles) in their own non-escort group perhaps?
12046 */
12047
12048 // The _escortPositions array is always MAX_ESCORTS long.
12049 // Kludge: return the same last escort position if we have escorts above MAX_ESCORTS...
12050 idx = MIN(idx, (unsigned)(MAX_ESCORTS - 1));
12051
12053}
#define MIN(A, B)
Definition OOMaths.h:91
Vector _escortPositions[MAX_ESCORTS]
Definition ShipEntity.h:457

References HPvector_add(), MAX_ESCORTS, MIN, quaternion_rotate_vector(), self, and vectorToHPVector().

Referenced by setUpEscorts, ShipEntity(Private)::setUpMixedEscorts, and update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ countEquipmentItem:

- (NSUInteger) countEquipmentItem: (NSString*) eqkey

Definition at line 2766 of file ShipEntity.m.

2766 :(NSString*)eqkey
2767{
2768 NSString* eq = nil;
2769 NSUInteger count = 0;
2770 foreach (eq, _equipment) {
2771 if ([eqkey isEqualToString:eq]) {
2772 ++count;
2773 }
2774 }
2775 return count;
2776}

References _equipment, count, and nil.

Referenced by PlayerEntity::commanderDataDictionary, PlayerEntity::equipmentList, equipmentListForScripting, ShipEquipmentStatus(), and ShipEquipmentStatus().

Here is the caller graph for this function:

◆ countsAsKill

- (BOOL) countsAsKill

Definition at line 1527 of file ShipEntity.m.

1528{
1529 return [[self shipInfoDictionary] oo_boolForKey:@"counts_as_kill" defaultValue:YES];
1530}

References countsAsKill, and shipInfoDictionary.

Referenced by cascadeIfAppropriateWithDamageAmount:cascadeOwner:, PlayerEntity::collectBountyFor:, countsAsKill, and octree.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ crew

- (NSArray *) crew

References crew, and crewForScripting.

Here is the call graph for this function:

◆ crewForScripting

- (NSArray *) crewForScripting

Definition at line 6888 of file ShipEntity.m.

6889{
6890 if (crew == nil) {
6891 return nil;
6892 }
6893 OOCharacter* crewMember = nil;
6894 NSMutableArray* result = [NSMutableArray arrayWithCapacity:4];
6895 foreach (crewMember, crew) {
6896 NSDictionary* crewDict = [crewMember infoForScripting];
6897 [result addObject:crewDict];
6898 }
6899 return result;
6900}
NSDictionary * infoForScripting()

References crew, crewForScripting, OOCharacter::infoForScripting, and nil.

Referenced by crew, crewForScripting, ShipGetProperty(), and ShipGetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cruiseSpeed

- (double) cruiseSpeed

References cruiseSpeed, and thrustVector.

Here is the call graph for this function:

◆ currentAimTolerance

- (GLfloat) currentAimTolerance

Definition at line 9770 of file ShipEntity.m.

9771{
9772 GLfloat basic_aim = aim_tolerance;
9773 GLfloat best_cos = 0.99999; // ~45m in 10km (track won't go better than 40)
9775 // better general targeting
9776 best_cos = 0.999999; // ~14m in 10km (track won't go better than 10)
9777 // if missing, aim better!
9778 basic_aim /= 1.0 + ((GLfloat)[self missedShots] / 4.0);
9779 }
9781 // deadly shots
9782 best_cos = 0.9999999; // ~4m in 10km (track won't go better than 4)
9783 // and start with extremely good aim circle
9784 basic_aim /= 5.0;
9785 }
9786 if (currentWeaponFacing == WEAPON_FACING_AFT && accuracy < COMBAT_AI_ISNT_AWFUL) { // bad shots with aft lasers
9787 basic_aim *= 1.3;
9788 } else if (currentWeaponFacing == WEAPON_FACING_PORT || currentWeaponFacing == WEAPON_FACING_STARBOARD) { // everyone a bit worse with side lasers
9789 if (accuracy < COMBAT_AI_ISNT_AWFUL) { // especially these
9790 basic_aim *= 1.3 + randf();
9791 } else {
9792 basic_aim *= 1.3;
9793 }
9794 }
9795 // only apply glare if ship is not shadowed
9796 if (isSunlit) {
9797 OOSunEntity* sun = [UNIVERSE sun];
9798 if (sun) {
9799 GLfloat sunGlareAngularSize = atan([sun radius] / HPdistance([self position], [sun position])) * SUN_GLARE_MULT_FACTOR + (SUN_GLARE_ADD_FACTOR);
9800 GLfloat glareLevel = [self lookingAtSunWithThresholdAngleCos:cos(sunGlareAngularSize)] * (1.0f - [self sunGlareFilter]);
9801 if (glareLevel > 0.1f) {
9802 // looking towards sun can seriously mess up aim (glareLevel 0..1)
9803 basic_aim *= (1.0 + glareLevel * 3.0);
9804 // OOLog(@"aim.debug",@"Sun glare affecting aim: %f for %@",glareLevel,self);
9805 if (glareLevel > 0.5f) {
9806 // strong glare makes precise targeting impossible
9807 best_cos = 0.99999;
9808 }
9809 }
9810 }
9811 }
9812
9813 GLfloat max_cos = sqrt(1 - (basic_aim * basic_aim / 100000000.0));
9814
9815 if (max_cos < best_cos) {
9816 return max_cos;
9817 }
9818 return best_cos;
9819}
@ WEAPON_FACING_PORT
Definition OOTypes.h:198
@ WEAPON_FACING_STARBOARD
Definition OOTypes.h:199
unsigned isSunlit
Definition Entity.m:160
OOWeaponFacing currentWeaponFacing
GLfloat sunGlareFilter

References accuracy, aim_tolerance, COMBAT_AI_ISNT_AWFUL, COMBAT_AI_TRACKS_CLOSER, currentAimTolerance, currentWeaponFacing, HPdistance(), Entity::isSunlit, lookingAtSunWithThresholdAngleCos:, missedShots, Entity::position, randf(), sunGlareFilter, WEAPON_FACING_AFT, WEAPON_FACING_PORT, and WEAPON_FACING_STARBOARD.

Referenced by coordinates, currentAimTolerance, onTarget:withWeapon:, trackPrimaryTarget:retreat:, and trackSideTarget:leftside:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ currentWeaponFacing

◆ damage

- (int) damage

Definition at line 7603 of file ShipEntity.m.

7604{
7605 return (int)(100 - (100 * energy / maxEnergy));
7606}

References damage, Entity::energy, int(), and Entity::maxEnergy.

Referenced by damage, dealEnergyDamage:atRange:withBias:, dealEnergyDamageWithinDesiredRange, maxFlightSpeed, and OOExhaustPlumeEntity::update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deactivateCloakingDevice

- (void) deactivateCloakingDevice

Reimplemented in PlayerEntity.

Definition at line 10756 of file ShipEntity.m.

10757{
10760 [self doScriptEvent:OOJSID("shipCloakDeactivated")];
10761 }
10762}

References cloaking_device_active, deactivateCloakingDevice, doScriptEvent:, and hasCloakingDevice.

Referenced by coordinates, PlayerEntity::deactivateCloakingDevice, deactivateCloakingDevice, fireMissileWithIdentifier:andTarget:, fireWeapon:direction:range:, launchCascadeMine, setCloaked:, and update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dealEnergyDamage:atRange:withBias:

- (void) dealEnergyDamage: (GLfloat) baseDamage
atRange: (GLfloat) range
withBias: (GLfloat) velocityBias 

Definition at line 7608 of file ShipEntity.m.

7608 :(GLfloat)baseDamage atRange:(GLfloat)range withBias:(GLfloat)velocityBias
7609{
7610 // this is limited to the player's scanner range
7611 GLfloat maxRange = fmin(range * sqrt(baseDamage), SCANNER_MAX_RANGE);
7612
7613 OOLog(@"missile.damage.calc", @"Range: %f | Damage: %f | MaxRange: %f", range, baseDamage, maxRange);
7614
7615 NSArray* targets = [UNIVERSE entitiesWithinRange:maxRange ofEntity:self];
7616 if ([targets count] > 0) {
7617 unsigned i;
7618 for (i = 0; i < [targets count]; i++) {
7619 Entity* e2 = [targets objectAtIndex:i];
7620 Vector p2 = [self vectorTo:e2];
7621 double ecr = [e2 collisionRadius];
7622 double d = (magnitude(p2) - ecr) / range;
7623 // base damage within defined range, inverse-square falloff outside
7624 double localDamage = baseDamage;
7625 OOLog(@"missile.damage.calc", @"Base damage: %f", baseDamage);
7626 if (velocityBias > 0) {
7627 Vector v2 = vector_subtract([self velocity], [e2 velocity]);
7628 double vSign = dot_product(vector_normal([self velocity]), vector_normal(p2));
7629 // vSign should always be positive for the missile's actual target
7630 // but might be negative for other nearby ships which are
7631 // actually moving further away from the missile
7632 // double vMag = vSign > 0.0 ? magnitude(v2) : -magnitude(v2);
7633 double vMag = vSign * magnitude(v2);
7634 if (vMag > 1000.0) {
7635 vMag = 1000.0;
7636 // cap effective closing speed to 1.0LM or injector-collisions can still do
7637 // ridiculous damage
7638 }
7639
7640 localDamage += vMag * velocityBias;
7641 OOLog(@"missile.damage.calc", @"Velocity magnitude + sign: %f , %f", magnitude(v2), vSign);
7642 OOLog(@"missile.damage.calc", @"Velocity magnitude factor: %f", vMag);
7643 OOLog(@"missile.damage.calc", @"Velocity corrected damage: %f", localDamage);
7644 }
7645 double damage = (d > 1) ? localDamage / (d * d) : localDamage;
7646 OOLog(@"missile.damage.calc", @"%f at range %f (d=%f)", damage, magnitude(p2) - ecr, d);
7647 if (damage > 0.0) {
7648 if ([self owner]) {
7649 [e2 takeEnergyDamage:damage from:self becauseOf:[self owner] weaponIdentifier:[self primaryRole]];
7650 } else {
7651 [e2 takeEnergyDamage:damage from:self becauseOf:self weaponIdentifier:[self primaryRole]];
7652 }
7653 }
7654 }
7655 }
7656
7657 /* the actual damage can't go more than S_M_R, so cap the range
7658 * for exploding purposes so that the visual appearance isn't
7659 * larger than that */
7660 if (range > SCANNER_MAX_RANGE / 4.0) {
7661 range = SCANNER_MAX_RANGE / 4.0;
7662 }
7663 // and a visual sign of the explosion
7664 // "fireball" explosion effect
7665 NSDictionary* explosion = [UNIVERSE explosionSetting:@"oolite-default-ship-explosion"];
7666 [UNIVERSE addEntity:[OOExplosionCloudEntity explosionCloudFromEntity:self withSize:range * 3.0 andSettings:explosion]];
7667}
#define SCANNER_MAX_RANGE
Definition Entity.h:53
void takeEnergyDamage:from:becauseOf:weaponIdentifier:(double amount,[from] Entity *ent,[becauseOf] Entity *other,[weaponIdentifier] NSString *weaponIdentifier)
Definition Entity.m:899
instancetype explosionCloudFromEntity:withSize:andSettings:(Entity *entity,[withSize] float size,[andSettings] NSDictionary *settings)

References Entity::collisionRadius, count, damage, dot_product(), OOExplosionCloudEntity::explosionCloudFromEntity:withSize:andSettings:, magnitude(), OOLog, Entity::owner, primaryRole, SCANNER_MAX_RANGE, Entity::takeEnergyDamage:from:becauseOf:weaponIdentifier:, vector_normal(), vector_subtract(), Entity::vectorTo:, and velocity.

Referenced by ShipDealEnergyDamage(), and ShipDealEnergyDamage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dealEnergyDamageWithinDesiredRange

- (void) dealEnergyDamageWithinDesiredRange

Definition at line 7671 of file ShipEntity.m.

7672{
7673 OOStandardsDeprecated([NSString stringWithFormat:@"dealEnergyDamageWithinDesiredRange is deprecated for %@", self]);
7674 // not over scannerRange
7675 NSArray* targets = [UNIVERSE entitiesWithinRange:(desired_range < SCANNER_MAX_RANGE ? desired_range : SCANNER_MAX_RANGE) ofEntity:self];
7676 if ([targets count] > 0) {
7677 unsigned i;
7678 for (i = 0; i < [targets count]; i++) {
7679 Entity* e2 = [targets objectAtIndex:i];
7680 Vector p2 = [self vectorTo:e2];
7681 double ecr = [e2 collisionRadius];
7682 double d = (magnitude(p2) - ecr) * 2.6; // 2.6 is a correction constant to stay in limits of the old code.
7683 double damage = (d > 0) ? weapon_damage * desired_range / (d * d) : weapon_damage;
7684 [e2 takeEnergyDamage:damage from:self becauseOf:[self owner] weaponIdentifier:[self primaryRole]];
7685 }
7686 }
7687}
void OOStandardsDeprecated(NSString *message)

References Entity::collisionRadius, count, damage, dealEnergyDamageWithinDesiredRange, desired_range, magnitude(), OOStandardsDeprecated(), Entity::owner, primaryRole, Entity::takeEnergyDamage:from:becauseOf:weaponIdentifier:, Entity::vectorTo:, and weapon_damage.

Referenced by dealEnergyDamageWithinDesiredRange, and maxFlightSpeed.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dealloc

- (void) dealloc
implementation

Reimplemented from OOEntityWithDrawable.

Reimplemented in DockEntity, PlayerEntity, and StationEntity.

Definition at line 986 of file ShipEntity.m.

987{
988 /* NOTE: we guarantee that entityDestroyed is sent immediately after the
989 JS ship becomes invalid (as a result of dropping the weakref), i.e.
990 with no intervening script activity.
991 It has to be after the invalidation so that scripts can't directly or
992 indirectly cause the ship to become strong-referenced. (Actually, we
993 could handle that situation by breaking out of dealloc, but that's a
994 nasty abuse of framework semantics and would require special-casing in
995 subclasses.)
996 -- Ahruman 2011-02-27
997 */
998 [weakSelf weakRefDrop];
999 weakSelf = nil;
1000 [self doScriptEvent:OOJSID("entityDestroyed")];
1001
1002 [self setTrackCloseContacts:NO]; // deallocs tracking dictionary
1003 [[self parentEntity] subEntityReallyDied:self]; // Will do nothing if we're not really a subentity
1004 [self clearSubEntities];
1005
1008 DESTROY(shipAI);
1009 DESTROY(cargo);
1010 DESTROY(name);
1024 DESTROY(script);
1028 DESTROY(crew);
1030 DESTROY(octree);
1033
1038
1040
1041 [self setSubEntityTakingDamage:nil];
1042 [self removeAllEquipment];
1043
1044 [_group removeShip:self];
1045 DESTROY(_group);
1046 [_escortGroup removeShip:self];
1048
1050
1054
1056
1057 [super dealloc];
1058}
OOWeakReference * weakSelf
OOColor * laser_color
Definition ShipEntity.h:218
OOColor * scanner_display_color_hostile2
Definition ShipEntity.h:224
NSDictionary * shipinfoDictionary
Definition ShipEntity.h:206
NSString * primaryRole
OOColor * scanner_display_color2
Definition ShipEntity.h:222
NSString * name
NSArray * portWeaponOffset
NSString * shipClassName
OOShipGroup * _group
Definition ShipEntity.h:452
OOWeakReference * _lastAegisLock
Definition ShipEntity.h:450
NSArray * starboardWeaponOffset
NSString * scan_description
Definition ShipEntity.h:320
NSString * shipUniqueName
OOColor * exhaust_emissive_color
Definition ShipEntity.h:220
NSArray * aftWeaponOffset
NSArray * forwardWeaponOffset
OOColor * scanner_display_color1
Definition ShipEntity.h:221
OOJSScript * script
OOColor * default_laser_color
Definition ShipEntity.h:219
OOJSScript * aiScript
Definition ShipEntity.h:212
OOColor * scanner_display_color_hostile1
Definition ShipEntity.h:223
NSString * displayName
NSString * lastRadioMessage
Definition ShipEntity.h:392
NSString * _shipKey
Definition ShipEntity.h:445

References _beaconCode, _beaconDrawable, _beaconLabel, _collisionExceptions, _defenseTargets, _escortGroup, _group, _lastAegisLock, _shipKey, aftWeaponOffset, aiScript, cargo, clearSubEntities, commodity_type, crew, OOEntityWithDrawable::dealloc, dealloc, default_laser_color, DESTROY, displayName, dockingInstructions, doScriptEvent:, exhaust_emissive_color, explosionType, forwardWeaponOffset, laser_color, lastRadioMessage, name, nil, octree, Entity::parentEntity, portWeaponOffset, previousCondition, primaryRole, removeAllEquipment, OOShipGroup::removeShip:, roleSet, scan_description, scanner_display_color1, scanner_display_color2, scanner_display_color_hostile1, scanner_display_color_hostile2, script, setSubEntityTakingDamage:, setTrackCloseContacts:, shipAI, shipClassName, shipinfoDictionary, shipUniqueName, starboardWeaponOffset, subEntityReallyDied:, OOWeakReference::weakRefDrop, and OOWeakRefObject::weakSelf.

Referenced by DockEntity::dealloc, PlayerEntity::dealloc, dealloc, and StationEntity::dealloc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dealMomentumWithinDesiredRange:

- (void) dealMomentumWithinDesiredRange: (double) amount

Definition at line 7689 of file ShipEntity.m.

7689 :(double)amount
7690{
7691 NSArray* targets = [UNIVERSE entitiesWithinRange:desired_range ofEntity:self];
7692 if ([targets count] > 0) {
7693 unsigned i;
7694 for (i = 0; i < [targets count]; i++) {
7695 ShipEntity* e2 = (ShipEntity*)[targets objectAtIndex:i];
7696 if ([e2 isShip] && [e2 isInSpace]) {
7697 Vector p2 = [self vectorTo:e2];
7698 double ecr = [e2 collisionRadius];
7699 double d2 = magnitude2(p2) - ecr * ecr;
7700 // limit momentum transfer to relatively sensible levels
7701 if (d2 < 0.1) {
7702 d2 = 0.1;
7703 }
7704 double moment = amount * desired_range / d2;
7705 [e2 addImpactMoment:vector_normal(p2) fraction:moment];
7706 }
7707 }
7708 }
7709}
BOOL isInSpace()
Definition Entity.m:1033
void addImpactMoment:fraction:(Vector moment,[fraction] GLfloat howmuch)

References addImpactMoment:fraction:, Entity::collisionRadius, count, desired_range, Entity::isInSpace, Entity::isShip, magnitude2(), and Entity::vectorTo:.

Referenced by becomeExplosion.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ debugDumpPendingMessages

- (void) debugDumpPendingMessages
implementation

Provided by category ShipEntity(PureAI).

Definition at line 790 of file ShipEntityAI.m.

791{
792 [shipAI debugDumpPendingMessages];
793}

◆ decrease_flight_pitch:

- (void) decrease_flight_pitch: (double) delta

Definition at line 7467 of file ShipEntity.m.

7467 :(double)delta
7468{
7469 flightPitch -= delta;
7472 else if (flightPitch < -max_flight_pitch)
7474}

References flightPitch, and max_flight_pitch.

Referenced by PlayerShipSetProperty(), PlayerShipSetProperty(), PlayerEntity(OOControlsPrivate)::pollFlightArrowKeyControls:, and PlayerEntity(OOControlsPrivate)::pollGuiArrowKeyControls:.

Here is the caller graph for this function:

◆ decrease_flight_roll:

- (void) decrease_flight_roll: (double) delta

Definition at line 7449 of file ShipEntity.m.

7449 :(double)delta
7450{
7451 flightRoll -= delta;
7454 else if (flightRoll < -max_flight_roll)
7456}

References flightRoll, and max_flight_roll.

Referenced by PlayerShipSetProperty(), PlayerShipSetProperty(), PlayerEntity(OOControlsPrivate)::pollFlightArrowKeyControls:, and PlayerEntity(OOControlsPrivate)::pollGuiArrowKeyControls:.

Here is the caller graph for this function:

◆ decrease_flight_speed:

- (void) decrease_flight_speed: (double) delta

Definition at line 7426 of file ShipEntity.m.

7426 :(double)delta
7427{
7428 double factor = 1.0;
7430 factor = MIN_HYPERSPEED_FACTOR;
7431 }
7432
7433 if (flightSpeed > factor * delta) {
7434 flightSpeed -= factor * delta;
7435 } else {
7436 flightSpeed = 0;
7437 }
7438}
#define MIN_HYPERSPEED_FACTOR

References flightSpeed, maxFlightSpeed, and MIN_HYPERSPEED_FACTOR.

Referenced by applyThrust:.

Here is the caller graph for this function:

◆ decrease_flight_yaw:

- (void) decrease_flight_yaw: (double) delta

Definition at line 7485 of file ShipEntity.m.

7485 :(double)delta
7486{
7487 flightYaw -= delta;
7490 else if (flightYaw < -max_flight_yaw)
7492}

References flightYaw, and max_flight_yaw.

Referenced by PlayerShipSetProperty(), PlayerShipSetProperty(), PlayerEntity(OOControlsPrivate)::pollFlightArrowKeyControls:, and PlayerEntity(OOControlsPrivate)::pollGuiArrowKeyControls:.

Here is the caller graph for this function:

◆ defenseTargetCount

- (NSUInteger) defenseTargetCount

Definition at line 9663 of file ShipEntity.m.

9664{
9665 return [_defenseTargets count];
9666}

References OOWeakSet::count, and defenseTargetCount.

Referenced by addDefenseTarget:, defenseTargetCount, isMissile, ShipGetProperty(), and ShipGetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ defenseTargetEnumerator

- (NSEnumerator *) defenseTargetEnumerator

Definition at line 9673 of file ShipEntity.m.

9674{
9675 return [_defenseTargets objectEnumerator];
9676}

References defenseTargetEnumerator, and OOWeakSet::objectEnumerator.

Referenced by behaviour_track_as_turret:, defenseTargetEnumerator, fireDirectLaserDefensiveShot, isMissile, ShipGetProperty(), and ShipGetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deployEscorts

- (void) deployEscorts

Definition at line 12056 of file ShipEntity.m.

12057{
12058 ShipEntity* escort = nil;
12059 ShipEntity* target = nil;
12060 NSMutableSet* idleEscorts = nil;
12061 unsigned deployCount;
12062
12063 if ([self primaryTarget] == nil || _escortGroup == nil)
12064 return;
12065
12066 OOShipGroup* escortGroup = [self escortGroup];
12067 NSUInteger escortCount = [escortGroup count] - 1; // escorts minus leader.
12068 if (escortCount == 0)
12069 return;
12070
12071 if ([self group] == nil)
12072 [self setGroup:escortGroup];
12073
12074 if ([self primaryTarget] == [self lastEscortTarget]) {
12075 // already deployed escorts onto this target!
12076 return;
12077 }
12078
12079 [self setLastEscortTarget:[self primaryTarget]];
12080
12081 // Find idle escorts
12082 idleEscorts = [NSMutableSet set];
12083 foreach (escort, [self escortEnumerator]) {
12084 if (![[[escort getAI] name] isEqualToString:@"interceptAI.plist"] && ![escort hasNewAI]) {
12085 [idleEscorts addObject:escort];
12086 } else if ([escort hasNewAI]) {
12087 // JS-based escorts get a help request
12088 [escort doScriptEvent:OOJSID("helpRequestReceived") withArgument:self andArgument:[self primaryTarget]];
12089 }
12090 }
12091
12092 escortCount = [idleEscorts count];
12093 if (escortCount == 0)
12094 return;
12095
12096 deployCount = ranrot_rand() % escortCount + 1;
12097
12098 // Deploy deployCount idle escorts.
12099 target = [self primaryTarget];
12100 foreach (escort, idleEscorts) {
12101 [escort addTarget:target];
12102 [escort setAITo:@"interceptAI.plist"];
12103 [escort doScriptEvent:OOJSID("escortAttack") withArgument:target];
12104
12105 if (--deployCount == 0)
12106 break;
12107 }
12108
12109 [self updateEscortFormation];
12110}
void addTarget:(Entity *targetEntity)
NSEnumerator * escortEnumerator()
void setAITo:(NSString *aiString)
Entity * lastEscortTarget()

References _escortGroup, addTarget:, OOShipGroup::count, deployEscorts, doScriptEvent:withArgument:, doScriptEvent:withArgument:andArgument:, escortCount, escortEnumerator, escortGroup, getAI, group, hasNewAI, lastEscortTarget, name, nil, primaryTarget, ranrot_rand, setAITo:, setGroup:, setLastEscortTarget:, and updateEscortFormation.

Referenced by coordinates, deployEscorts, ShipEntity(PureAI)::fightOrFleeHostiles, ShipDeployEscorts(), and ShipDeployEscorts().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ descriptionComponents

- (NSString *) descriptionComponents
implementation

Reimplemented from Entity.

Reimplemented in StationEntity.

Definition at line 1090 of file ShipEntity.m.

1091{
1092 if (![self isSubEntity]) {
1093 return [NSString stringWithFormat:@"\"%@\" %@", [self name], [super descriptionComponents]];
1094 } else {
1095 // ID, scanClass and status are of no interest for subentities.
1096 NSString* subtype = nil;
1097 if ([self behaviour] == BEHAVIOUR_TRACK_AS_TURRET)
1098 subtype = @"(turret)";
1099 else
1100 subtype = @"(subentity)";
1101
1102 return [NSString stringWithFormat:@"\"%@\" position: %@ %@", [self name], HPVectorDescription([self position]), subtype];
1103 }
1104}

References behaviour, Entity::descriptionComponents, descriptionComponents, Entity::isSubEntity, name, nil, and Entity::position.

Referenced by descriptionComponents, and StationEntity::descriptionComponents.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deserializeShipSubEntitiesFrom:

- (void) deserializeShipSubEntitiesFrom: (NSString*) string

Definition at line 771 of file ShipEntity.m.

771 :(NSString*)string
772{
773 NSArray* subEnts = [[self shipSubEntityEnumerator] allObjects];
774 NSInteger i, idx, start = [subEnts count] - 1;
775 NSInteger strMaxIdx = [string length] - 1;
776
777 ShipEntity* se = nil;
778
779 for (i = start; i >= 0; i--) {
780 se = (ShipEntity*)[subEnts objectAtIndex:i];
781 idx = [se subIdx]; // should be identical to i, but better safe than sorry...
782 if (idx <= strMaxIdx && [[string substringWithRange:NSMakeRange(idx, 1)] isEqualToString:@"0"]) {
783 [se setSuppressExplosion:NO];
784 [se setEnergy:1];
785 [se takeEnergyDamage:500000000.0 from:nil becauseOf:nil weaponIdentifier:@""];
786 }
787 }
788}
void setEnergy:(GLfloat amount)
Definition Entity.m:748
void takeEnergyDamage:from:becauseOf:weaponIdentifier:(double amount, [from] Entity *ent, [becauseOf] Entity *other, [weaponIdentifier] NSString *weaponIdentifier)
NSUInteger subIdx()
Definition ShipEntity.m:729

References nil, Entity::setEnergy:, setSuppressExplosion:, shipSubEntityEnumerator, subIdx, and takeEnergyDamage:from:becauseOf:weaponIdentifier:.

Referenced by PlayerEntity::setCommanderDataFromDictionary:, and PlayerEntity::showShipModelWithKey:shipData:personality:factorX:factorY:factorZ:inContext:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ desiredRange

- (double) desiredRange

Definition at line 7399 of file ShipEntity.m.

7400{
7401 return desired_range;
7402}

References desired_range, and desiredRange.

Referenced by cargo, and desiredRange.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ desiredSpeed

- (double) desiredSpeed

Definition at line 7394 of file ShipEntity.m.

7395{
7396 return desired_speed;
7397}

References desired_speed, and desiredSpeed.

Referenced by cargo, and desiredSpeed.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ destination

- (HPVector) destination

Definition at line 8843 of file ShipEntity.m.

8844{
8845 return _destination;
8846}

References _destination, and destination.

Referenced by coordinates, destination, PlayerEntity::enterWormhole:, and Universe::update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ destinationSystem

- (OOSystemID) destinationSystem

Definition at line 6830 of file ShipEntity.m.

6831{
6832 return destination_system;
6833}
OOSystemID destination_system
Definition ShipEntity.h:369

References destination_system, and destinationSystem.

Referenced by destinationSystem, and reportAIMessages.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ disengageAutopilot

- (void) disengageAutopilot
implementation

Reimplemented in PlayerEntity.

Provided by category ShipEntity(PureAI).

Definition at line 1418 of file ShipEntityAI.m.

1419{
1420 OOLogERR(@"ai.invalid.notPlayer", @"Error in %@:%@, AI method endAutoPilot is only applicable to the player.", [shipAI name], [shipAI state]);
1421}
#define OOLogERR(class, format,...)
Definition OOLogging.h:125

Referenced by removeEquipmentItem:.

Here is the caller graph for this function:

◆ displayName

- (NSString *) displayName

References displayName, scanDescription, and scanDescriptionForScripting.

Here is the call graph for this function:

◆ distance_six:

- (HPVector) distance_six: (GLfloat) dist

Definition at line 8858 of file ShipEntity.m.

8858 :(GLfloat)dist
8859{
8860 HPVector six = position;
8861 six.x -= dist * v_forward.x;
8862 six.y -= dist * v_forward.y;
8863 six.z -= dist * v_forward.z;
8864 return six;
8865}

References Entity::position, v_forward, HPVector::x, HPVector::y, and HPVector::z.

◆ distance_twelve:withOffset:

- (HPVector) distance_twelve: (GLfloat) dist
withOffset: (GLfloat) offset 

Definition at line 8867 of file ShipEntity.m.

8867 :(GLfloat)dist withOffset:(GLfloat)offset
8868{
8869 HPVector twelve = position;
8870 twelve.x += dist * v_up.x;
8871 twelve.y += dist * v_up.y;
8872 twelve.z += dist * v_up.z;
8873 twelve.x += offset * v_right.x;
8874 twelve.y += offset * v_right.y;
8875 twelve.z += offset * v_right.z;
8876 return twelve;
8877}

References Entity::position, v_right, v_up, HPVector::x, HPVector::y, and HPVector::z.

◆ dockEscorts

- (void) dockEscorts

Definition at line 12113 of file ShipEntity.m.

12114{
12115 if (![self hasEscorts])
12116 return;
12117
12118 OOShipGroup* escortGroup = [self escortGroup];
12119 ShipEntity* escort = nil;
12120 ShipEntity* target = [self primaryTarget];
12121 unsigned i = 0;
12122 // Note: works on escortArray rather than escortEnumerator because escorts may be mutated.
12123 foreach (escort, [self escortArray]) {
12124 float delay = i++ * 3.0 + 1.5; // send them off at three second intervals
12125 AI* ai = [escort getAI];
12126
12127 // act individually now!
12128 if ([escort group] == escortGroup)
12129 [escort setGroup:nil];
12130 if ([escort owner] == self)
12131 [escort setOwner:escort];
12132 if (target && [target isStation])
12133 [escort setTargetStation:target];
12134 // JSAI: handles own delay
12135 if (![escort hasNewAI]) {
12136 [escort setAITo:@"dockingAI.plist"];
12137 [ai setState:@"ABORT" afterDelay:delay + 0.25];
12138 }
12139 [escort doScriptEvent:OOJSID("escortDock") withArgument:[NSNumber numberWithFloat:delay]];
12140 }
12141
12142 // We now have no escorts.
12143 [_escortGroup release];
12144 _escortGroup = nil;
12145}
void setState:afterDelay:(NSString *stateName,[afterDelay] NSTimeInterval delay)
Definition AI.m:324
void setTargetStation:(Entity *targetEntity)

References _escortGroup, dockEscorts, doScriptEvent:withArgument:, escortArray, escortGroup, getAI, group, hasEscorts, hasNewAI, Entity::isStation, nil, Entity::owner, primaryTarget, setAITo:, setGroup:, setOwner:, AI::setState:afterDelay:, and setTargetStation:.

Referenced by coordinates, dockEscorts, ShipDockEscorts(), and ShipDockEscorts().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dockingInstructions

- (NSDictionary *) dockingInstructions

References broadcastThargoidDestroyed, and dockingInstructions.

Here is the call graph for this function:

◆ doesHitLine:v1:

- (GLfloat) doesHitLine: (HPVector) v0
v1: (HPVector) v1 

Definition at line 1314 of file ShipEntity.m.

1314 :(HPVector)v0 v1:(HPVector)v1
1315{
1316 Vector u0 = HPVectorToVector(HPvector_between(position, v0)); // relative to origin of model / octree
1318 Vector w0 = make_vector(dot_product(u0, v_right), dot_product(u0, v_up), dot_product(u0, v_forward)); // in ijk vectors
1320 return [octree isHitByLine:w0 v1:w1];
1321}

References dot_product(), HPvector_between, HPVectorToVector(), Octree::isHitByLine:v1:, make_vector(), Entity::position, v_forward, v_right, and v_up.

Here is the call graph for this function:

◆ doesHitLine:v1:hitEntity:

- (GLfloat) doesHitLine: (HPVector) v0
v1: (HPVector) v1
hitEntity: (ShipEntity**) hitEntity 

Reimplemented in PlayerEntity.

Definition at line 1323 of file ShipEntity.m.

1323 :(HPVector)v0 v1:(HPVector)v1 hitEntity:(ShipEntity**)hitEntity
1324{
1325 if (hitEntity)
1326 hitEntity[0] = (ShipEntity*)nil;
1327 Vector u0 = HPVectorToVector(HPvector_between(position, v0)); // relative to origin of model / octree
1329 Vector w0 = make_vector(dot_product(u0, v_right), dot_product(u0, v_up), dot_product(u0, v_forward)); // in ijk vectors
1331 GLfloat hit_distance = [octree isHitByLine:w0 v1:w1];
1332 if (hit_distance) {
1333 if (hitEntity)
1334 hitEntity[0] = self;
1335 }
1336
1337 NSEnumerator* subEnum = nil;
1338 ShipEntity* se = nil;
1339 for (subEnum = [self shipSubEntityEnumerator]; (se = [subEnum nextObject]);) {
1341 Triangle ijk = [se absoluteIJKForSubentity];
1342 u0 = HPVectorToVector(HPvector_between(p0, v0));
1343 u1 = HPVectorToVector(HPvector_between(p0, v1));
1344 w0 = resolveVectorInIJK(u0, ijk);
1345 w1 = resolveVectorInIJK(u1, ijk);
1346
1347 GLfloat hitSub = [se->octree isHitByLine:w0 v1:w1];
1348 if (hitSub && (hit_distance == 0 || hit_distance > hitSub)) {
1349 hit_distance = hitSub;
1350 if (hitEntity) {
1351 *hitEntity = se;
1352 }
1353 }
1354 }
1355
1356 return hit_distance;
1357}
OOINLINE Vector resolveVectorInIJK(Vector v0, Triangle ijk)
Definition OOTriangle.h:58
Triangle absoluteIJKForSubentity()

References absoluteIJKForSubentity, Entity::absolutePositionForSubentity, dot_product(), HPvector_between, HPVectorToVector(), Octree::isHitByLine:v1:, make_vector(), nil, Entity::position, resolveVectorInIJK(), shipSubEntityEnumerator, v_forward, v_right, and v_up.

Referenced by Universe::firstShipHitByLaserFromShip:inDirection:offset:gettingRangeFound:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ doesHitLine:v1:withPosition:i:j:k:

- (GLfloat) doesHitLine: (HPVector) v0
v1: (HPVector) v1
withPosition: (HPVector) o
i: (Vector) i
j: (Vector) j
k: (Vector) k 

Definition at line 1359 of file ShipEntity.m.

1359 :(HPVector)v0 v1:(HPVector)v1 withPosition:(HPVector)o i:(Vector)i j:(Vector)j k:(Vector)k
1360{
1361 Vector u0 = HPVectorToVector(HPvector_between(o, v0)); // relative to origin of model / octree
1363 Vector w0 = make_vector(dot_product(u0, i), dot_product(u0, j), dot_product(u0, k)); // in ijk vectors
1364 Vector w1 = make_vector(dot_product(u1, j), dot_product(u1, j), dot_product(u1, k));
1365 return [octree isHitByLine:w0 v1:w1];
1366}

References dot_product(), HPvector_between, HPVectorToVector(), Octree::isHitByLine:v1:, and make_vector().

Here is the call graph for this function:

◆ doNothing

- (void) doNothing
implementation

Definition at line 12950 of file ShipEntity.m.

12951{
12952}

References doNothing.

Referenced by doNothing.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ doOctreesCollide

- (ShipEntity *) doOctreesCollide (ShipEntity *) prime
(ShipEntity *) other 
implementation

Definition at line 1878 of file ShipEntity.m.

1879{
1880 // octree check
1881 Octree* prime_octree = prime->octree;
1882 Octree* other_octree = other->octree;
1883
1884 HPVector prime_position = [prime absolutePositionForSubentity];
1885 Triangle prime_ijk = [prime absoluteIJKForSubentity];
1886 HPVector other_position = [other absolutePositionForSubentity];
1887 Triangle other_ijk = [other absoluteIJKForSubentity];
1888
1889 Vector relative_position_of_other = resolveVectorInIJK(HPVectorToVector(HPvector_between(prime_position, other_position)), prime_ijk);
1890 Triangle relative_ijk_of_other;
1891 relative_ijk_of_other.v[0] = resolveVectorInIJK(other_ijk.v[0], prime_ijk);
1892 relative_ijk_of_other.v[1] = resolveVectorInIJK(other_ijk.v[1], prime_ijk);
1893 relative_ijk_of_other.v[2] = resolveVectorInIJK(other_ijk.v[2], prime_ijk);
1894
1895 // check hull octree against other hull octree
1896 if ([prime_octree isHitByOctree:other_octree
1897 withOrigin:relative_position_of_other
1898 andIJK:relative_ijk_of_other]) {
1899 return other;
1900 }
1901
1902 // check prime subentities against the other's hull
1903 NSArray* prime_subs = prime->subEntities;
1904 if (prime_subs) {
1905 NSUInteger i, n_subs = [prime_subs count];
1906 for (i = 0; i < n_subs; i++) {
1907 Entity* se = [prime_subs objectAtIndex:i];
1908 if ([se isShip] && [se canCollide] && doOctreesCollide((ShipEntity*)se, other))
1909 return other;
1910 }
1911 }
1912
1913 // check prime hull against the other's subentities
1914 NSArray* other_subs = other->subEntities;
1915 if (other_subs) {
1916 NSUInteger i, n_subs = [other_subs count];
1917 for (i = 0; i < n_subs; i++) {
1918 Entity* se = [other_subs objectAtIndex:i];
1919 if ([se isShip] && [se canCollide] && doOctreesCollide(prime, (ShipEntity*)se))
1920 return (ShipEntity*)se;
1921 }
1922 }
1923
1924 // check prime subenties against the other's subentities
1925 if ((prime_subs) && (other_subs)) {
1926 NSUInteger i, n_osubs = [other_subs count];
1927 for (i = 0; i < n_osubs; i++) {
1928 Entity* oe = [other_subs objectAtIndex:i];
1929 if ([oe isShip] && [oe canCollide]) {
1930 NSUInteger j, n_psubs = [prime_subs count];
1931 for (j = 0; j < n_psubs; j++) {
1932 Entity* pe = [prime_subs objectAtIndex:j];
1933 if ([pe isShip] && [pe canCollide] && doOctreesCollide((ShipEntity*)pe, (ShipEntity*)oe))
1934 return (ShipEntity*)oe;
1935 }
1936 }
1937 }
1938 }
1939
1940 // fall through => no collision
1941 return nil;
1942}
static BOOL isHitByOctree(Octree_details axialDetails, Octree_details otherDetails, Vector delta, Triangle other_ijk)
BOOL canCollide()

References absoluteIJKForSubentity, Entity::absolutePositionForSubentity, canCollide, doOctreesCollide(), HPvector_between, HPVectorToVector(), isHitByOctree(), Entity::isShip, nil, octree, resolveVectorInIJK(), subEntities, and Triangle::v.

Here is the call graph for this function:

◆ doScriptEvent:

- (void) doScriptEvent: (OOJSPropID) message

Definition at line 12775 of file ShipEntity.m.

12775 :(OOJSPropID)message
12776{
12777 JSContext* context = OOJSAcquireContext();
12778 [self doScriptEvent:message inContext:context withArguments:NULL count:0];
12779 OOJSRelinquishContext(context);
12780}
jsid OOJSPropID
Definition OOJSPropID.h:31

References doScriptEvent:inContext:withArguments:count:, OOJSAcquireContext(), and OOJSRelinquishContext().

Referenced by DockEntity::abortAllDockings, StationEntity::abortAllDockings, StationEntity::abortDockingForShip:, StationEntity::acceptDockingClearanceRequestFrom:, activateCloakingDevice, Universe::allShipsDoScriptEvent:andReactToAIMessage:, StationEntity::autoDockShipsOnApproach, behaviour_face_destination:, behaviour_fly_from_destination:, behaviour_fly_to_destination:, behaviour_intercept_target:, PlayerEntity::cancelDockingRequest:, PlayerEntity(Controls)::cancelWitchspaceCountdown, deactivateCloakingDevice, dealloc, PlayerEntity::disengageAutopilot, WormholeEntity::disgorgeShips, PlayerEntity::doBookkeeping:, doScriptEvent:andReactToAIMessage:, PlayerEntity::interpretAIMessage:, PlayerEntity::performDockingRequest:, PlayerEntity(OOControlsPrivate)::pollGuiArrowKeyControls:, DockEntity::pruneAndCountShipsOnApproach, StationEntity::sanityCheckShipsOnApproach, ShipEntity(PureAI)::sendScriptMessage:, WormholeEntity::suckInShip:, update:, and StationEntity::update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ doScriptEvent:andReactToAIMessage:

- (void) doScriptEvent: (OOJSPropID) scriptEvent
andReactToAIMessage: (NSString*) aiMessage 

Definition at line 12869 of file ShipEntity.m.

12869 :(OOJSPropID)scriptEvent andReactToAIMessage:(NSString*)aiMessage
12870{
12871 [self doScriptEvent:scriptEvent];
12872 [self reactToAIMessage:aiMessage context:nil];
12873}

References doScriptEvent:, and reactToAIMessage:context:.

Referenced by behaviour_fly_thru_navpoints:, WormholeEntity::disgorgeShips, takeEnergyDamage:from:becauseOf:weaponIdentifier:, takeHeatDamage:, and takeScrapeDamage:from:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ doScriptEvent:inContext:withArguments:count:

- (void) doScriptEvent: (OOJSPropID) message
inContext: (JSContext*) context
withArguments: (jsval*) argv
count: (int) argc 

Reimplemented in PlayerEntity.

Definition at line 12852 of file ShipEntity.m.

12852 :(OOJSPropID)message inContext:(JSContext*)context withArguments:(OOJSVal*)argv count:(int)argc
12853{
12854 // This method is a bottleneck so that PlayerEntity can override at one point.
12855 [script callMethod:message inContext:context withArguments:argv count:argc result:NULL];
12856 [aiScript callMethod:message inContext:context withArguments:argv count:argc result:NULL];
12857}

References OOJSScript::callMethod:inContext:withArguments:count:result:.

Referenced by doScriptEvent:, PlayerEntity::doScriptEvent:inContext:withArguments:count:, doScriptEvent:withArgument:, doScriptEvent:withArgument:andArgument:, doScriptEvent:withArguments:, and doScriptEvent:withArguments:count:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ doScriptEvent:withArgument:

- (void) doScriptEvent: (OOJSPropID) message
withArgument: (id) argument 

Definition at line 12782 of file ShipEntity.m.

12782 :(OOJSPropID)message withArgument:(id)argument
12783{
12784 JSContext* context = OOJSAcquireContext();
12785
12786 OOJSVal value = OOJSValueFromNativeObject(context, argument);
12787 [self doScriptEvent:message inContext:context withArguments:&value count:1];
12788 OOJSFreeValue(context, value);
12789
12790 OOJSRelinquishContext(context);
12791}
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)

References doScriptEvent:inContext:withArguments:count:, OOJSAcquireContext(), OOJSFreeValue, OOJSRelinquishContext(), and OOJSValueFromNativeObject().

Referenced by acceptAsEscort:, StationEntity::acceptDockingClearanceRequestFrom:, addEquipmentItem:withValidation:inContext:, addTarget:, PlayerEntity(LoadSave)::autosavePlayer, broadcastEnergyBlastImminent, Universe::carryPlayerOn:inWormhole:, checkForAegis, deployEscorts, PlayerEntity::docked, dockEscorts, StationEntity::dockingInstructionsForShip:, doScriptEvent:withArgument:andReactToAIMessage:, dumpItem:, PlayerEntity::engageAutopilotToStation:, PlayerEntity::enterDock:, enterDock:, PlayerEntity::enterWitchspace, ShipEntity(PureAI)::fightOrFleeMissile, fireMissileWithIdentifier:andTarget:, fireSubentityLaserShot:, PlayerEntity::launchEscapeCapsule, PlayerEntity::launchMine:, DockEntity::launchShip:, PlayerEntity::leaveWitchspace, PlayerEntity(OOLoadSavePrivate)::nativeSavePlayer:, StationEntity::noteDockedShip:, ShipEntity(Private)::noteFrustration:, noteLostTarget, noteTargetDestroyed:, PlayerEntity::performDockingRequest:, ShipEntity(OOAIPrivate)::performHyperSpaceExitReplace:toSystem:, PlayerEntity(OOPrivate)::performLaunchingUpdates:, PlayerEntity(OOPrivate)::performWitchspaceCountdownUpdates:, PlayerEntity(OOPrivate)::performWitchspaceExitUpdates:, PlayerReplaceShip(), PlayerReplaceShip(), PlayerShipSetProperty(), PlayerShipSetProperty(), PlayerEntity(OOControlsPrivate)::pollFlightControls:, PlayerEntity(OOControlsPrivate)::pollGuiArrowKeyControls:, PlayerEntity(LoadSave)::quicksavePlayer, removeEquipmentItem:, PlayerEntity(Contracts)::replaceShipWithNamedShip:, respondToAttackFrom:becauseOf:, scoopUpProcess:processEvents:processMessages:, ShipEntity(PureAI)::sendScriptMessage:, PlayerEntity(ScriptMethods)::setMissionChoice:keyPress:withEvent:, ShipEntity(PureAI)::setTargetToPrimaryAggressor, ShipEntity(Private)::setUpOneEscort:inGroup:withRole:atPosition:andCount:, Universe::setUpUniverseFromStation, ShipAwardEquipment(), ShipAwardEquipment(), DockEntity::shipIsInDockingCorridor:, ShipRemove(), ShipRemove(), ShipSetEquipmentStatus(), ShipSetEquipmentStatus(), ShipEntity(AI)::suggestEscortTo:, PlayerEntity::takeEnergyDamage:from:becauseOf:weaponIdentifier:, PlayerEntity::takeInternalDamage, transitionToAegisNone, PlayerEntity(OOPrivate)::tryBuyingItem:, update:, PlayerEntity(OOPrivate)::updateClocks:, PlayerEntity::witchJumpChecklist:, ShipEntity(AI)::wormholeEscorts, and ShipEntity(PureAI)::wormholeGroup.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ doScriptEvent:withArgument:andArgument:

- (void) doScriptEvent: (OOJSPropID) message
withArgument: (id) argument1
andArgument: (id) argument2 

Definition at line 12793 of file ShipEntity.m.

12793 :(OOJSPropID)message
12794 withArgument:(id)argument1
12795 andArgument:(id)argument2
12796{
12797 JSContext* context = OOJSAcquireContext();
12798
12799 OOJSVal argv[2] = { OOJSValueFromNativeObject(context, argument1), OOJSValueFromNativeObject(context, argument2) };
12800 [self doScriptEvent:message inContext:context withArguments:argv count:2];
12801 OOJSFreeValue(context, argv[0]);
12802 OOJSFreeValue(context, argv[1]);
12803
12804 OOJSRelinquishContext(context);
12805}

References doScriptEvent:inContext:withArguments:count:, OOJSAcquireContext(), OOJSFreeValue, OOJSRelinquishContext(), and OOJSValueFromNativeObject().

Referenced by ShipEntity(AI)::broadcastDistressMessageWithDumping:, broadcastHitByLaserFrom:, deployEscorts, dumpCargoItem:, fireMissileWithIdentifier:andTarget:, ShipEntity(AI)::groupAttackTarget, launchEscapeCapsule, PlayerReplaceShip(), PlayerReplaceShip(), PlayerEntity(OOControlsPrivate)::pollGuiArrowKeyControls:, receiveCommsMessage:from:, StationEntity::setAlertLevel:signallingScript:, and PlayerEntity(OOPrivate)::updateAlertCondition.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ doScriptEvent:withArgument:andReactToAIMessage:

- (void) doScriptEvent: (OOJSPropID) scriptEvent
withArgument: (id) argument
andReactToAIMessage: (NSString*) aiMessage 

Definition at line 12875 of file ShipEntity.m.

12875 :(OOJSPropID)scriptEvent withArgument:(id)argument andReactToAIMessage:(NSString*)aiMessage
12876{
12877 [self doScriptEvent:scriptEvent withArgument:argument];
12878 [self reactToAIMessage:aiMessage context:nil];
12879}

References doScriptEvent:withArgument:, and reactToAIMessage:context:.

Referenced by checkCloseCollisionWith:, collideWithShip:, landOnPlanet:, DockEntity::launchShip:, respondToAttackFrom:becauseOf:, and update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ doScriptEvent:withArguments:

- (void) doScriptEvent: (OOJSPropID) message
withArguments: (NSArray*) arguments 

Definition at line 12807 of file ShipEntity.m.

12807 :(OOJSPropID)message withArguments:(NSArray*)arguments
12808{
12809 JSContext* context = OOJSAcquireContext();
12810 int i, argc;
12811 OOJSVal* argv = NULL;
12812
12813 // Convert arguments to JS values and make them temporarily un-garbage-collectable.
12814 argc = (int)[arguments count];
12815 if (argc != 0) {
12816 argv = malloc(sizeof *argv * argc);
12817 if (argv != NULL) {
12818 for (i = 0; i != argc; ++i) {
12819 argv[i] = [[arguments objectAtIndex:i] oo_jsValueInContext:context];
12820#if !OOJS_QUICKJS
12821 OOJSAddGCValueRoot(context, &argv[i], "event parameter");
12822#endif
12823 }
12824 } else
12825 argc = 0;
12826 }
12827
12828 [self doScriptEvent:message inContext:context withArguments:argv count:argc];
12829
12830 // Re-garbage-collectibalize (or, with QuickJS, release) the arguments and free the array.
12831 if (argv != NULL) {
12832 for (i = 0; i != argc; ++i) {
12833#if OOJS_QUICKJS
12834 OOJSFreeValue(context, argv[i]);
12835#else
12836 JS_RemoveValueRoot(context, &argv[i]);
12837#endif
12838 }
12839 free(argv);
12840 }
12841
12842 OOJSRelinquishContext(context);
12843}
#define OOJSAddGCValueRoot(context, root, name)

References count, doScriptEvent:inContext:withArguments:count:, int(), OOJSAcquireContext(), OOJSAddGCValueRoot, OOJSFreeValue, and OOJSRelinquishContext().

Referenced by PlayerEntity(Contracts)::addParcel:start:destination:eta:fee:premium:risk:, PlayerEntity(Contracts)::addPassenger:start:destination:eta:fee:advance:risk:, PlayerEntity(Contracts)::awardContract:commodity:start:destination:eta:fee:premium:, PlayerEntity(Controls)::beginWitchspaceCountdown:, PlayerEntity::buySelectedItem, PlayerEntity(Contracts)::buySelectedShip, PlayerEntity(Contracts)::checkPassengerContracts, PlayerEntity(OOControlsPrivate)::pollFlightControls:, PlayerEntity(Contracts)::processEscapePods, PlayerEntity::tryBuyingCommodity:all:, PlayerEntity::trySellingCommodity:all:, and PlayerEntity::validateCompassTarget.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ doScriptEvent:withArguments:count:

- (void) doScriptEvent: (OOJSPropID) message
withArguments: (jsval*) argv
count: (int) argc 

Definition at line 12845 of file ShipEntity.m.

12845 :(OOJSPropID)message withArguments:(OOJSVal*)argv count:(int)argc
12846{
12847 JSContext* context = OOJSAcquireContext();
12848 [self doScriptEvent:message inContext:context withArguments:argv count:argc];
12849 OOJSRelinquishContext(context);
12850}

References doScriptEvent:inContext:withArguments:count:, OOJSAcquireContext(), and OOJSRelinquishContext().

Here is the call graph for this function:

◆ drawDebugStuff

- (void) drawDebugStuff
implementation

Provided by category ShipEntity(Private).

Referenced by drawImmediate:translucent:.

Here is the caller graph for this function:

◆ drawImmediate:translucent:

- (void) drawImmediate: (bool) immediate
translucent: (bool) translucent 
implementation

Reimplemented from OOEntityWithDrawable.

Reimplemented in DockEntity, and PlayerEntity.

Definition at line 5500 of file ShipEntity.m.

5500 :(bool)immediate translucent:(bool)translucent
5501{
5502 if ((no_draw_distance < cam_zero_distance) || // Done redundantly to skip subentities
5503 (cloaking_device_active && randf() > 0.10)) {
5504 // Don't draw.
5505 return;
5506 }
5507
5508 // Draw self.
5509 [super drawImmediate:immediate translucent:translucent];
5510
5511#ifdef OO_DEBUG_MONITOR_ENABLED
5512 // Draw bounding boxes if we have to before going for the subentities.
5513 // TODO: the translucent flag here makes very little sense. Something's wrong with the matrices.
5514 if (translucent)
5515 [self drawDebugStuff];
5516 else if (gDebugFlags & DEBUG_BOUNDING_BOXES && ![self isSubEntity]) {
5518 OODebugDrawColoredBoundingBox(totalBoundingBox, [OOColor purpleColor]);
5519 }
5520#endif
5521
5522 // Draw subentities.
5523 if (!immediate) // TODO: is this relevant any longer?
5524 {
5525 // save time by not copying the subentity array if it's empty - CIM
5526 if ([self subEntityCount] > 0) {
5527 Entity<OOSubEntity>* subEntity = nil;
5528 foreach (subEntity, [self subEntities]) {
5529 NSAssert3([subEntity owner] == self, @"Subentity ownership broke - %@ should be owned by %@ but is owned by %@.", subEntity, self, [subEntity owner]);
5530 [subEntity drawSubEntityImmediate:immediate translucent:translucent];
5531 }
5532 }
5533 }
5534}
#define gDebugFlags
@ DEBUG_BOUNDING_BOXES
#define OODebugDrawBoundingBox(box)
void drawSubEntityImmediate:translucent:(bool immediate, [translucent] bool translucent)
GLfloat cam_zero_distance
Definition Entity.h:105
GLfloat no_draw_distance
Definition Entity.h:106
BoundingBox totalBoundingBox
void drawDebugStuff()
NSUInteger subEntityCount()

References Entity::boundingBox, Entity::cam_zero_distance, cloaking_device_active, DEBUG_BOUNDING_BOXES, drawDebugStuff, OOEntityWithDrawable::drawImmediate:translucent:, Entity::drawSubEntityImmediate:translucent:, gDebugFlags, Entity::isSubEntity, nil, Entity::no_draw_distance, OODebugDrawBoundingBox, Entity::owner, randf(), subEntities, subEntityCount, and totalBoundingBox.

Referenced by DockEntity::drawImmediate:translucent:, PlayerEntity::drawImmediate:translucent:, and drawSubEntityImmediate:translucent:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ drawSubEntityImmediate:translucent:

- (void) drawSubEntityImmediate: (bool) immediate
translucent: (bool) translucent 
implementation

Reimplemented from Entity.

Definition at line 5563 of file ShipEntity.m.

5563 :(bool)immediate translucent:(bool)translucent
5564{
5566
5567 if (cam_zero_distance > no_draw_distance) // this test provides an opportunity to do simple LoD culling
5568 {
5569 return; // TOO FAR AWAY
5570 }
5572
5573 // HPVect: need to make camera-relative
5576 [self drawImmediate:immediate translucent:translucent];
5577
5578#ifdef OO_DEBUG_MONITOR_ENABLED
5581 }
5582#endif
5583
5585
5587}
void OOGLPushModelView(void)
void OOGLTranslateModelView(Vector vector)
void OOGLMultModelView(OOMatrix matrix)
OOMatrix OOGLPopModelView(void)
#define OOVerifyOpenGLState()
Definition OOOpenGL.h:133
OOMatrix rotMatrix
Definition Entity.h:134

References Entity::boundingBox, Entity::cam_zero_distance, DEBUG_BOUNDING_BOXES, drawImmediate:translucent:, gDebugFlags, HPVectorToVector(), Entity::no_draw_distance, OODebugDrawBoundingBox, OOGLMultModelView(), OOGLPopModelView(), OOGLPushModelView(), OOGLTranslateModelView(), OOVerifyOpenGLState, Entity::position, and Entity::rotMatrix.

Here is the call graph for this function:

◆ dropMessages:

- (void) dropMessages: (NSString*) messageString
implementation

Provided by category ShipEntity(PureAI).

Definition at line 778 of file ShipEntityAI.m.

778 :(NSString*)messageString
779{
780 NSArray* messages = nil;
781 NSString* message = nil;
782 NSCharacterSet* whiteSpace = [NSCharacterSet whitespaceCharacterSet];
783
784 messages = [messageString componentsSeparatedByString:@","];
785 foreach (message, messages) {
786 [shipAI dropMessage:[message stringByTrimmingCharactersInSet:whiteSpace]];
787 }
788}

◆ dumpCargo

- (OOCommodityType) dumpCargo

Reimplemented in PlayerEntity.

Definition at line 10865 of file ShipEntity.m.

10866{
10867 ShipEntity* jetto = [self dumpCargoItem:nil];
10868 if (jetto != nil) {
10869 return [jetto commodityType];
10870 } else {
10871 return nil;
10872 }
10873}

References commodityType, dumpCargo, dumpCargoItem:, and nil.

Referenced by coordinates, PlayerEntity::dumpCargo, dumpCargo, and ShipEntity(PureAI)::ejectCargo.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dumpCargoItem:

- (ShipEntity *) dumpCargoItem: (OOCommodityType) preferred

Definition at line 10875 of file ShipEntity.m.

10875 :(OOCommodityType)preferred
10876{
10877 ShipEntity* jetto = nil;
10878 NSUInteger i = 0;
10879
10880 if (([cargo count] > 0) && ([UNIVERSE getTime] - cargo_dump_time > 0.5)) // space them 0.5s or 10m apart
10881 {
10882 if (preferred == nil) {
10883 jetto = [[[cargo objectAtIndex:0] retain] autorelease];
10884 } else {
10885 BOOL found = NO;
10886 for (i = 0; i < [cargo count]; i++) {
10887 if ([[[cargo objectAtIndex:i] commodityType] isEqualToString:preferred]) {
10888 jetto = [[[cargo objectAtIndex:i] retain] autorelease];
10889 found = YES;
10890 break;
10891 }
10892 }
10893 if (found == NO) {
10894 // dump anything
10895 jetto = [[[cargo objectAtIndex:0] retain] autorelease];
10896 i = 0;
10897 }
10898 }
10899 if (jetto != nil) {
10900 [self dumpItem:jetto]; // CLASS_CARGO, STATUS_IN_FLIGHT, AI state GLOBAL
10901 [cargo removeObjectAtIndex:i];
10902 [self broadcastAIMessage:@"CARGO_DUMPED"]; // goes only to 16 nearby ships in range, but that should be enough.
10903 unsigned i;
10904 // only send script event to powered entities
10905 [self checkScannerIgnoringUnpowered];
10906 for (i = 0; i < n_scanned_ships; i++) {
10907 ShipEntity* other = scanned_ships[i];
10908 [other doScriptEvent:OOJSID("cargoDumpedNearby") withArgument:jetto andArgument:self];
10909 }
10910 }
10911 }
10912
10913 return jetto;
10914}
OOTimeAbsolute cargo_dump_time
Definition ShipEntity.h:347

References broadcastAIMessage:, cargo, cargo_dump_time, checkScannerIgnoringUnpowered, commodityType, count, doScriptEvent:withArgument:andArgument:, dumpItem:, n_scanned_ships, nil, scanned_ships, and UNIVERSE.

Referenced by dumpCargo.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dumpItem:

- (OOCargoType) dumpItem: (ShipEntity*) jetto

Definition at line 10916 of file ShipEntity.m.

10916 :(ShipEntity*)cargoObj
10917{
10918 if (!cargoObj)
10919 return 0;
10920
10921 ShipEntity* jetto = [UNIVERSE reifyCargoPod:cargoObj];
10922
10923 int result = [jetto cargoType];
10924 AI* jettoAI = nil;
10925 Vector start;
10926
10927 // players get to see their old ship sailing forth, while NPCs run away more efficiently!
10928 // cargo is ejected at higher speed from any ship
10929 double eject_speed = EXPECT_NOT([jetto crew] && [jetto isPlayer]) ? 20.0 : 100.0;
10930 double eject_reaction = -eject_speed * [jetto mass] / [self mass];
10931 double jcr = jetto->collision_radius;
10932
10933 Quaternion jetto_orientation = kIdentityQuaternion;
10934 Vector vel, v_eject, v_eject_normal;
10935 HPVector rpos = [self absolutePositionForSubentity];
10936 double jetto_roll = 0;
10937 double jetto_pitch = 0;
10938
10939 // default launching position
10940 start.x = 0.0; // in the middle
10941 start.y = 0.0; //
10942 start.z = boundingBox.min.z - jcr; // 1m behind of bounding box
10943
10944 // custom launching position
10945 start = [shipinfoDictionary oo_vectorForKey:@"aft_eject_position" defaultValue:start];
10946
10947 v_eject = vector_normal(start);
10948
10949 // check if start is within bounding box...
10950 while ((start.x > boundingBox.min.x - jcr) && (start.x < boundingBox.max.x + jcr) && (start.y > boundingBox.min.y - jcr) && (start.y < boundingBox.max.y + jcr) && (start.z > boundingBox.min.z - jcr) && (start.z < boundingBox.max.z + jcr)) {
10951 start = vector_add(start, vector_multiply_scalar(v_eject, jcr));
10952 }
10953
10954 v_eject = quaternion_rotate_vector([self normalOrientation], start);
10955 rpos = HPvector_add(rpos, vectorToHPVector(v_eject));
10956 v_eject = vector_normal(v_eject);
10957 v_eject_normal = v_eject;
10958
10959 v_eject.x += (randf() - randf()) / eject_speed;
10960 v_eject.y += (randf() - randf()) / eject_speed;
10961 v_eject.z += (randf() - randf()) / eject_speed;
10962
10964 velocity = vector_add(velocity, vector_multiply_scalar(v_eject, eject_reaction));
10965
10966 [jetto setPosition:rpos];
10967 if ([jetto crew]) // jetto has a crew, so assume it is an escape pod.
10968 {
10969 // orient the pod away from the ship to avoid colliding with it.
10970 jetto_orientation = quaternion_rotation_between(v_eject_normal, kBasisZVector);
10971 } else {
10972 // It is true cargo, let it tumble.
10973 jetto_roll = ((ranrot_rand() % 1024) - 512.0) / 1024.0; // -0.5 to +0.5
10974 jetto_pitch = ((ranrot_rand() % 1024) - 512.0) / 1024.0; // -0.5 to +0.5
10975 quaternion_set_random(&jetto_orientation);
10976 }
10977
10978 [jetto setOrientation:jetto_orientation];
10979 [jetto setRoll:jetto_roll];
10980 [jetto setPitch:jetto_pitch];
10981 [jetto setVelocity:vel];
10982 [jetto setScanClass:CLASS_CARGO];
10983 [jetto setTemperature:[self randomEjectaTemperature]];
10984 [UNIVERSE addEntity:jetto]; // STATUS_IN_FLIGHT, AI state GLOBAL
10985
10986 jettoAI = [jetto getAI];
10987 if ([jettoAI hasSuspendedStateMachines]) // check if this was previous scooped cargo.
10988 {
10989 [jetto setThrust:[jetto maxThrust]]; // restore old thrust.
10990 [jetto setOwner:jetto];
10991 [jettoAI exitStateMachineWithMessage:nil]; // exit nullAI.
10992 }
10993 [jetto doScriptEvent:OOJSID("shipWasDumped") withArgument:self];
10994 [self doScriptEvent:OOJSID("shipDumpedCargo") withArgument:jetto];
10995
10996 cargo_dump_time = [UNIVERSE getTime];
10997 return result;
10998}
Quaternion quaternion_rotation_between(Vector v0, Vector v1) CONST_FUNC
float maxThrust()
void setRoll:(double amount)
void setThrust:(double amount)
void setPitch:(double amount)

References Entity::absolutePositionForSubentity, Entity::boundingBox, cargo_dump_time, cargoType, Entity::collision_radius, crew, doScriptEvent:withArgument:, AI::exitStateMachineWithMessage:, EXPECT_NOT, flightSpeed, getAI, HPvector_add(), Entity::isPlayer, kBasisZVector, kIdentityQuaternion, Entity::mass, maxThrust, nil, Entity::normalOrientation, quaternion_rotate_vector(), quaternion_rotation_between(), quaternion_set_random(), randf(), randomEjectaTemperature, ranrot_rand, Entity::setOrientation:, setOwner:, setPitch:, Entity::setPosition:, setRoll:, Entity::setScanClass:, setTemperature:, setThrust:, Entity::setVelocity:, v_forward, vector_add(), vector_multiply_scalar(), vector_normal(), vectorToHPVector(), velocity, Vector::x, Vector::y, and Vector::z.

Referenced by dumpCargoItem:, ShipEntity(ScriptMethods)::ejectShipOfRole:, ShipEntity(ScriptMethods)::ejectShipOfType:, PlayerEntity::launchMine:, and ShipEntity(Private)::launchPodWithCrew:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ejectCargo

- (void) ejectCargo
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1449 of file ShipEntityAI.m.

1450{
1451 OOCargoQuantity i, cargo_to_go = 0.1 * [self maxAvailableCargoSpace];
1452 while (cargo_to_go > 15) {
1453 cargo_to_go = ranrot_rand() % cargo_to_go;
1454 }
1455 [self dumpCargo];
1456 for (i = 1; i < cargo_to_go; i++) {
1457 [self performSelector:@selector(dumpCargo) withObject:nil afterDelay:0.75 * i]; // drop 3 canisters per 2 seconds
1458 }
1459}

Referenced by ShipEntity(AI)::broadcastDistressMessageWithDumping:.

Here is the caller graph for this function:

◆ ejectShipOfRole:

- (ShipEntity *) ejectShipOfRole: (NSString*) role

Provided by category ShipEntity(ScriptMethods).

Definition at line 47 of file ShipEntityScriptMethods.m.

47 :(NSString*)role
48{
49 ShipEntity* item = nil;
50
51 if (role != nil) {
52 item = [[UNIVERSE newShipWithRole:role] autorelease];
53 if (item != nil)
54 [self dumpItem:item];
55 }
56
57 return item;
58}

◆ ejectShipOfType:

- (ShipEntity *) ejectShipOfType: (NSString*) shipKey

Provided by category ShipEntity(ScriptMethods).

Definition at line 34 of file ShipEntityScriptMethods.m.

34 :(NSString*)shipKey
35{
36 ShipEntity* item = nil;
37
38 if (shipKey != nil) {
39 item = [[UNIVERSE newShipWithName:shipKey] autorelease];
40 if (item != nil)
41 [self dumpItem:item];
42 }
43
44 return item;
45}

Referenced by PlayerEntity(Scripting)::ejectItem:.

Here is the caller graph for this function:

◆ energyRechargeRate

- (float) energyRechargeRate

Definition at line 6486 of file ShipEntity.m.

6487{
6488 return energy_recharge_rate;
6489}

References energy_recharge_rate, and energyRechargeRate.

Referenced by PlayerEntity::doBookkeeping:, energyRechargeRate, OOShipLibraryGenerator(), and weaponRange.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enterDock:

- (void) enterDock: (StationEntity*) station

Reimplemented in PlayerEntity.

Definition at line 11715 of file ShipEntity.m.

11715 :(StationEntity*)station
11716{
11717 // throw these away now we're docked...
11718 if (dockingInstructions != nil) {
11719 [dockingInstructions autorelease];
11721 }
11722
11723 [self doScriptEvent:OOJSID("shipWillDockWithStation") withArgument:station];
11724 [self doScriptEvent:OOJSID("shipDockedWithStation") withArgument:station];
11725 [shipAI message:@"DOCKED"];
11726 [station noteDockedShip:self];
11727 [UNIVERSE removeEntity:self];
11728}
void noteDockedShip:(ShipEntity *ship)

References dockingInstructions, doScriptEvent:withArgument:, AI::message:, nil, and StationEntity::noteDockedShip:.

Referenced by DockEntity(OOPrivate)::pullInShipIfPermitted:, and StationEntity(OOPrivate)::pullInShipIfPermitted:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enterPlayerWormhole

- (void) enterPlayerWormhole

Provided by category ShipEntity(AI).

Definition at line 564 of file ShipEntityAI.m.

565{
566 [self enterWormhole:[PLAYER wormhole] replacing:NO];
567}

◆ enterTargetWormhole

- (void) enterTargetWormhole

Provided by category ShipEntity(AI).

Definition at line 569 of file ShipEntityAI.m.

570{
571 WormholeEntity* whole = nil;
572 ShipEntity* targEnt = [self primaryTarget];
573 double found_d2 = scannerRange * scannerRange;
574
575 if (targEnt && (HPdistance2(position, [targEnt position]) < found_d2)) {
576 if ([targEnt isWormhole])
577 whole = (WormholeEntity*)targEnt;
578 else if ([targEnt isPlayer])
579 whole = [PLAYER wormhole];
580 }
581
582 if (!whole) {
583 // locate nearest wormhole
584 int ent_count = UNIVERSE->n_entities;
585 Entity** uni_entities = UNIVERSE->sortedEntities; // grab the public sorted list
586 WormholeEntity* wormholes[ent_count];
587 int i;
588 int wh_count = 0;
589 for (i = 0; i < ent_count; i++)
590 if (uni_entities[i]->isWormhole)
591 wormholes[wh_count++] = [(WormholeEntity*)uni_entities[i] retain];
592 //
593 // double found_d2 = scannerRange * scannerRange;
594 for (i = 0; i < wh_count; i++) {
595 WormholeEntity* wh = wormholes[i];
596 double d2 = HPdistance2(position, wh->position);
597 if (d2 < found_d2) {
598 whole = wh;
599 found_d2 = d2;
600 }
601 [wh release];
602 }
603 }
604
605 [self enterWormhole:whole replacing:NO];
606}
unsigned isWormhole
Definition Entity.m:175

Referenced by Universe::forceWitchspaceEntries.

Here is the caller graph for this function:

◆ enterWitchspace

- (void) enterWitchspace

Reimplemented in PlayerEntity.

Definition at line 11774 of file ShipEntity.m.

11775{
11776 [UNIVERSE addWitchspaceJumpEffectForShip:self];
11777 [shipAI message:@"ENTERED_WITCHSPACE"];
11778
11779 if (![[UNIVERSE sun] willGoNova]) {
11780 // if the sun's not going nova, add a new ship like this one leaving.
11781 [UNIVERSE witchspaceShipWithPrimaryRole:[self primaryRole]];
11782 }
11783
11784 [UNIVERSE removeEntity:self];
11785}

References enterWitchspace, AI::message:, primaryRole, and UNIVERSE.

Referenced by coordinates, and enterWitchspace.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enterWormhole:

- (void) enterWormhole: (WormholeEntity*) w_hole

Reimplemented in PlayerEntity.

Definition at line 11739 of file ShipEntity.m.

11739 :(WormholeEntity*)w_hole
11740{
11741 [self enterWormhole:w_hole replacing:YES];
11742}

References enterWormhole:replacing:.

Referenced by manageCollisions.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enterWormhole:replacing:

- (void) enterWormhole: (WormholeEntity*) w_hole
replacing: (BOOL) replacing 

Definition at line 11744 of file ShipEntity.m.

11744 :(WormholeEntity*)w_hole replacing:(BOOL)replacing
11745{
11746 if (w_hole == nil)
11747 return;
11748 if ([self status] == STATUS_ENTERING_WITCHSPACE) {
11749 return; // has already entered a different wormhole
11750 }
11751 // Replacement ships now handled by system repopulator
11752
11753 // MKW 2011.02.27 - Moved here from ShipEntityAI so escorts reliably follow
11754 // mother in all wormhole cases, not just when the ship
11755 // creates the wormhole.
11756 [self addTarget:w_hole];
11757 [self setFoundTarget:w_hole];
11758 [shipAI reactToMessage:@"WITCHSPACE OKAY" context:@"performHyperSpaceExit"]; // must be a reaction, the ship is about to disappear
11759
11760 // CIM 2012.07.22 above only covers those cases where ship expected to leave
11761 if ([[self escortArray] count] > 1) {
11762 // so wormhole escorts anyway if it leaves unexpectedly.
11763 [self wormholeEscorts];
11764 }
11765
11766 if ([self scriptedMisjump]) {
11767 [self setScriptedMisjump:NO];
11768 [w_hole setMisjumpWithRange:[self scriptedMisjumpRange]];
11769 [self setScriptedMisjumpRange:0.5];
11770 }
11771 [w_hole suckInShip:self]; // removes ship from universe
11772}
BOOL scriptedMisjump()
BOOL suckInShip:(ShipEntity *ship)
void setMisjumpWithRange:(GLfloat range)

References addTarget:, count, escortArray, nil, AI::reactToMessage:context:, scriptedMisjump, scriptedMisjumpRange, setFoundTarget:, WormholeEntity::setMisjumpWithRange:, setScriptedMisjump:, setScriptedMisjumpRange:, Entity::status, WormholeEntity::suckInShip:, and wormholeEscorts.

Referenced by ShipEntity(AI)::enterPlayerWormhole, ShipEntity(AI)::enterTargetWormhole, enterWormhole:, manageCollisions, and ShipEntity(OOAIPrivate)::performHyperSpaceExitReplace:toSystem:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ entityForShaderProperties

- (Entity *) entityForShaderProperties

Definition at line 12745 of file ShipEntity.m.

12746{
12747 return [self rootShipEntity];
12748}

References entityForShaderProperties, and Entity::rootShipEntity.

Referenced by entityForShaderProperties, and scriptInfo.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ entityPersonality

- (GLfloat) entityPersonality

Definition at line 8414 of file ShipEntity.m.

8415{
8417}
#define ENTITY_PERSONALITY_MAX
Definition ShipEntity.h:112

References entity_personality, ENTITY_PERSONALITY_MAX, and entityPersonality.

Referenced by entityPersonality, and maxFlightSpeed.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ entityPersonalityInt

- (GLint) entityPersonalityInt

Definition at line 8419 of file ShipEntity.m.

8420{
8421 return entity_personality;
8422}

References entity_personality, and entityPersonalityInt.

Referenced by DockEntity(OOPrivate)::addShipToShipsOnApproach:, entityPersonalityInt, maxFlightSpeed, PlayerEntity::setGuiToStatusScreen, and setUpOneStandardSubentity:asTurret:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ equipmentCount

- (NSUInteger) equipmentCount

Definition at line 3262 of file ShipEntity.m.

3263{
3264 return [_equipment count];
3265}

References equipmentCount.

Referenced by equipmentCount, and isFrangible.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ equipmentEnumerator

- (NSEnumerator *) equipmentEnumerator

Definition at line 3257 of file ShipEntity.m.

3258{
3259 return [_equipment objectEnumerator];
3260}

References equipmentEnumerator.

Referenced by PlayerEntity::commanderDataDictionary, equipmentEnumerator, isFrangible, ShipEntity(LoadRestore)::savedShipDictionaryWithContext:, and PlayerEntity::takeInternalDamage.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ equipmentItemProviding:

- (NSString *) equipmentItemProviding: (NSString*) equipmentType

Definition at line 2820 of file ShipEntity.m.

2820 :(NSString*)equipmentType
2821{
2822 NSString* key = nil;
2823 foreach (key, _equipment) {
2824 if ([key isEqualToString:equipmentType]) {
2825 // equipment always provides itself
2826 return [[key copy] autorelease];
2827 } else {
2828 OOEquipmentType* et = [OOEquipmentType equipmentTypeWithIdentifier:key];
2829 if (et != nil && [et provides:equipmentType]) {
2830 return [[key copy] autorelease];
2831 }
2832 }
2833 }
2834 return nil;
2835}

References _equipment, OOEquipmentType::equipmentTypeWithIdentifier:, and nil.

Referenced by abandonShip, PlayerEntity::enterGalacticWitchspace, and PlayerEntity::launchEscapeCapsule.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ equipmentListForScripting

- (NSArray *) equipmentListForScripting

Definition at line 2993 of file ShipEntity.m.

2994{
2995 NSArray* eqTypes = [OOEquipmentType allEquipmentTypes];
2996 NSMutableArray* quip = [NSMutableArray arrayWithCapacity:[eqTypes count]];
2997 OOEquipmentType* eqType = nil;
2998 BOOL isDamaged;
2999
3000 foreach (eqType, eqTypes) {
3001 // Equipment list, consistent with the rest of the API - Kaks
3002 if ([eqType canCarryMultiple]) {
3003 NSString* damagedIdentifier = [[eqType identifier] stringByAppendingString:@"_DAMAGED"];
3004 NSUInteger i, count = 0;
3005 count += [self countEquipmentItem:[eqType identifier]];
3006 count += [self countEquipmentItem:damagedIdentifier];
3007 for (i = 0; i < count; i++) {
3008 [quip addObject:eqType];
3009 }
3010 } else {
3011 isDamaged = [self hasEquipmentItem:[[eqType identifier] stringByAppendingString:@"_DAMAGED"]];
3012 if ([self hasEquipmentItem:[eqType identifier]] || isDamaged) {
3013 [quip addObject:eqType];
3014 }
3015 }
3016 }
3017
3018 // Passengers - not supported yet for NPCs, but it's here for genericity.
3019 if ([self passengerCapacity] > 0) {
3020 eqType = [OOEquipmentType equipmentTypeWithIdentifier:@"EQ_PASSENGER_BERTH"];
3021 //[quip addObject:[self eqDictionaryWithType:eqType isDamaged:NO]];
3022 [quip addObject:eqType];
3023 }
3024
3025 return [[quip copy] autorelease];
3026}
NSArray * allEquipmentTypes()
NSString * identifier()
NSUInteger passengerCapacity()

References OOEquipmentType::allEquipmentTypes, count, countEquipmentItem:, equipmentListForScripting, OOEquipmentType::equipmentTypeWithIdentifier:, hasEquipmentItem:, OOEquipmentType::identifier, nil, and passengerCapacity.

Referenced by cargo, equipmentListForScripting, ShipGetProperty(), and ShipGetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ equipmentValidToAdd:inContext:

- (BOOL) equipmentValidToAdd: (NSString*) equipmentKey
inContext: (NSString*) context 

Definition at line 3028 of file ShipEntity.m.

3028 :(NSString*)equipmentKey inContext:(NSString*)context
3029{
3030 return [self equipmentValidToAdd:equipmentKey whileLoading:NO inContext:context];
3031}

References equipmentValidToAdd:whileLoading:inContext:.

Here is the call graph for this function:

◆ equipmentValidToAdd:whileLoading:inContext:

- (BOOL) equipmentValidToAdd: (NSString*) equipmentKey
whileLoading: (BOOL) loading
inContext: (NSString*) context 

Definition at line 3033 of file ShipEntity.m.

3033 :(NSString*)equipmentKey whileLoading:(BOOL)loading inContext:(NSString*)context
3034{
3035 OOEquipmentType* eqType = nil;
3036 BOOL validationForDamagedEquipment = NO;
3037
3038 if ([equipmentKey hasSuffix:@"_DAMAGED"]) {
3039 equipmentKey = [equipmentKey substringToIndex:[equipmentKey length] - [@"_DAMAGED" length]];
3040 }
3041
3042 eqType = [OOEquipmentType equipmentTypeWithIdentifier:equipmentKey];
3043 if (eqType == nil)
3044 return NO;
3045
3046 // need to know if we are trying to add a Repair version of the equipment. In some cases
3047 // (e.g. available cargo space required), it makes sense to deny installation of equipment
3048 // if the condition is not satisfied, but it doesn't make sense to deny repair when the
3049 // equipment is already installed. For now, we are checking only the cargo space condition,
3050 // but other conditions might need to be revised too. - Nikos, 20151115
3051 if ([self hasEquipmentItem:[eqType damagedIdentifier]]) {
3052 validationForDamagedEquipment = YES;
3053 }
3054
3055 // not all conditions make sence checking while loading a game with already purchaged equipment.
3056 // while loading, we mainly need to catch changes when the installed oxps set has changed since saving.
3057 if ([eqType requiresEmptyPylon] && [self missileCount] >= [self missileCapacity] && !loading)
3058 return NO;
3059 if ([eqType requiresMountedPylon] && [self missileCount] == 0 && !loading)
3060 return NO;
3061 if ([self availableCargoSpace] < [eqType requiredCargoSpace] && !validationForDamagedEquipment && !loading)
3062 return NO;
3063 if ([eqType requiresEquipment] != nil && ![self hasAllEquipment:[eqType requiresEquipment] includeWeapons:YES whileLoading:loading])
3064 return NO;
3065 if ([eqType requiresAnyEquipment] != nil && ![self hasEquipmentItem:[eqType requiresAnyEquipment] includeWeapons:YES whileLoading:loading])
3066 return NO;
3067 if ([eqType incompatibleEquipment] != nil && [self hasEquipmentItem:[eqType incompatibleEquipment] includeWeapons:YES whileLoading:loading])
3068 return NO;
3069 if ([eqType requiresCleanLegalRecord] && [self legalStatus] != 0 && !loading)
3070 return NO;
3071 if ([eqType requiresNonCleanLegalRecord] && [self legalStatus] == 0 && !loading)
3072 return NO;
3073 if ([eqType requiresFreePassengerBerth] && [self passengerCount] >= [self passengerCapacity])
3074 return NO;
3075 if ([eqType requiresFullFuel] && [self fuel] < [self fuelCapacity] && !loading)
3076 return NO;
3077 if ([eqType requiresNonFullFuel] && [self fuel] >= [self fuelCapacity] && !loading)
3078 return NO;
3079
3080 if (!loading) {
3081 NSString* condition_script = [eqType conditionScript];
3082 if (condition_script != nil) {
3083 OOJSScript* condScript = [UNIVERSE getConditionScript:condition_script];
3084 if (condScript != nil) // should always be non-nil, but just in case
3085 {
3086 JSContext* JScontext = OOJSAcquireContext();
3087 BOOL OK;
3088 BOOL allow_addition = NO;
3089 OOJSVal result = OOJSUndefinedValue();
3090 OOJSVal args[] = { OOJSValueFromNativeObject(JScontext, equipmentKey), OOJSValueFromNativeObject(JScontext, self), OOJSValueFromNativeObject(JScontext, context) };
3091
3092 OK = [condScript callMethod:OOJSID("allowAwardEquipment")
3093 inContext:JScontext
3094 withArguments:args
3095 count:sizeof args / sizeof *args
3096 result:&result];
3097
3098 if (OK)
3099 allow_addition = OOJSValueToBOOL(JScontext, result);
3100
3101 OOJSFreeValue(JScontext, result);
3102 OOJSFreeValue(JScontext, args[0]);
3103 OOJSFreeValue(JScontext, args[1]);
3104 OOJSFreeValue(JScontext, args[2]);
3105 OOJSRelinquishContext(JScontext);
3106
3107 if (OK && !allow_addition) {
3108 /* if the script exists, the function exists, the function
3109 * returns a bool, and that bool is false, block
3110 * addition. Otherwise allow it as default */
3111 return NO;
3112 }
3113 }
3114 }
3115 }
3116
3117 if ([self isPlayer]) {
3118 if (![eqType isAvailableToPlayer])
3119 return NO;
3120 if (![eqType isAvailableToAll]) {
3121 // find options that agree with this ship. Only player ships have these options.
3122 OOShipRegistry* registry = [OOShipRegistry sharedRegistry];
3123 NSDictionary* shipyardInfo = [registry shipyardInfoForKey:[self shipDataKey]];
3124 NSMutableSet* options = [NSMutableSet setWithArray:[shipyardInfo oo_arrayForKey:KEY_OPTIONAL_EQUIPMENT]];
3125 [options addObjectsFromArray:[[shipyardInfo oo_dictionaryForKey:KEY_STANDARD_EQUIPMENT] oo_arrayForKey:KEY_EQUIPMENT_EXTRAS]];
3126 if (![options containsObject:equipmentKey])
3127 return NO;
3128 }
3129 } else {
3130 if (![eqType isAvailableToNPCs])
3131 return NO;
3132 }
3133
3134 return YES;
3135}
OOINLINE BOOL OOJSValueToBOOL(JSContext *context, jsval value)
NSString * conditionScript()
BOOL callMethod:inContext:withArguments:count:result:(jsid methodID,[inContext] JSContext *context,[withArguments] jsval *argv,[count] intN argc,[result] jsval *outResult)
Definition OOJSScript.m:328
NSDictionary * shipyardInfoForKey:(NSString *key)
OOShipRegistry * sharedRegistry()
NSUInteger passengerCount()
NSUInteger missileCount()
OOCargoQuantity availableCargoSpace()
OOFuelQuantity fuelCapacity()
NSUInteger missileCapacity()

References availableCargoSpace, OOJSScript::callMethod:inContext:withArguments:count:result:, OOEquipmentType::conditionScript, OOEquipmentType::equipmentTypeWithIdentifier:, fuel, fuelCapacity, Entity::isPlayer, legalStatus, missileCapacity, missileCount, nil, OOJSAcquireContext(), OOJSFreeValue, OOJSRelinquishContext(), OOJSUndefinedValue, OOJSValueFromNativeObject(), OOJSValueToBOOL(), passengerCapacity, passengerCount, OOShipRegistry::sharedRegistry, shipDataKey, and OOShipRegistry::shipyardInfoForKey:.

Referenced by equipmentValidToAdd:inContext:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ escortArray

- (NSArray *) escortArray

Definition at line 6051 of file ShipEntity.m.

6052{
6053 if (_escortGroup == nil)
6054 return [NSArray array];
6055 return [[self escortEnumerator] allObjects];
6056}

References _escortGroup, escortArray, escortEnumerator, and nil.

Referenced by abandonShip, dockEscorts, enterWormhole:replacing:, escortArray, messageTime, and update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ escortCheckMother

- (void) escortCheckMother
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1591 of file ShipEntityAI.m.

1592{
1593 ShipEntity* mother = [self owner];
1594
1595 if ([mother acceptAsEscort:self]) {
1596 [self setOwner:mother];
1597 [self setGroup:[mother escortGroup]];
1598 [shipAI message:@"ESCORTING"];
1599 } else {
1600 [self setOwner:self];
1601 if ([self group] == [mother escortGroup])
1602 [self setGroup:nil];
1603 [shipAI message:@"NOT_ESCORTING"];
1604 }
1605}

◆ escortCount

- (uint8_t) escortCount

Definition at line 6058 of file ShipEntity.m.

6059{
6060 if (_escortGroup == nil)
6061 return 0;
6062 return [_escortGroup count] - 1;
6063}

References _escortGroup, OOShipGroup::count, escortCount, and nil.

Referenced by acceptAsEscort:, deployEscorts, escortCount, and messageTime.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ escortEnumerator

- (NSEnumerator *) escortEnumerator

Definition at line 6044 of file ShipEntity.m.

6045{
6046 if (_escortGroup == nil)
6047 return [[NSArray array] objectEnumerator];
6048 return [[_escortGroup mutationSafeEnumerator] ooExcludingObject:self];
6049}

References _escortGroup, escortEnumerator, OOShipGroup::mutationSafeEnumerator, and nil.

Referenced by deployEscorts, escortArray, escortEnumerator, and messageTime.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ escortGroup

- (OOShipGroup *) escortGroup

Definition at line 6000 of file ShipEntity.m.

6001{
6002 if (_escortGroup == nil) {
6003 _escortGroup = [[OOShipGroup alloc] initWithName:@"escort group"];
6004 [_escortGroup setLeader:self];
6005 }
6006
6007 return _escortGroup;
6008}

References _escortGroup, escortGroup, nil, and OOShipGroup::setLeader:.

Referenced by abandonShip, acceptAsEscort:, deployEscorts, dockEscorts, ShipEntity(PureAI)::escortCheckMother, escortGroup, fireMissileWithIdentifier:andTarget:, StationEntity::launchIndependentShip:, messageTime, setUpEscorts, ShipEntity(Private)::setUpMixedEscorts, ShipGetProperty(), ShipGetProperty(), ShipEntity(AI)::suggestEscortTo:, and update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ evasiveAction:

- (void) evasiveAction: (double) delta_t

Definition at line 9012 of file ShipEntity.m.

9012 :(double)delta_t
9013{
9014 stick_roll = flightRoll; // desired roll and pitch
9016
9017 ShipEntity* target = [self primaryTarget];
9018 if (!target) // leave now!
9019 {
9020 [self noteLostTargetAndGoIdle]; // NOTE: was AI message: rather than reactToMessage:
9021 return;
9022 }
9023
9024 double agreement = dot_product(v_right, target->v_right);
9025 if (agreement > -0.3 && agreement < 0.3) {
9026 stick_roll = 0.0;
9027 } else {
9028 if (stick_roll >= 0.0) {
9030 } else {
9032 }
9033 }
9034 if (stick_pitch >= 0.0) {
9036 } else {
9038 }
9039
9040 [self applySticks:delta_t];
9041}

References applySticks:, dot_product(), flightPitch, flightRoll, max_flight_pitch, max_flight_roll, noteLostTargetAndGoIdle, primaryTarget, stick_pitch, stick_roll, and v_right.

Referenced by behaviour_attack_break_off_target:, and behaviour_evasive_action:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exhaustEmissiveColor

- (OOColor *) exhaustEmissiveColor

Definition at line 10166 of file ShipEntity.m.

10167{
10168 return [[exhaust_emissive_color retain] autorelease];
10169}

References exhaustEmissiveColor.

Referenced by coordinates, exhaustEmissiveColor, ShipGetProperty(), ShipGetProperty(), and OOExhaustPlumeEntity::update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exhaustEnumerator

- (NSEnumerator *) exhaustEnumerator

Definition at line 1229 of file ShipEntity.m.

1230{
1231 return [[self subEntities] objectEnumeratorFilteredWithSelector:@selector(isExhaust)];
1232}

References exhaustEnumerator, and subEntities.

Referenced by exhaustEnumerator, frustumRadius, resetExhaustPlumes, ShipGetProperty(), ShipGetProperty(), and subEntities.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exitAIWithMessage:

- (void) exitAIWithMessage: (NSString*) message
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1229 of file ShipEntityAI.m.

1229 :(NSString*)message
1230{
1231 if ([message length] == 0)
1232 message = @"RESTARTED";
1233 [shipAI exitStateMachineWithMessage:message];
1234}

◆ explodeSelf

- (void) explodeSelf
implementation

Provided by category ShipEntity(PureAI).

Definition at line 2307 of file ShipEntityAI.m.

2308{
2309 [self getDestroyedBy:nil damageType:kOODamageTypeEnergy];
2310}

◆ extraCargo

- (NSUInteger) extraCargo

Definition at line 3526 of file ShipEntity.m.

3527{
3528 return extra_cargo;
3529}

References extra_cargo, and extraCargo.

Referenced by extraCargo, and isFrangible.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fightOrFleeHostiles

- (void) fightOrFleeHostiles
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1542 of file ShipEntityAI.m.

1543{
1544 [self addDefenseTarget:[self foundTarget]];
1545
1546 if ([self hasEscorts]) {
1547 Entity* leTarget = [self lastEscortTarget];
1548 if (leTarget != nil) {
1549 [self setFoundTarget:leTarget];
1550 [shipAI message:@"FLEEING"];
1551 return;
1552 }
1553
1554 [self setPrimaryAggressor:[self foundTarget]];
1555 [self addTarget:[self foundTarget]];
1556 [self deployEscorts];
1557 [shipAI message:@"DEPLOYING_ESCORTS"];
1558 [shipAI message:@"FLEEING"];
1559 return;
1560 }
1561
1562 // consider launching a missile
1563 if (missiles > 2) // keep a reserve
1564 {
1565 if (randf() < 0.50) {
1566 [self setPrimaryAggressor:[self foundTarget]];
1567 [self addTarget:[self foundTarget]];
1568 [self fireMissile];
1569 [shipAI message:@"FLEEING"];
1570 return;
1571 }
1572 }
1573
1574 // consider fighting
1575 if (energy > maxEnergy * 0.80) {
1576 [self setPrimaryAggressor:[self foundTarget]];
1577 //[self performAttack];
1578 [shipAI message:@"FIGHTING"];
1579 return;
1580 }
1581
1582 [shipAI message:@"FLEEING"];
1583}

◆ fightOrFleeMissile

- (void) fightOrFleeMissile
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1075 of file ShipEntityAI.m.

1076{
1077 // find an incoming missile...
1078 //
1079 ShipEntity* missile = nil;
1080 unsigned i;
1081 ShipEntity* escort = nil;
1082 ShipEntity* target = nil;
1083
1084 [self checkScannerIgnoringUnpowered];
1085 for (i = 0; (i < n_scanned_ships) && (missile == nil); i++) {
1086 ShipEntity* thing = scanned_ships[i];
1087 if (thing->scanClass == CLASS_MISSILE) {
1088 target = [thing primaryTarget];
1089
1090 if (target == self) {
1091 missile = thing;
1092 } else {
1093 foreach (escort, [self escortEnumerator]) {
1094 if (target == escort) {
1095 missile = thing;
1096 }
1097 }
1098 }
1099 }
1100 }
1101
1102 if (missile == nil)
1103 return;
1104
1105 [self addTarget:missile];
1106 [self addDefenseTarget:missile];
1107
1108 // Notify own ship script that we are being attacked.
1109 ShipEntity* hunter = [missile owner];
1110 [self doScriptEvent:OOJSID("shipBeingAttacked") withArgument:hunter];
1111 [hunter doScriptEvent:OOJSID("shipAttackedOther") withArgument:self];
1112
1113 if ([self isPolice]) {
1114 // Notify other police in group of attacker.
1115 // Note: prior to 1.73 this was done only if we had ECM.
1116 ShipEntity* police = nil;
1117
1118 foreach (police, [[self group] mutationSafeEnumerator]) {
1119 [police setFoundTarget:hunter];
1120 [police setPrimaryAggressor:hunter];
1121 }
1122 }
1123
1124 // if I'm a copper and you're not, then mark the other as an offender!
1125 if ([self isPolice] && ![hunter isPolice])
1126 [hunter markAsOffender:64 withReason:kOOLegalStatusReasonAttackedPolice];
1127
1128 if ([self hasECM]) {
1129 // use the ECM and battle on
1130
1131 [self setPrimaryAggressor:hunter]; // lets get them now for that!
1132 [self setFoundTarget:hunter];
1133
1134 [self fireECM];
1135 return;
1136 }
1137
1138 // RUN AWAY !!
1139 desired_range = 10000;
1140 [self performFlee];
1141 [shipAI message:@"FLEEING"];
1142}
void setPrimaryAggressor:(Entity *targetEntity)

◆ findBoundingBoxRelativeTo:i:j:k:

- (BoundingBox) findBoundingBoxRelativeTo: (Entity*) other
i: (Vector) i
j: (Vector) j
k: (Vector) k 
implementation

Definition at line 12480 of file ShipEntity.m.

12480 :(Entity*)other i:(Vector)i j:(Vector)j k:(Vector)k
12481{
12482 HPVector opv = other ? other->position : position;
12483 return [self findBoundingBoxRelativeToPosition:opv i:i j:j k:k];
12484}

References findBoundingBoxRelativeToPosition:i:j:k:, and Entity::position.

Here is the call graph for this function:

◆ findBoundingBoxRelativeToPosition:i:j:k:

- (BoundingBox) findBoundingBoxRelativeToPosition: (HPVector) opv
i: (Vector) i
j: (Vector) j
k: (Vector) k 

Definition at line 1291 of file ShipEntity.m.

1291 :(HPVector)opv i:(Vector)i j:(Vector)j k:(Vector)k
1292{
1293 // HPVect: check that this conversion doesn't lose needed precision
1294 return [[self mesh] findBoundingBoxRelativeToPosition:HPVectorToVector(opv)
1295 ri:i
1296 rj:j
1297 rk:k
1298 selfPosition:HPVectorToVector(position)
1299 si:v_right
1300 sj:v_up
1301 sk:v_forward];
1302}

References OOMesh::findBoundingBoxRelativeToPosition:ri:rj:rk:selfPosition:si:sj:sk:, and mesh.

Referenced by findBoundingBoxRelativeTo:i:j:k:, positionOffsetForShipInRotationToAlignment, and DockEntity::shipIsInDockingCorridor:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ findNearestPlanet

- (OOPlanetEntity *) findNearestPlanet

Definition at line 6599 of file ShipEntity.m.

6600{
6601 /*
6602 Performance note: this method is called every frame by every ship, and
6603 has a significant profiler presence.
6604 -- Ahruman 2012-09-13
6605 */
6606 OOPlanetEntity *planet = nil, *bestPlanet = nil;
6607 float bestRange = INFINITY;
6608 HPVector myPosition = [self position];
6609
6610 // valgrind complains about this line here. Might be compiler/GNUstep bug?
6611 // should we go back to a traditional enumerator? - CIM
6612 // similar complaints about the other foreach() in this file
6613 foreach (planet, [UNIVERSE planets]) {
6614 // Ignore miniature planets.
6615 if ([planet planetType] == STELLAR_TYPE_MINIATURE)
6616 continue;
6617
6618 float range = SurfaceDistanceSqaredV(myPosition, planet);
6619 if (range < bestRange) {
6620 bestPlanet = planet;
6621 bestRange = range;
6622 }
6623 }
6624
6625 return bestPlanet;
6626}
@ STELLAR_TYPE_MINIATURE

References findNearestPlanet, nil, Entity::position, STELLAR_TYPE_MINIATURE, SurfaceDistanceSqaredV, and UNIVERSE.

Referenced by findNearestPlanet, findNearestStellarBody, ShipEntity(PureAI)::landOnPlanet, ShipEntity(AI)::performLandOnPlanet, reportAIMessages, and ShipEntity(PureAI)::setTakeOffFromPlanet.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ findNearestPlanetExcludingMoons

- (OOPlanetEntity *) findNearestPlanetExcludingMoons

Definition at line 6642 of file ShipEntity.m.

6643{
6644 OOPlanetEntity* result = nil;
6645 OOPlanetEntity* planet = nil;
6646 NSArray* bodies = nil;
6647 NSArray* planets = nil;
6648 unsigned i;
6649
6650 bodies = [UNIVERSE planets];
6651 planets = [NSMutableArray arrayWithCapacity:[bodies count]];
6652
6653 for (i = 0; i < [bodies count]; i++) {
6654 planet = [bodies objectAtIndex:i];
6655 if ([planet planetType] == STELLAR_TYPE_NORMAL_PLANET)
6656 planets = [planets arrayByAddingObject:planet];
6657 }
6658
6659 if ([planets count] == 0)
6660 return nil;
6661
6662 planets = [planets sortedArrayUsingFunction:ComparePlanetsBySurfaceDistance context:self];
6663 result = [planets objectAtIndex:0];
6664
6665 return result;
6666}
@ STELLAR_TYPE_NORMAL_PLANET

References count, findNearestPlanetExcludingMoons, nil, and STELLAR_TYPE_NORMAL_PLANET.

Referenced by findNearestPlanetExcludingMoons, reportAIMessages, and ShipEntity(PureAI)::setCourseToPlanet.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ findNearestStellarBody

- (Entity< OOStellarBody > *) findNearestStellarBody

Definition at line 6628 of file ShipEntity.m.

6629{
6630 Entity<OOStellarBody>* match = [self findNearestPlanet];
6631 OOSunEntity* sun = [UNIVERSE sun];
6632
6633 if (sun != nil) {
6634 if (match == nil || SurfaceDistanceSqared(self, sun) < SurfaceDistanceSqared(self, match)) {
6635 match = sun;
6636 }
6637 }
6638
6639 return match;
6640}
static float SurfaceDistanceSqared(Entity *reference, Entity< OOStellarBody > *stellar)

References findNearestPlanet, findNearestStellarBody, nil, and SurfaceDistanceSqared.

Referenced by ShipEntity(PureAI)::checkAegis, checkForAegis, PlayerEntity::dialAltitude, findNearestStellarBody, and reportAIMessages.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ findNewDefenseTarget

- (void) findNewDefenseTarget
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1336 of file ShipEntityAI.m.

1337{
1338 [self checkScanner];
1339 unsigned i;
1340 for (i = 0; i < n_scanned_ships; i++) {
1341 ShipEntity* ship = scanned_ships[i];
1342 if (![ship isCloaked] && (([ship primaryTarget] == self && [ship hasHostileTarget]) || [ship isMine] || ([ship isThargoid] != [self isThargoid]))) {
1343 if (![self isDefenseTarget:ship]) {
1344 [self addDefenseTarget:ship];
1345 return;
1346 }
1347 }
1348 }
1349}

◆ findSubentityBoundingBox

- (BoundingBox) findSubentityBoundingBox

Definition at line 2002 of file ShipEntity.m.

2003{
2004 return [[self mesh] findSubentityBoundingBoxWithPosition:HPVectorToVector(position) rotMatrix:rotMatrix];
2005}

References findSubentityBoundingBox, OOMesh::findSubentityBoundingBoxWithPosition:rotMatrix:, and mesh.

Referenced by PlayerEntity::doBookkeeping:, findSubentityBoundingBox, maxFlightSpeed, setUpOneStandardSubentity:asTurret:, and update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fireAftWeapon:

- (BOOL) fireAftWeapon: (double) range

Definition at line 10057 of file ShipEntity.m.

10057 :(double)range
10058{
10059 // set the values from aft_weapon_type.
10061 [self setWeaponDataFromType:aft_weapon_type];
10062
10063 return [self fireWeapon:aft_weapon_type direction:WEAPON_FACING_AFT range:range];
10064}

References currentWeaponFacing, fireWeapon:direction:range:, setWeaponDataFromType:, and WEAPON_FACING_AFT.

Referenced by behaviour_running_defense:, and behaviour_scripted_ai:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fireDirectLaserDefensiveShot

- (BOOL) fireDirectLaserDefensiveShot

Definition at line 10266 of file ShipEntity.m.

10267{
10268 NSEnumerator* targetEnum = [self defenseTargetEnumerator];
10269 Entity* target = nil;
10270 while ((target = [[targetEnum nextObject] weakRefUnderlyingObject])) {
10271 // can't fire defensively at cloaked ships
10272 if ([target scanClass] == CLASS_NO_DRAW || [(ShipEntity*)target isCloaked] || [target energy] <= 0.0) {
10273 [self removeDefenseTarget:target];
10274 } else {
10275 double range = [self rangeToSecondaryTarget:target];
10276 if (range < weaponRange) {
10277 return [self fireDirectLaserShotAt:target];
10278 } else if (range > scannerRange) {
10279 [self removeDefenseTarget:target];
10280 }
10281 }
10282 }
10283 return NO;
10284}

References defenseTargetEnumerator, Entity::energy, fireDirectLaserDefensiveShot, fireDirectLaserShotAt:, isCloaked, nil, rangeToSecondaryTarget:, removeDefenseTarget:, scanClass, scannerRange, and weaponRange.

Referenced by coordinates, fireDirectLaserDefensiveShot, and fireDirectLaserShot:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fireDirectLaserShot:

- (BOOL) fireDirectLaserShot: (double) range

Definition at line 10254 of file ShipEntity.m.

10254 :(double)range
10255{
10256 Entity* my_target = [self primaryTarget];
10257 if (my_target == nil)
10258 return [self fireDirectLaserDefensiveShot];
10259 if (range > randf() * weaponRange * (accuracy + 5.5))
10260 return [self fireDirectLaserDefensiveShot];
10261 if (range > weaponRange)
10262 return [self fireDirectLaserDefensiveShot];
10263 return [self fireDirectLaserShotAt:my_target];
10264}

References accuracy, fireDirectLaserDefensiveShot, fireDirectLaserShotAt:, nil, primaryTarget, randf(), and weaponRange.

Referenced by fireWeapon:direction:range:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fireDirectLaserShotAt:

- (BOOL) fireDirectLaserShotAt: (Entity*) my_target

Definition at line 10286 of file ShipEntity.m.

10286 :(Entity*)my_target
10287{
10288 GLfloat hit_at_range;
10289 double range_limit2 = weaponRange * weaponRange;
10290 Vector r_pos;
10291
10292 r_pos = vector_normal_or_zbasis([self vectorTo:my_target]);
10293
10295
10296 GLfloat acc_factor = (10.0 - accuracy) * 0.001;
10297
10298 q_laser.x += acc_factor * (randf() - 0.5); // randomise aim a little (+/- 0.005 at accuracy 0, never miss at accuracy 10)
10299 q_laser.y += acc_factor * (randf() - 0.5);
10300 q_laser.z += acc_factor * (randf() - 0.5);
10301 quaternion_normalize(&q_laser);
10302
10303 Quaternion q_save = orientation; // save rotation
10304 orientation = q_laser; // face in direction of laser
10305 // weapon offset for thargoid lasers is always zero
10306 ShipEntity* victim = [UNIVERSE firstShipHitByLaserFromShip:self inDirection:WEAPON_FACING_FORWARD offset:kZeroVector gettingRangeFound:&hit_at_range];
10307 [self setShipHitByLaser:victim];
10308 orientation = q_save; // restore rotation
10309
10311
10312 // do special effects laser line
10313 OOLaserShotEntity* shot = [OOLaserShotEntity laserFromShip:self direction:WEAPON_FACING_FORWARD offset:kZeroVector];
10314 [shot setColor:laser_color];
10315 [shot setScanClass:CLASS_NO_DRAW];
10316 [shot setPosition:position];
10317 [shot setOrientation:q_laser];
10318 [shot setVelocity:vel];
10319
10320 if (victim != nil) {
10321 ShipEntity* subent = [victim subEntityTakingDamage];
10322 if (subent != nil && [victim isFrangible]) {
10323 // do 1% bleed-through damage...
10324 [victim takeEnergyDamage:0.01 * weapon_damage from:self becauseOf:self weaponIdentifier:[[self weaponTypeForFacing:WEAPON_FACING_FORWARD strict:YES] identifier]];
10325 victim = subent;
10326 }
10327
10328 if (hit_at_range * hit_at_range < range_limit2) {
10329 [victim takeEnergyDamage:weapon_damage from:self becauseOf:self weaponIdentifier:[[self weaponTypeForFacing:WEAPON_FACING_FORWARD strict:YES] identifier]]; // a very palpable hit
10330
10331 [shot setRange:hit_at_range];
10333 HPVector flash_pos = HPvector_add([shot position], vectorToHPVector(vector_multiply_scalar(vd, hit_at_range)));
10334 [UNIVERSE addLaserHitEffectsAt:flash_pos against:victim damage:weapon_damage color:laser_color];
10335 }
10336 }
10337
10338 [UNIVERSE addEntity:shot];
10339
10340 [self resetShotTime];
10341
10342 return YES;
10343}
OOINLINE void quaternion_normalize(Quaternion *quat) NONNULL_FUNC ALWAYS_INLINE_FUNC
OOINLINE Vector vector_normal_or_zbasis(Vector vec) INLINE_CONST_FUNC
Definition OOVector.h:265
void setRange:(GLfloat range)
void setColor:(OOColor *color)
instancetype laserFromShip:direction:offset:(ShipEntity *ship,[direction] OOWeaponFacing direction,[offset] Vector offset)
ShipEntity * subEntityTakingDamage()
OOScalar x
OOScalar y
OOScalar z

References accuracy, flightSpeed, HPvector_add(), OOEquipmentType::identifier, isFrangible, kBasisZVector, OOLaserShotEntity::laserFromShip:direction:offset:, nil, Entity::orientation, Entity::position, quaternion_normalize(), quaternion_rotation_between(), randf(), resetShotTime, OOLightParticleEntity::setColor:, Entity::setOrientation:, Entity::setPosition:, Entity::setScanClass:, setShipHitByLaser:, Entity::setVelocity:, subEntityTakingDamage, takeEnergyDamage:from:becauseOf:weaponIdentifier:, v_forward, vector_forward_from_quaternion(), vector_multiply_scalar(), vector_normal_or_zbasis(), vectorToHPVector(), weaponRange, weaponTypeForFacing:strict:, Quaternion::x, Quaternion::y, and Quaternion::z.

Referenced by fireDirectLaserDefensiveShot, and fireDirectLaserShot:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fireECM

- (BOOL) fireECM

Reimplemented in PlayerEntity.

Definition at line 10733 of file ShipEntity.m.

10734{
10735 if (![self hasECM])
10736 return NO;
10737
10738 OOECMBlastEntity* ecmDevice = [[OOECMBlastEntity alloc] initFromShip:self];
10739 [UNIVERSE addEntity:ecmDevice];
10740 [ecmDevice release];
10741 return YES;
10742}

References fireECM, and hasECM.

Referenced by coordinates, ShipEntity(PureAI)::fightOrFleeMissile, fireECM, ShipFireECM(), and ShipFireECM().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fireLaserShotInDirection:weaponIdentifier:

- (BOOL) fireLaserShotInDirection: (OOWeaponFacing) direction
weaponIdentifier: (NSString*) weaponIdentifier 

Definition at line 10369 of file ShipEntity.m.

10369 :(OOWeaponFacing)direction weaponIdentifier:(NSString*)weaponIdentifier
10370{
10371 double range_limit2 = weaponRange * weaponRange;
10372 GLfloat hit_at_range;
10373 NSUInteger i, barrels;
10375 NSArray* laserPortOffsets = [self laserPortOffset:direction];
10376 OOLaserShotEntity* shot = nil;
10377
10378 barrels = [laserPortOffsets count];
10379 NSMutableArray* shotEntities = [NSMutableArray arrayWithCapacity:barrels];
10380
10381 GLfloat effective_damage = weapon_damage;
10382 if (barrels > 1 && !_multiplyWeapons) {
10383 // then divide the shot power between the shots
10384 effective_damage /= (GLfloat)barrels;
10385 }
10386
10387 for (i = 0; i < barrels; i++) {
10388 Vector laserPortOffset = [laserPortOffsets oo_vectorAtIndex:i];
10389
10390 last_shot_time = [UNIVERSE getTime];
10391
10392 ShipEntity* victim = [UNIVERSE firstShipHitByLaserFromShip:self inDirection:direction offset:laserPortOffset gettingRangeFound:&hit_at_range];
10393 [self setShipHitByLaser:victim];
10394
10395 shot = [OOLaserShotEntity laserFromShip:self direction:direction offset:laserPortOffset];
10396 if ([self isPlayer]) {
10397 [shotEntities addObject:shot];
10398 }
10399
10400 [shot setColor:laser_color];
10401 [shot setScanClass:CLASS_NO_DRAW];
10402 [shot setVelocity:vel];
10403
10404 if (victim != nil) {
10405 [self adjustMissedShots:-1];
10406 if ([self isPlayer]) {
10407 [PLAYER addRoleForAggression:victim];
10408 }
10409
10410 /* CRASH in [victim->sub_entities containsObject:subent] here (1.69, OS X/x86).
10411 Analysis: Crash is in _freedHandler called from CFEqual, indicating either a dead
10412 object in victim->sub_entities or dead victim->subentity_taking_damage. I suspect
10413 the latter. Probable solution: dying subentities must cause parent to clean up
10414 properly. This was probably obscured by the entity recycling scheme in the past.
10415 Fix: made subentity_taking_damage a weak reference accessed via a method.
10416 -- Ahruman 20070706, 20080304
10417 */
10418 ShipEntity* subent = [victim subEntityTakingDamage];
10419 if (subent != nil && [victim isFrangible]) {
10420 // do 1% bleed-through damage...
10421 [victim takeEnergyDamage:0.01 * effective_damage from:self becauseOf:self weaponIdentifier:weaponIdentifier];
10422 victim = subent;
10423 }
10424
10425 if (hit_at_range * hit_at_range < range_limit2) {
10426 [victim takeEnergyDamage:effective_damage from:self becauseOf:self weaponIdentifier:weaponIdentifier]; // a very palpable hit
10427
10428 [shot setRange:hit_at_range];
10430 HPVector flash_pos = HPvector_add([shot position], vectorToHPVector(vector_multiply_scalar(vd, hit_at_range)));
10431 [UNIVERSE addLaserHitEffectsAt:flash_pos against:victim damage:effective_damage color:laser_color];
10432 }
10433 } else {
10434 [self adjustMissedShots:+1];
10435
10436 // shot missed
10437 if (![self isCloaked]) {
10438 victim = [self primaryTarget];
10439 if ([victim isShip]) // it might not be - fixes crash bug
10440 {
10441
10442 /* player currently gets a bit of an advantage here if
10443 * they ambush without having their target actually
10444 * targeted. Though in those circumstances they
10445 * shouldn't be missing their first shot anyway. */
10446 if (dot_product(vector_forward_from_quaternion([shot orientation]), vector_normal([self vectorTo:victim])) > 0.995) {
10447 /* plausibly aimed at target. Allows reaction
10448 * before attacker actually hits. But we need to
10449 * be able to distinguish in AI from ATTACKED so
10450 * that ships in combat aren't bothered by
10451 * amateurs. So should only respond to
10452 * ATTACKER_MISSED if not already fighting */
10453 if ([self isPlayer]) {
10454 [PLAYER addRoleForAggression:victim];
10455 }
10456 [victim setPrimaryAggressor:self];
10457 [victim setFoundTarget:self];
10458 [victim reactToAIMessage:@"ATTACKER_MISSED" context:@"attacker narrowly misses"];
10459 [victim doScriptEvent:OOJSID("shipBeingAttackedUnsuccessfully") withArgument:self];
10460 }
10461 }
10462 }
10463 }
10464
10465 [UNIVERSE addEntity:shot];
10466 }
10467
10468 if ([self isPlayer]) {
10469 [(PlayerEntity*)self setLastShot:shotEntities];
10470 }
10471
10472 [self resetShotTime];
10473
10474 return YES;
10475}
OOWeaponFacing
Definition OOTypes.h:195
void setLastShot:(NSArray *shot)
OOTimeAbsolute last_shot_time
Definition ShipEntity.h:348
BOOL _multiplyWeapons
Definition ShipEntity.h:379

References _multiplyWeapons, adjustMissedShots:, dot_product(), flightSpeed, HPvector_add(), isCloaked, isFrangible, Entity::isPlayer, Entity::isShip, OOLaserShotEntity::laserFromShip:direction:offset:, laserPortOffset:, last_shot_time, nil, Entity::orientation, Entity::position, primaryTarget, resetShotTime, OOLightParticleEntity::setColor:, Entity::setScanClass:, setShipHitByLaser:, Entity::setVelocity:, subEntityTakingDamage, takeEnergyDamage:from:becauseOf:weaponIdentifier:, v_forward, vector_forward_from_quaternion(), vector_multiply_scalar(), vector_normal(), vectorToHPVector(), weapon_damage, and weaponRange.

Referenced by PlayerEntity::fireMainWeapon, and fireWeapon:direction:range:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fireMainWeapon:

- (BOOL) fireMainWeapon: (double) range

Definition at line 10018 of file ShipEntity.m.

10018 :(double)range
10019{
10020 // set the values from forward_weapon_type.
10021 // OXPs can override the default front laser energy damage.
10023 [self setWeaponDataFromType:forward_weapon_type];
10024
10025 // weapon damage override no longer effective
10026 // weapon_damage = weapon_damage_override;
10027
10028 BOOL result = [self fireWeapon:forward_weapon_type direction:WEAPON_FACING_FORWARD range:range];
10030 // need to check subentities to avoid AI oddities
10031 // will already have fired them by now, though
10032 NSEnumerator* subEnum = [self shipSubEntityEnumerator];
10033 ShipEntity* se = nil;
10034 OOWeaponType weapon_type = nil;
10035 BOOL hasTurrets = NO;
10036 while (isWeaponNone(weapon_type) && (se = [subEnum nextObject])) {
10037 weapon_type = se->forward_weapon_type;
10039 if (se->behaviour == BEHAVIOUR_TRACK_AS_TURRET) {
10040 hasTurrets = YES;
10041 }
10042 }
10043 if (isWeaponNone(weapon_type) && hasTurrets) { /* no forward weapon but has turrets, so set up range calculations accordingly
10044 note: this was hard-coded to 10000.0, although turrets have a notably
10045 shorter range. We are using a multiplier of 1.667 in order to not change
10046 something that already works, but probably it would be best to use
10047 TURRET_SHOT_RANGE * COMBAT_WEAPON_RANGE_FACTOR here
10048 */
10050 } else {
10051 [self setWeaponDataFromType:weapon_type];
10052 }
10053 }
10054 return result;
10055}
#define TURRET_SHOT_RANGE
Definition ShipEntity.h:84

References behaviour, currentWeaponFacing, fireWeapon:direction:range:, forward_weapon_temp, forward_weapon_type, isWeaponNone(), nil, setWeaponDataFromType:, shipSubEntityEnumerator, TURRET_SHOT_RANGE, WEAPON_FACING_FORWARD, weapon_temp, and weaponRange.

Referenced by behaviour_attack_fly_to_target:, behaviour_attack_mining_target:, behaviour_attack_sniper:, behaviour_evasive_action:, behaviour_flee_target:, behaviour_fly_to_target_six:, behaviour_running_defense:, and behaviour_scripted_ai:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fireMissile

- (ShipEntity *) fireMissile

Reimplemented in PlayerEntity.

Definition at line 10567 of file ShipEntity.m.

10568{
10569 return [self fireMissileWithIdentifier:nil andTarget:[self primaryTarget]];
10570}

References fireMissile, fireMissileWithIdentifier:andTarget:, and primaryTarget.

Referenced by considerFiringMissile:, coordinates, ShipEntity(PureAI)::fightOrFleeHostiles, fireMissile, ShipFireMissile(), and ShipFireMissile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fireMissileWithIdentifier:andTarget:

- (ShipEntity *) fireMissileWithIdentifier: (NSString*) identifier
andTarget: (Entity*) target 

Definition at line 10572 of file ShipEntity.m.

10572 :(NSString*)identifier andTarget:(Entity*)target
10573{
10574 // both players and NPCs!
10575 //
10576 ShipEntity* missile = nil;
10577 ShipEntity* target_ship = nil;
10578
10579 Vector vel;
10580 Vector start, v_eject;
10581
10582 if ([UNIVERSE getTime] < missile_launch_time)
10583 return nil;
10584
10585 start = [self missileLaunchPosition];
10586
10587 double throw_speed = 250.0f;
10588
10589 if ((missiles <= 0) || (target == nil) || ([target scanClass] == CLASS_NO_DRAW)) // no missile lock!
10590 return nil;
10591
10592 if ([target isShip]) {
10593 target_ship = (ShipEntity*)target;
10594 if ([target_ship isCloaked]) {
10595 return nil;
10596 }
10597 // missile fire requires being in scanner range
10599 return nil;
10600 }
10601 if (![self hasMilitaryScannerFilter] && [target_ship isJammingScanning]) {
10602 return nil;
10603 }
10604 }
10605
10606 unsigned i;
10607 if (identifier == nil) {
10608 // use a random missile from the list
10609 i = floor(randf() * (double)missiles);
10610 identifier = [missile_list[i] identifier];
10611 missile = [UNIVERSE newShipWithRole:identifier];
10612 if (EXPECT_NOT(missile == nil)) // invalid missile role.
10613 {
10614 // remove that invalid missile role from the missiles list.
10615 while (++i < missiles)
10616 missile_list[i - 1] = missile_list[i];
10617 missiles--;
10618 }
10619 } else
10620 missile = [UNIVERSE newShipWithRole:identifier];
10621
10622 if (EXPECT_NOT(missile == nil))
10623 return nil;
10624
10625 // By definition, the player will always have the specified missile.
10626 // What if the NPC didn't actually have the specified missile to begin with?
10627 if (!isPlayer && ![self removeExternalStore:[OOEquipmentType equipmentTypeWithIdentifier:identifier]]) {
10628 [missile release];
10629 return nil;
10630 }
10631
10632 double mcr = missile->collision_radius;
10633 v_eject = vector_normal(start);
10634 vel = kZeroVector; // starting velocity
10635
10636 // check if start is within bounding box...
10637 while ((start.x > boundingBox.min.x - mcr) && (start.x < boundingBox.max.x + mcr) && (start.y > boundingBox.min.y - mcr) && (start.y < boundingBox.max.y + mcr) && (start.z > boundingBox.min.z - mcr) && (start.z < boundingBox.max.z + mcr)) {
10638 start = vector_add(start, vector_multiply_scalar(v_eject, mcr));
10639 }
10640
10641 vel = vector_add(vel, vector_multiply_scalar(v_forward, flightSpeed + throw_speed));
10642
10643 Quaternion q1 = [self normalOrientation];
10645
10646 if (isPlayer)
10647 [missile setScanClass:CLASS_MISSILE];
10648
10649 // special cases
10650
10651 // We don't want real missiles in a group. Missiles could become escorts when the group is also used as escortGroup.
10652 if ([missile scanClass] == CLASS_THARGOID) {
10653 if ([self group] == nil)
10654 [self setGroup:[OOShipGroup groupWithName:@"thargoid group"]];
10655
10656 ShipEntity* thisGroupLeader = [_group leader];
10657
10658 if ([thisGroupLeader escortGroup] != _group) // avoid adding tharons to escort groups
10659 {
10660 [missile setGroup:[self group]];
10661 }
10662 }
10663
10664 // is this a submunition?
10665 if (![self isMissileFlagSet])
10666 [missile setOwner:self];
10667 else
10668 [missile setOwner:[self owner]];
10669
10670 // end special cases
10671
10672 [missile setPosition:origin];
10673 [missile addTarget:target];
10674 [missile setOrientation:q1];
10675 [missile setIsMissileFlag:YES];
10676 [missile setVelocity:vel];
10677 [missile setSpeed:150.0f];
10678 [missile setDistanceTravelled:0.0f];
10679 [missile resetShotTime];
10680 missile_launch_time = [UNIVERSE getTime] + missile_load_time; // set minimum launchtime for the next missile.
10681
10682 [UNIVERSE addEntity:missile]; // STATUS_IN_FLIGHT, AI state GLOBAL
10683 [missile release]; // release
10684
10685 // missile lives on after UNIVERSE addEntity
10686 if ([missile isMissile] && [target isShip]) {
10687 [self doScriptEvent:OOJSID("shipFiredMissile") withArgument:missile andArgument:target_ship];
10688 [target_ship setPrimaryAggressor:self];
10689 [target_ship doScriptEvent:OOJSID("shipAttackedWithMissile") withArgument:missile andArgument:self];
10690 [target_ship reactToAIMessage:@"INCOMING_MISSILE" context:@"someone's shooting at me!"];
10692 // parity between player &NPCs, only deactivate cloak for missiles
10693 [self deactivateCloakingDevice];
10694 }
10695 } else {
10696 [self doScriptEvent:OOJSID("shipReleasedEquipment") withArgument:missile];
10697 }
10698
10699 return missile;
10700}
void setDistanceTravelled:(GLfloat value)
Definition Entity.m:723
instancetype groupWithName:(NSString *name)
Definition OOShipGroup.m:94
BOOL isJammingScanning()
void setSpeed:(double amount)
OOTimeDelta missile_load_time
Definition ShipEntity.h:311
BOOL hasMilitaryScannerFilter()
OOTimeAbsolute missile_launch_time
Definition ShipEntity.h:312
BOOL isMissileFlagSet()
unsigned cloakPassive
void resetShotTime()
void setIsMissileFlag:(BOOL newValue)
voidpf uLong int origin
Definition ioapi.h:132

References _group, addTarget:, Entity::boundingBox, cloaking_device_active, cloakPassive, Entity::collision_radius, deactivateCloakingDevice, doScriptEvent:withArgument:, doScriptEvent:withArgument:andArgument:, escortGroup, EXPECT_NOT, flightSpeed, group, OOShipGroup::groupWithName:, hasMilitaryScannerFilter, HPmagnitude2(), HPvector_add(), HPvector_subtract(), OOEquipmentType::identifier, isCloaked, isJammingScanning, isMissile, isMissileFlagSet, Entity::isPlayer, Entity::isShip, kZeroVector, OOShipGroup::leader, missile_launch_time, missile_list, missile_load_time, missileLaunchPosition, missiles, nil, Entity::normalOrientation, Entity::owner, Entity::position, quaternion_rotate_vector(), randf(), reactToAIMessage:context:, resetShotTime, scanClass, scannerRange, Entity::setDistanceTravelled:, setGroup:, setIsMissileFlag:, Entity::setOrientation:, setOwner:, Entity::setPosition:, setPrimaryAggressor:, Entity::setScanClass:, setSpeed:, Entity::setVelocity:, UNIVERSE, v_forward, vector_add(), vector_multiply_scalar(), vector_normal(), vectorToHPVector(), Vector::x, Vector::y, and Vector::z.

Referenced by PlayerEntity::fireMissile, fireMissile, ShipFireMissile(), and ShipFireMissile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ firePortWeapon:

- (BOOL) firePortWeapon: (double) range

Definition at line 10066 of file ShipEntity.m.

10066 :(double)range
10067{
10068 // set the values from port_weapon_type.
10070 [self setWeaponDataFromType:port_weapon_type];
10071
10072 return [self fireWeapon:port_weapon_type direction:WEAPON_FACING_PORT range:range];
10073}

References currentWeaponFacing, fireWeapon:direction:range:, setWeaponDataFromType:, and WEAPON_FACING_PORT.

Referenced by behaviour_attack_broadside_target:leftside:, and behaviour_scripted_ai:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fireStarboardWeapon:

- (BOOL) fireStarboardWeapon: (double) range

Definition at line 10075 of file ShipEntity.m.

10075 :(double)range
10076{
10077 // set the values from starboard_weapon_type.
10079 [self setWeaponDataFromType:starboard_weapon_type];
10080
10081 return [self fireWeapon:starboard_weapon_type direction:WEAPON_FACING_STARBOARD range:range];
10082}

References currentWeaponFacing, fireWeapon:direction:range:, setWeaponDataFromType:, and WEAPON_FACING_STARBOARD.

Referenced by behaviour_attack_broadside_target:leftside:, and behaviour_scripted_ai:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fireSubentityLaserShot:

- (BOOL) fireSubentityLaserShot: (double) range

Definition at line 10171 of file ShipEntity.m.

10171 :(double)range
10172{
10173 [self setShipHitByLaser:nil];
10174
10176 return NO;
10177 [self setWeaponDataFromType:forward_weapon_type];
10178
10179 ShipEntity* parent = [self owner];
10180 NSAssert([parent isShipWithSubEntityShip:self], @"-fireSubentityLaserShot: called on ship which is not a subentity.");
10181
10182 // subentity lasers still draw power from the main entity
10183 if ([parent energy] <= weapon_energy_use)
10184 return NO;
10185 if ([self shotTime] < weapon_recharge_rate)
10186 return NO;
10188 return NO;
10189 if (range > weaponRange)
10190 return NO;
10191
10193 [parent setEnergy:([parent energy] - weapon_energy_use)];
10194
10195 GLfloat hitAtRange = weaponRange;
10197 ShipEntity* victim = [UNIVERSE firstShipHitByLaserFromShip:self inDirection:direction offset:kZeroVector gettingRangeFound:&hitAtRange];
10198 [self setShipHitByLaser:victim];
10199
10200 OOLaserShotEntity* shot = [OOLaserShotEntity laserFromShip:self direction:direction offset:kZeroVector];
10201 [shot setColor:laser_color];
10202 [shot setScanClass:CLASS_NO_DRAW];
10203
10204 if (victim != nil) {
10205 [self adjustMissedShots:-1];
10206
10207 if ([self isPlayer]) {
10208 [PLAYER addRoleForAggression:victim];
10209 }
10210
10211 ShipEntity* subent = [victim subEntityTakingDamage];
10212 if (subent != nil && [victim isFrangible]) {
10213 // do 1% bleed-through damage...
10214 [victim takeEnergyDamage:0.01 * weapon_damage from:self becauseOf:parent weaponIdentifier:[[self weaponTypeForFacing:WEAPON_FACING_FORWARD strict:YES] identifier]];
10215 victim = subent;
10216 }
10217
10218 if (hitAtRange < weaponRange) {
10219 [victim takeEnergyDamage:weapon_damage from:self becauseOf:parent weaponIdentifier:[[self weaponTypeForFacing:WEAPON_FACING_FORWARD strict:YES] identifier]]; // a very palpable hit
10220
10221 [shot setRange:hitAtRange];
10223 HPVector flash_pos = HPvector_add([shot position], vectorToHPVector(vector_multiply_scalar(vd, hitAtRange)));
10224 [UNIVERSE addLaserHitEffectsAt:flash_pos against:victim damage:weapon_damage color:laser_color];
10225 }
10226 } else {
10227 [self adjustMissedShots:+1];
10228
10229 // see ATTACKER_MISSED section of main entity laser routine
10230 if (![parent isCloaked]) {
10231 victim = [parent primaryTarget];
10232
10233 Vector shotDirection = vector_forward_from_quaternion([shot orientation]);
10234 Vector victimDirection = vector_normal(HPVectorToVector(HPvector_subtract([victim position], [parent position])));
10235 if (dot_product(shotDirection, victimDirection) > 0.995) // Within 84.26 degrees
10236 {
10237 if ([self isPlayer]) {
10238 [PLAYER addRoleForAggression:victim];
10239 }
10240 [victim setPrimaryAggressor:parent];
10241 [victim setFoundTarget:parent];
10242 [victim reactToAIMessage:@"ATTACKER_MISSED" context:@"attacker narrowly misses"];
10243 [victim doScriptEvent:OOJSID("shipBeingAttackedUnsuccessfully") withArgument:parent];
10244 }
10245 }
10246 }
10247
10248 [UNIVERSE addEntity:shot];
10249 [self resetShotTime];
10250
10251 return YES;
10252}
#define NPC_MAX_WEAPON_TEMP
Definition ShipEntity.h:116
#define WEAPON_COOLING_CUTOUT
Definition ShipEntity.h:117
GLfloat weapon_energy_use
Definition ShipEntity.h:303
GLfloat weapon_shot_temperature
Definition ShipEntity.h:303
float weapon_recharge_rate
Definition ShipEntity.h:345

References adjustMissedShots:, doScriptEvent:withArgument:, dot_product(), Entity::energy, forward_weapon_temp, forward_weapon_type, HPvector_add(), HPvector_subtract(), HPVectorToVector(), OOEquipmentType::identifier, isCloaked, isFrangible, Entity::isPlayer, isWeaponNone(), OOLaserShotEntity::laserFromShip:direction:offset:, nil, NPC_MAX_WEAPON_TEMP, Entity::orientation, Entity::owner, Entity::position, primaryTarget, reactToAIMessage:context:, resetShotTime, OOLightParticleEntity::setColor:, Entity::setEnergy:, setFoundTarget:, setPrimaryAggressor:, Entity::setScanClass:, setShipHitByLaser:, setWeaponDataFromType:, shotTime, subEntityTakingDamage, takeEnergyDamage:from:becauseOf:weaponIdentifier:, vector_forward_from_quaternion(), vector_multiply_scalar(), vector_normal(), vectorToHPVector(), WEAPON_COOLING_CUTOUT, weapon_energy_use, WEAPON_FACING_FORWARD, weapon_recharge_rate, weapon_shot_temperature, weaponRange, and weaponTypeForFacing:strict:.

Here is the call graph for this function:

◆ fireTurretCannon:

- (BOOL) fireTurretCannon: (double) range

Definition at line 10094 of file ShipEntity.m.

10094 :(double)range
10095{
10096 if ([self shotTime] < weapon_recharge_rate)
10097 return NO;
10098 if (range > weaponRange * 1.01) // 1% more than max range - open up just slightly early
10099 return NO;
10100 ShipEntity* root = [self rootShipEntity];
10101 if ([root isPlayer] && ![PLAYER weaponsOnline])
10102 return NO;
10103
10104 if ([root isCloaked] && [root cloakPassive]) {
10105 // can't fire turrets while cloaked
10106 return NO;
10107 }
10108
10109 Vector vel;
10110 HPVector origin = [self position];
10111
10112 Entity* last = nil;
10113 Entity* father = [self parentEntity];
10114 OOMatrix r_mat;
10115
10117 // adjust velocity and position vectors to absolute coordinates
10118 while ((father) && (father != last) && (father != NO_TARGET)) {
10119 r_mat = [father drawRotationMatrix];
10121 vel = OOVectorMultiplyMatrix(vel, r_mat);
10122 last = father;
10123 if (![last isSubEntity])
10124 break;
10125 father = [father owner];
10126 }
10127
10128 origin = HPvector_add(origin, vectorToHPVector(vector_multiply_scalar(vel, collision_radius + 0.5))); // Start just outside collision sphere
10129 vel = vector_multiply_scalar(vel, TURRET_SHOT_SPEED); // Shot velocity
10130
10131 OOPlasmaShotEntity* shot = [[OOPlasmaShotEntity alloc] initWithPosition:origin
10132 velocity:vel
10133 energy:weapon_damage
10134 duration:weaponRange / TURRET_SHOT_SPEED
10135 color:laser_color];
10136
10137 [shot autorelease];
10138 [UNIVERSE addEntity:shot];
10139 [shot setOwner:[self rootShipEntity]]; // has to be done AFTER adding shot to the UNIVERSE
10140
10141 [self resetShotTime];
10142 return YES;
10143}
HPVector OOHPVectorMultiplyMatrix(HPVector v, OOMatrix m) CONST_FUNC
Definition OOMatrix.m:137

References cloakPassive, Entity::collision_radius, Entity::drawRotationMatrix, HPvector_add(), isCloaked, Entity::isPlayer, Entity::isSubEntity, nil, NO_TARGET, OOHPVectorMultiplyMatrix(), OOVectorMultiplyMatrix(), Entity::orientation, Entity::owner, Entity::parentEntity, PLAYER, Entity::position, resetShotTime, Entity::rootShipEntity, Entity::setOwner:, shotTime, TURRET_SHOT_SPEED, vector_forward_from_quaternion(), vector_multiply_scalar(), vectorToHPVector(), weapon_recharge_rate, and weaponRange.

Referenced by behaviour_track_as_turret:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fireWeapon:direction:range:

- (BOOL) fireWeapon: (OOWeaponType) weapon_type
direction: (OOWeaponFacing) direction
range: (double) range 
implementation

Definition at line 9921 of file ShipEntity.m.

9921 :(OOWeaponType)weapon_type direction:(OOWeaponFacing)direction range:(double)range
9922{
9923 weapon_temp = 0.0;
9924 switch (direction) {
9927 break;
9928
9929 case WEAPON_FACING_AFT:
9931 break;
9932
9933 case WEAPON_FACING_PORT:
9935 break;
9936
9939 break;
9940
9941 case WEAPON_FACING_NONE:
9942 break;
9943 }
9945 return NO;
9946
9947 NSUInteger multiplier = 1;
9948 if (_multiplyWeapons) {
9949 // multiple fitted
9950 multiplier = [[self laserPortOffset:direction] count];
9951 }
9952
9953 if (energy <= weapon_energy_use * multiplier)
9954 return NO;
9955 if ([self shotTime] < weapon_recharge_rate)
9956 return NO;
9957 if (![weapon_type isTurretLaser]) { // thargoid laser may just pick secondary target in this case
9958 if (range > randf() * weaponRange * (accuracy + 7.5))
9959 return NO;
9960 if (range > weaponRange)
9961 return NO;
9962 }
9963 if (![self onTarget:direction withWeapon:weapon_type])
9964 return NO;
9965
9966 BOOL fired = NO;
9967 if (!isWeaponNone(weapon_type)) {
9968 if ([weapon_type isTurretLaser]) {
9969 [self fireDirectLaserShot:range];
9970 fired = YES;
9971 } else {
9972 [self fireLaserShotInDirection:direction weaponIdentifier:[weapon_type identifier]];
9973 fired = YES;
9974 }
9975 }
9976
9977 if (fired) {
9978 energy -= weapon_energy_use * multiplier;
9979 switch (direction) {
9982 break;
9983
9984 case WEAPON_FACING_AFT:
9986 break;
9987
9988 case WEAPON_FACING_PORT:
9990 break;
9991
9994 break;
9995
9996 case WEAPON_FACING_NONE:
9997 break;
9998 }
9999 }
10000
10001 if (direction == WEAPON_FACING_FORWARD) {
10002 // can we fire lasers from our subentities?
10003 ShipEntity* se = nil;
10004 foreach (se, [self shipSubEntityEnumerator]) {
10005 if ([se fireSubentityLaserShot:range]) {
10006 fired = YES;
10007 }
10008 }
10009 }
10010
10011 if (fired && cloaking_device_active && cloakPassive) {
10012 [self deactivateCloakingDevice];
10013 }
10014
10015 return fired;
10016}
@ WEAPON_FACING_NONE
Definition OOTypes.h:201

References _multiplyWeapons, accuracy, aft_weapon_temp, cloaking_device_active, cloakPassive, deactivateCloakingDevice, Entity::energy, fireDirectLaserShot:, fireLaserShotInDirection:weaponIdentifier:, forward_weapon_temp, OOEquipmentType::identifier, isWeaponNone(), laserPortOffset:, nil, NPC_MAX_WEAPON_TEMP, port_weapon_temp, randf(), shipSubEntityEnumerator, shotTime, starboard_weapon_temp, WEAPON_COOLING_CUTOUT, weapon_energy_use, WEAPON_FACING_AFT, WEAPON_FACING_FORWARD, WEAPON_FACING_NONE, WEAPON_FACING_PORT, WEAPON_FACING_STARBOARD, weapon_recharge_rate, weapon_shot_temperature, weapon_temp, and weaponRange.

Referenced by fireAftWeapon:, fireMainWeapon:, firePortWeapon:, and fireStarboardWeapon:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ flasherEnumerator

- (NSEnumerator *) flasherEnumerator

Definition at line 1224 of file ShipEntity.m.

1225{
1226 return [[self subEntities] objectEnumeratorFilteredWithSelector:@selector(isFlasher)];
1227}

References flasherEnumerator, and subEntities.

Referenced by flasherEnumerator, ShipGetProperty(), ShipGetProperty(), subEntities, switchLightsOff, and switchLightsOn.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ flightPitch

- (GLfloat) flightPitch

References flightPitch.

◆ flightRoll

- (GLfloat) flightRoll

References flightRoll.

◆ flightSpeed

- (GLfloat) flightSpeed

References flightSpeed, and maxFlightPitch.

Here is the call graph for this function:

◆ flightYaw

- (GLfloat) flightYaw

References flightYaw.

◆ forceAegisCheck

- (void) forceAegisCheck

Definition at line 6798 of file ShipEntity.m.

6799{
6800 _nextAegisCheck = -1.0f;
6801}
double _nextAegisCheck
Definition ShipEntity.h:476

References _nextAegisCheck, and forceAegisCheck.

Referenced by EntitySetProperty(), EntitySetProperty(), forceAegisCheck, and reportAIMessages.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ forwardVector

- (Vector) forwardVector

Definition at line 1164 of file ShipEntity.m.

1165{
1166 return v_forward;
1167}

References forwardVector, and v_forward.

Referenced by behaviour_land_on_planet:, forwardVector, PlayerEntity::leaveWitchspace, missileTrackPrimaryTarget:, ShipEntity(PureAI)::setPlanetPatrolCoordinates, DockEntity::shipIsInDockingCorridor:, totalBoundingBox, and OOExhaustPlumeEntity::update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ forwardWeaponOffset

- (NSArray *) forwardWeaponOffset

References forwardWeaponOffset.

◆ foundTarget

- (Entity *) foundTarget

Definition at line 8548 of file ShipEntity.m.

8549{
8550 Entity* result = [_foundTarget weakRefUnderlyingObject];
8551 if (result == nil || ![self isValidTarget:result]) {
8553 return nil;
8554 }
8555 return result;
8556}

References _foundTarget, DESTROY, foundTarget, nil, and OOWeakReference::weakRefUnderlyingObject.

Referenced by ShipEntity(OOAIPrivate)::acceptDistressMessageFrom:, ShipEntity(PureAI)::addFoundTargetAsDefenseTarget, PlayerEntity::doBookkeeping:, ShipEntity(PureAI)::fightOrFleeHostiles, foundTarget, maxFlightSpeed, ShipEntity(PureAI)::setTargetToFoundTarget, ShipGetProperty(), ShipGetProperty(), PlayerEntity(Scripting)::targetNearestHostile, and PlayerEntity(Scripting)::targetNearestIncomingMissile.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ frustration

- (double) frustration

References frustration.

◆ frustumRadius

- (GLfloat) frustumRadius

Reimplemented from Entity.

Definition at line 822 of file ShipEntity.m.

823{
824 OOScalar exhaust_length = 0;
825 NSEnumerator* exEnum = nil;
826 OOExhaustPlumeEntity* exEnt = nil;
827 for (exEnum = [self exhaustEnumerator]; (exEnt = [exEnum nextObject]);) {
828 if ([exEnt findCollisionRadius] > exhaust_length) {
829 exhaust_length = [exEnt findCollisionRadius];
830 }
831 }
832 return _profileRadius + exhaust_length;
833}
GLfloat OOScalar
Definition OOMaths.h:49
NSEnumerator * exhaustEnumerator()

References _profileRadius, exhaustEnumerator, OOEntityWithDrawable::findCollisionRadius, OOExhaustPlumeEntity::findCollisionRadius, frustumRadius, and nil.

Referenced by OOEntityWithDrawable::drawImmediate:translucent:, frustumRadius, and octree.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fuel

References fuel, fuelCapacity, and fuelChargeRate.

Here is the call graph for this function:

◆ fuelCapacity

- (OOFuelQuantity) fuelCapacity

Definition at line 7005 of file ShipEntity.m.

7006{
7007 // FIXME: shipdata.plist can allow greater fuel quantities (without extending hyperspace range). Need some consistency here.
7008 return PLAYER_MAX_FUEL;
7009}
#define PLAYER_MAX_FUEL

References fuelCapacity, and PLAYER_MAX_FUEL.

Referenced by PlayerEntity(Scripting)::awardEquipment:, PlayerEntity::dialFuel, PlayerEntity::doBookkeeping:, equipmentValidToAdd:whileLoading:inContext:, fuel, fuelCapacity, PlayerEntity(Contracts)::newShipCommonSetup:yardInfo:baseInfo:, PlayerEntity(Scripting)::sendAllShipsAway, setFuel:, PlayerEntity(OOPrivate)::tryBuyingItem:, and update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fuelChargeRate

- (GLfloat) fuelChargeRate

Reimplemented in PlayerEntity.

Definition at line 7011 of file ShipEntity.m.

7012{
7013 GLfloat rate = 1.0; // Standard (& strict play) charge rate.
7014
7015#if MASS_DEPENDENT_FUEL_PRICES
7016
7017 if (EXPECT(PLAYER != nil && mass > 0 && mass != [PLAYER baseMass])) {
7018 rate = calcFuelChargeRate(mass);
7019 }
7020
7021 OOLog(@"fuelPrices", @"\"%@\" fuel charge rate: %.2f (mass ratio: %.2f/%.2f)", [self shipDataKey], rate, mass, [PLAYER baseMass]);
7022#endif
7023
7024 return rate;
7025}
static GLfloat calcFuelChargeRate(GLfloat myMass)
Definition ShipEntity.m:104
NSString * shipDataKey()

References calcFuelChargeRate(), EXPECT, fuelChargeRate, Entity::mass, nil, OOLog, PLAYER, and shipDataKey.

Referenced by fuel, PlayerEntity::fuelChargeRate, fuelChargeRate, and update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ generateMissileEquipmentTypeFrom:

- (OOEquipmentType *) generateMissileEquipmentTypeFrom: (NSString*) role
implementation

Provided by category ShipEntity(Private).

Definition at line 2971 of file ShipEntity.m.

2971 :(NSString*)role
2972{
2973 /* The generated missile equipment type provides for backward compatibility with pre-1.74 OXPs missile_roles
2974 and follows this template:
2975
2976 //NPC equipment, incompatible with player ship. Not buyable because of its TL.
2977 (
2978 100, 100000, "Missile",
2979 "EQ_X_MISSILE",
2980 "Unidentified missile type.",
2981 {
2982 is_external_store = true;
2983 }
2984 )
2985 */
2986 NSArray* itemInfo = [NSArray arrayWithObjects:@"100", @"100000", @"Missile", role, @"Unidentified missile type.",
2987 [NSDictionary dictionaryWithObjectsAndKeys:@"true", @"is_external_store", nil], nil];
2988
2991}
void addEquipmentWithInfo:(NSArray *itemInfo)

References OOEquipmentType::addEquipmentWithInfo:, and OOEquipmentType::equipmentTypeWithIdentifier:.

Referenced by verifiedMissileTypeFromRole:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getAI

◆ getDemoStartTime

- (OOTimeAbsolute) getDemoStartTime
implementation

Definition at line 12769 of file ShipEntity.m.

12770{
12771 return demoStartTime;
12772}
OOTimeAbsolute demoStartTime
Definition ShipEntity.h:481

References demoStartTime, and getDemoStartTime.

Referenced by getDemoStartTime.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getDestroyedBy:damageType:

- (void) getDestroyedBy: (Entity*) whom
damageType: (OOShipDamageType) type 

Reimplemented in PlayerEntity.

Definition at line 7777 of file ShipEntity.m.

7777 :(Entity*)whom damageType:(OOShipDamageType)type
7778{
7779 [self noteKilledBy:whom damageType:type];
7780 [self abortDocking];
7781 [self becomeExplosion];
7782}
OOShipDamageType
Definition ShipEntity.h:175

References abortDocking, becomeExplosion, and noteKilledBy:damageType:.

Referenced by ShipEntity(PureAI)::explodeSelf, takeEnergyDamage:from:becauseOf:weaponIdentifier:, takeHeatDamage:, and takeScrapeDamage:from:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getJSClass:andPrototype:

- (void) getJSClass: (JSClass**) outClass
andPrototype: (JSObject**) outPrototype 
implementation

Reimplemented from Entity.

Reimplemented in DockEntity, and StationEntity.

Provided by category ShipEntity(OOJavaScriptExtensions).

Definition at line 110 of file EntityOOJavaScriptExtensions.m.

110 :(JSClass**)outClass andPrototype:(JSObject**)outPrototype
111{
112 *outClass = JSShipClass();
113 *outPrototype = JSShipPrototype();
114}
JSObject * JSShipPrototype(void)
Definition OOJSShip.m:587
JSClass * JSShipClass(void)
Definition OOJSShip.m:582

◆ getTractoredBy:

- (void) getTractoredBy: (ShipEntity*) other

Definition at line 11220 of file ShipEntity.m.

11220 :(ShipEntity*)other
11221{
11222 if ([self status] == STATUS_BEING_SCOOPED)
11223 return; // both cargo and ship call this. Act only once.
11224 desired_speed = 0.0;
11225 [self setAITo:@"nullAI.plist"]; // prevent AI from changing status or behaviour.
11226 behaviour = BEHAVIOUR_TRACTORED;
11227 [self setStatus:STATUS_BEING_SCOOPED];
11228 [self addTarget:other];
11229 [self setOwner:other];
11230 // should we make this an all rather than first 16? - CIM
11231 // made it ignore other cargopods and similar at least. - CIM 28/7/2013
11232 [self checkScannerIgnoringUnpowered];
11233 unsigned i;
11234 ShipEntity* scooper;
11235 for (i = 0; i < n_scanned_ships; i++) {
11236 scooper = (ShipEntity*)scanned_ships[i];
11237 // 'Dibs!' - Stops other ships from trying to scoop/shoot this cargo.
11238 if (other != scooper && (id)self == [scooper primaryTarget]) {
11239 [scooper noteLostTarget];
11240 }
11241 }
11242}
void noteLostTarget()

References addTarget:, behaviour, checkScannerIgnoringUnpowered, desired_speed, n_scanned_ships, noteLostTarget, primaryTarget, scanned_ships, setAITo:, setOwner:, setStatus:, and Entity::status.

Here is the call graph for this function:

◆ getWeaponOffsetFrom:withKey:inMode:

- (NSArray *) getWeaponOffsetFrom: (NSDictionary*) dict
withKey: (NSString*) key
inMode: (NSString*) mode 

Definition at line 1797 of file ShipEntity.m.

1797 :(NSDictionary*)dict withKey:(NSString*)key inMode:(NSString*)mode
1798{
1799 Vector offset;
1800 if ([mode isEqualToString:@"single"]) {
1801 offset = vector_multiply_scalar([dict oo_vectorForKey:key defaultValue:kZeroVector], _scaleFactor);
1802 return [NSArray arrayWithObject:MAKE_VECTOR_ARRAY(offset)];
1803 } else {
1804 NSArray* offsets = [dict oo_arrayForKey:key defaultValue:nil];
1805 if (offsets == nil) {
1807 return [NSArray arrayWithObject:MAKE_VECTOR_ARRAY(offset)];
1808 }
1809 NSMutableArray* output = [NSMutableArray arrayWithCapacity:[offsets count]];
1810 NSUInteger i;
1811 for (i = 0; i < [offsets count]; i++) {
1812 offset = vector_multiply_scalar([offsets oo_vectorAtIndex:i defaultValue:kZeroVector], _scaleFactor);
1813 [output addObject:MAKE_VECTOR_ARRAY(offset)];
1814 }
1815 return [NSArray arrayWithArray:output];
1816 }
1817}
GLfloat _scaleFactor
Definition ShipEntity.h:377
const char int mode
Definition ioapi.h:125

References _scaleFactor, kZeroVector, nil, and vector_multiply_scalar().

Here is the call graph for this function:

◆ getWitchspaceEntryCoordinates

- (void) getWitchspaceEntryCoordinates
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1037 of file ShipEntityAI.m.

1038{
1039 /*- calculates coordinates from the nearest station it can find, or just fly 10s forward -*/
1040 if (!UNIVERSE) {
1041 Vector vr = vector_multiply_scalar(v_forward, maxFlightSpeed * 10.0); // 10 second flying away
1043 return;
1044 }
1045 //
1046 // find the nearest station...
1047 //
1048 // we don't use "checkScanner" because we must rely on finding a present station.
1049 //
1050 StationEntity* station = nil;
1051 station = [UNIVERSE nearestShipMatchingPredicate:IsStationPredicate
1052 parameter:nil
1053 relativeToEntity:self];
1054
1055 if (station && HPdistance2([station position], position) < SCANNER_MAX_RANGE2) // there is a station in range.
1056 {
1057 Vector vr = vector_multiply_scalar([station rightVector], 10000); // 10km from station
1059 } else {
1060 Vector vr = vector_multiply_scalar(v_forward, maxFlightSpeed * 10.0); // 10 second flying away
1062 }
1063}
HPVector coordinates
Vector rightVector()

◆ group

◆ groupAttackTarget

- (void) groupAttackTarget

Provided by category ShipEntity(AI).

Definition at line 315 of file ShipEntityAI.m.

316{
317 ShipEntity *target = nil, *ship = nil;
318
319 target = [self primaryTarget];
320
321 if (target == nil)
322 return;
323
324 if ([self group] == nil) // ship is alone!
325 {
326 [self setFoundTarget:target];
327 [shipAI reactToMessage:@"GROUP_ATTACK_TARGET" context:@"groupAttackTarget"];
328 [self doScriptEvent:OOJSID("helpRequestReceived") withArgument:self andArgument:target];
329 return;
330 }
331
332 foreach (ship, [[self group] mutationSafeEnumerator]) {
333 [ship setFoundTarget:target];
334 [ship reactToAIMessage:@"GROUP_ATTACK_TARGET" context:@"groupAttackTarget"];
335 [ship doScriptEvent:OOJSID("helpRequestReceived") withArgument:self andArgument:target];
336
337 if ([ship escortGroup] != [ship group] && [[ship escortGroup] count] > 1) // Ship has a seperate escort group.
338 {
339 ShipEntity* escort = nil;
340 NSArray* escortMembers = [[ship escortGroup] memberArrayExcludingLeader];
341 foreach (escort, escortMembers) {
342 [escort setFoundTarget:target];
343 [escort reactToAIMessage:@"GROUP_ATTACK_TARGET" context:@"groupAttackTarget"];
344 [escort doScriptEvent:OOJSID("helpRequestReceived") withArgument:self andArgument:target];
345 }
346 }
347 }
348}

◆ hasAllEquipment:

- (BOOL) hasAllEquipment: (id) equipmentKeys

Definition at line 2859 of file ShipEntity.m.

2859 :(id)equipmentKeys
2860{
2861 return [self hasAllEquipment:equipmentKeys includeWeapons:NO whileLoading:NO];
2862}

References hasAllEquipment:includeWeapons:whileLoading:.

Here is the call graph for this function:

◆ hasAllEquipment:includeWeapons:whileLoading:

- (BOOL) hasAllEquipment: (id) equipmentKeys
includeWeapons: (BOOL) includeWeapons
whileLoading: (BOOL) loading 

Definition at line 2837 of file ShipEntity.m.

2837 :(id)equipmentKeys includeWeapons:(BOOL)includeWeapons whileLoading:(BOOL)loading
2838{
2839 NSEnumerator* keyEnum = nil;
2840 id key = nil;
2841
2842 if (_equipment == nil)
2843 return NO;
2844
2845 // Make sure it's an array or set, using a single-object set if it's a string.
2846 if ([equipmentKeys isKindOfClass:[NSString class]])
2847 equipmentKeys = [NSArray arrayWithObject:equipmentKeys];
2848 else if (![equipmentKeys isKindOfClass:[NSArray class]] && ![equipmentKeys isKindOfClass:[NSSet class]])
2849 return NO;
2850
2851 for (keyEnum = [equipmentKeys objectEnumerator]; (key = [keyEnum nextObject]);) {
2852 if (![self hasOneEquipmentItem:key includeWeapons:includeWeapons whileLoading:loading])
2853 return NO;
2854 }
2855
2856 return YES;
2857}

References _equipment, and nil.

Referenced by hasAllEquipment:.

Here is the caller graph for this function:

◆ hasAutoAI

- (BOOL) hasAutoAI

Definition at line 6922 of file ShipEntity.m.

6923{
6924 return [[self shipInfoDictionary] oo_fuzzyBooleanForKey:@"auto_ai" defaultValue:YES];
6925}

References hasAutoAI, and shipInfoDictionary.

Referenced by hasAutoAI.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasAutoCloak

- (BOOL) hasAutoCloak

Definition at line 5773 of file ShipEntity.m.

5774{
5775 return cloakAutomatic;
5776}

References cloakAutomatic, and hasAutoCloak.

Referenced by hasAutoCloak, and reactionTime.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasAutoWeapons

- (BOOL) hasAutoWeapons

Definition at line 6932 of file ShipEntity.m.

6933{
6934 return [[self shipInfoDictionary] oo_fuzzyBooleanForKey:@"auto_weapons" defaultValue:NO];
6935}

References hasAutoWeapons, and shipInfoDictionary.

Referenced by hasAutoWeapons, selectMissile, and starboardWeaponOffset.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasCargoScoop

- (BOOL) hasCargoScoop

Definition at line 3543 of file ShipEntity.m.

3544{
3545 return [self hasEquipmentItemProviding:@"EQ_CARGO_SCOOPS"];
3546}

References hasCargoScoop, and hasEquipmentItemProviding:.

Referenced by canScoop:, hasCargoScoop, and isFrangible.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasCascadeMine

- (BOOL) hasCascadeMine

Definition at line 3605 of file ShipEntity.m.

3606{
3607 /* TODO: this could be providing since theoretically OXP
3608 * deployable mines could also do cascade effects, but there are
3609 * probably better ways to manage OXP pylon AI */
3610 return [self hasEquipmentItem:@"EQ_QC_MINE" includeWeapons:YES whileLoading:NO];
3611}

References hasCascadeMine, and hasEquipmentItem:includeWeapons:whileLoading:.

Referenced by behaviour_flee_target:, hasCascadeMine, isFrangible, and launchCascadeMine.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasCloakingDevice

- (BOOL) hasCloakingDevice

Definition at line 3553 of file ShipEntity.m.

3554{
3555 /* TODO: Checks above stop this being 'providing'. */
3556 return [self hasEquipmentItem:@"EQ_CLOAKING_DEVICE"];
3557}

References hasCloakingDevice, and hasEquipmentItem:.

Referenced by PlayerEntity::activateCloakingDevice, activateCloakingDevice, PlayerEntity::deactivateCloakingDevice, deactivateCloakingDevice, PlayerEntity::doBookkeeping:, hasCloakingDevice, isFrangible, and update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasDockingComputer

- (BOOL) hasDockingComputer

Definition at line 3618 of file ShipEntity.m.

3619{
3620 return [self hasEquipmentItemProviding:@"EQ_DOCK_COMP"];
3621}

References hasDockingComputer, and hasEquipmentItemProviding:.

Referenced by hasDockingComputer, isFrangible, and removeEquipmentItem:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasECM

- (BOOL) hasECM

Definition at line 3548 of file ShipEntity.m.

3549{
3550 return [self hasEquipmentItemProviding:@"EQ_ECM"];
3551}

References hasECM, and hasEquipmentItemProviding:.

Referenced by fireECM, hasECM, and isFrangible.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasEquipmentItem:

- (BOOL) hasEquipmentItem: (id) equipmentKeys

Definition at line 2796 of file ShipEntity.m.

2796 :(id)equipmentKeys
2797{
2798 return [self hasEquipmentItem:equipmentKeys includeWeapons:NO whileLoading:NO];
2799}

References hasEquipmentItem:includeWeapons:whileLoading:.

Referenced by PlayerEntity::buySelectedItem, equipmentListForScripting, hasCloakingDevice, hasExpandedCargoBay, hasMilitaryShieldEnhancer, hasShieldBooster, ShipAwardEquipment(), ShipAwardEquipment(), ShipSetEquipmentStatus(), ShipSetEquipmentStatus(), and PlayerEntity(Scripting)::testForEquipment:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasEquipmentItem:includeWeapons:whileLoading:

- (BOOL) hasEquipmentItem: (id) equipmentKeys
includeWeapons: (BOOL) includeWeapons
whileLoading: (BOOL) loading 

Definition at line 2778 of file ShipEntity.m.

2778 :(id)equipmentKeys includeWeapons:(BOOL)includeWeapons whileLoading:(BOOL)loading
2779{
2780 // this method is also used internally to find out if an equipped item is undamaged.
2781 if ([equipmentKeys isKindOfClass:[NSString class]]) {
2782 return [self hasOneEquipmentItem:equipmentKeys includeWeapons:includeWeapons whileLoading:loading];
2783 } else {
2784 NSParameterAssert([equipmentKeys isKindOfClass:[NSArray class]] || [equipmentKeys isKindOfClass:[NSSet class]]);
2785
2786 id key = nil;
2787 foreach (key, equipmentKeys) {
2788 if ([self hasOneEquipmentItem:key includeWeapons:includeWeapons whileLoading:loading])
2789 return YES;
2790 }
2791 }
2792
2793 return NO;
2794}

References hasOneEquipmentItem:includeWeapons:whileLoading:, and nil.

Referenced by hasCascadeMine, and hasEquipmentItem:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasEquipmentItemProviding:

- (BOOL) hasEquipmentItemProviding: (NSString*) equipmentType

Definition at line 2803 of file ShipEntity.m.

2803 :(NSString*)equipmentType
2804{
2805 NSString* key = nil;
2806 foreach (key, _equipment) {
2807 if ([key isEqualToString:equipmentType]) {
2808 // equipment always provides itself
2809 return YES;
2810 } else {
2811 OOEquipmentType* et = [OOEquipmentType equipmentTypeWithIdentifier:key];
2812 if (et != nil && [et provides:equipmentType]) {
2813 return YES;
2814 }
2815 }
2816 }
2817 return NO;
2818}

References _equipment, OOEquipmentType::equipmentTypeWithIdentifier:, and nil.

Referenced by hasCargoScoop, hasDockingComputer, hasECM, hasEscapePod, hasFuelInjection, hasFuelScoop, hasGalacticHyperdrive, hasHeatShield, hasMilitaryJammer, hasMilitaryScannerFilter, hasScoop, and ProxyPlayerEntity::initWithKey:definition:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasEscapePod

- (BOOL) hasEscapePod

Definition at line 3613 of file ShipEntity.m.

3614{
3615 return [self hasEquipmentItemProviding:@"EQ_ESCAPE_POD"];
3616}

References hasEquipmentItemProviding:, and hasEscapePod.

Referenced by abandonShip, hasEscapePod, isFrangible, and takeEnergyDamage:from:becauseOf:weaponIdentifier:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasEscorts

- (BOOL) hasEscorts

Definition at line 6037 of file ShipEntity.m.

6038{
6039 if (_escortGroup == nil)
6040 return NO;
6041 return [_escortGroup count] > 1; // If only one member, it's self.
6042}

References _escortGroup, OOShipGroup::count, hasEscorts, and nil.

Referenced by abandonShip, dockEscorts, hasEscorts, DockEntity::launchShip:, messageTime, and update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasExpandedCargoBay

- (BOOL) hasExpandedCargoBay

Definition at line 3577 of file ShipEntity.m.

3578{
3579 /* Not 'providing' - controlled through scripts */
3580 return [self hasEquipmentItem:@"EQ_CARGO_BAY"];
3581}

References hasEquipmentItem:, and hasExpandedCargoBay.

Referenced by hasExpandedCargoBay, isFrangible, and PlayerEntity::setCommanderDataFromDictionary:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasFuelInjection

- (BOOL) hasFuelInjection

Definition at line 3600 of file ShipEntity.m.

3601{
3602 return [self hasEquipmentItemProviding:@"EQ_FUEL_INJECTION"];
3603}

References hasEquipmentItemProviding:, and hasFuelInjection.

Referenced by applyThrust:, behaviour_attack_break_off_target:, behaviour_attack_broadside:, behaviour_attack_broadside_target:leftside:, behaviour_attack_fly_from_target:, behaviour_attack_fly_to_target:, behaviour_attack_sniper:, behaviour_evasive_action:, behaviour_flee_target:, behaviour_fly_to_target_six:, hasFuelInjection, increase_flight_speed:, isFrangible, and WormholeEntity::suckInShip:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasFuelScoop

- (BOOL) hasFuelScoop

Definition at line 3537 of file ShipEntity.m.

3538{
3539 return [self hasEquipmentItemProviding:@"EQ_FUEL_SCOOPS"];
3540}

References hasEquipmentItemProviding:, and hasFuelScoop.

Referenced by PlayerEntity::doBookkeeping:, hasFuelScoop, isFrangible, and update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasGalacticHyperdrive

- (BOOL) hasGalacticHyperdrive

Definition at line 3623 of file ShipEntity.m.

3624{
3625 return [self hasEquipmentItemProviding:@"EQ_GAL_DRIVE"];
3626}

References hasEquipmentItemProviding:, and hasGalacticHyperdrive.

Referenced by hasGalacticHyperdrive, and isFrangible.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasHeatShield

- (BOOL) hasHeatShield

Definition at line 3595 of file ShipEntity.m.

3596{
3597 return [self hasEquipmentItemProviding:@"EQ_HEAT_SHIELD"];
3598}

References hasEquipmentItemProviding:, and hasHeatShield.

Referenced by hasHeatShield, isFrangible, and setUpShipFromDictionary:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasHostileTarget

- (BOOL) hasHostileTarget

Reimplemented in PlayerEntity, and StationEntity.

Definition at line 6439 of file ShipEntity.m.

6440{
6441 Entity* t = [self primaryTarget];
6442 if (t == nil || ![t isShip]) {
6443 return NO;
6444 }
6445 if ([self isMissile]) {
6446 return YES; // missiles are always fired against a hostile target
6447 }
6448 if ((behaviour == BEHAVIOUR_AVOID_COLLISION) && (previousCondition)) {
6449 int old_behaviour = [previousCondition oo_intForKey:@"behaviour"];
6450 return IsBehaviourHostile(old_behaviour);
6451 }
6453}
static BOOL IsBehaviourHostile(OOBehaviour behaviour)

References behaviour, hasHostileTarget, IsBehaviourHostile, isMissile, Entity::isShip, nil, previousCondition, and primaryTarget.

Referenced by alertCondition, behaviour_track_as_turret:, HeadUpDisplay(Private)::drawScanner:, hasHostileTarget, StationEntity::hasHostileTarget, HeadUpDisplay::hudDrawReticleOnTarget, IsHostileAgainstTargetPredicate(), isHostileTo:, isMissile, noteTakingDamage:from:type:, realAlertCondition, and PlayerEntity(OOPrivate)::updateAlertConditionForNearbyEntities.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasHyperspaceMotor

- (BOOL) hasHyperspaceMotor

Definition at line 2864 of file ShipEntity.m.

2865{
2866 return hyperspaceMotorSpinTime >= 0;
2867}
float hyperspaceMotorSpinTime
Definition ShipEntity.h:236

References hasHyperspaceMotor, and hyperspaceMotorSpinTime.

Referenced by hasHyperspaceMotor, isFrangible, and PlayerEntity::setGuiToStatusScreen.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasMilitaryJammer

- (BOOL) hasMilitaryJammer

Definition at line 3568 of file ShipEntity.m.

3569{
3570#if USEMASC
3571 return [self hasEquipmentItemProviding:@"EQ_MILITARY_JAMMER"];
3572#else
3573 return NO;
3574#endif
3575}

References hasEquipmentItemProviding:, and hasMilitaryJammer.

Referenced by PlayerEntity::doBookkeeping:, hasMilitaryJammer, isFrangible, isJammingScanning, and update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasMilitaryScannerFilter

- (BOOL) hasMilitaryScannerFilter

Definition at line 3559 of file ShipEntity.m.

3560{
3561#if USEMASC
3562 return [self hasEquipmentItemProviding:@"EQ_MILITARY_SCANNER_FILTER"];
3563#else
3564 return NO;
3565#endif
3566}

References hasEquipmentItemProviding:, and hasMilitaryScannerFilter.

Referenced by fireMissileWithIdentifier:andTarget:, hasMilitaryScannerFilter, identFromShip:, isFrangible, PlayerEntity::isValidTarget:, and scannerDisplayColorForShip:isHostile:flash:scannerDisplayColor1:scannerDisplayColor2:scannerDisplayColorH1:scannerDisplayColorH2:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasMilitaryShieldEnhancer

- (BOOL) hasMilitaryShieldEnhancer

Definition at line 3589 of file ShipEntity.m.

3590{
3591 /* Not 'providing' - controlled through scripts */
3592 return [self hasEquipmentItem:@"EQ_NAVAL_SHIELD_BOOSTER"];
3593}

References hasEquipmentItem:, and hasMilitaryShieldEnhancer.

Referenced by hasMilitaryShieldEnhancer, isFrangible, shieldBoostFactor, and shieldRechargeRate.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasNewAI

- (BOOL) hasNewAI

Definition at line 6927 of file ShipEntity.m.

6928{
6929 return [[[self getAI] name] isEqualToString:@"nullAI.plist"];
6930}

References getAI, hasNewAI, and AI::name.

Referenced by deployEscorts, dockEscorts, hasNewAI, respondToAttackFrom:becauseOf:, takeEnergyDamage:from:becauseOf:weaponIdentifier:, StationEntity::takeEnergyDamage:from:becauseOf:weaponIdentifier:, and StationEntity::update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasOneEquipmentItem:includeMissiles:whileLoading:

- (BOOL) hasOneEquipmentItem: (NSString*) itemKey
includeMissiles: (BOOL) includeMissiles
whileLoading: (BOOL) loading 

Definition at line 2722 of file ShipEntity.m.

2722 :(NSString*)itemKey includeMissiles:(BOOL)includeMissiles whileLoading:(BOOL)loading
2723{
2724 if ([_equipment containsObject:itemKey])
2725 return YES;
2726
2727 if (loading) {
2728 NSString* damaged = [itemKey stringByAppendingString:@"_DAMAGED"];
2729 if ([_equipment containsObject:damaged])
2730 return YES;
2731 }
2732
2733 if (includeMissiles && missiles > 0) {
2734 unsigned i;
2735 if ([itemKey isEqualToString:@"thargon"])
2736 itemKey = @"EQ_THARGON";
2737 for (i = 0; i < missiles; i++) {
2738 if (missile_list[i] != nil && [[missile_list[i] identifier] isEqualTo:itemKey])
2739 return YES;
2740 }
2741 }
2742
2743 return NO;
2744}

References _equipment, missile_list, missiles, and nil.

Referenced by ShipRemoveEquipment(), and ShipRemoveEquipment().

Here is the caller graph for this function:

◆ hasOneEquipmentItem:includeWeapons:whileLoading:

- (BOOL) hasOneEquipmentItem: (NSString*) itemKey
includeWeapons: (BOOL) includeMissiles
whileLoading: (BOOL) loading 

Definition at line 2699 of file ShipEntity.m.

2699 :(NSString*)itemKey includeWeapons:(BOOL)includeWeapons whileLoading:(BOOL)loading
2700{
2701 if ([self hasOneEquipmentItem:itemKey includeMissiles:includeWeapons whileLoading:loading])
2702 return YES;
2703
2704 if (loading) {
2705 NSString* damaged = [itemKey stringByAppendingString:@"_DAMAGED"];
2706 if ([_equipment containsObject:damaged])
2707 return YES;
2708 }
2709
2710 if (includeWeapons) {
2711 // Check for primary weapon
2713 if (!isWeaponNone(weaponType)) {
2714 if ([self hasPrimaryWeapon:weaponType])
2715 return YES;
2716 }
2717 }
2718
2719 return NO;
2720}
OOWeaponType OOWeaponTypeFromEquipmentIdentifierStrict(NSString *string) PURE_FUNC

References _equipment, isWeaponNone(), and OOWeaponTypeFromEquipmentIdentifierStrict().

Referenced by hasEquipmentItem:includeWeapons:whileLoading:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasPrimaryRole:

- (BOOL) hasPrimaryRole: (NSString*) role

Definition at line 6336 of file ShipEntity.m.

6336 :(NSString*)role
6337{
6338 return [[self primaryRole] isEqual:role];
6339}

References primaryRole.

Referenced by HasPrimaryRolePredicate().

Here is the caller graph for this function:

◆ hasPrimaryWeapon:

- (BOOL) hasPrimaryWeapon: (OOWeaponType) weaponType

Reimplemented in PlayerEntity.

Definition at line 2746 of file ShipEntity.m.

2746 :(OOWeaponType)weaponType
2747{
2748 NSEnumerator* subEntEnum = nil;
2749 ShipEntity* subEntity = nil;
2750
2751 if ([[forward_weapon_type identifier] isEqualToString:[weaponType identifier]] ||
2752 [[aft_weapon_type identifier] isEqualToString:[weaponType identifier]] ||
2753 [[port_weapon_type identifier] isEqualToString:[weaponType identifier]] ||
2754 [[starboard_weapon_type identifier] isEqualToString:[weaponType identifier]]) {
2755 return YES;
2756 }
2757
2758 for (subEntEnum = [self shipSubEntityEnumerator]; (subEntity = [subEntEnum nextObject]);) {
2759 if ([subEntity hasPrimaryWeapon:weaponType])
2760 return YES;
2761 }
2762
2763 return NO;
2764}

References aft_weapon_type, forward_weapon_type, nil, port_weapon_type, shipSubEntityEnumerator, and starboard_weapon_type.

Referenced by PlayerEntity::hasPrimaryWeapon:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasProximityAlertIgnoringTarget:

- (BOOL) hasProximityAlertIgnoringTarget: (BOOL) ignore_target

Definition at line 9760 of file ShipEntity.m.

9760 :(BOOL)ignore_target
9761{
9762 if (([self proximityAlert] != nil) && (!ignore_target || ([self proximityAlert] != [self primaryTarget]))) {
9763 return YES;
9764 }
9765 return NO;
9766}

References nil, primaryTarget, and proximityAlert.

Here is the call graph for this function:

◆ hasRole:

- (BOOL) hasRole: (NSString*) role

Definition at line 6271 of file ShipEntity.m.

6271 :(NSString*)role
6272{
6273 return [roleSet hasRole:role] || [role isEqual:primaryRole] || [role isEqual:[self shipDataKeyAutoRole]];
6274}

References OORoleSet::hasRole:, and shipDataKeyAutoRole.

Referenced by HasRolePredicate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasScoop

- (BOOL) hasScoop

Definition at line 3532 of file ShipEntity.m.

3533{
3534 return [self hasEquipmentItemProviding:@"EQ_FUEL_SCOOPS"] || [self hasEquipmentItemProviding:@"EQ_CARGO_SCOOPS"];
3535}

References hasEquipmentItemProviding:, and hasScoop.

Referenced by PlayerEntity::dialFuelScoopStatus, hasScoop, ProxyPlayerEntity::initWithKey:definition:, and isFrangible.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasShieldBooster

- (BOOL) hasShieldBooster

Definition at line 3583 of file ShipEntity.m.

3584{
3585 /* Not 'providing' - controlled through scripts */
3586 return [self hasEquipmentItem:@"EQ_SHIELD_BOOSTER"];
3587}

References hasEquipmentItem:, and hasShieldBooster.

Referenced by hasShieldBooster, isFrangible, and shieldBoostFactor.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasSubEntity:

- (BOOL) hasSubEntity: (Entity<OOSubEntity>*) sub

Definition at line 1209 of file ShipEntity.m.

1209 :(Entity<OOSubEntity>*)sub
1210{
1211 return [subEntities containsObject:sub];
1212}

◆ heatInsulation

- (GLfloat) heatInsulation

Definition at line 7593 of file ShipEntity.m.

7594{
7595 return _heatInsulation;
7596}
float _heatInsulation
Definition ShipEntity.h:448

References _heatInsulation, and heatInsulation.

Referenced by PlayerEntity::doBookkeeping:, heatInsulation, StationEntity::launchDefenseShip, StationEntity::launchMiner, StationEntity::launchPatrol, StationEntity::launchPirateShip, StationEntity::launchPolice, StationEntity::launchScavenger, maxFlightSpeed, ShipEntity(Private)::setUpOneEscort:inGroup:withRole:atPosition:andCount:, PlayerEntity::takeEnergyDamage:from:becauseOf:weaponIdentifier:, takeEnergyDamage:from:becauseOf:weaponIdentifier:, and update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ homeSystem

- (OOSystemID) homeSystem

Definition at line 6825 of file ShipEntity.m.

6826{
6827 return home_system;
6828}
OOSystemID home_system
Definition ShipEntity.h:368

References home_system, and homeSystem.

Referenced by homeSystem, reportAIMessages, and setSingleCrewWithRole:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hullHeatLevel

- (GLfloat) hullHeatLevel

Definition at line 8408 of file ShipEntity.m.

8409{
8410 GLfloat result = (GLfloat)ship_temperature / (GLfloat)SHIP_MAX_CABIN_TEMP;
8411 return OOClamp_0_1_f(result);
8412}
OOINLINE float OOClamp_0_1_f(float value) INLINE_CONST_FUNC
#define SHIP_MAX_CABIN_TEMP
Definition ShipEntity.h:69
float ship_temperature
Definition ShipEntity.h:398

References hullHeatLevel, OOClamp_0_1_f(), SHIP_MAX_CABIN_TEMP, and ship_temperature.

Referenced by hullHeatLevel, maxFlightSpeed, PlayerEntity(OOPrivate)::updateAlertConditionForNearbyEntities, and OOTrumble::updateTrumble:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hyperspaceSpinTime

- (float) hyperspaceSpinTime

Definition at line 2869 of file ShipEntity.m.

2870{
2872}

References hyperspaceMotorSpinTime, and hyperspaceSpinTime.

Referenced by hyperspaceSpinTime, and isFrangible.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ identFromShip:

- (NSString *) identFromShip: (ShipEntity*) otherShip

Definition at line 6263 of file ShipEntity.m.

6263 :(ShipEntity*)otherShip
6264{
6265 if ([self isJammingScanning] && ![otherShip hasMilitaryScannerFilter]) {
6266 return DESC(@"unknown-target");
6267 }
6268 return [self displayName];
6269}
#define DESC(key)
Definition Universe.h:832

References DESC, displayName, hasMilitaryScannerFilter, and isJammingScanning.

Referenced by PlayerEntity::dialTargetName, and sendExpandedMessage:toShip:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ increase_flight_pitch:

- (void) increase_flight_pitch: (double) delta

Definition at line 7458 of file ShipEntity.m.

7458 :(double)delta
7459{
7460 flightPitch += delta;
7463 else if (flightPitch < -max_flight_pitch)
7465}

References flightPitch, and max_flight_pitch.

Referenced by PlayerEntity(OOControlsPrivate)::pollFlightArrowKeyControls:, and PlayerEntity(OOControlsPrivate)::pollGuiArrowKeyControls:.

Here is the caller graph for this function:

◆ increase_flight_roll:

- (void) increase_flight_roll: (double) delta

Definition at line 7440 of file ShipEntity.m.

7440 :(double)delta
7441{
7442 flightRoll += delta;
7445 else if (flightRoll < -max_flight_roll)
7447}

References flightRoll, and max_flight_roll.

Referenced by PlayerEntity(OOControlsPrivate)::pollFlightArrowKeyControls:, and PlayerEntity(OOControlsPrivate)::pollGuiArrowKeyControls:.

Here is the caller graph for this function:

◆ increase_flight_speed:

- (void) increase_flight_speed: (double) delta

Definition at line 7414 of file ShipEntity.m.

7414 :(double)delta
7415{
7416 double factor = 1.0;
7418 factor = [self afterburnerFactor];
7419
7420 if (flightSpeed < maxFlightSpeed * factor)
7421 flightSpeed += delta * factor;
7422 else
7423 flightSpeed = maxFlightSpeed * factor;
7424}
BOOL hasFuelInjection()

References afterburnerFactor, desired_speed, flightSpeed, fuel, hasFuelInjection, maxFlightSpeed, and MIN_FUEL.

Referenced by applyThrust:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ increase_flight_yaw:

- (void) increase_flight_yaw: (double) delta

Definition at line 7476 of file ShipEntity.m.

7476 :(double)delta
7477{
7478 flightYaw += delta;
7481 else if (flightYaw < -max_flight_yaw)
7483}

References flightYaw, and max_flight_yaw.

Referenced by PlayerEntity(OOControlsPrivate)::pollFlightArrowKeyControls:, and PlayerEntity(OOControlsPrivate)::pollGuiArrowKeyControls:.

Here is the caller graph for this function:

◆ init

- (id) init
implementation

Reimplemented from Entity.

Reimplemented in PlayerEntity.

Definition at line 174 of file ShipEntity.m.

175{
176 /* -init used to set up a bunch of defaults that were different from
177 those in -reinit and -setUpShipFromDictionary:. However, it seems that
178 no ships are ever used which are not -setUpShipFromDictionary: (which
179 is as it should be), so these different defaults were meaningless.
180 */
181 return [self initWithKey:@"" definition:nil];
182}

References init, and initWithKey:definition:.

Referenced by init.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initBypassForPlayer

- (id) initBypassForPlayer
implementation

Provided by category ShipEntity(Hax).

Definition at line 184 of file ShipEntity.m.

185{
186 return [super init];
187}

References Entity::init, and ShipEntity(Hax)::initBypassForPlayer.

Referenced by PlayerEntity::init, and ShipEntity(Hax)::initBypassForPlayer.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initWithKey:definition:

- (id) initWithKey: (NSString*) key
definition: (NSDictionary*) dict 

Reimplemented in DockEntity, ProxyPlayerEntity, and StationEntity.

Definition at line 190 of file ShipEntity.m.

190 :(NSString*)key definition:(NSDictionary*)dict
191{
193
194 NSParameterAssert(dict != nil);
195
196 self = [super init];
197 if (self == nil)
198 return nil;
199
200 _shipKey = [key retain];
201
202 isShip = YES;
204 [self setStatus:STATUS_IN_FLIGHT];
205
210 weapon_temp = 0.0f;
212 forward_weapon_temp = 0.0f;
213 aft_weapon_temp = 0.0f;
214 port_weapon_temp = 0.0f;
216
217 _nextAegisCheck = -0.1f;
219
220 if (![self setUpShipFromDictionary:dict]) {
221 [self release];
222 self = nil;
223 }
224
225 // Problem observed in testing -- Ahruman
226 if (self != nil && !isfinite(maxFlightSpeed)) {
227 OOLog(@"ship.sanityCheck.failed", @"Ship %@ %@ infinite top speed, clamped to 300.", self, @"generated with");
228 maxFlightSpeed = 300;
229 }
230 return self;
231
233}
#define OOJS_PROFILE_EXIT
#define OOJS_PROFILE_ENTER
#define INITIAL_SHOT_TIME
Definition ShipEntity.h:102
#define SHIP_MIN_CABIN_TEMP
Definition ShipEntity.h:70
GLfloat zero_distance
Definition Entity.h:104
OOTimeDelta shot_time
Definition ShipEntity.h:186

References _nextAegisCheck, _shipKey, aft_weapon_temp, aiScriptWakeTime, currentWeaponFacing, entity_personality, ENTITY_PERSONALITY_MAX, forward_weapon_temp, Entity::init, INITIAL_SHOT_TIME, Entity::isShip, maxFlightSpeed, nil, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOLog, port_weapon_temp, Ranrot(), SCANNER_MAX_RANGE2, setStatus:, SHIP_MIN_CABIN_TEMP, ship_temperature, shot_time, starboard_weapon_temp, WEAPON_FACING_FORWARD, weapon_recharge_rate, weapon_temp, and Entity::zero_distance.

Referenced by init, DockEntity::initWithKey:definition:, ProxyPlayerEntity::initWithKey:definition:, and StationEntity::initWithKey:definition:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ interpretAIMessage:

- (void) interpretAIMessage: (NSString*) message

Reimplemented in PlayerEntity.

Definition at line 12456 of file ShipEntity.m.

12456 :(NSString*)ms
12457{
12458 if ([ms hasPrefix:AIMS_AGGRESSOR_SWITCHED_TARGET]) {
12459 // if I'm under attack send a thank-you message to the rescuer
12460 //
12461 NSArray* tokens = ScanTokensFromString(ms);
12462 int switcher_id = [(NSString*)[tokens objectAtIndex:1] intValue]; // Attacker that switched targets.
12463 Entity* switcher = [UNIVERSE entityForUniversalID:switcher_id];
12464 int rescuer_id = [(NSString*)[tokens objectAtIndex:2] intValue]; // New primary target of attacker.
12465 Entity* rescuer = [UNIVERSE entityForUniversalID:rescuer_id];
12466 if ((switcher == [self primaryAggressor]) && (switcher == [self primaryTarget]) && (switcher) && (rescuer) && (rescuer->isShip) && ([self thankedShip] != rescuer) && (scanClass != CLASS_THARGOID)) {
12467 ShipEntity* rescueShip = (ShipEntity*)rescuer;
12468 // ShipEntity* switchingShip = (ShipEntity*)switcher;
12469 if (scanClass == CLASS_POLICE) {
12470 [self sendExpandedMessage:@"[police-thanks-for-assist]" toShip:rescueShip];
12471 [rescueShip setBounty:[rescueShip bounty] * 0.80 withReason:kOOLegalStatusReasonAssistingPolice]; // lower bounty by 20%
12472 } else {
12473 [self sendExpandedMessage:@"[thanks-for-assist]" toShip:rescueShip];
12474 }
12475 [self setThankedShip:rescuer];
12476 }
12477 }
12478}
NSMutableArray * ScanTokensFromString(NSString *values)
#define AIMS_AGGRESSOR_SWITCHED_TARGET
Definition ShipEntity.h:96
Entity * thankedShip()

References AIMS_AGGRESSOR_SWITCHED_TARGET, bounty, Entity::isShip, primaryAggressor, primaryTarget, scanClass, ScanTokensFromString(), sendExpandedMessage:toShip:, setBounty:withReason:, setThankedShip:, and thankedShip.

Here is the call graph for this function:

◆ isBeacon

- (BOOL) isBeacon
implementation

Reimplemented from <OOBeaconEntity>.

Definition at line 1448 of file ShipEntity.m.

1449{
1450 return [self beaconCode] != nil;
1451}

References beaconCode, isBeacon, and nil.

Referenced by isBeacon.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsBehaviourHostile

+ (BOOL) IsBehaviourHostile (OOBehaviour) behaviour
implementation

Definition at line 6407 of file ShipEntity.m.

6408{
6409 switch (behaviour) {
6410 case BEHAVIOUR_ATTACK_TARGET:
6411 case BEHAVIOUR_ATTACK_FLY_TO_TARGET:
6412 case BEHAVIOUR_ATTACK_FLY_FROM_TARGET:
6413 case BEHAVIOUR_RUNNING_DEFENSE:
6414 case BEHAVIOUR_FLEE_TARGET:
6415 case BEHAVIOUR_ATTACK_BREAK_OFF_TARGET:
6416 case BEHAVIOUR_ATTACK_SLOW_DOGFIGHT:
6417 case BEHAVIOUR_EVASIVE_ACTION:
6418 case BEHAVIOUR_FLEE_EVASIVE_ACTION:
6419 case BEHAVIOUR_ATTACK_FLY_TO_TARGET_SIX:
6420 // case BEHAVIOUR_ATTACK_MINING_TARGET:
6421 case BEHAVIOUR_ATTACK_FLY_TO_TARGET_TWELVE:
6422 case BEHAVIOUR_ATTACK_BROADSIDE:
6423 case BEHAVIOUR_ATTACK_BROADSIDE_LEFT:
6424 case BEHAVIOUR_ATTACK_BROADSIDE_RIGHT:
6425 case BEHAVIOUR_CLOSE_TO_BROADSIDE_RANGE:
6426 case BEHAVIOUR_CLOSE_WITH_TARGET:
6427 case BEHAVIOUR_ATTACK_SNIPER:
6428 case BEHAVIOUR_SCRIPTED_ATTACK_AI:
6429 return YES;
6430
6431 default:
6432 return NO;
6433 }
6434
6435 return 100 < behaviour && behaviour < 120;
6436}

References behaviour.

Referenced by hasHostileTarget.

Here is the caller graph for this function:

◆ isBoulder

- (BOOL) isBoulder

Definition at line 1512 of file ShipEntity.m.

1513{
1514 return [roleSet hasRole:kBoulderRole];
1515}

References OORoleSet::hasRole:, and isBoulder.

Referenced by becomeExplosion, isBoulder, isMinable, and octree.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isCloaked

- (BOOL) isCloaked

Definition at line 5755 of file ShipEntity.m.

5756{
5758}

References cloaking_device_active, and isCloaked.

Referenced by behaviour_track_as_turret:, PlayerEntity(OOPrivate)::checkEntityForMassLock:withScanClass:, checkScanner, checkScannerIgnoringUnpowered, PlayerEntity::collectBountyFor:, fireDirectLaserDefensiveShot, fireLaserShotInDirection:weaponIdentifier:, fireMissileWithIdentifier:andTarget:, fireSubentityLaserShot:, fireTurretCannon:, isCloaked, PlayerEntity::isValidTarget:, PlayerEntity::markAsOffender:withReason:, markAsOffender:withReason:, PlayerEntity::moveTargetMemoryBy:, reactionTime, removeEquipmentItem:, takeEnergyDamage:from:becauseOf:weaponIdentifier:, and updateTrackingCurve.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isDefenseTarget:

- (BOOL) isDefenseTarget: (Entity*) target

Definition at line 9711 of file ShipEntity.m.

9711 :(Entity*)target
9712{
9713 return [_defenseTargets containsObject:target];
9714}

References OOWeakSet::containsObject:.

Here is the call graph for this function:

◆ isDemoShip

- (BOOL) isDemoShip

References isDemoShip.

◆ isEscort

- (BOOL) isEscort

Definition at line 6377 of file ShipEntity.m.

6378{
6379 return [UNIVERSE role:[self primaryRole] isInCategory:@"oolite-escort"];
6380}

References isEscort, and primaryRole.

Referenced by canAcceptEscort:, isEscort, isMissile, setUpEscorts, and takeEnergyDamage:from:becauseOf:weaponIdentifier:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isExplicitlyUnpiloted

- (BOOL) isExplicitlyUnpiloted

Definition at line 6397 of file ShipEntity.m.

6398{
6399 return _explicitlyUnpiloted;
6400}
unsigned _explicitlyUnpiloted
Definition ShipEntity.h:263

References _explicitlyUnpiloted, and isExplicitlyUnpiloted.

Referenced by PlayerEntity::addRoleForAggression:, isExplicitlyUnpiloted, isMissile, isUnpiloted, StationEntity::isUnpiloted, and setCrew:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isFrangible

◆ isFriendlyTo:

- (BOOL) isFriendlyTo: (ShipEntity*) otherShip

Definition at line 8757 of file ShipEntity.m.

8757 :(ShipEntity*)otherShip
8758{
8759 BOOL isFriendly = NO;
8760 OOShipGroup* myGroup = [self group];
8761 OOShipGroup* otherGroup = [otherShip group];
8762
8763 if ((otherShip == self) || ([self isPolice] && [otherShip isPolice]) || ([self isThargoid] && [otherShip isThargoid]) || (myGroup != nil && otherGroup != nil && (myGroup == otherGroup || [otherGroup leader] == self)) || ([self scanClass] == CLASS_MILITARY && [otherShip scanClass] == CLASS_MILITARY)) {
8764 isFriendly = YES;
8765 }
8766
8767 return isFriendly;
8768}

References group, isPolice, isThargoid, nil, and scanClass.

Here is the call graph for this function:

◆ isHostileTo:

- (BOOL) isHostileTo: (Entity*) entity

Definition at line 6455 of file ShipEntity.m.

6455 :(Entity*)entity
6456{
6457 return ([self hasHostileTarget] && [self primaryTarget] == entity);
6458}

References hasHostileTarget, and primaryTarget.

Referenced by Universe::IsFriendlyStationPredicate.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isHulk

- (BOOL) isHulk

References isHulk.

◆ isJammingScanning

- (BOOL) isJammingScanning
implementation

Reimplemented from <OOBeaconEntity>.

Definition at line 5783 of file ShipEntity.m.

5784{
5785 return ([self hasMilitaryJammer] && military_jammer_active);
5786}
BOOL hasMilitaryJammer()
unsigned military_jammer_active
Definition ShipEntity.h:238

References hasMilitaryJammer, isJammingScanning, and military_jammer_active.

Referenced by fireMissileWithIdentifier:andTarget:, identFromShip:, isJammingScanning, PlayerEntity::isValidTarget:, scannerDisplayColorForShip:isHostile:flash:scannerDisplayColor1:scannerDisplayColor2:scannerDisplayColorH1:scannerDisplayColorH2:, PlayerEntity::setNextCompassMode, and PlayerEntity::setPrevCompassMode.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isMinable

- (BOOL) isMinable

Definition at line 1517 of file ShipEntity.m.

1518{
1519 if ([self hasRole:@"asteroid"] || [self isBoulder]) {
1520 if (!noRocks) {
1521 return YES;
1522 }
1523 }
1524 return NO;
1525}

References isBoulder, isMinable, and noRocks.

Referenced by isMinable, and octree.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isMine

- (BOOL) isMine

Definition at line 6367 of file ShipEntity.m.

6368{
6369 return [[self primaryRole] hasSuffix:@"MINE"];
6370}

References isMine, and primaryRole.

Referenced by PlayerEntity::fireMissile, isMine, isMissile, and isWeapon.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isMining

- (BOOL) isMining

Reimplemented in PlayerEntity.

Definition at line 12451 of file ShipEntity.m.

12452{
12453 return ((behaviour == BEHAVIOUR_ATTACK_MINING_TARGET) && ([forward_weapon_type isMiningLaser]));
12454}

References behaviour, forward_weapon_type, and isMining.

Referenced by isMining, sunGlareFilter, and takeEnergyDamage:from:becauseOf:weaponIdentifier:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isMissile

- (BOOL) isMissile

References alertCondition, allDefenseTargets, collisionExceptions, defenseTargetCount, defenseTargetEnumerator, hasHostileTarget, isEscort, isExplicitlyUnpiloted, isMine, isMissile, isPirateVictim, isShuttle, isTurret, isUnpiloted, isWeapon, realAlertCondition, removeAllDefenseTargets, and validateDefenseTargets.

Here is the call graph for this function:

◆ isMissileFlagSet

- (BOOL) isMissileFlagSet

Definition at line 10702 of file ShipEntity.m.

10703{
10704 return isMissile; // were we created using fireMissile? (for tracking submunitions and preventing collisions at launch)
10705}

References isMissile, and isMissileFlagSet.

Referenced by coordinates, fireMissileWithIdentifier:andTarget:, and isMissileFlagSet.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isPirate

- (BOOL) isPirate

Definition at line 6357 of file ShipEntity.m.

6358{
6359 return [UNIVERSE role:[self primaryRole] isInCategory:@"oolite-pirate"];
6360}

References isPirate, and primaryRole.

Referenced by isPirate, primaryRole, and takeEnergyDamage:from:becauseOf:weaponIdentifier:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isPirateVictim

- (BOOL) isPirateVictim

Definition at line 6392 of file ShipEntity.m.

6393{
6394 return [UNIVERSE roleIsPirateVictim:[self primaryRole]];
6395}

References isPirateVictim, and primaryRole.

Referenced by PlayerEntity::addRoleForAggression:, isMissile, and isPirateVictim.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isPolice

- (BOOL) isPolice

Definition at line 6341 of file ShipEntity.m.

6342{
6343 // bounty hunters have a police role, but are not police, so we must test by scan class, not by role
6344 return [self scanClass] == CLASS_POLICE;
6345}

References isPolice, and scanClass.

Referenced by PlayerEntity::collectBountyFor:, collectBountyFor:, isFriendlyTo:, isPolice, StationEntity::launchDefenseShip, markAsOffender:withReason:, primaryRole, respondToAttackFrom:becauseOf:, setUpEscorts, and takeEnergyDamage:from:becauseOf:weaponIdentifier:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isShipWithSubEntityShip:

- (BOOL) isShipWithSubEntityShip: (Entity*) other
implementation

Reimplemented from Entity.

Provided by category ShipEntity(SubEntityRelationship).

Definition at line 12984 of file ShipEntity.m.

12984 :(Entity*)other
12985{
12986 assert([self isShip]);
12987
12988 if (![other isShip])
12989 return NO;
12990 if (![other isSubEntity])
12991 return NO;
12992 if ([other owner] != self)
12993 return NO;
12994
12995#ifndef NDEBUG
12996 // Sanity check; this should always be true.
12997 if (![self hasSubEntity:(ShipEntity*)other]) {
12998 OOLogERR(@"ship.subentity.sanityCheck.failed", @"%@ thinks it's a subentity of %@, but the supposed parent does not agree. %@", [other shortDescription], [self shortDescription], @"This is an internal error, please report it.");
12999 [other setOwner:nil];
13000 return NO;
13001 }
13002#endif
13003
13004 return YES;
13005}

◆ isShuttle

- (BOOL) isShuttle

Definition at line 6382 of file ShipEntity.m.

6383{
6384 return [UNIVERSE role:[self primaryRole] isInCategory:@"oolite-shuttle"];
6385}

References isShuttle, and primaryRole.

Referenced by isMissile, isShuttle, and landOnPlanet:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isTemplateCargoPod

- (BOOL) isTemplateCargoPod

Definition at line 932 of file ShipEntity.m.

933{
934 return [[self primaryRole] isEqualToString:@"oolite-template-cargopod"];
935}

References isTemplateCargoPod, and primaryRole.

Referenced by bounty, and isTemplateCargoPod.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isThargoid

- (BOOL) isThargoid

Definition at line 6347 of file ShipEntity.m.

6348{
6349 return [self scanClass] == CLASS_THARGOID;
6350}

References isThargoid, and scanClass.

Referenced by addEquipmentItem:withValidation:inContext:, becomeExplosion, behaviour_fly_to_target_six:, canAddEquipment:inContext:, isFriendlyTo:, isThargoid, primaryRole, removeEquipmentItem:, selectMissile, and setUpEscorts.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isTrader

- (BOOL) isTrader

Definition at line 6352 of file ShipEntity.m.

6353{
6354 return [UNIVERSE role:[self primaryRole] isInCategory:@"oolite-trader"];
6355}

References isTrader, and primaryRole.

Referenced by isTrader, primaryRole, and takeEnergyDamage:from:becauseOf:weaponIdentifier:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isTurret

- (BOOL) isTurret

Definition at line 6387 of file ShipEntity.m.

6388{
6389 return behaviour == BEHAVIOUR_TRACK_AS_TURRET;
6390}

References behaviour, and isTurret.

Referenced by isMissile, isTurret, and turretCount.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isUnpiloted

- (BOOL) isUnpiloted

Reimplemented in StationEntity.

Definition at line 6402 of file ShipEntity.m.

6403{
6404 return [self isExplicitlyUnpiloted] || [self isHulk] || [self scanClass] == CLASS_ROCK || [self scanClass] == CLASS_CARGO;
6405}

References isExplicitlyUnpiloted, isHulk, isUnpiloted, and scanClass.

Referenced by isMissile, isUnpiloted, and setSingleCrewWithRole:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isValidTarget:

- (BOOL) isValidTarget: (Entity*) target

Reimplemented in PlayerEntity.

Definition at line 8647 of file ShipEntity.m.

8647 :(Entity*)target
8648{
8649 if (target == nil) {
8650 return NO;
8651 }
8652 if ([target isShip]) {
8653 OOEntityStatus tstatus = [target status];
8654 if (tstatus == STATUS_ENTERING_WITCHSPACE || tstatus == STATUS_IN_HOLD || tstatus == STATUS_DOCKED || tstatus == STATUS_DEAD)
8655 // 2013-01-13, Eric: added STATUS_DEAD because I keep seeing ships locked on dead ships in attack mode.
8656 {
8657 return NO;
8658 }
8659 return YES;
8660 }
8661 if ([target isWormhole] && [target scanClass] != CLASS_NO_DRAW) {
8662 return YES;
8663 }
8664 return NO;
8665}
OOEntityStatus
Definition Entity.h:60

References Entity::isShip, Entity::isWormhole, nil, scanClass, and Entity::status.

Referenced by noteLostTarget.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isVisible

- (BOOL) isVisible
implementation

Reimplemented from Entity.

Definition at line 1443 of file ShipEntity.m.

1444{
1446}

References Entity::cam_zero_distance, isVisible, and Entity::no_draw_distance.

Referenced by becomeExplosion, PlayerEntity::equipmentList, isVisible, and PlayerEntity::lookingAtSunWithThresholdAngleCos:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isVisibleToScripts

- (BOOL) isVisibleToScripts
implementation

Reimplemented from Entity.

Provided by category ShipEntity(OOJavaScriptExtensions).

Definition at line 105 of file EntityOOJavaScriptExtensions.m.

106{
107 return YES;
108}

◆ isWeapon

- (BOOL) isWeapon

Definition at line 6372 of file ShipEntity.m.

6373{
6374 return [self isMissile] || [self isMine];
6375}

References isMine, isMissile, and isWeapon.

Referenced by isMissile, and isWeapon.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ landOnPlanet

- (void) landOnPlanet
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1177 of file ShipEntityAI.m.

1178{
1179 // Selects the nearest planet it can find.
1180 [self landOnPlanet:[self findNearestPlanet]];
1181}

Referenced by coordinates, and landOnPlanet:.

Here is the caller graph for this function:

◆ landOnPlanet:

- (void) landOnPlanet: (OOPlanetEntity*) planet

Definition at line 12228 of file ShipEntity.m.

12228 :(OOPlanetEntity*)planet
12229{
12230 if (planet && [self isShuttle]) {
12231 [planet welcomeShuttle:self];
12232 }
12233 [self doScriptEvent:OOJSID("shipLandedOnPlanet") withArgument:planet andReactToAIMessage:@"LANDED_ON_PLANET"];
12234
12235#ifndef NDEBUG
12236 if ([self reportAIMessages]) {
12237 OOLog(@"planet.collide.shuttleLanded", @"DEBUG: %@ landed on planet %@", self, planet);
12238 }
12239#endif
12240
12241 [UNIVERSE removeEntity:self];
12242}
BOOL isShuttle()

References doScriptEvent:withArgument:andReactToAIMessage:, isShuttle, landOnPlanet, OOLog, and reportAIMessages.

Referenced by behaviour_land_on_planet:, and ShipEntity(PureAI)::landOnPlanet.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ laserColor

- (OOColor *) laserColor

Definition at line 10161 of file ShipEntity.m.

10162{
10163 return [[laser_color retain] autorelease];
10164}

References laserColor.

Referenced by coordinates, and laserColor.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ laserHeatLevel

- (GLfloat) laserHeatLevel

Reimplemented in PlayerEntity.

Definition at line 8367 of file ShipEntity.m.

8368{
8369 GLfloat result = weapon_temp / NPC_MAX_WEAPON_TEMP;
8370 return OOClamp_0_1_f(result);
8371}

References laserHeatLevel, NPC_MAX_WEAPON_TEMP, OOClamp_0_1_f(), and weapon_temp.

Referenced by laserHeatLevel, and maxFlightSpeed.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ laserHeatLevelAft

- (GLfloat) laserHeatLevelAft

Reimplemented in PlayerEntity.

Definition at line 8373 of file ShipEntity.m.

8374{
8375 GLfloat result = aft_weapon_temp / NPC_MAX_WEAPON_TEMP;
8376 return OOClamp_0_1_f(result);
8377}

References aft_weapon_temp, laserHeatLevelAft, NPC_MAX_WEAPON_TEMP, and OOClamp_0_1_f().

Referenced by laserHeatLevelAft, and maxFlightSpeed.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ laserHeatLevelForward

- (GLfloat) laserHeatLevelForward

Reimplemented in PlayerEntity.

Definition at line 8379 of file ShipEntity.m.

8380{
8381 GLfloat result = forward_weapon_temp / NPC_MAX_WEAPON_TEMP;
8382 if (isWeaponNone(forward_weapon_type)) { // must check subents
8383 OOWeaponType forward_weapon_real_type = nil;
8384 NSEnumerator* subEnum = [self shipSubEntityEnumerator];
8385 ShipEntity* se = nil;
8386 while (isWeaponNone(forward_weapon_real_type) && (se = [subEnum nextObject])) {
8388 forward_weapon_real_type = se->forward_weapon_type;
8390 }
8391 }
8392 }
8393 return OOClamp_0_1_f(result);
8394}

References forward_weapon_temp, forward_weapon_type, isWeaponNone(), laserHeatLevelForward, nil, NPC_MAX_WEAPON_TEMP, OOClamp_0_1_f(), and shipSubEntityEnumerator.

Referenced by laserHeatLevelForward, and maxFlightSpeed.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ laserHeatLevelPort

- (GLfloat) laserHeatLevelPort

Reimplemented in PlayerEntity.

Definition at line 8396 of file ShipEntity.m.

8397{
8398 GLfloat result = port_weapon_temp / NPC_MAX_WEAPON_TEMP;
8399 return OOClamp_0_1_f(result);
8400}

References laserHeatLevelPort, NPC_MAX_WEAPON_TEMP, OOClamp_0_1_f(), and port_weapon_temp.

Referenced by laserHeatLevelPort, and maxFlightSpeed.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ laserHeatLevelStarboard

- (GLfloat) laserHeatLevelStarboard

Reimplemented in PlayerEntity.

Definition at line 8402 of file ShipEntity.m.

8403{
8404 GLfloat result = starboard_weapon_temp / NPC_MAX_WEAPON_TEMP;
8405 return OOClamp_0_1_f(result);
8406}

References laserHeatLevelStarboard, NPC_MAX_WEAPON_TEMP, OOClamp_0_1_f(), and starboard_weapon_temp.

Referenced by laserHeatLevelStarboard, and maxFlightSpeed.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ laserPortOffset:

- (NSArray *) laserPortOffset: (OOWeaponFacing) direction

Definition at line 10345 of file ShipEntity.m.

10345 :(OOWeaponFacing)direction
10346{
10347 NSArray* laserPortOffset = nil;
10348 switch (direction) {
10350 case WEAPON_FACING_NONE:
10351 laserPortOffset = forwardWeaponOffset;
10352 break;
10353
10354 case WEAPON_FACING_AFT:
10355 laserPortOffset = aftWeaponOffset;
10356 break;
10357
10358 case WEAPON_FACING_PORT:
10359 laserPortOffset = portWeaponOffset;
10360 break;
10361
10363 laserPortOffset = starboardWeaponOffset;
10364 break;
10365 }
10366 return laserPortOffset;
10367}

References aftWeaponOffset, forwardWeaponOffset, nil, portWeaponOffset, starboardWeaponOffset, WEAPON_FACING_AFT, WEAPON_FACING_FORWARD, WEAPON_FACING_NONE, WEAPON_FACING_PORT, and WEAPON_FACING_STARBOARD.

Referenced by PlayerEntity::currentLaserOffset, fireLaserShotInDirection:weaponIdentifier:, PlayerEntity::fireMainWeapon, and fireWeapon:direction:range:.

Here is the caller graph for this function:

◆ lastAegisLock

- (Entity< OOStellarBody > *) lastAegisLock
implementation

Provided by category ShipEntity(Private).

Definition at line 6808 of file ShipEntity.m.

6809{
6810 Entity<OOStellarBody>* stellar = [_lastAegisLock weakRefUnderlyingObject];
6811 if (stellar == nil) {
6812 [_lastAegisLock release];
6814 }
6815
6816 return stellar;
6817}

References ShipEntity(Private)::lastAegisLock, and nil.

Referenced by checkForAegis, ShipEntity(Private)::drawDebugStuff, ShipEntity(Private)::lastAegisLock, and transitionToAegisNone.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lastEscortTarget

- (Entity *) lastEscortTarget

Definition at line 8580 of file ShipEntity.m.

8581{
8582 Entity* result = [_lastEscortTarget weakRefUnderlyingObject];
8583 if (result == nil || ![self isValidTarget:result]) {
8585 return nil;
8586 }
8587 return result;
8588}
OOWeakReference * _lastEscortTarget
Definition ShipEntity.h:429

References _lastEscortTarget, DESTROY, lastEscortTarget, nil, and OOWeakReference::weakRefUnderlyingObject.

Referenced by deployEscorts, ShipEntity(PureAI)::fightOrFleeHostiles, lastEscortTarget, and maxFlightSpeed.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ launchCascadeMine

- (BOOL) launchCascadeMine

Definition at line 10764 of file ShipEntity.m.

10765{
10766 if (![self hasCascadeMine])
10767 return NO;
10768 [self setSpeed:maxFlightSpeed + 300];
10769 ShipEntity* bomb = [UNIVERSE newShipWithRole:@"energy-bomb"];
10770 if (bomb == nil)
10771 return NO;
10772
10773 [self removeEquipmentItem:@"EQ_QC_MINE"];
10774
10775 double start = collision_radius + bomb->collision_radius;
10776 Quaternion random_direction;
10777 Vector vel;
10778 HPVector rpos;
10779 double random_roll = randf() - 0.5; // -0.5 to +0.5
10780 double random_pitch = randf() - 0.5; // -0.5 to +0.5
10781 quaternion_set_random(&random_direction);
10782
10784
10785 double eject_speed = -800.0;
10786 vel = vector_multiply_scalar(v_forward, [self flightSpeed] + eject_speed);
10787 eject_speed *= 0.5 * (randf() - 0.5); // -0.25x .. +0.25x
10788 vel = vector_add(vel, vector_multiply_scalar(v_up, eject_speed));
10789 eject_speed *= 0.5 * (randf() - 0.5); // -0.0625x .. +0.0625x
10790 vel = vector_add(vel, vector_multiply_scalar(v_right, eject_speed));
10791
10792 [bomb setPosition:rpos];
10793 [bomb setOrientation:random_direction];
10794 [bomb setRoll:random_roll];
10795 [bomb setPitch:random_pitch];
10796 [bomb setVelocity:vel];
10797 [bomb setScanClass:CLASS_MINE];
10798 [bomb setEnergy:5.0]; // 5 second countdown
10799 [bomb setBehaviour:BEHAVIOUR_ENERGY_BOMB_COUNTDOWN];
10800 [bomb setOwner:self];
10801 [UNIVERSE addEntity:bomb]; // STATUS_IN_FLIGHT, AI state GLOBAL
10802 [bomb release];
10803
10805 [self deactivateCloakingDevice];
10806 }
10807
10808 if (self != PLAYER) // get the heck out of here
10809 {
10810 [self addTarget:bomb];
10811 [self setBehaviour:BEHAVIOUR_FLEE_TARGET];
10812 frustration = 0.0;
10813 }
10814 return YES;
10815}
void setBehaviour:(OOBehaviour cond)

References addTarget:, cloaking_device_active, cloakPassive, Entity::collision_radius, deactivateCloakingDevice, flightSpeed, frustration, hasCascadeMine, HPvector_subtract(), launchCascadeMine, nil, PLAYER, Entity::position, quaternion_set_random(), randf(), removeEquipmentItem:, setBehaviour:, Entity::setEnergy:, Entity::setOrientation:, setOwner:, setPitch:, Entity::setPosition:, setRoll:, Entity::setScanClass:, setSpeed:, Entity::setVelocity:, v_forward, v_right, v_up, vector_add(), vector_multiply_scalar(), and vectorToHPVector().

Referenced by behaviour_flee_target:, coordinates, and launchCascadeMine.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ launchEscapeCapsule

- (ShipEntity *) launchEscapeCapsule

Reimplemented in PlayerEntity.

Definition at line 10817 of file ShipEntity.m.

10818{
10819 ShipEntity* result = nil;
10820 ShipEntity* mainPod = nil;
10821 unsigned n_pods, i;
10822 NSMutableArray* passengers = nil;
10823
10824 /*
10825 CHANGE: both player & NPCs can now launch escape pods in interstellar
10826 space. -- Kaks 20101113
10827 */
10828
10829 // check number of pods aboard -- require at least one.
10830 n_pods = [shipinfoDictionary oo_unsignedIntForKey:@"has_escape_pod"];
10831 if (n_pods > 65)
10832 n_pods = 65; // maximum of 64 passengers.
10833 if (n_pods > 1)
10834 passengers = [NSMutableArray arrayWithCapacity:n_pods - 1];
10835
10836 if (crew) // transfer crew
10837 {
10838 // make sure crew inherit any legalStatus
10839 for (i = 0; i < [crew count]; i++) {
10840 OOCharacter* ch = (OOCharacter*)[crew objectAtIndex:i];
10841 [ch setLegalStatus:[self legalStatus] | [ch legalStatus]];
10842 }
10843 mainPod = [self launchPodWithCrew:crew];
10844 if (mainPod) {
10845 result = mainPod;
10846 [self setCrew:nil];
10847 [self setHulk:YES]; // we are without crew now.
10848 }
10849 }
10850
10851 // launch other pods (passengers)
10852 for (i = 1; i < n_pods; i++) {
10853 ShipEntity* passenger = nil;
10854 passenger = [self launchPodWithCrew:[NSArray arrayWithObject:[OOCharacter randomCharacterWithRole:@"passenger" andOriginalSystem:gen_rnd_number()]]];
10855 [passengers addObject:passenger];
10856 }
10857
10858 if (mainPod)
10859 [self doScriptEvent:OOJSID("shipLaunchedEscapePod") withArgument:mainPod andArgument:passengers];
10860
10861 return result;
10862}
#define OOJSID(str)
Definition OOJSPropID.h:42
void setLegalStatus:(int value)
OOCharacter * randomCharacterWithRole:andOriginalSystem:(NSString *c_role,[andOriginalSystem] OOSystemID s)
Definition OOCharacter.m:94

References crew, doScriptEvent:withArgument:andArgument:, launchEscapeCapsule, launchPodWithCrew:, OOCharacter::legalStatus, legalStatus, nil, OOCharacter::randomCharacterWithRole:andOriginalSystem:, setCrew:, setHulk:, and OOCharacter::setLegalStatus:.

Referenced by abandonShip, coordinates, and launchEscapeCapsule.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ launchPatrol

- (BOOL) launchPatrol
implementation

Reimplemented in StationEntity.

Provided by category ShipEntity(OOAIStationStubs).

Definition at line 2565 of file ShipEntityAI.m.

2566{
2567 OOLog(@"ai.invalid.notAStation", @"Attempt to use station AI method \"%s\" on non-station %@.", "launchPatrol", self);
2568 return NO;
2569}

◆ launchPodWithCrew:

- (ShipEntity *) launchPodWithCrew: (NSArray*) podCrew
implementation

Provided by category ShipEntity(Private).

Definition at line 2047 of file ShipEntity.m.

2047 :(NSArray*)podCrew
2048{
2049 ShipEntity* pod = nil;
2050
2051 pod = [UNIVERSE newShipWithRole:[shipinfoDictionary oo_stringForKey:@"escape_pod_role"]]; // or nil
2052 if (!pod) {
2053 // _role not defined? it might have _model defined;
2054 pod = [UNIVERSE newShipWithRole:[shipinfoDictionary oo_stringForKey:@"escape_pod_model" defaultValue:@"escape-capsule"]];
2055 if (!pod) {
2056 pod = [UNIVERSE newShipWithRole:@"escape-capsule"];
2057 OOLog(@"shipEntity.noEscapePod", @"Ship %@ has no correct escape_pod_role defined. Now using default capsule.", self);
2058 }
2059 }
2060
2061 if (pod) {
2062 [pod setOwner:self];
2063 [pod setTemperature:[self randomEjectaTemperatureWithMaxFactor:0.9]];
2064 [pod setCommodity:@"slaves" andAmount:1];
2065 [pod setCrew:podCrew];
2066 [pod switchAITo:@"oolite-shuttleAI.js"];
2067 [self dumpItem:pod]; // CLASS_CARGO, STATUS_IN_FLIGHT, AI state GLOBAL
2068 [pod release]; // release
2069 }
2070
2071 return pod;
2072}
void setCrew:(NSArray *crewArray)
void switchAITo:(NSString *aiString)

References dumpItem:, nil, OOLog, randomEjectaTemperatureWithMaxFactor:, setCommodity:andAmount:, setCrew:, setOwner:, setTemperature:, and switchAITo:.

Referenced by launchEscapeCapsule.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ leaveDock:

- (void) leaveDock: (StationEntity*) station

Reimplemented in PlayerEntity.

Definition at line 11730 of file ShipEntity.m.

11730 :(StationEntity*)station
11731{
11732 // This code is never used. Currently npc ships are only launched from the stations launch queue.
11733 if (station == nil)
11734 return;
11735
11736 [station launchShip:self];
11737}
void launchShip:(ShipEntity *ship)

References StationEntity::launchShip:, and nil.

Here is the call graph for this function:

◆ leaveWitchspace

- (void) leaveWitchspace

Reimplemented in PlayerEntity.

Definition at line 11787 of file ShipEntity.m.

11788{
11789 Quaternion q1;
11792 double d1 = 0.0;
11793
11794 GLfloat min_d1 = [UNIVERSE safeWitchspaceExitDistance];
11795
11796 while (fabs(d1) < min_d1) {
11797 // not scannerRange - has no effect on witchspace exit
11798 d1 = SCANNER_MAX_RANGE * (randf() - randf());
11799 }
11800
11801 HPVector exitposition = [UNIVERSE getWitchspaceExitPosition];
11802 exitposition.x += v1.x * d1; // randomise exit position
11803 exitposition.y += v1.y * d1;
11804 exitposition.z += v1.z * d1;
11805 [self setPosition:exitposition];
11806 [self witchspaceLeavingEffects];
11807}

References leaveWitchspace, quaternion_set_random(), randf(), SCANNER_MAX_RANGE, Entity::setPosition:, vector_forward_from_quaternion(), witchspaceLeavingEffects, HPVector::x, HPVector::y, and HPVector::z.

Referenced by coordinates, leaveWitchspace, and Universe::witchspaceShipWithPrimaryRole:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ legalStatus

- (int) legalStatus

Definition at line 7155 of file ShipEntity.m.

7156{
7157 if (scanClass == CLASS_THARGOID)
7158 return 5 * collision_radius;
7159 if (scanClass == CLASS_ROCK)
7160 return 0;
7161 return (int)[self bounty];
7162}

References bounty, Entity::collision_radius, int(), legalStatus, and scanClass.

Referenced by bounty, ShipEntity(PureAI)::checkOwnLegalStatus, ShipEntity(PureAI)::checkTargetLegalStatus, StationEntity::dockingInstructionsForShip:, equipmentValidToAdd:whileLoading:inContext:, launchEscapeCapsule, legalStatus, markForFines, scanDescription, ShipEntity(PureAI)::scanForOffenders, and scoopUpProcess:processEvents:processMessages:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lightsActive

- (BOOL) lightsActive

Definition at line 11898 of file ShipEntity.m.

11899{
11900 return _lightsActive;
11901}
unsigned _lightsActive
Definition ShipEntity.h:271

References _lightsActive, and lightsActive.

Referenced by coordinates, and lightsActive.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lookingAtSunWithThresholdAngleCos:

- (GLfloat) lookingAtSunWithThresholdAngleCos: (GLfloat) thresholdAngleCos

Reimplemented in PlayerEntity.

Definition at line 9822 of file ShipEntity.m.

9822 :(GLfloat)thresholdAngleCos
9823{
9824 OOSunEntity* sun = [UNIVERSE sun];
9825 GLfloat measuredCos = 999.0f, measuredCosAbs;
9826 GLfloat sunBrightness = 0.0f;
9827 Vector relativePosition, unitRelativePosition;
9828
9829 if (EXPECT_NOT(!sun))
9830 return 0.0f;
9831
9833 unitRelativePosition = vector_normal_or_zbasis(relativePosition);
9834 switch (currentWeaponFacing) {
9836 measuredCos = -dot_product(unitRelativePosition, v_forward);
9837 break;
9838 case WEAPON_FACING_AFT:
9839 measuredCos = +dot_product(unitRelativePosition, v_forward);
9840 break;
9841 case WEAPON_FACING_PORT:
9842 measuredCos = +dot_product(unitRelativePosition, v_right);
9843 break;
9845 measuredCos = -dot_product(unitRelativePosition, v_right);
9846 break;
9847 default:
9848 break;
9849 }
9850 measuredCosAbs = fabs(measuredCos);
9851 if (thresholdAngleCos <= measuredCosAbs && measuredCosAbs <= 1.0f) // angle from viewpoint to sun <= desired threshold
9852 {
9853 sunBrightness = (measuredCos - thresholdAngleCos) / (1.0f - thresholdAngleCos);
9854 if (sunBrightness < 0.0f)
9855 sunBrightness = 0.0f;
9856 }
9857 return sunBrightness * sunBrightness * sunBrightness;
9858}
Vector relativePosition()
Definition Entity.m:598

References currentWeaponFacing, dot_product(), EXPECT_NOT, HPvector_subtract(), HPVectorToVector(), Entity::position, Entity::relativePosition, v_forward, v_right, vector_normal_or_zbasis(), WEAPON_FACING_AFT, WEAPON_FACING_FORWARD, WEAPON_FACING_PORT, and WEAPON_FACING_STARBOARD.

Referenced by currentAimTolerance.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ manageCollisions

- (void) manageCollisions

Definition at line 11000 of file ShipEntity.m.

11001{
11002 // deal with collisions
11003 //
11004 Entity* ent;
11005 ShipEntity* other_ship;
11006
11007 while ([collidingEntities count] > 0) {
11008 // EMMSTRAN: investigate if doing this backwards would be more efficient. (Not entirely obvious, NSArray is kinda funky.) -- Ahruman 2011-02-12
11009 ent = [[[collidingEntities objectAtIndex:0] retain] autorelease];
11010 [collidingEntities removeObjectAtIndex:0];
11011 if (ent) {
11012 if ([ent isShip]) {
11013 other_ship = (ShipEntity*)ent;
11014 [self collideWithShip:other_ship];
11015 } else if ([ent isStellarObject]) {
11016 [self getDestroyedBy:ent damageType:[ent isSun] ? kOODamageTypeHitASun : kOODamageTypeHitAPlanet];
11017 if (self == PLAYER)
11018 [self retain];
11019 } else if ([ent isWormhole]) {
11020 if ([self isPlayer])
11021 [self enterWormhole:(WormholeEntity*)ent];
11022 else
11023 [self enterWormhole:(WormholeEntity*)ent replacing:NO];
11024 }
11025 }
11026 }
11027}
BOOL isStellarObject()
Definition Entity.m:165

References collideWithShip:, Entity::collidingEntities, count, enterWormhole:, enterWormhole:replacing:, Entity::isPlayer, Entity::isShip, Entity::isStellarObject, Entity::isSun, Entity::isWormhole, manageCollisions, and PLAYER.

Referenced by coordinates, manageCollisions, PlayerEntity::update:, and update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ markAsOffender:

- (void) markAsOffender: (int) offence_value

Reimplemented in PlayerEntity.

Definition at line 11836 of file ShipEntity.m.

11836 :(int)offence_value
11837{
11838 [self markAsOffender:offence_value withReason:kOOLegalStatusReasonUnknown];
11839}

References markAsOffender:withReason:.

Here is the call graph for this function:

◆ markAsOffender:withReason:

- (void) markAsOffender: (int) offence_value
withReason: (OOLegalStatusReason) reason 

Reimplemented in PlayerEntity.

Definition at line 11841 of file ShipEntity.m.

11841 :(int)offence_value withReason:(OOLegalStatusReason)reason
11842{
11843 if (![self isPolice] && ![self isCloaked] && self != [UNIVERSE station]) {
11844 if ([self isSubEntity]) {
11845 [[self parentEntity] markAsOffender:offence_value withReason:reason];
11846 } else {
11847 if ((scanClass == CLASS_THARGOID || scanClass == CLASS_STATION) && reason != kOOLegalStatusReasonSetup && reason != kOOLegalStatusReasonByScript) {
11848 return; // no non-scripted bounties for thargoids and stations
11849 }
11850
11851 JSContext* context = OOJSAcquireContext();
11852
11853 OOJSVal amountVal = OOJSValueFromDouble(context, (bounty | offence_value) - bounty);
11854
11855 bounty |= offence_value; // can't set the new bounty until the size of the change is known
11856
11857 OOJSVal reasonVal = OOJSValueFromLegalStatusReason(context, reason);
11858
11859 ShipScriptEvent(context, self, "shipBountyChanged", amountVal, reasonVal);
11860
11861 OOJSRelinquishContext(context);
11862 }
11863 }
11864}
OOINLINE jsval OOJSValueFromLegalStatusReason(JSContext *context, OOLegalStatusReason value)
OOLegalStatusReason
Definition OOTypes.h:139
#define ShipScriptEvent(context, ship, event,...)

References bounty, isCloaked, isPolice, Entity::isSubEntity, markAsOffender:withReason:, OOJSAcquireContext(), OOJSRelinquishContext(), OOJSValueFromDouble(), OOJSValueFromLegalStatusReason(), Entity::parentEntity, scanClass, ShipScriptEvent, and UNIVERSE.

Referenced by StationEntity(OOAIPrivate)::acceptDistressMessageFrom:, collectBountyFor:, ShipEntity(PureAI)::fightOrFleeMissile, markAsOffender:, markAsOffender:withReason:, ShipEntity(PureAI)::markTargetForOffence:, ShipEntity(Private)::setUpOneEscort:inGroup:withRole:atPosition:andCount:, ShipEntity(AI)::suggestEscortTo:, takeEnergyDamage:from:becauseOf:weaponIdentifier:, and StationEntity::takeEnergyDamage:from:becauseOf:weaponIdentifier:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ markedForFines

- (BOOL) markedForFines

Definition at line 12438 of file ShipEntity.m.

12439{
12440 return being_fined;
12441}
unsigned being_fined
Definition ShipEntity.h:248

References being_fined, and markedForFines.

Referenced by markedForFines, and sunGlareFilter.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ markForFines

- (BOOL) markForFines

Definition at line 12443 of file ShipEntity.m.

12444{
12445 if (being_fined)
12446 return NO; // can't mark twice
12447 being_fined = ([self legalStatus] > 0);
12448 return being_fined;
12449}

References being_fined, legalStatus, and markForFines.

Referenced by PlayerEntity(OOControlsPrivate)::handleAutopilotOn:, markForFines, ShipMarkTargetForFines(), ShipMarkTargetForFines(), and sunGlareFilter.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ markTargetForFines

- (void) markTargetForFines
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1814 of file ShipEntityAI.m.

1815{
1816 ShipEntity* ship = [self primaryTarget];
1817 if ((ship == nil) || ([ship status] == STATUS_DEAD) || ([ship status] == STATUS_DOCKED)) {
1818 [self noteLostTarget];
1819 return;
1820 }
1821 if ([ship markForFines])
1822 [shipAI message:@"TARGET_MARKED"];
1823}
BOOL markForFines()

◆ markTargetForOffence:

- (void) markTargetForOffence: (NSString*) valueString
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1825 of file ShipEntityAI.m.

1825 :(NSString*)valueString
1826{
1827 if ((isStation) || (scanClass == CLASS_POLICE)) {
1828 ShipEntity* ship = [self primaryTarget];
1829 if ((ship == nil) || ([ship status] == STATUS_DEAD) || ([ship status] == STATUS_DOCKED)) {
1830 [self noteLostTarget];
1831 return;
1832 }
1833 NSString* finalValue = OOExpand(valueString); // expand values
1834 [ship markAsOffender:[finalValue intValue] withReason:kOOLegalStatusReasonSeenByPolice];
1835 }
1836}

◆ maxAftShieldLevel

- (float) maxAftShieldLevel

Reimplemented in PlayerEntity.

Definition at line 3646 of file ShipEntity.m.

3647{
3648 return BASELINE_SHIELD_LEVEL * [self shieldBoostFactor];
3649}
#define BASELINE_SHIELD_LEVEL
Definition ShipEntity.h:101

References BASELINE_SHIELD_LEVEL, maxAftShieldLevel, and shieldBoostFactor.

Referenced by isFrangible, and maxAftShieldLevel.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ maxAvailableCargoSpace

◆ maxEscortCount

- (uint8_t) maxEscortCount

Definition at line 6075 of file ShipEntity.m.

6076{
6077 return _maxEscortCount;
6078}

References _maxEscortCount, and maxEscortCount.

Referenced by maxEscortCount, and messageTime.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ maxFlightPitch

- (GLfloat) maxFlightPitch

Definition at line 7514 of file ShipEntity.m.

7515{
7516 return max_flight_pitch;
7517}

References max_flight_pitch, and maxFlightPitch.

Referenced by flightSpeed, maxFlightPitch, and OOShipLibraryTurnRate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ maxFlightRoll

- (GLfloat) maxFlightRoll

Definition at line 7524 of file ShipEntity.m.

7525{
7526 return max_flight_roll;
7527}

References max_flight_roll, and maxFlightRoll.

Referenced by maxFlightRoll, maxFlightSpeed, and OOShipLibraryTurnRate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ maxFlightSpeed

◆ maxFlightYaw

- (GLfloat) maxFlightYaw

Definition at line 7529 of file ShipEntity.m.

7530{
7531 return max_flight_yaw;
7532}

References max_flight_yaw, and maxFlightYaw.

Referenced by maxFlightSpeed, and maxFlightYaw.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ maxForwardShieldLevel

- (float) maxForwardShieldLevel

Reimplemented in PlayerEntity.

Definition at line 3641 of file ShipEntity.m.

3642{
3643 return BASELINE_SHIELD_LEVEL * [self shieldBoostFactor];
3644}

References BASELINE_SHIELD_LEVEL, maxForwardShieldLevel, and shieldBoostFactor.

Referenced by isFrangible, and maxForwardShieldLevel.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ maxHyperspaceDistance

- (double) maxHyperspaceDistance

Definition at line 3656 of file ShipEntity.m.

3657{
3658 return MAX_JUMP_RANGE;
3659}
#define MAX_JUMP_RANGE
Definition ShipEntity.h:109

References MAX_JUMP_RANGE, and maxHyperspaceDistance.

Referenced by isFrangible, maxHyperspaceDistance, and PlayerEntity::witchJumpChecklist:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ maxShipSubEntities

- (NSUInteger) maxShipSubEntities

Definition at line 734 of file ShipEntity.m.

735{
736 return _maxShipSubIdx;
737}
NSUInteger _maxShipSubIdx
Definition ShipEntity.h:332

References _maxShipSubIdx, and maxShipSubEntities.

Referenced by PlayerEntity::canAddEquipment:inContext:, maxShipSubEntities, PlayerEntity(Contracts)::missingSubEntitiesAdjustment, serializeShipSubEntities, and subEntities.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ maxThrust

- (float) maxThrust

Definition at line 3681 of file ShipEntity.m.

3682{
3683 return max_thrust;
3684}
GLfloat max_thrust
Definition ShipEntity.h:234

References max_thrust, and maxThrust.

Referenced by behaviour_tractored:, dumpItem:, isFrangible, maxThrust, releaseCargoPodsDebris, ShipSetProperty(), and ShipSetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mesh

- (OOMesh *) mesh

Definition at line 1145 of file ShipEntity.m.

1146{
1147 return (OOMesh*)[self drawable];
1148}

References OOEntityWithDrawable::drawable, and mesh.

Referenced by accuracy, PlayerEntity::doBookkeeping:, findBoundingBoxRelativeToPosition:i:j:k:, findSubentityBoundingBox, PlayerEntity::launchEscapeCapsule, mesh, setEntityPersonalityInt:, setMesh:, PlayerEntity::setUpTrumbles, ShipSetMaterialsInternal(), and ShipSetMaterialsInternal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ messageMother:

- (void) messageMother: (NSString*) msgString
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1652 of file ShipEntityAI.m.

1652 :(NSString*)msgString
1653{
1654 ShipEntity* mother = [self owner];
1655 if (mother != nil && mother != self) {
1656 NSString* context = nil;
1657#ifndef NDEBUG
1658 context = [NSString stringWithFormat:@"%@ messageMother", [self shortDescription]];
1659#endif
1660 [mother reactToAIMessage:msgString
1661 context:context];
1662 }
1663}

◆ messageSelf:

- (void) messageSelf: (NSString*) msgString
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1665 of file ShipEntityAI.m.

1665 :(NSString*)msgString
1666{
1667 [self sendAIMessage:msgString];
1668}

◆ messageTime

- (double) messageTime

References escortArray, escortCount, escortEnumerator, escortGroup, group, hasEscorts, maxEscortCount, messageTime, pendingEscortCount, stationGroup, and turretCount.

Here is the call graph for this function:

◆ missedShots

- (int) missedShots

Definition at line 10489 of file ShipEntity.m.

10490{
10491 if ([self isSubEntity]) {
10492 return [[self owner] missedShots];
10493 } else {
10494 return _missed_shots;
10495 }
10496}

References _missed_shots, int(), Entity::isSubEntity, missedShots, and Entity::owner.

Referenced by coordinates, currentAimTolerance, missedShots, and trackPrimaryTarget:retreat:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ missileCapacity

- (NSUInteger) missileCapacity

Definition at line 3521 of file ShipEntity.m.

3522{
3523 return max_missiles;
3524}

References max_missiles, and missileCapacity.

Referenced by equipmentValidToAdd:whileLoading:inContext:, isFrangible, missileCapacity, PlayerEntity::mountMissileWithRole:, and OOShipLibraryWeapons().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ missileCount

- (NSUInteger) missileCount

Definition at line 3516 of file ShipEntity.m.

3517{
3518 return missiles;
3519}

References missileCount, and missiles.

Referenced by equipmentValidToAdd:whileLoading:inContext:, isFrangible, missileCount, PlayerEntity::mountMissileWithRole:, and PlayerEntity::setCommanderDataFromDictionary:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ missileLaunchPosition

- (Vector) missileLaunchPosition

Definition at line 10543 of file ShipEntity.m.

10544{
10545 Vector start;
10546 // default launching position
10547 start.x = 0.0f; // in the middle
10548 start.y = boundingBox.min.y - 4.0f; // 4m below bounding box
10549 start.z = boundingBox.max.z + 1.0f; // 1m ahead of bounding box
10550
10551 // custom launching position
10552 start = [shipinfoDictionary oo_vectorForKey:@"missile_launch_position" defaultValue:start];
10553 if (EXPECT_NOT(_scaleFactor != 1.0)) {
10554 start = vector_multiply_scalar(start, _scaleFactor);
10555 }
10556
10557 if (start.x == 0.0f && start.y == 0.0f && start.z <= 0.0f) // The kZeroVector as start is illegal also.
10558 {
10559 OOLog(@"ship.missileLaunch.invalidPosition", @"***** ERROR: The missile_launch_position defines a position %@ behind the %@. In future versions such missiles may explode on launch because they have to travel through the ship.", VectorDescription(start), self);
10560 start.x = 0.0f;
10561 start.y = boundingBox.min.y - 4.0f;
10562 start.z = boundingBox.max.z + 1.0f;
10563 }
10564 return start;
10565}

References _scaleFactor, Entity::boundingBox, EXPECT_NOT, missileLaunchPosition, OOLog, vector_multiply_scalar(), Vector::x, Vector::y, and Vector::z.

Referenced by coordinates, PlayerEntity::fireMissile, fireMissileWithIdentifier:andTarget:, and missileLaunchPosition.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ missileLoadTime

- (OOTimeDelta) missileLoadTime

Definition at line 10712 of file ShipEntity.m.

10713{
10714 return missile_load_time;
10715}

References missile_load_time, and missileLoadTime.

Referenced by coordinates, and missileLoadTime.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ missilesList

- (NSArray *) missilesList

Reimplemented in PlayerEntity.

Definition at line 2950 of file ShipEntity.m.

2951{
2952 // if missile_list is empty, avoid exception and return empty NSArray instead
2953 return missile_list[0] != nil ? [NSArray arrayWithObjects:missile_list count:missiles] : [NSArray array];
2954}

References missile_list, missilesList, and nil.

Referenced by cargo, PlayerEntity::missilesList, missilesList, ShipGetProperty(), and ShipGetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ missileTrackPrimaryTarget:

- (double) missileTrackPrimaryTarget: (double) delta_t

Definition at line 9365 of file ShipEntity.m.

9365 :(double)delta_t
9366{
9367 Vector relPos;
9368 GLfloat d_forward, d_up, d_right;
9369 ShipEntity* target = [self primaryTarget];
9370 BOOL inPursuit = YES;
9371
9372 if (!target || ![target isShip]) // leave now!
9373 return 0.0;
9374
9375 double damping = 0.5 * delta_t;
9376
9377 stick_roll = 0.0; // desired roll and pitch
9378 stick_pitch = 0.0;
9379 stick_yaw = 0.0;
9380
9381 relPos = [self vectorTo:target];
9382
9383 // Adjust missile course by taking into account target's velocity and missile
9384 // accuracy. Modification on original code contributed by Cmdr James.
9385
9386 float missileSpeed = (float)[self speed];
9387
9388 // Avoid getting ourselves in a divide by zero situation by setting a missileSpeed
9389 // low threshold. Arbitrarily chosen 0.01, since it seems to work quite well.
9390 // Missile accuracy is already clamped within the 0.0 to 10.0 range at initialization,
9391 // but doing these calculations every frame when accuracy equals 0.0 just wastes cycles.
9392 if (missileSpeed > 0.01f && accuracy > 0.0f) {
9393 inPursuit = (dot_product([target forwardVector], v_forward) > 0.0f);
9394 if (inPursuit) {
9395 Vector leading = [target velocity];
9396 float lead = magnitude(relPos) / missileSpeed;
9397
9398 // Adjust where we are going to take into account target's velocity.
9399 // Use accuracy value to determine how well missile will track target.
9400 relPos.x += (lead * leading.x * (accuracy / 10.0f));
9401 relPos.y += (lead * leading.y * (accuracy / 10.0f));
9402 relPos.z += (lead * leading.z * (accuracy / 10.0f));
9403 }
9404 }
9405
9406 if (!vector_equal(relPos, kZeroVector))
9407 relPos = vector_normal(relPos);
9408 else
9409 relPos.z = 1.0;
9410
9411 d_right = dot_product(relPos, v_right); // = cosine of angle between angle to target and v_right
9412 d_up = dot_product(relPos, v_up); // = cosine of angle between angle to target and v_up
9413 d_forward = dot_product(relPos, v_forward); // = cosine of angle between angle to target and v_forward
9414
9415 // begin rule-of-thumb manoeuvres
9416
9417 stick_roll = 0.0;
9418
9419 if (pitching_over)
9420 pitching_over = (stick_pitch != 0.0);
9421
9422 if ((d_forward < -pitch_tolerance) && (!pitching_over)) {
9423 pitching_over = YES;
9424 if (d_up >= 0)
9426 if (d_up < 0)
9428 }
9429
9430 if (pitching_over) {
9431 pitching_over = (d_forward < 0.5);
9432 } else {
9433 stick_pitch = -max_flight_pitch * d_up;
9434 stick_roll = -max_flight_roll * d_right;
9435 }
9436
9437 // end rule-of-thumb manoeuvres
9438
9439 // apply damping
9440 if (flightRoll < 0)
9441 flightRoll += (flightRoll < -damping) ? damping : -flightRoll;
9442 if (flightRoll > 0)
9443 flightRoll -= (flightRoll > damping) ? damping : flightRoll;
9444 if (flightPitch < 0)
9445 flightPitch += (flightPitch < -damping) ? damping : -flightPitch;
9446 if (flightPitch > 0)
9447 flightPitch -= (flightPitch > damping) ? damping : flightPitch;
9448
9449 [self applySticks:delta_t];
9450
9451 //
9452 // return target confidence 0.0 .. 1.0
9453 //
9454 if (d_forward < 0.0)
9455 return 0.0;
9456 return d_forward;
9457}
OOINLINE bool vector_equal(Vector a, Vector b) INLINE_CONST_FUNC
Definition OOVector.h:232
Vector forwardVector()
GLfloat pitch_tolerance
Definition ShipEntity.h:363

References accuracy, applySticks:, dot_product(), flightPitch, flightRoll, forwardVector, Entity::isShip, kZeroVector, magnitude(), max_flight_pitch, max_flight_roll, pitch_tolerance, pitching_over, primaryTarget, Entity::speed, stick_pitch, stick_roll, stick_yaw, v_forward, v_right, v_up, vector_equal(), vector_normal(), Entity::vectorTo:, Entity::velocity, Vector::x, Vector::y, and Vector::z.

Referenced by trackPrimaryTarget:retreat:, and trackSideTarget:leftside:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ name

- (NSString *) name

References name.

◆ nextBeacon

- (Entity< OOBeaconEntity > *) nextBeacon
implementation

Reimplemented from <OOBeaconEntity>.

Definition at line 1481 of file ShipEntity.m.

1482{
1483 return [_nextBeacon weakRefUnderlyingObject];
1484}

References nextBeacon, and OOWeakReference::weakRefUnderlyingObject.

Referenced by nextBeacon, setNextBeacon:, PlayerEntity::setNextCompassMode, PlayerEntity::setPrevCompassMode, and PlayerEntity::validateCompassTarget.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ noteFrustration:

- (void) noteFrustration: (NSString*) context
implementation

Provided by category ShipEntity(Private).

Definition at line 2641 of file ShipEntity.m.

2641 :(NSString*)context
2642{
2643 [shipAI reactToMessage:@"FRUSTRATED" context:context];
2644 [self doScriptEvent:OOJSID("shipAIFrustrated") withArgument:context];
2645}

References doScriptEvent:withArgument:.

Referenced by behaviour_attack_broadside_target:leftside:, behaviour_attack_fly_to_target:, behaviour_attack_sniper:, behaviour_face_destination:, behaviour_flee_target:, behaviour_fly_thru_navpoints:, behaviour_fly_to_destination:, behaviour_formation_form_up:, and behaviour_intercept_target:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ noteKilledBy:damageType:

- (void) noteKilledBy: (Entity*) whom
damageType: (OOShipDamageType) type 

Definition at line 7752 of file ShipEntity.m.

7752 :(Entity*)whom damageType:(OOShipDamageType)type
7753{
7754 if ([self status] == STATUS_DEAD)
7755 return;
7756
7757 [PLAYER setScriptTarget:self];
7758
7759 JSContext* context = OOJSAcquireContext();
7760
7761 OOJSVal whomVal = OOJSValueFromNativeObject(context, whom);
7762 OOJSVal typeVal = OOJSValueFromShipDamageType(context, type);
7763 OOEntityStatus originalStatus = [self status];
7764 [self setStatus:STATUS_DEAD];
7765
7766 ShipScriptEvent(context, self, "shipDied", whomVal, typeVal); // Frees whomVal and typeVal.
7767 if ([whom isShip]) {
7768 OOJSVal selfVal = OOJSValueFromNativeObject(context, self);
7769 typeVal = OOJSValueFromShipDamageType(context, type);
7770 ShipScriptEvent(context, (ShipEntity*)whom, "shipKilledOther", selfVal, typeVal);
7771 }
7772
7773 [self setStatus:originalStatus];
7774 OOJSRelinquishContext(context);
7775}
OOINLINE jsval OOJSValueFromShipDamageType(JSContext *context, OOShipDamageType value)

References Entity::isShip, OOJSAcquireContext(), OOJSRelinquishContext(), OOJSValueFromNativeObject(), OOJSValueFromShipDamageType(), setStatus:, ShipScriptEvent, and Entity::status.

Referenced by becomeEnergyBlast, PlayerEntity::getDestroyedBy:damageType:, and getDestroyedBy:damageType:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ noteLostTarget

- (void) noteLostTarget

Definition at line 8783 of file ShipEntity.m.

8784{
8785 id target = nil;
8786 if ([self primaryTarget] != nil) {
8787 ShipEntity* ship = [self primaryTarget];
8788 if ([self isDefenseTarget:ship]) {
8789 [self removeDefenseTarget:ship];
8790 }
8791 // for compatibility with 1.76 behaviour of this function, only pass
8792 // the target as a function parameter if the target is still a potential
8793 // valid target (e.g. not scooped, docked, hyperspaced, etc.)
8794 target = (ship && ship->isShip && [self isValidTarget:ship]) ? (id)ship : nil;
8795 if ([self primaryAggressor] == ship) {
8797 }
8799 }
8800 // always do target lost
8801 [self doScriptEvent:OOJSID("shipTargetLost") withArgument:target];
8802 if (target == nil)
8803 [shipAI message:@"TARGET_LOST"]; // stale target? no major urgency.
8804 else
8805 [shipAI reactToMessage:@"TARGET_LOST" context:@"flight updates"]; // execute immediately otherwise.
8806}
OOWeakReference * _primaryAggressor
Definition ShipEntity.h:426

References _primaryAggressor, _primaryTarget, DESTROY, doScriptEvent:withArgument:, Entity::isShip, isValidTarget:, AI::message:, nil, noteLostTarget, primaryAggressor, primaryTarget, AI::reactToMessage:context:, and removeDefenseTarget:.

Referenced by getTractoredBy:, PlayerEntity(OOControlsPrivate)::handleButtonIdent, PlayerEntity(OOControlsPrivate)::handleButtonTargetMissile, StationEntity::launchDefenseShip, StationEntity::launchPirateShip, StationEntity::launchPolice, PlayerEntity::loseTargetStatus, ShipEntity(PureAI)::markTargetForFines, ShipEntity(PureAI)::markTargetForOffence:, maxFlightSpeed, noteLostTarget, noteLostTargetAndGoIdle, PlayerEntity(OOControlsPrivate)::pollFlightControls:, removeTarget:, scoopUpProcess:processEvents:processMessages:, PlayerEntity::selectNextMissile, ShipEntity(PureAI)::sendTargetCommsMessage:, update:, PlayerEntity(OOPrivate)::updateTargeting, and PlayerEntity(OOPrivate)::witchStart.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ noteLostTargetAndGoIdle

- (void) noteLostTargetAndGoIdle

Definition at line 8808 of file ShipEntity.m.

8809{
8810 behaviour = BEHAVIOUR_IDLE;
8811 frustration = 0.0;
8812 [self noteLostTarget];
8813}

References behaviour, frustration, noteLostTarget, and noteLostTargetAndGoIdle.

Referenced by behaviour_attack_break_off_target:, behaviour_attack_broadside:, behaviour_attack_broadside_target:leftside:, behaviour_attack_fly_from_target:, behaviour_attack_fly_to_target:, behaviour_attack_mining_target:, behaviour_attack_slow_dogfight:, behaviour_attack_sniper:, behaviour_close_to_broadside_range:, behaviour_close_with_target:, behaviour_flee_target:, behaviour_fly_to_target_six:, behaviour_intercept_target:, behaviour_running_defense:, behaviour_track_target:, evasiveAction:, maxFlightSpeed, noteLostTargetAndGoIdle, ShipEntity(AI)::performMining, trackPrimaryTarget:retreat:, and trackSideTarget:leftside:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ noteTakingDamage:from:type:

- (void) noteTakingDamage: (double) amount
from: (Entity*) entity
type: (OOShipDamageType) type 

Reimplemented in DockEntity.

Definition at line 7723 of file ShipEntity.m.

7723 :(double)amount from:(Entity*)entity type:(OOShipDamageType)type
7724{
7725 if (amount < 0 || (amount == 0 && [[UNIVERSE gameController] isGamePaused]))
7726 return;
7727
7728 JSContext* context = OOJSAcquireContext();
7729
7730 OOJSVal amountVal = OOJSValueFromDouble(context, amount);
7731 OOJSVal entityVal = OOJSValueFromNativeObject(context, entity);
7732 OOJSVal typeVal = OOJSValueFromShipDamageType(context, type);
7733
7734 ShipScriptEvent(context, self, "shipTakingDamage", amountVal, entityVal, typeVal);
7735 OOJSRelinquishContext(context);
7736
7737 if ([entity isShip]) {
7738 // ShipEntity* attacker = (ShipEntity *)entity;
7739 if ([self hasHostileTarget] && accuracy >= COMBAT_AI_IS_SMART && (randf() * 10.0 < accuracy || desired_speed < 0.5 * maxFlightSpeed) && behaviour != BEHAVIOUR_EVASIVE_ACTION && behaviour != BEHAVIOUR_FLEE_EVASIVE_ACTION && behaviour != BEHAVIOUR_SCRIPTED_ATTACK_AI) {
7740 if (behaviour == BEHAVIOUR_FLEE_TARGET) {
7741 // jink should be sufficient to avoid being hit most of the time
7742 // if not, this will make a sharp turn and then select a new jink position
7743 behaviour = BEHAVIOUR_FLEE_EVASIVE_ACTION;
7744 } else {
7745 behaviour = BEHAVIOUR_EVASIVE_ACTION;
7746 }
7747 frustration = 0.0;
7748 }
7749 }
7750}

References accuracy, behaviour, COMBAT_AI_IS_SMART, desired_speed, frustration, hasHostileTarget, Entity::isShip, maxFlightSpeed, OOJSAcquireContext(), OOJSRelinquishContext(), OOJSValueFromDouble(), OOJSValueFromNativeObject(), OOJSValueFromShipDamageType(), randf(), ShipScriptEvent, and UNIVERSE.

Referenced by DockEntity::noteTakingDamage:from:type:, PlayerEntity::takeEnergyDamage:from:becauseOf:weaponIdentifier:, takeEnergyDamage:from:becauseOf:weaponIdentifier:, takeHeatDamage:, and takeScrapeDamage:from:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ noteTargetDestroyed:

- (void) noteTargetDestroyed: (ShipEntity*) target

Definition at line 8815 of file ShipEntity.m.

8815 :(ShipEntity*)target
8816{
8817 [self collectBountyFor:(ShipEntity*)target];
8818 if ([self primaryTarget] == target) {
8819 [self removeTarget:target];
8820 [self doScriptEvent:OOJSID("shipTargetDestroyed") withArgument:target];
8821 [shipAI message:@"TARGET_DESTROYED"];
8822 }
8823 if ([self isDefenseTarget:target]) {
8824 [self removeDefenseTarget:target];
8825 [shipAI message:@"DEFENSE_TARGET_DESTROYED"];
8826 [self doScriptEvent:OOJSID("defenseTargetDestroyed") withArgument:target];
8827 }
8828}

References collectBountyFor:, doScriptEvent:withArgument:, AI::message:, primaryTarget, removeDefenseTarget:, and removeTarget:.

Referenced by PlayerEntity::takeEnergyDamage:from:becauseOf:weaponIdentifier:, takeEnergyDamage:from:becauseOf:weaponIdentifier:, and takeScrapeDamage:from:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ noticeECM

- (void) noticeECM

Reimplemented in PlayerEntity.

Definition at line 10723 of file ShipEntity.m.

10724{
10725 if (accuracy >= COMBAT_AI_ISNT_AWFUL && missiles > 0 && [[missile_list[0] identifier] isEqualTo:@"EQ_MISSILE"]) {
10726 // if we're being ECMd, and our missiles appear to be standard, and we
10727 // have some combat sense, wait a bit before firing the next one!
10728 missile_launch_time = [UNIVERSE getTime] + fmax(2.0, missile_load_time); // set minimum launchtime for the next missile.
10729 }
10730}

References accuracy, COMBAT_AI_ISNT_AWFUL, missile_launch_time, missile_list, missile_load_time, missiles, and noticeECM.

Referenced by coordinates, noticeECM, and OOECMBlastEntity::update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ numberOfScannedShips

- (int) numberOfScannedShips

Definition at line 8543 of file ShipEntity.m.

8544{
8545 return n_scanned_ships;
8546}

References int(), n_scanned_ships, and numberOfScannedShips.

Referenced by maxFlightSpeed, and numberOfScannedShips.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ octree

- (Octree *) octree

References absoluteTractorPosition, countsAsKill, frustumRadius, isBoulder, isMinable, octree, setUpEscorts, setUpSubEntities, shipDataKey, shipDataKeyAutoRole, shipInfoDictionary, updateEscortFormation, and volume.

Here is the call graph for this function:

◆ onTarget:withWeapon:

- (BOOL) onTarget: (OOWeaponFacing) direction
withWeapon: (OOWeaponType) weapon 

Definition at line 9860 of file ShipEntity.m.

9860 :(OOWeaponFacing)direction withWeapon:(OOWeaponType)weapon_type
9861{
9862 // initialize dq to a value that would normally return NO; dq is handled inside the defaultless switch(direction) statement
9863 // and should alaways be recalculated anyway. Initialization here needed to silence compiler warning - Nikos 20120526
9864 GLfloat dq = -1.0f;
9865 GLfloat d2, radius, astq;
9866 Vector rel_pos, urp;
9867 if ([weapon_type isTurretLaser]) {
9868 return YES;
9869 }
9870
9871 Entity* target = [self primaryTarget];
9872 if (target == nil)
9873 return NO;
9874 if ([target status] == STATUS_DEAD)
9875 return NO;
9876
9877 if (isSunlit && (target->isSunlit == NO) && (randf() < 0.75)) {
9878 return NO; // 3/4 of the time you can't see from a lit place into a darker place
9879 }
9880 radius = target->collision_radius;
9882 d2 = magnitude2(rel_pos);
9883 urp = vector_normal_or_zbasis(rel_pos);
9884
9885 switch (direction) {
9887 dq = +dot_product(urp, v_forward); // cosine of angle between v_forward and unit relative position
9888 break;
9889
9890 case WEAPON_FACING_AFT:
9891 dq = -dot_product(urp, v_forward); // cosine of angle between v_forward and unit relative position
9892 break;
9893
9894 case WEAPON_FACING_PORT:
9895 dq = -dot_product(urp, v_right); // cosine of angle between v_right and unit relative position
9896 break;
9897
9899 dq = +dot_product(urp, v_right); // cosine of angle between v_right and unit relative position
9900 break;
9901
9902 case WEAPON_FACING_NONE:
9903 break;
9904 }
9905
9906 if (dq < 0.0)
9907 return NO;
9908
9909 GLfloat aim = [self currentAimTolerance];
9910 if (dq > aim * aim)
9911 return YES;
9912
9913 // cosine of 1/3 of half angle subtended by target (mostly they'll
9914 // fire sooner anyway due to currentAimTolerance, but this should
9915 // almost always be a solid hit)
9916 astq = sqrt(1.0 - radius * radius / (d2 * 9));
9917
9918 return (fabs(dq) >= astq);
9919}
HPVector calculateTargetPosition()

References calculateTargetPosition, Entity::collision_radius, currentAimTolerance, dot_product(), HPvector_subtract(), HPVectorToVector(), Entity::isSunlit, magnitude2(), nil, Entity::position, primaryTarget, randf(), Entity::status, v_forward, v_right, vector_normal_or_zbasis(), WEAPON_FACING_AFT, WEAPON_FACING_FORWARD, WEAPON_FACING_NONE, WEAPON_FACING_PORT, and WEAPON_FACING_STARBOARD.

Here is the call graph for this function:

◆ oo_jsClassID

- (JSClassID) oo_jsClassID
implementation

Reimplemented from Entity.

Reimplemented in DockEntity, PlayerEntity, and StationEntity.

Provided by category ShipEntity(OOJavaScriptExtensions).

Definition at line 103 of file EntityOOJavaScriptExtensions.m.

104{
105 return JSShipClassID();
106}
JSClassID JSShipClassID(void)
Definition OOJSShip.m:576

◆ oo_jsClassName

- (NSString *) oo_jsClassName
implementation

Reimplemented from Entity.

Reimplemented in DockEntity, PlayerEntity, and StationEntity.

Provided by category ShipEntity(OOJavaScriptExtensions).

Definition at line 116 of file EntityOOJavaScriptExtensions.m.

117{
118 return @"Ship";
119}

◆ orientationChanged

- (void) orientationChanged
implementation

Reimplemented from Entity.

Reimplemented in PlayerEntity.

Definition at line 5865 of file ShipEntity.m.

5866{
5867 [super orientationChanged];
5868
5872}
Vector vector_up_from_quaternion(Quaternion quat) CONST_FUNC
Vector vector_right_from_quaternion(Quaternion quat) CONST_FUNC

References Entity::orientation, Entity::orientationChanged, orientationChanged, v_forward, v_right, v_up, vector_forward_from_quaternion(), vector_right_from_quaternion(), and vector_up_from_quaternion().

Referenced by applyRoll:andClimb:, applyRoll:climb:andYaw:, ballTrackLeadingTarget:atTarget:, orientationChanged, and trackOntoTarget:withDForward:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ overrideScriptInfo:

- (void) overrideScriptInfo: (NSDictionary*) override

Definition at line 12733 of file ShipEntity.m.

12733 :(NSDictionary*)override
12734{
12735 if (scriptInfo == nil)
12736 scriptInfo = [override retain];
12737 else if (override != nil) {
12738 NSMutableDictionary* newInfo = [NSMutableDictionary dictionaryWithDictionary:scriptInfo];
12739 [newInfo addEntriesFromDictionary:override];
12740 [scriptInfo release];
12741 scriptInfo = [newInfo copy];
12742 }
12743}
NSDictionary * scriptInfo

References nil, and scriptInfo.

Referenced by setUpOneStandardSubentity:asTurret:.

Here is the caller graph for this function:

◆ parcelCount

- (NSUInteger) parcelCount

Reimplemented in PlayerEntity.

Definition at line 3501 of file ShipEntity.m.

3502{
3503 return 0;
3504}

References parcelCount.

Referenced by isFrangible, and parcelCount.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parcelListForScripting

- (NSArray *) parcelListForScripting

Reimplemented in PlayerEntity.

Definition at line 2961 of file ShipEntity.m.

2962{
2963 return [NSArray array];
2964}

References parcelListForScripting.

Referenced by cargo, parcelListForScripting, ShipGetProperty(), and ShipGetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ passengerCapacity

- (NSUInteger) passengerCapacity

Reimplemented in PlayerEntity.

Definition at line 3511 of file ShipEntity.m.

3512{
3513 return 0;
3514}

References passengerCapacity.

Referenced by equipmentListForScripting, equipmentValidToAdd:whileLoading:inContext:, isFrangible, passengerCapacity, ShipRemoveEquipment(), and ShipRemoveEquipment().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ passengerCount

- (NSUInteger) passengerCount

Reimplemented in PlayerEntity.

Definition at line 3506 of file ShipEntity.m.

3507{
3508 return 0;
3509}

References passengerCount.

Referenced by equipmentValidToAdd:whileLoading:inContext:, isFrangible, and passengerCount.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ passengerListForScripting

- (NSArray *) passengerListForScripting

Reimplemented in PlayerEntity.

Definition at line 2956 of file ShipEntity.m.

2957{
2958 return [NSArray array];
2959}

References passengerListForScripting.

Referenced by cargo, passengerListForScripting, ShipGetProperty(), and ShipGetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ patrolReportIn

- (void) patrolReportIn
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1779 of file ShipEntityAI.m.

1780{
1781 // Set a report time in the patrolled station to delay a new launch.
1782 ShipEntity* the_station = [[self group] leader];
1783 if (!the_station || ![the_station isStation])
1784 the_station = [UNIVERSE station];
1786}
void acceptPatrolReportFrom:(ShipEntity *patrol_ship)

◆ pauseAI:

- (void) pauseAI: (NSString*) intervalString
implementation

Provided by category ShipEntity(PureAI).

Definition at line 757 of file ShipEntityAI.m.

757 :(NSString*)intervalString
758{
759 [shipAI setNextThinkTime:[UNIVERSE getTime] + [intervalString doubleValue]];
760}

◆ pendingEscortCount

- (uint8_t) pendingEscortCount

Definition at line 6065 of file ShipEntity.m.

6066{
6067 return _pendingEscortCount;
6068}
uint8_t _pendingEscortCount
Definition ShipEntity.h:455

References _pendingEscortCount, and pendingEscortCount.

Referenced by Universe::addShipAt:withRole:withinRadius:, StationEntity::launchIndependentShip:, DockEntity::launchShip:, messageTime, pendingEscortCount, PlayerEntity::showShipModelWithKey:shipData:personality:factorX:factorY:factorZ:inContext:, and Universe::witchspaceShipWithPrimaryRole:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ performAttack

- (void) performAttack

Provided by category ShipEntity(AI).

Definition at line 350 of file ShipEntityAI.m.

351{
352 if (behaviour != BEHAVIOUR_EVASIVE_ACTION) {
353 behaviour = BEHAVIOUR_ATTACK_TARGET;
354 desired_range = 1250 * randf() + 750; // 750 til 2000
355 frustration = 0.0;
356 }
357}

◆ performBuoyTumble

- (void) performBuoyTumble
implementation

Provided by category ShipEntity(AI).

Definition at line 458 of file ShipEntityAI.m.

459{
460 stick_roll = 0.10;
461 stick_pitch = 0.15;
462 behaviour = BEHAVIOUR_TUMBLE;
463 frustration = 0.0;
464}

◆ performCollect

- (void) performCollect

Provided by category ShipEntity(AI).

Definition at line 359 of file ShipEntityAI.m.

360{
361 behaviour = BEHAVIOUR_COLLECT_TARGET;
362 frustration = 0.0;
363}

◆ performEscort

- (void) performEscort

Provided by category ShipEntity(AI).

Definition at line 365 of file ShipEntityAI.m.

366{
367 if (behaviour != BEHAVIOUR_FORMATION_FORM_UP) {
368 behaviour = BEHAVIOUR_FORMATION_FORM_UP;
369 frustration = 0.0; // behavior changed, reset frustration.
370 }
371}

◆ performFaceDestination

- (void) performFaceDestination

Provided by category ShipEntity(AI).

Definition at line 373 of file ShipEntityAI.m.

374{
375 behaviour = BEHAVIOUR_FACE_DESTINATION;
376 frustration = 0.0;
377}

◆ performFlee

- (void) performFlee

Provided by category ShipEntity(AI).

Definition at line 379 of file ShipEntityAI.m.

380{
381 if (behaviour != BEHAVIOUR_FLEE_EVASIVE_ACTION) {
382 behaviour = BEHAVIOUR_FLEE_TARGET;
383 [self setEvasiveJink:400.0];
384 frustration = 0.0;
386 // alert! they've got us in their sights! react!!
387 if ([self approachAspectToPrimaryTarget] > 0.9995) {
388 behaviour = randf() < 0.15 ? BEHAVIOUR_EVASIVE_ACTION : BEHAVIOUR_FLEE_EVASIVE_ACTION;
389 }
390 }
391 }
392}

Referenced by ShipEntity(AI)::broadcastDistressMessageWithDumping:, and ShipEntity(PureAI)::fightOrFleeMissile.

Here is the caller graph for this function:

◆ performFlyRacepoints

- (void) performFlyRacepoints
implementation

Provided by category ShipEntity(PureAI).

Definition at line 2382 of file ShipEntityAI.m.

2383{
2386 behaviour = BEHAVIOUR_FLY_THRU_NAVPOINTS;
2387}

◆ performFlyToRangeFromDestination

- (void) performFlyToRangeFromDestination

Provided by category ShipEntity(AI).

Definition at line 394 of file ShipEntityAI.m.

395{
396 behaviour = BEHAVIOUR_FLY_RANGE_FROM_DESTINATION;
397 frustration = 0.0;
398}

◆ performHold

- (void) performHold

Provided by category ShipEntity(AI).

Definition at line 400 of file ShipEntityAI.m.

401{
402 desired_speed = 0.0;
403 behaviour = BEHAVIOUR_TRACK_TARGET;
404 frustration = 0.0;
405}

◆ performHyperSpaceExit

- (void) performHyperSpaceExit
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1408 of file ShipEntityAI.m.

1409{
1410 [self performHyperSpaceExitReplace:YES];
1411}

◆ performHyperSpaceExitReplace:

- (BOOL) performHyperSpaceExitReplace: (BOOL) replace
implementation

Provided by category ShipEntity(OOAIPrivate).

Definition at line 2402 of file ShipEntityAI.m.

2402 :(BOOL)replace
2403{
2404 return [self performHyperSpaceExitReplace:replace toSystem:-1];
2405}

Referenced by ShipEntity(PureAI)::performHyperSpaceExit, and ShipEntity(PureAI)::performHyperSpaceExitWithoutReplacing.

Here is the caller graph for this function:

◆ performHyperSpaceExitReplace:toSystem:

- (BOOL) performHyperSpaceExitReplace: (BOOL) replace
toSystem: (OOSystemID) systemID 
implementation

Provided by category ShipEntity(OOAIPrivate).

Definition at line 2407 of file ShipEntityAI.m.

2407 :(BOOL)replace toSystem:(OOSystemID)systemID
2408{
2409 if (![self hasHyperspaceMotor]) {
2410 [shipAI reactToMessage:@"WITCHSPACE UNAVAILABLE" context:@"performHyperSpaceExit"];
2411 return NO;
2412 }
2413 if ([self status] == STATUS_ENTERING_WITCHSPACE) {
2414 // already in a wormhole
2415 return NO;
2416 }
2417
2418 NSArray* sDests = nil;
2419 OOSystemID targetSystem;
2420 NSUInteger i = 0;
2421
2422 // get a list of destinations within range
2423 sDests = [UNIVERSE nearbyDestinationsWithinRange:0.1f * fuel];
2424 NSUInteger n_dests = [sDests count];
2425
2426 // if none available report to the AI and exit
2427 if (n_dests == 0) {
2428 [shipAI reactToMessage:@"WITCHSPACE UNAVAILABLE" context:@"performHyperSpaceExit"];
2429
2430 // If no systems exist near us, the AI is switched to a different state, so we do not need
2431 // the nearby destinations array anymore.
2432 return NO;
2433 }
2434
2435 // check if we're clear of nearby masses
2436 ShipEntity* blocker = [UNIVERSE entityForUniversalID:[self checkShipsInVicinityForWitchJumpExit]];
2437 if (blocker) {
2438 [self setFoundTarget:blocker];
2439 [shipAI reactToMessage:@"WITCHSPACE BLOCKED" context:@"performHyperSpaceExit"];
2440 [self doScriptEvent:OOJSID("shipWitchspaceBlocked") withArgument:blocker];
2441
2442 return NO;
2443 }
2444
2445 if (systemID == -1) {
2446 // select one at random
2447 if (n_dests > 1) {
2448 i = ranrot_rand() % n_dests;
2449 }
2450
2451 targetSystem = [[sDests oo_dictionaryAtIndex:i] oo_intForKey:@"sysID"];
2452 } else {
2453 targetSystem = systemID;
2454
2455 for (i = 0; i < n_dests; i++) {
2456 if (systemID == [[sDests oo_dictionaryAtIndex:i] oo_intForKey:@"sysID"])
2457 break;
2458 }
2459
2460 if (i == n_dests) // no match found
2461 {
2462 return NO;
2463 }
2464 }
2465 float dist = [[sDests oo_dictionaryAtIndex:i] oo_floatForKey:@"distance"];
2466 if (dist > [self maxHyperspaceDistance] || dist > fuel / 10.0f) {
2467 OOLogWARN(@"script.debug", @"DEBUG: %@ Jumping %f which is further than allowed. I have %d fuel", self, dist, fuel);
2468 }
2469 fuel -= 10 * dist;
2470
2471 // create wormhole
2472 WormholeEntity* whole = [[[WormholeEntity alloc] initWormholeTo:targetSystem fromShip:self] autorelease];
2473 [UNIVERSE addEntity:whole];
2474
2475 [self enterWormhole:whole replacing:replace];
2476
2477 // we've no need for the destinations array anymore.
2478 return YES;
2479}
#define OOLogWARN(class, format,...)
Definition OOLogging.h:126
int16_t OOSystemID
Definition OOTypes.h:183
double maxHyperspaceDistance()
BOOL hasHyperspaceMotor()

Referenced by ShipEntity(OOAIPrivate)::performHyperSpaceExitReplace:, and ShipEntity(AI)::performHyperSpaceToSpecificSystem:.

Here is the caller graph for this function:

◆ performHyperSpaceExitWithoutReplacing

- (void) performHyperSpaceExitWithoutReplacing
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1413 of file ShipEntityAI.m.

1414{
1415 [self performHyperSpaceExitReplace:NO];
1416}

◆ performHyperSpaceToSpecificSystem:

- (BOOL) performHyperSpaceToSpecificSystem: (OOSystemID) systemID

Provided by category ShipEntity(AI).

Definition at line 481 of file ShipEntityAI.m.

481 :(OOSystemID)systemID
482{
483 return [self performHyperSpaceExitReplace:NO toSystem:systemID];
484}

Referenced by ShipExitSystem(), and ShipExitSystem().

Here is the caller graph for this function:

◆ performIdle

- (void) performIdle

Provided by category ShipEntity(AI).

Definition at line 407 of file ShipEntityAI.m.

408{
409 behaviour = BEHAVIOUR_IDLE;
410 frustration = 0.0;
411}

◆ performIntercept

- (void) performIntercept

Provided by category ShipEntity(AI).

Definition at line 413 of file ShipEntityAI.m.

414{
415 behaviour = BEHAVIOUR_INTERCEPT_TARGET;
416 frustration = 0.0;
417}

◆ performLandOnPlanet

- (void) performLandOnPlanet

Provided by category ShipEntity(AI).

Definition at line 419 of file ShipEntityAI.m.

420{
421 OOPlanetEntity* nearest = [self findNearestPlanet];
423 _destination = [nearest position];
424 behaviour = BEHAVIOUR_LAND_ON_PLANET;
425 planetForLanding = [nearest universalID];
426 } else {
427 behaviour = BEHAVIOUR_IDLE;
428 [shipAI message:@"NO_PLANET_NEARBY"];
429 }
430
431 frustration = 0.0;
432}
OOUniversalID planetForLanding
Definition ShipEntity.h:335

◆ performMining

- (void) performMining

Provided by category ShipEntity(AI).

Definition at line 434 of file ShipEntityAI.m.

435{
436 Entity* target = [self primaryTarget];
437 // mining is not seen as hostile behaviour, so ensure it is only used against rocks.
438 if (target && [target scanClass] == CLASS_ROCK) {
439 behaviour = BEHAVIOUR_ATTACK_MINING_TARGET;
440 frustration = 0.0;
441 } else {
442 [self noteLostTargetAndGoIdle];
443 }
444}

◆ performScriptedAI

- (void) performScriptedAI

Provided by category ShipEntity(AI).

Definition at line 446 of file ShipEntityAI.m.

447{
448 behaviour = BEHAVIOUR_SCRIPTED_AI;
449 frustration = 0.0;
450}

◆ performScriptedAttackAI

- (void) performScriptedAttackAI

Provided by category ShipEntity(AI).

Definition at line 452 of file ShipEntityAI.m.

453{
454 behaviour = BEHAVIOUR_SCRIPTED_ATTACK_AI;
455 frustration = 0.0;
456}

◆ performStop

- (void) performStop

Provided by category ShipEntity(AI).

Definition at line 466 of file ShipEntityAI.m.

467{
468 behaviour = BEHAVIOUR_STOP_STILL;
469 desired_speed = 0.0;
470 frustration = 0.0;
471}

◆ performTumble

- (void) performTumble

Provided by category ShipEntity(AI).

Definition at line 473 of file ShipEntityAI.m.

474{
475 stick_roll = max_flight_roll * 2.0 * (randf() - 0.5);
476 stick_pitch = max_flight_pitch * 2.0 * (randf() - 0.5);
477 behaviour = BEHAVIOUR_TUMBLE;
478 frustration = 0.0;
479}

Referenced by Universe::addWreckageFrom:withRole:at:scale:lifetime:, and behaviour_tractored:.

Here is the caller graph for this function:

◆ portWeaponOffset

- (NSArray *) portWeaponOffset

References portWeaponOffset.

◆ positionOffsetForAlignment:

- (Vector) positionOffsetForAlignment: (NSString*) align

Definition at line 8219 of file ShipEntity.m.

8219 :(NSString*)align
8220{
8221 NSString* padAlign = [NSString stringWithFormat:@"%@---", align];
8222 Vector result = kZeroVector;
8223 switch ([padAlign characterAtIndex:0]) {
8224 case (unichar)'c':
8225 case (unichar)'C':
8226 result.x = 0.5 * (boundingBox.min.x + boundingBox.max.x);
8227 break;
8228 case (unichar)'M':
8229 result.x = boundingBox.max.x;
8230 break;
8231 case (unichar)'m':
8232 result.x = boundingBox.min.x;
8233 break;
8234 }
8235 switch ([padAlign characterAtIndex:1]) {
8236 case (unichar)'c':
8237 case (unichar)'C':
8238 result.y = 0.5 * (boundingBox.min.y + boundingBox.max.y);
8239 break;
8240 case (unichar)'M':
8241 result.y = boundingBox.max.y;
8242 break;
8243 case (unichar)'m':
8244 result.y = boundingBox.min.y;
8245 break;
8246 }
8247 switch ([padAlign characterAtIndex:2]) {
8248 case (unichar)'c':
8249 case (unichar)'C':
8250 result.z = 0.5 * (boundingBox.min.z + boundingBox.max.z);
8251 break;
8252 case (unichar)'M':
8253 result.z = boundingBox.max.z;
8254 break;
8255 case (unichar)'m':
8256 result.z = boundingBox.min.z;
8257 break;
8258 }
8259 return result;
8260}

References Entity::boundingBox, and kZeroVector.

◆ positionOffsetForShipInRotationToAlignment

- (Vector) positionOffsetForShipInRotationToAlignment (ShipEntity *) ship
(Quaternion) q
(NSString *) align 

Definition at line 8262 of file ShipEntity.m.

8263{
8264 NSString* padAlign = [NSString stringWithFormat:@"%@---", align];
8268 BoundingBox arbb = [ship findBoundingBoxRelativeToPosition:kZeroHPVector i:i j:j k:k];
8269 Vector result = kZeroVector;
8270 switch ([padAlign characterAtIndex:0]) {
8271 case (unichar)'c':
8272 case (unichar)'C':
8273 result.x = 0.5 * (arbb.min.x + arbb.max.x);
8274 break;
8275 case (unichar)'M':
8276 result.x = arbb.max.x;
8277 break;
8278 case (unichar)'m':
8279 result.x = arbb.min.x;
8280 break;
8281 }
8282 switch ([padAlign characterAtIndex:1]) {
8283 case (unichar)'c':
8284 case (unichar)'C':
8285 result.y = 0.5 * (arbb.min.y + arbb.max.y);
8286 break;
8287 case (unichar)'M':
8288 result.y = arbb.max.y;
8289 break;
8290 case (unichar)'m':
8291 result.y = arbb.min.y;
8292 break;
8293 }
8294 switch ([padAlign characterAtIndex:2]) {
8295 case (unichar)'c':
8296 case (unichar)'C':
8297 result.z = 0.5 * (arbb.min.z + arbb.max.z);
8298 break;
8299 case (unichar)'M':
8300 result.z = arbb.max.z;
8301 break;
8302 case (unichar)'m':
8303 result.z = arbb.min.z;
8304 break;
8305 }
8306 return result;
8307}
BoundingBox findBoundingBoxRelativeToPosition:i:j:k:(HPVector opv,[i] Vector i,[j] Vector j,[k] Vector k)

References findBoundingBoxRelativeToPosition:i:j:k:, kZeroVector, BoundingBox::max, BoundingBox::min, positionOffsetForShipInRotationToAlignment, vector_forward_from_quaternion(), vector_right_from_quaternion(), vector_up_from_quaternion(), Vector::x, Vector::y, and Vector::z.

Referenced by maxFlightSpeed, and positionOffsetForShipInRotationToAlignment.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ prevBeacon

- (Entity< OOBeaconEntity > *) prevBeacon
implementation

Reimplemented from <OOBeaconEntity>.

Definition at line 1476 of file ShipEntity.m.

1477{
1478 return [_prevBeacon weakRefUnderlyingObject];
1479}

References prevBeacon, and OOWeakReference::weakRefUnderlyingObject.

Referenced by prevBeacon, and setPrevBeacon:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ primaryAggressor

- (Entity *) primaryAggressor

Definition at line 8564 of file ShipEntity.m.

8565{
8566 Entity* result = [_primaryAggressor weakRefUnderlyingObject];
8567 if (result == nil || ![self isValidTarget:result]) {
8569 return nil;
8570 }
8571 return result;
8572}

References _primaryAggressor, DESTROY, nil, primaryAggressor, and OOWeakReference::weakRefUnderlyingObject.

Referenced by ShipEntity(PureAI)::addPrimaryAggressorAsDefenseTarget, PlayerEntity::addRoleForAggression:, becomeExplosion, PlayerEntity::interpretAIMessage:, interpretAIMessage:, maxFlightSpeed, noteLostTarget, primaryAggressor, ShipEntity(PureAI)::setTargetToPrimaryAggressor, ShipGetProperty(), and ShipGetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ primaryRole

- (NSString *) primaryRole

References isPirate, isPolice, isThargoid, isTrader, and primaryRole.

Here is the call graph for this function:

◆ primaryTarget

- (id) primaryTarget

Definition at line 8727 of file ShipEntity.m.

8728{
8729 id result = [_primaryTarget weakRefUnderlyingObject];
8730 if ((result == nil && _primaryTarget != nil)
8731 || ![self isValidTarget:result]) {
8733 return nil;
8734 } else if (EXPECT_NOT(result == self)) {
8735 /* Added in response to a crash report showing recursion in
8736 [PlayerEntity hasHostileTarget].
8737 -- Ahruman 2009-12-17
8738 */
8740 }
8741 return result;
8742}

References _primaryTarget, DESTROY, EXPECT_NOT, nil, primaryTarget, and OOWeakReference::weakRefUnderlyingObject.

Referenced by ShipEntity(OOAIPrivate)::acceptDistressMessageFrom:, StationEntity(OOAIPrivate)::acceptDistressMessageFrom:, approachAspectToPrimaryTarget, avoidCollision, behaviour_attack_break_off_target:, behaviour_attack_broadside_target:leftside:, behaviour_attack_fly_from_target:, behaviour_attack_fly_to_target:, behaviour_attack_slow_dogfight:, behaviour_attack_sniper:, behaviour_attack_target:, behaviour_close_to_broadside_range:, behaviour_close_with_target:, behaviour_evasive_action:, behaviour_flee_target:, behaviour_fly_to_target_six:, behaviour_intercept_target:, behaviour_track_as_turret:, behaviour_track_target:, calculateTargetPosition, ShipEntity(PureAI)::checkGroupOddsVersusTarget, ShipEntity(PureAI)::checkTargetLegalStatus, deployEscorts, PlayerEntity::dialTargetName, PlayerEntity::doBookkeeping:, dockEscorts, HeadUpDisplay(Private)::drawScanner:, HeadUpDisplay(Private)::drawSecondaryTargetReticle:, ShipEntity(AI)::enterTargetWormhole, evasiveAction:, ShipEntity(PureAI)::fightOrFleeMissile, fireDirectLaserShot:, fireLaserShotInDirection:weaponIdentifier:, PlayerEntity::fireMissile, fireMissile, fireSubentityLaserShot:, Universe::forceWitchspaceEntries, getTractoredBy:, ShipEntity(AI)::groupAttackTarget, PlayerEntity(OOControlsPrivate)::handleAutopilotOn:, PlayerEntity(OOControlsPrivate)::handleButtonTargetMissile, PlayerEntity::hasHostileTarget, hasHostileTarget, StationEntity::hasHostileTarget, hasProximityAlertIgnoringTarget:, HeadUpDisplay::hudDrawReticleOnTarget, interpretAIMessage:, IsHostileAgainstTargetPredicate(), isHostileTo:, StationEntity::launchDefenseShip, StationEntity::launchPirateShip, StationEntity::launchPolice, PlayerEntity::localMarket, PlayerEntity::loseTargetStatus, PlayerEntity::marketScreenTitle, ShipEntity(PureAI)::markTargetForFines, ShipEntity(PureAI)::markTargetForOffence:, maxFlightSpeed, missileTrackPrimaryTarget:, noteLostTarget, noteTargetDestroyed:, onTarget:withWeapon:, ShipEntity(AI)::performMining, PlayerEntity(OOControlsPrivate)::pollFlightControls:, primaryTarget, PlayerEntity::printIdentLockedOnForMissile:, rangeToPrimaryTarget, ShipEntity(AI)::recallDockingInstructions, PlayerEntity::safeAllMissiles, ShipEntity(PureAI)::safeScriptActionOnTarget:, ShipEntity(PureAI)::scriptActionOnTarget:, PlayerEntity::selectNextMissile, ShipEntity(PureAI)::sendTargetCommsMessage:, ShipEntity(PureAI)::setDestinationToTarget, ShipEntity(PureAI)::setDestinationWithinTarget, PlayerEntity::setDockingClearanceStatus:, PlayerEntity::setGuiToMarketScreen, PlayerEntity::setNextCompassMode, PlayerEntity::setPrevCompassMode, ShipEntity(PureAI)::setRacepointsFromTarget, ShipEntity(OOJavaScriptExtensions)::setTargetForScript:, ShipEntity(PureAI)::setTargetToPrimaryAggressor, ShipFireMissile(), ShipFireMissile(), ShipGetProperty(), ShipGetProperty(), ShipEntity(ScriptMethods)::spawnShipsWithRole:count:, startTrackingCurve, ShipEntity(PureAI)::storeTarget, ShipEntity(PureAI)::suggestEscort, ShipEntity(PureAI)::targetNextBeaconWithCode:, trackOntoTarget:withDForward:, trackPrimaryTarget:retreat:, trackSideTarget:leftside:, update:, PlayerEntity(OOPrivate)::updateAlertConditionForNearbyEntities, PlayerEntity(OOPrivate)::updateTargeting, updateTrackingCurve, PlayerEntity::validateCompassTarget, ShipEntity(AI)::wormholeEscorts, and ShipEntity(PureAI)::wormholeGroup.

Here is the call graph for this function:

◆ primaryTargetWithoutValidityCheck

- (id) primaryTargetWithoutValidityCheck

Definition at line 8746 of file ShipEntity.m.

8747{
8748 id result = [_primaryTarget weakRefUnderlyingObject];
8749 if (EXPECT_NOT(result == self)) {
8750 // just in case
8752 return nil;
8753 }
8754 return result;
8755}

References _primaryTarget, DESTROY, EXPECT_NOT, nil, primaryTargetWithoutValidityCheck, and OOWeakReference::weakRefUnderlyingObject.

Referenced by canStillTrackPrimaryTarget, maxFlightSpeed, primaryTargetWithoutValidityCheck, realAlertCondition, and scoopUpProcess:processEvents:processMessages:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ processBehaviour:

- (void) processBehaviour: (OOTimeDelta) delta_t

Definition at line 2485 of file ShipEntity.m.

2485 :(OOTimeDelta)delta_t
2486{
2487 BOOL applyThrust = YES;
2488 switch (behaviour) {
2489 case BEHAVIOUR_TUMBLE:
2490 [self behaviour_tumble:delta_t];
2491 break;
2492
2493 case BEHAVIOUR_STOP_STILL:
2494 case BEHAVIOUR_STATION_KEEPING:
2495 [self behaviour_stop_still:delta_t];
2496 break;
2497
2498 case BEHAVIOUR_IDLE:
2499 if ([self isSubEntity]) {
2500 applyThrust = NO;
2501 }
2502 [self behaviour_idle:delta_t];
2503 break;
2504
2505 case BEHAVIOUR_TRACTORED:
2506 [self behaviour_tractored:delta_t];
2507 break;
2508
2509 case BEHAVIOUR_TRACK_TARGET:
2510 [self behaviour_track_target:delta_t];
2511 break;
2512
2513 case BEHAVIOUR_INTERCEPT_TARGET:
2514 case BEHAVIOUR_COLLECT_TARGET:
2515 [self behaviour_intercept_target:delta_t];
2516 break;
2517
2518 case BEHAVIOUR_ATTACK_TARGET:
2519 [self behaviour_attack_target:delta_t];
2520 break;
2521
2522 case BEHAVIOUR_ATTACK_FLY_TO_TARGET_SIX:
2523 case BEHAVIOUR_ATTACK_FLY_TO_TARGET_TWELVE:
2524 [self behaviour_fly_to_target_six:delta_t];
2525 break;
2526
2527 case BEHAVIOUR_ATTACK_MINING_TARGET:
2528 [self behaviour_attack_mining_target:delta_t];
2529 break;
2530
2531 case BEHAVIOUR_ATTACK_FLY_TO_TARGET:
2532 [self behaviour_attack_fly_to_target:delta_t];
2533 break;
2534
2535 case BEHAVIOUR_ATTACK_FLY_FROM_TARGET:
2536 [self behaviour_attack_fly_from_target:delta_t];
2537 break;
2538
2539 case BEHAVIOUR_ATTACK_BREAK_OFF_TARGET:
2540 [self behaviour_attack_break_off_target:delta_t];
2541 break;
2542
2543 case BEHAVIOUR_ATTACK_SLOW_DOGFIGHT:
2544 [self behaviour_attack_slow_dogfight:delta_t];
2545 break;
2546
2547 case BEHAVIOUR_RUNNING_DEFENSE:
2548 [self behaviour_running_defense:delta_t];
2549 break;
2550
2551 case BEHAVIOUR_ATTACK_BROADSIDE:
2552 [self behaviour_attack_broadside:delta_t];
2553 break;
2554
2555 case BEHAVIOUR_ATTACK_BROADSIDE_LEFT:
2556 [self behaviour_attack_broadside_left:delta_t];
2557 break;
2558
2559 case BEHAVIOUR_ATTACK_BROADSIDE_RIGHT:
2560 [self behaviour_attack_broadside_right:delta_t];
2561 break;
2562
2563 case BEHAVIOUR_CLOSE_TO_BROADSIDE_RANGE:
2564 [self behaviour_close_to_broadside_range:delta_t];
2565 break;
2566
2567 case BEHAVIOUR_CLOSE_WITH_TARGET:
2568 [self behaviour_close_with_target:delta_t];
2569 break;
2570
2571 case BEHAVIOUR_ATTACK_SNIPER:
2572 [self behaviour_attack_sniper:delta_t];
2573 break;
2574
2575 case BEHAVIOUR_EVASIVE_ACTION:
2576 case BEHAVIOUR_FLEE_EVASIVE_ACTION:
2577 [self behaviour_evasive_action:delta_t];
2578 break;
2579
2580 case BEHAVIOUR_FLEE_TARGET:
2581 [self behaviour_flee_target:delta_t];
2582 break;
2583
2584 case BEHAVIOUR_FLY_RANGE_FROM_DESTINATION:
2585 [self behaviour_fly_range_from_destination:delta_t];
2586 break;
2587
2588 case BEHAVIOUR_FACE_DESTINATION:
2589 [self behaviour_face_destination:delta_t];
2590 break;
2591
2592 case BEHAVIOUR_LAND_ON_PLANET:
2593 [self behaviour_land_on_planet:delta_t];
2594 break;
2595
2596 case BEHAVIOUR_FORMATION_FORM_UP:
2597 [self behaviour_formation_form_up:delta_t];
2598 break;
2599
2600 case BEHAVIOUR_FLY_TO_DESTINATION:
2601 [self behaviour_fly_to_destination:delta_t];
2602 break;
2603
2604 case BEHAVIOUR_FLY_FROM_DESTINATION:
2605 case BEHAVIOUR_FORMATION_BREAK:
2606 [self behaviour_fly_from_destination:delta_t];
2607 break;
2608
2609 case BEHAVIOUR_AVOID_COLLISION:
2610 [self behaviour_avoid_collision:delta_t];
2611 break;
2612
2613 case BEHAVIOUR_TRACK_AS_TURRET:
2614 applyThrust = NO;
2615 [self behaviour_track_as_turret:delta_t];
2616 break;
2617
2618 case BEHAVIOUR_FLY_THRU_NAVPOINTS:
2619 [self behaviour_fly_thru_navpoints:delta_t];
2620 break;
2621
2622 case BEHAVIOUR_SCRIPTED_AI:
2623 case BEHAVIOUR_SCRIPTED_ATTACK_AI:
2624 [self behaviour_scripted_ai:delta_t];
2625 break;
2626
2627 case BEHAVIOUR_ENERGY_BOMB_COUNTDOWN:
2628 applyThrust = NO;
2629 // Do nothing
2630 break;
2631 }
2632
2633 // generally the checks above should be turning this *off* for subents
2634 if (applyThrust) {
2635 [self applyAttitudeChanges:delta_t];
2636 [self applyThrust:delta_t];
2637 }
2638}
double OOTimeDelta
Definition OOTypes.h:193

References applyAttitudeChanges:, applyThrust:, behaviour, behaviour_attack_break_off_target:, behaviour_attack_broadside:, behaviour_attack_broadside_left:, behaviour_attack_broadside_right:, behaviour_attack_fly_from_target:, behaviour_attack_fly_to_target:, behaviour_attack_mining_target:, behaviour_attack_slow_dogfight:, behaviour_attack_sniper:, behaviour_attack_target:, behaviour_avoid_collision:, behaviour_close_to_broadside_range:, behaviour_close_with_target:, behaviour_evasive_action:, behaviour_face_destination:, behaviour_flee_target:, behaviour_fly_from_destination:, behaviour_fly_range_from_destination:, behaviour_fly_thru_navpoints:, behaviour_fly_to_destination:, behaviour_fly_to_target_six:, behaviour_formation_form_up:, behaviour_idle:, behaviour_intercept_target:, behaviour_land_on_planet:, behaviour_running_defense:, behaviour_scripted_ai:, behaviour_stop_still:, behaviour_track_as_turret:, behaviour_track_target:, behaviour_tractored:, behaviour_tumble:, and Entity::isSubEntity.

Referenced by PlayerEntity(OOPrivate)::performAutopilotUpdates:, and update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ proximityAlert

- (Entity *) proximityAlert

Definition at line 6098 of file ShipEntity.m.

6099{
6100 Entity* prox = [_proximityAlert weakRefUnderlyingObject];
6101 if (prox == nil) {
6103 }
6104 return prox;
6105}
OOWeakReference * _proximityAlert
Definition ShipEntity.h:432

References _proximityAlert, DESTROY, nil, proximityAlert, and OOWeakReference::weakRefUnderlyingObject.

Referenced by avoidCollision, behaviour_attack_broadside_target:leftside:, behaviour_attack_fly_to_target:, behaviour_attack_mining_target:, behaviour_attack_slow_dogfight:, behaviour_avoid_collision:, behaviour_close_to_broadside_range:, behaviour_close_with_target:, behaviour_evasive_action:, behaviour_fly_to_target_six:, hasProximityAlertIgnoringTarget:, maxFlightSpeed, proximityAlert, setProximityAlert:, ShipGetProperty(), and ShipGetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ randomEjectaTemperature

- (float) randomEjectaTemperature

Definition at line 7571 of file ShipEntity.m.

7572{
7573 return [self randomEjectaTemperatureWithMaxFactor:0.99f];
7574}

References randomEjectaTemperature, and randomEjectaTemperatureWithMaxFactor:.

Referenced by becomeExplosion, dumpItem:, maxFlightSpeed, randomEjectaTemperature, releaseCargoPodsDebris, and ShipEntity(ScriptMethods)::spawnShipsWithRole:count:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ randomEjectaTemperatureWithMaxFactor:

- (float) randomEjectaTemperatureWithMaxFactor: (float) factor

Definition at line 7576 of file ShipEntity.m.

7576 :(float)factor
7577{
7578 const float kRange = 0.02f;
7579 factor -= kRange;
7580
7581 float parentTemp = [self temperature];
7582 float adjusted = parentTemp * (bellf(5) * (kRange * 2.0f) - kRange + factor);
7583 if (adjusted > SHIP_MAX_CABIN_TEMP) {
7584 adjusted = SHIP_MAX_CABIN_TEMP;
7585 }
7586
7587 // Interpolate so that result == parentTemp when parentTemp is SHIP_MIN_CABIN_TEMP
7588 float interp = OOClamp_0_1_f((parentTemp - SHIP_MIN_CABIN_TEMP) / (SHIP_MAX_CABIN_TEMP - SHIP_MIN_CABIN_TEMP));
7589
7590 return OOLerp(SHIP_MIN_CABIN_TEMP, adjusted, interp);
7591}
OOINLINE float OOLerp(float v0, float v1, float fraction) INLINE_CONST_FUNC
float bellf(int n)

References bellf(), OOClamp_0_1_f(), OOLerp(), SHIP_MAX_CABIN_TEMP, SHIP_MIN_CABIN_TEMP, and temperature.

Referenced by ShipEntity(Private)::launchPodWithCrew:, and randomEjectaTemperature.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ randomPauseAI:

- (void) randomPauseAI: (NSString*) intervalString
implementation

Provided by category ShipEntity(PureAI).

Definition at line 762 of file ShipEntityAI.m.

762 :(NSString*)intervalString
763{
764 NSArray* tokens = ScanTokensFromString(intervalString);
765 double start, end;
766
767 if ([tokens count] != 2) {
768 OOLog(@"ai.syntax.randomPauseAI", @"***** ERROR: cannot read min and max value for randomPauseAI:, needs 2 values: '%@'.", intervalString);
769 return;
770 }
771
772 start = [tokens oo_doubleAtIndex:0];
773 end = [tokens oo_doubleAtIndex:1];
774
775 [shipAI setNextThinkTime:[UNIVERSE getTime] + (start + (end - start) * randf())];
776}

◆ randomSeedForShaders

- (uint32_t) randomSeedForShaders
implementation

Definition at line 8424 of file ShipEntity.m.

8425{
8426 return entity_personality * 0x00010001;
8427}

References entity_personality, and randomSeedForShaders.

Referenced by randomSeedForShaders.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rangeToDestination

- (GLfloat) rangeToDestination

Definition at line 9626 of file ShipEntity.m.

9627{
9629}

References _destination, HPdistance(), Entity::position, and rangeToDestination.

Referenced by behaviour, behaviour_avoid_collision:, behaviour_face_destination:, behaviour_fly_from_destination:, behaviour_fly_range_from_destination:, behaviour_fly_to_destination:, behaviour_fly_to_target_six:, behaviour_formation_form_up:, behaviour_intercept_target:, behaviour_tractored:, and rangeToDestination.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rangeToPrimaryTarget

- (double) rangeToPrimaryTarget

Definition at line 9727 of file ShipEntity.m.

9728{
9729 return [self rangeToSecondaryTarget:[self primaryTarget]];
9730}

References primaryTarget, rangeToPrimaryTarget, and rangeToSecondaryTarget:.

Referenced by behaviour_attack_break_off_target:, behaviour_attack_broadside:, behaviour_attack_broadside_target:leftside:, behaviour_attack_fly_from_target:, behaviour_attack_fly_to_target:, behaviour_attack_mining_target:, behaviour_attack_slow_dogfight:, behaviour_attack_sniper:, behaviour_attack_target:, behaviour_close_to_broadside_range:, behaviour_close_with_target:, behaviour_evasive_action:, behaviour_flee_target:, behaviour_fly_to_target_six:, behaviour_intercept_target:, behaviour_running_defense:, behaviour_scripted_ai:, coordinates, and rangeToPrimaryTarget.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rangeToSecondaryTarget:

- (double) rangeToSecondaryTarget: (Entity*) target

Definition at line 9732 of file ShipEntity.m.

9732 :(Entity*)target
9733{
9734 double dist;
9735 Vector delta;
9736 if (target == nil) // leave now!
9737 return 0.0;
9739 dist = magnitude(delta);
9740 dist -= target->collision_radius;
9741 dist -= collision_radius;
9742 return dist;
9743}

References Entity::collision_radius, HPvector_subtract(), HPVectorToVector(), magnitude(), nil, and Entity::position.

Referenced by behaviour_track_as_turret:, fireDirectLaserDefensiveShot, and rangeToPrimaryTarget.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reactionTime

- (float) reactionTime

References avoidCollision, calculateTargetPosition, calculateTrackingCurve, hasAutoCloak, isCloaked, reactionTime, resumePostProximityAlert, scannerDisplayColor1, scannerDisplayColor2, scannerDisplayColorHostile1, scannerDisplayColorHostile2, startTrackingCurve, and updateTrackingCurve.

Here is the call graph for this function:

◆ reactToAIMessage:context:

- (void) reactToAIMessage: (NSString*) message
context: (NSString*) debugContext 

Definition at line 12859 of file ShipEntity.m.

12859 :(NSString*)message context:(NSString*)debugContext
12860{
12861 [shipAI reactToMessage:message context:debugContext];
12862}

References AI::reactToMessage:context:.

Referenced by broadcastEnergyBlastImminent, broadcastHitByLaserFrom:, doScriptEvent:andReactToAIMessage:, doScriptEvent:withArgument:andReactToAIMessage:, fireMissileWithIdentifier:andTarget:, fireSubentityLaserShot:, ShipEntity(AI)::groupAttackTarget, ShipEntity(PureAI)::messageMother:, ShipReactToAIMessage(), ShipReactToAIMessage(), OOECMBlastEntity::update:, ShipEntity(AI)::wormholeEscorts, and ShipEntity(PureAI)::wormholeGroup.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ realAlertCondition

- (OOAlertCondition) realAlertCondition

Reimplemented in PlayerEntity.

Definition at line 12894 of file ShipEntity.m.

12895{
12896 if ([self status] == STATUS_DOCKED) {
12898 }
12899 if ([self hasHostileTarget]) {
12900 return ALERT_CONDITION_RED;
12901 } else {
12902 NSEnumerator* sEnum = [_defenseTargets objectEnumerator];
12903 ShipEntity* ship = nil;
12904 double scanrange2 = scannerRange * scannerRange;
12905 // FIXME: OOWeakSet doesn't implement NSFastEnumeration protocol.
12906 foreach (ship, sEnum) {
12907 if ([ship hasHostileTarget] || ([ship isPlayer] && [PLAYER weaponsOnline])) {
12908 if (HPdistance2([ship position], position) < scanrange2) {
12909 return ALERT_CONDITION_RED;
12910 }
12911 }
12912 }
12913 // also need to check primary target separately
12914 if ([self hasHostileTarget]) {
12915 Entity* ptarget = [self primaryTargetWithoutValidityCheck];
12916 if (ptarget != nil && [ptarget isShip]) {
12917 ship = (ShipEntity*)ptarget;
12918 if ([ship hasHostileTarget] || ([ship isPlayer] && [PLAYER weaponsOnline])) {
12919 if (HPdistance2([ship position], position) < scanrange2 * 1.5625) {
12920 return ALERT_CONDITION_RED;
12921 }
12922 }
12923 }
12924 }
12925 if (_group) {
12926 sEnum = [_group objectEnumerator];
12927 while ((ship = [sEnum nextObject])) {
12928 if ([ship hasHostileTarget] || ([ship isPlayer] && [PLAYER weaponsOnline])) {
12929 if (HPdistance2([ship position], position) < scanrange2) {
12930 return ALERT_CONDITION_RED;
12931 }
12932 }
12933 }
12934 }
12935 if (_escortGroup && _group != _escortGroup) {
12936 sEnum = [_escortGroup objectEnumerator];
12937 while ((ship = [sEnum nextObject])) {
12938 if ([ship hasHostileTarget] || ([ship isPlayer] && [PLAYER weaponsOnline])) {
12939 if (HPdistance2([ship position], position) < scanrange2) {
12940 return ALERT_CONDITION_RED;
12941 }
12942 }
12943 }
12944 }
12945 }
12947}

References _escortGroup, _group, ALERT_CONDITION_DOCKED, ALERT_CONDITION_RED, ALERT_CONDITION_YELLOW, hasHostileTarget, HPdistance2(), Entity::isPlayer, Entity::isShip, nil, OOShipGroup::objectEnumerator, OOWeakSet::objectEnumerator, PLAYER, Entity::position, primaryTargetWithoutValidityCheck, realAlertCondition, scannerRange, and Entity::status.

Referenced by isMissile, and realAlertCondition.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ recallDockingInstructions

- (void) recallDockingInstructions

Provided by category ShipEntity(AI).

Definition at line 536 of file ShipEntityAI.m.

537{
538 if (dockingInstructions != nil) {
539 _destination = [dockingInstructions oo_hpvectorForKey:@"destination"];
540 desired_speed = fmin([dockingInstructions oo_floatForKey:@"speed"], maxFlightSpeed);
541 desired_range = [dockingInstructions oo_floatForKey:@"range"];
542 if ([dockingInstructions objectForKey:@"station"]) {
543 StationEntity* targetStation = [[dockingInstructions objectForKey:@"station"] weakRefUnderlyingObject];
544 if (targetStation != nil) {
545 [self addTarget:targetStation];
546 [self setTargetStation:targetStation];
547 } else {
548 [self removeTarget:[self primaryTarget]];
549 }
550 }
551 docking_match_rotation = [dockingInstructions oo_boolForKey:@"match_rotation"];
552 }
553}

Referenced by ShipEntity(AI)::requestDockingCoordinates.

Here is the caller graph for this function:

◆ recallStoredTarget

- (void) recallStoredTarget
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1849 of file ShipEntityAI.m.

1850{
1851 ShipEntity* oldTarget = (ShipEntity*)[self rememberedShip];
1852 BOOL found = NO;
1853
1854 if (oldTarget && ![oldTarget isCloaked]) {
1855 GLfloat range2 = HPdistance2([oldTarget position], position);
1856 if (range2 <= scannerRange * scannerRange && range2 <= SCANNER_MAX_RANGE2) {
1857 found = YES;
1858 }
1859 }
1860
1861 if (found) {
1862 [self setFoundTarget:oldTarget];
1863 [shipAI message:@"TARGET_FOUND"];
1864 } else {
1865 if (oldTarget == nil)
1866 DESTROY(_rememberedShip); // ship no longer exists
1867 [shipAI message:@"NOTHING_FOUND"];
1868 }
1869}
Entity * rememberedShip()
OOWeakReference * _rememberedShip
Definition ShipEntity.h:431

◆ receiveCommsMessage:from:

- (void) receiveCommsMessage: (NSString*) message_text
from: (ShipEntity*) other 

Reimplemented in PlayerEntity.

Definition at line 12418 of file ShipEntity.m.

12418 :(NSString*)message_text from:(ShipEntity*)other
12419{
12420 // Too complex for AI scripts to handle, JS event only.
12421 [self doScriptEvent:OOJSID("commsMessageReceived") withArgument:message_text andArgument:other];
12422}

References doScriptEvent:withArgument:andArgument:.

Referenced by broadcastMessage:withUnpilotedOverride:, PlayerEntity::receiveCommsMessage:from:, and sendMessage:toShip:withUnpilotedOverride:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reference

References reference.

◆ refreshEscortPositions

- (void) refreshEscortPositions
implementation

Provided by category ShipEntity(Private).

Definition at line 12005 of file ShipEntity.m.

12006{
12007 if (!_escortPositionsValid) {
12008 JSContext* context = OOJSAcquireContext();
12009 OOJSVal result;
12010 OOJSVal args[] = { OOJSValueFromDouble(context, 0), OOJSValueFromDouble(context, _maxEscortCount) };
12011 BOOL OK;
12012
12013 // Reset validity first so updateEscortFormation can be called from the update callback.
12015
12016 uint8_t i;
12017 for (i = 0; i < _maxEscortCount; i++) {
12018 args[0] = OOJSValueFromDouble(context, i); // Numbers need not be freed.
12019 result = OOJSUndefinedValue();
12020 OK = [script callMethod:OOJSID("coordinatesForEscortPosition")
12021 inContext:context
12022 withArguments:args
12023 count:sizeof args / sizeof *args
12024 result:&result];
12025
12026 if (OK)
12027 OK = JSValueToVector(context, result, &_escortPositions[i]);
12028 OOJSFreeValue(context, result);
12029
12030 if (!OK)
12032 }
12033
12034 OOJSRelinquishContext(context);
12035 }
12036}
BOOL JSValueToVector(JSContext *context, jsval value, Vector *outVector) NONNULL_FUNC
Definition OOJSVector.m:341
BOOL _escortPositionsValid
Definition ShipEntity.h:458

References JSValueToVector(), kZeroVector, OOJSAcquireContext(), OOJSFreeValue, OOJSRelinquishContext(), OOJSUndefinedValue, OOJSValueFromDouble(), and ShipEntity(Private)::refreshEscortPositions.

Referenced by ShipEntity(Private)::drawDebugStuff, ShipEntity(Private)::refreshEscortPositions, setUpEscorts, ShipEntity(Private)::setUpMixedEscorts, and update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ releaseCargoPodsDebris

- (void) releaseCargoPodsDebris
implementation

Definition at line 7823 of file ShipEntity.m.

7824{
7825 HPVector xposition = position;
7826 NSUInteger i;
7827 Vector v;
7828 Quaternion q;
7829 int speed_low = 200;
7830
7831 NSArray* jetsam = nil; // this will contain the stuff to get thrown out
7832 unsigned cargo_chance = 70;
7833 jetsam = [NSArray arrayWithArray:cargo]; // what the ship is carrying
7834 [cargo removeAllObjects]; // dispense with it!
7835 unsigned limit = 15;
7836 // Throw out cargo
7837 NSUInteger n_jetsam = [jetsam count];
7838
7839 for (i = 0; i < n_jetsam; i++) {
7840 if (Ranrot() % 100 < cargo_chance) // chance of any given piece of cargo surviving decompression
7841 {
7842 // a higher chance of getting at least a couple of bits of cargo out
7843 if (cargo_chance > 10) {
7844 if (EXPECT_NOT([self isPlayer])) {
7845 cargo_chance -= 20;
7846 } else {
7847 cargo_chance -= 30;
7848 }
7849 }
7850 limit--;
7851 ShipEntity* cargoObj = [jetsam objectAtIndex:i];
7852 ShipEntity* container = [UNIVERSE reifyCargoPod:cargoObj];
7853 /* TODO: this debris position/velocity setting code is
7854 * duplicated - sometimes not very cleanly - all over the
7855 * place. Unify to a single function - CIM */
7856 HPVector rpos = xposition;
7858 rpos.x += rrand.x;
7859 rpos.y += rrand.y;
7860 rpos.z += rrand.z;
7861 rpos.x += (ranrot_rand() % 7) - 3;
7862 rpos.y += (ranrot_rand() % 7) - 3;
7863 rpos.z += (ranrot_rand() % 7) - 3;
7864 [container setPosition:rpos];
7865 v.x = 0.1 * ((ranrot_rand() % speed_low) - speed_low / 2);
7866 v.y = 0.1 * ((ranrot_rand() % speed_low) - speed_low / 2);
7867 v.z = 0.1 * ((ranrot_rand() % speed_low) - speed_low / 2);
7868 [container setVelocity:vector_add(v, [self velocity])];
7870 [container setOrientation:q];
7871
7872 [container setTemperature:[self randomEjectaTemperature]];
7873 [container setScanClass:CLASS_CARGO];
7874 [UNIVERSE addEntity:container]; // STATUS_IN_FLIGHT, AI state GLOBAL
7875
7876 AI* containerAI = [container getAI];
7877 if ([containerAI hasSuspendedStateMachines]) // check if new or recycled cargo.
7878 {
7879 [containerAI exitStateMachineWithMessage:nil];
7880 [container setThrust:[container maxThrust]]; // restore old value. Was set to zero on previous scooping.
7881 [container setOwner:container];
7882 }
7883 }
7884 if (limit <= 0) {
7885 break; // even really big ships won't have too much cargo survive an explosion
7886 }
7887 }
7888}
void exitStateMachineWithMessage:(NSString *message)
Definition AI.m:268

References Entity::boundingBox, AI::exitStateMachineWithMessage:, EXPECT_NOT, getAI, Entity::isPlayer, maxThrust, nil, OORandomPositionInBoundingBox(), Entity::position, quaternion_set_random(), randomEjectaTemperature, Ranrot(), ranrot_rand, releaseCargoPodsDebris, Entity::setOrientation:, setOwner:, Entity::setPosition:, Entity::setScanClass:, setTemperature:, setThrust:, Entity::setVelocity:, velocity, HPVector::x, Vector::x, HPVector::y, Vector::y, HPVector::z, and Vector::z.

Referenced by becomeExplosion, becomeLargeExplosion:, and releaseCargoPodsDebris.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rememberedShip

- (Entity *) rememberedShip

Definition at line 8612 of file ShipEntity.m.

8613{
8614 Entity* result = [_rememberedShip weakRefUnderlyingObject];
8615 if (result == nil || ![self isValidTarget:result]) {
8617 return nil;
8618 }
8619 return result;
8620}

References _rememberedShip, DESTROY, nil, rememberedShip, and OOWeakReference::weakRefUnderlyingObject.

Referenced by maxFlightSpeed, and rememberedShip.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeAllDefenseTargets

- (void) removeAllDefenseTargets

Definition at line 9717 of file ShipEntity.m.

9718{
9719 [_defenseTargets removeAllObjects];
9720}

References removeAllDefenseTargets, and OOWeakSet::removeAllObjects.

Referenced by isMissile, and removeAllDefenseTargets.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeAllEquipment

- (void) removeAllEquipment

Definition at line 3489 of file ShipEntity.m.

3490{
3491 [_equipment release];
3492 _equipment = nil;
3493}

References _equipment, nil, and removeAllEquipment.

Referenced by dealloc, PlayerEntity::getDestroyedBy:damageType:, isFrangible, PlayerEntity(Contracts)::newShipCommonSetup:yardInfo:baseInfo:, removeAllEquipment, removeEquipmentItem:, PlayerEntity::setCommanderDataFromDictionary:, PlayerEntity::setUpShipFromDictionary:, and ShipEntity(LoadRestore)::shipRestoredFromDictionary:useFallback:context:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeCargo:amount:

- (BOOL) removeCargo: (OOCommodityType) commodity
amount: (OOCargoQuantity) amount 

Definition at line 7294 of file ShipEntity.m.

7294 :(OOCommodityType)commodity amount:(OOCargoQuantity)amount
7295{
7296 OOCargoQuantity found = 0;
7297 ShipEntity* pod = nil;
7298 foreach (pod, cargo) {
7299 if ([[pod commodityType] isEqualToString:commodity]) {
7300 found++;
7301 }
7302 }
7303 if (found < amount) {
7304 // don't remove any if there aren't enough to remove the full amount
7305 return NO;
7306 }
7307
7308 NSUInteger i = [cargo count] - 1;
7309 // iterate downwards to be safe removing during iteration
7310 while (amount > 0) {
7311 if ([[[cargo objectAtIndex:i] commodityType] isEqualToString:commodity]) {
7312 amount--;
7313 [cargo removeObjectAtIndex:i];
7314 }
7315 // check above means array index can't underflow here
7316 i--;
7317 }
7318
7319 return YES;
7320}

References cargo, commodityType, and nil.

Here is the call graph for this function:

◆ removeCollisionException:

- (void) removeCollisionException: (ShipEntity*) ship

Definition at line 9648 of file ShipEntity.m.

9648 :(ShipEntity*)ship
9649{
9650 if (_collisionExceptions != nil) {
9651 [_collisionExceptions removeObject:ship];
9652 }
9653}

References _collisionExceptions, nil, and OOWeakSet::removeObject:.

Referenced by ShipRemoveCollisionException(), and ShipRemoveCollisionException().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeDefenseTarget:

- (void) removeDefenseTarget: (Entity*) target

Definition at line 9722 of file ShipEntity.m.

9722 :(Entity*)target
9723{
9724 [_defenseTargets removeObject:target];
9725}

References OOWeakSet::removeObject:.

Referenced by ShipEntity(PureAI)::becomeUncontrolledThargon, behaviour_track_as_turret:, fireDirectLaserDefensiveShot, noteLostTarget, noteTargetDestroyed:, and validateDefenseTargets.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeEquipmentItem:

- (void) removeEquipmentItem: (NSString*) equipmentKey

Reimplemented in PlayerEntity.

Definition at line 3267 of file ShipEntity.m.

3267 :(NSString*)equipmentKey
3268{
3269 NSString* equipmentTypeCheckKey = equipmentKey;
3270 NSString* lcEquipmentKey = [equipmentKey lowercaseString];
3271 NSUInteger equipmentIndex = NSNotFound;
3272 // determine the equipment type and make sure it works also in the case of damaged equipment
3273 if ([equipmentKey hasSuffix:@"_DAMAGED"]) {
3274 equipmentTypeCheckKey = [equipmentKey substringToIndex:[equipmentKey length] - [@"_DAMAGED" length]];
3275 }
3276 OOEquipmentType* eqType = [OOEquipmentType equipmentTypeWithIdentifier:equipmentTypeCheckKey];
3277 if (eqType == nil)
3278 return;
3279
3280 if ([eqType isMissileOrMine] || ([self isThargoid] && ([lcEquipmentKey hasSuffix:@"thargon"] || [lcEquipmentKey hasPrefix:@"thargon"]))) {
3281 [self removeExternalStore:eqType];
3282 } else {
3283 if ([_equipment containsObject:equipmentKey]) {
3284 if (![equipmentKey isEqualToString:@"EQ_PASSENGER_BERTH"]) {
3285 equipment_weight -= [eqType requiredCargoSpace]; // all other cases;
3286 }
3287
3288 if ([equipmentKey isEqualToString:@"EQ_CLOAKING_DEVICE"]) {
3289 if ([self isCloaked])
3290 [self setCloaked:NO];
3291 }
3292
3293 if (!isPlayer) {
3294 if ([equipmentKey isEqualToString:@"EQ_SHIELD_BOOSTER"]) {
3295 maxEnergy -= 256.0f;
3296 if (maxEnergy < energy)
3297 energy = maxEnergy;
3298 } else if ([equipmentKey isEqualToString:@"EQ_SHIELD_ENHANCER"]) {
3299 maxEnergy -= 256.0f;
3300 energy_recharge_rate /= 1.5;
3301 if (maxEnergy < energy)
3302 energy = maxEnergy;
3303 } else if ([equipmentKey isEqual:@"EQ_CARGO_BAY"]) {
3305 }
3306 }
3307 }
3308
3309 if (![equipmentKey hasSuffix:@"_DAMAGED"] && ![eqType canCarryMultiple]) {
3310 NSString* damagedKey = [equipmentKey stringByAppendingString:@"_DAMAGED"];
3311 if ([_equipment containsObject:damagedKey]) {
3312 equipmentIndex = [_equipment indexOfObject:damagedKey];
3313 if (equipmentIndex != NSNotFound) {
3314 // remove damaged counterpart
3315 [_equipment removeObjectAtIndex:equipmentIndex];
3316 }
3317 equipment_weight -= [eqType requiredCargoSpace];
3318 }
3319 }
3320 equipmentIndex = [_equipment indexOfObject:equipmentKey];
3321 if (equipmentIndex != NSNotFound) {
3322 [_equipment removeObjectAtIndex:equipmentIndex];
3323 }
3324 // this event must come after the item is actually removed
3325 [self doScriptEvent:OOJSID("equipmentRemoved") withArgument:equipmentKey];
3326
3327 // if all docking computers are damaged while active
3328 if ([self isPlayer] && [self status] == STATUS_AUTOPILOT_ENGAGED && ![self hasDockingComputer]) {
3330 }
3331
3332 if ([_equipment count] == 0)
3333 [self removeAllEquipment];
3334 }
3335}
void disengageAutopilot()
BOOL hasDockingComputer()

References _equipment, count, disengageAutopilot, doScriptEvent:withArgument:, Entity::energy, energy_recharge_rate, equipment_weight, OOEquipmentType::equipmentTypeWithIdentifier:, extra_cargo, hasDockingComputer, isCloaked, Entity::isPlayer, isThargoid, max_cargo, Entity::maxEnergy, nil, removeAllEquipment, removeExternalStore:, OOEquipmentType::requiredCargoSpace, setCloaked:, and Entity::status.

Referenced by abandonShip, launchCascadeMine, Universe::makeDemoShipWithRole:spinning:, PlayerEntity::removeEquipmentItem:, Universe::setupIntroFirstGo:, ShipRemoveEquipment(), ShipRemoveEquipment(), ShipSetEquipmentStatus(), ShipSetEquipmentStatus(), and Universe::update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeExhaust:

- (void) removeExhaust: (OOExhaustPlumeEntity*) exhaust

Definition at line 8182 of file ShipEntity.m.

8182 :(OOExhaustPlumeEntity*)exhaust
8183{
8184 [subEntities removeObject:exhaust];
8185 [exhaust setOwner:nil];
8186}

References Entity::setOwner:.

Referenced by ExhaustPlumeRemove(), and ExhaustPlumeRemove().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeExternalStore:

- (BOOL) removeExternalStore: (OOEquipmentType*) eqType

Reimplemented in PlayerEntity.

Definition at line 3337 of file ShipEntity.m.

3337 :(OOEquipmentType*)eqType
3338{
3339 NSString* identifier = [eqType identifier];
3340 unsigned i;
3341
3342 for (i = 0; i < missiles; i++) {
3343 if ([[missile_list[i] identifier] isEqualTo:identifier]) {
3344 // now 'delete' [i] by compacting the array
3345 while (++i < missiles)
3346 missile_list[i - 1] = missile_list[i];
3347
3348 missiles--;
3349 return YES;
3350 }
3351 }
3352 return NO;
3353}

References OOEquipmentType::identifier, missile_list, and missiles.

Referenced by removeEquipmentItem:, and PlayerEntity::removeFromPylon:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeFlasher:

- (void) removeFlasher: (OOFlasherEntity*) flasher

Definition at line 8188 of file ShipEntity.m.

8188 :(OOFlasherEntity*)flasher
8189{
8190 [subEntities removeObject:flasher];
8191 [flasher setOwner:nil];
8192}

References Entity::setOwner:.

Referenced by FlasherRemove(), and FlasherRemove().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeMissiles

- (OOCreditsQuantity) removeMissiles

Reimplemented in PlayerEntity.

Definition at line 3495 of file ShipEntity.m.

3496{
3497 missiles = 0;
3498 return 0;
3499}

References missiles, and removeMissiles.

Referenced by isFrangible, removeMissiles, ShipAwardEquipment(), ShipAwardEquipment(), and ShipEntity(LoadRestore)::shipRestoredFromDictionary:useFallback:context:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeRole:

- (void) removeRole: (NSString*) role

Definition at line 6303 of file ShipEntity.m.

6303 :(NSString*)role
6304{
6305 if ([self hasRole:role]) {
6306 OORoleSet* newRoles = [roleSet roleSetWithRemovedRole:role];
6307 if (newRoles != nil) {
6308 [roleSet release];
6309 roleSet = [newRoles retain];
6310 }
6311 }
6312}

References nil, roleSet, and OORoleSet::roleSetWithRemovedRole:.

Referenced by setIsBoulder:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeScript

- (void) removeScript

Definition at line 1060 of file ShipEntity.m.

1061{
1062 [script autorelease];
1063 script = nil;
1064}

References nil, removeScript, and script.

Referenced by removeScript, ShipRemove(), and ShipRemove().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeTarget:

- (void) removeTarget: (Entity*) targetEntity

Definition at line 8682 of file ShipEntity.m.

8682 :(Entity*)targetEntity
8683{
8684 if (targetEntity != nil)
8685 [self noteLostTarget];
8686 else
8688 // targetEntity == nil is currently only true for mounted player missiles.
8689 // we don't want to send lostTarget messages while the missile is mounted.
8690
8691 [[self shipSubEntityEnumerator] makeObjectsPerformSelector:@selector(removeTarget:) withObject:targetEntity];
8692}

References _primaryTarget, DESTROY, nil, noteLostTarget, and shipSubEntityEnumerator.

Referenced by ShipEntity(PureAI)::becomeUncontrolledThargon, PlayerEntity::doBookkeeping:, noteTargetDestroyed:, ShipEntity(AI)::recallDockingInstructions, PlayerEntity::safeAllMissiles, PlayerEntity::selectNextMissile, and ShipEntity(OOJavaScriptExtensions)::setTargetForScript:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ repeatString:times:

- (NSString *) repeatString: (NSString*) str
times: (NSUInteger) times 
implementation

Definition at line 739 of file ShipEntity.m.

739 :(NSString*)str times:(NSUInteger)times
740{
741 if (times == 0)
742 return @"";
743
744 NSMutableString* result = [NSMutableString stringWithCapacity:[str length] * times];
745
746 for (NSUInteger i = 0; i < times; i++) {
747 [result appendString:str];
748 }
749
750 return result;
751}

Referenced by serializeShipSubEntities.

Here is the caller graph for this function:

◆ reportAIMessages

- (BOOL) reportAIMessages

References checkForAegis, destinationSystem, findNearestPlanet, findNearestPlanetExcludingMoons, findNearestStellarBody, forceAegisCheck, homeSystem, reportAIMessages, transitionToAegisNone, and withinStationAegis.

Here is the call graph for this function:

◆ requestDockingCoordinates

- (void) requestDockingCoordinates

Provided by category ShipEntity(AI).

Definition at line 486 of file ShipEntityAI.m.

487{
488 /*- requests coordinates from the target station
489 if the target station can't be found
490 then use the nearest it can find (which may be a rock hermit) -*/
491
492 StationEntity* station = nil;
493 Entity* targStation = nil;
494 NSString* message = nil;
495 double distanceToStation2 = 0.0;
496
497 targStation = [self targetStation];
498 if ([targStation isStation]) {
499 station = (StationEntity*)targStation;
500 } else {
501 station = [UNIVERSE nearestShipMatchingPredicate:IsStationPredicate
502 parameter:nil
503 relativeToEntity:self];
504 }
505
506 distanceToStation2 = HPdistance2([station position], [self position]);
507
508 // Player check for being inside the aegis already exists in PlayerEntityControls. We just
509 // check here that distance to station is less than 2.5 times scanner range to avoid problems with
510 // NPC ships getting stuck with a dockingAI while just outside the aegis - Nikos 20090630, as proposed by Eric
511 // On very busy systems (> 50 docking ships) docking ships can be sent to a hold position outside the range,
512 // so also test for presence of dockingInstructions. - Eric 20091130
513 if (station != nil && (distanceToStation2 < SCANNER_MAX_RANGE2 * 6.25 || dockingInstructions != nil)) {
514 // remember the instructions
515 [dockingInstructions release];
516 dockingInstructions = [[station dockingInstructionsForShip:self] retain];
517 if (dockingInstructions != nil) {
518 [self recallDockingInstructions];
519
520 message = [dockingInstructions objectForKey:@"ai_message"];
521 if (message != nil)
522 [shipAI message:message];
523 message = [dockingInstructions objectForKey:@"comms_message"];
524 if (message != nil)
525 [station sendExpandedMessage:message toShip:self];
526 }
527 } else {
529 }
530
531 if (dockingInstructions == nil) {
532 [shipAI message:@"NO_STATION_FOUND"];
533 }
534}

◆ requestNewTarget

- (void) requestNewTarget
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1936 of file ShipEntityAI.m.

1937{
1938 ShipEntity* mother = [[self group] leader];
1939 if (mother == nil) {
1940 [shipAI message:@"MOTHER_LOST"];
1941 return;
1942 }
1943
1944 /*-- Locates all the ships in range targeting the mother ship and chooses the nearest/biggest --*/
1946 [self checkScanner];
1947 unsigned i;
1948 GLfloat found_d2 = scannerRange * scannerRange;
1949 GLfloat max_e = 0;
1950 for (i = 0; i < n_scanned_ships; i++) {
1951 ShipEntity* thing = scanned_ships[i];
1952 GLfloat d2 = distance2_scanned_ships[i];
1953 GLfloat e1 = [thing energy];
1954 if ((d2 < found_d2) && ![thing isCloaked] && (([thing isThargoid] && ![mother isThargoid]) || (([thing primaryTarget] == mother) && [thing hasHostileTarget]))) {
1955 if (e1 > max_e) {
1956 [self setFoundTarget:thing];
1957 max_e = e1;
1958 }
1959 }
1960 }
1961
1962 [self checkFoundTarget];
1963}

◆ rescaleBy:

- (void) rescaleBy: (GLfloat) factor
implementation

Reimplemented from <OOSubEntity>.

Provided by category ShipEntity(Private).

Definition at line 7784 of file ShipEntity.m.

7784 :(GLfloat)factor
7785{
7786 [self rescaleBy:factor writeToCache:YES];
7787}

References rescaleBy:writeToCache:.

Here is the call graph for this function:

◆ rescaleBy:writeToCache:

- (void) rescaleBy: (GLfloat) factor
writeToCache: (BOOL) writeToCache 
implementation

Reimplemented from <OOSubEntity>.

Provided by category ShipEntity(Private).

Definition at line 7789 of file ShipEntity.m.

7789 :(GLfloat)factor writeToCache:(BOOL)writeToCache
7790{
7791 _scaleFactor *= factor;
7792 OOMesh* mesh = nil;
7793
7794 NSDictionary* shipDict = [self shipInfoDictionary];
7795 NSString* modelName = [shipDict oo_stringForKey:@"model"];
7796 if (modelName != nil) {
7797 mesh = [OOMesh meshWithName:modelName
7798 cacheKey:[NSString stringWithFormat:@"%@-%.3f", _shipKey, _scaleFactor]
7799 materialDictionary:[shipDict oo_dictionaryForKey:@"materials"]
7800 shadersDictionary:[shipDict oo_dictionaryForKey:@"shaders"]
7801 smooth:[shipDict oo_boolForKey:@"smooth" defaultValue:NO]
7802 shaderMacros:OODefaultShipShaderMacros()
7804 scaleFactor:factor
7805 cacheWriteable:writeToCache];
7806
7807 if (mesh == nil)
7808 return;
7809 [self setMesh:mesh];
7810 }
7811
7812 // rescale subentities
7813 Entity<OOSubEntity>* se = nil;
7814 foreach (se, [self subEntities]) {
7815 [se setPosition:HPvector_multiply_scalar([se position], factor)];
7816 [se rescaleBy:factor writeToCache:writeToCache];
7817 }
7818
7819 // rescale mass
7820 mass *= factor * factor * factor;
7821}
instancetype meshWithName:cacheKey:materialDictionary:shadersDictionary:smooth:shaderMacros:shaderBindingTarget:scaleFactor:cacheWriteable:(NSString *name,[cacheKey] NSString *cacheKey,[materialDictionary] NSDictionary *materialDict,[shadersDictionary] NSDictionary *shadersDict,[smooth] BOOL smooth,[shaderMacros] NSDictionary *macros,[shaderBindingTarget] id< OOWeakReferenceSupport > object,[scaleFactor] float factor,[cacheWriteable] BOOL cacheWriteable)
Definition OOMesh.m:242
OOMesh * mesh()

References OOMesh::meshWithName:cacheKey:materialDictionary:shadersDictionary:smooth:shaderMacros:shaderBindingTarget:scaleFactor:cacheWriteable:, nil, Entity::position, rescaleBy:writeToCache:, setMesh:, Entity::setPosition:, and shipInfoDictionary.

Referenced by Universe::addWreckageFrom:withRole:at:scale:lifetime:, ShipEntity(Private)::rescaleBy:, and ShipEntity(Private)::rescaleBy:writeToCache:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resetExhaustPlumes

- (void) resetExhaustPlumes

Definition at line 8442 of file ShipEntity.m.

8443{
8444 OOExhaustPlumeEntity* exEnt = nil;
8445
8446 foreach (exEnt, [self exhaustEnumerator]) {
8447 [exEnt resetPlume];
8448 }
8449}

References exhaustEnumerator, nil, resetExhaustPlumes, and OOExhaustPlumeEntity::resetPlume.

Referenced by EntitySetProperty(), EntitySetProperty(), DockEntity::launchShip:, maxFlightSpeed, PlayerEntity(OOPrivate)::performWitchspaceExitUpdates:, resetExhaustPlumes, and wasAddedToUniverse.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resetShotTime

- (void) resetShotTime

Definition at line 10089 of file ShipEntity.m.

10090{
10091 shot_time = 0.0;
10092}

References resetShotTime, and shot_time.

Referenced by coordinates, fireDirectLaserShotAt:, fireLaserShotInDirection:weaponIdentifier:, fireMissileWithIdentifier:andTarget:, fireSubentityLaserShot:, fireTurretCannon:, PlayerEntity::launchEscapeCapsule, resetShotTime, and PlayerEntity(OOPrivate)::showGameOver.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ respondToAttackFrom:becauseOf:

- (void) respondToAttackFrom: (Entity*) from
becauseOf: (Entity*) other 

Definition at line 2647 of file ShipEntity.m.

2647 :(Entity*)from becauseOf:(Entity*)other
2648{
2649 Entity* source = nil;
2650
2651 if ([other isKindOfClass:[ShipEntity class]]) {
2652 source = other;
2653
2654 // JSAIs handle friendly fire themselves
2655 if (![self hasNewAI]) {
2656
2657 ShipEntity* hunter = (ShipEntity*)other;
2658 // if we are in the same group, then we have to be careful about how we handle things
2659 if ([self isPolice] && [hunter isPolice]) {
2660 // police never get into a fight with each other
2661 return;
2662 }
2663
2664 OOShipGroup* group = [self group];
2665
2666 if (group != nil && group == [hunter group]) {
2667 // we are in the same group, do we forgive you?
2668 // criminals are less likely to forgive
2669 if (randf() < (0.8 - (bounty / 100))) {
2670 // it was an honest mistake, lets get on with it
2671 return;
2672 }
2673
2674 ShipEntity* groupLeader = [group leader];
2675 if (hunter == groupLeader) {
2676 // oops we were attacked by our leader, desert him
2677 [group removeShip:self];
2678 } else {
2679 // evict them from our group
2680 [group removeShip:hunter];
2681
2682 [groupLeader setFoundTarget:other];
2683 [groupLeader setPrimaryAggressor:hunter];
2684 [groupLeader respondToAttackFrom:from becauseOf:other];
2685 }
2686 }
2687 }
2688 } else {
2689 source = from;
2690 }
2691
2692 [self doScriptEvent:OOJSID("shipBeingAttacked") withArgument:source andReactToAIMessage:@"ATTACKED"];
2693 if ([source isShip])
2694 [(ShipEntity*)source doScriptEvent:OOJSID("shipAttackedOther") withArgument:self];
2695}
void respondToAttackFrom:becauseOf:(Entity *from,[becauseOf] Entity *other)

References bounty, doScriptEvent:withArgument:, doScriptEvent:withArgument:andReactToAIMessage:, group, hasNewAI, isPolice, Entity::isShip, OOShipGroup::leader, nil, randf(), OOShipGroup::removeShip:, respondToAttackFrom:becauseOf:, setFoundTarget:, and setPrimaryAggressor:.

Referenced by respondToAttackFrom:becauseOf:, takeEnergyDamage:from:becauseOf:weaponIdentifier:, and StationEntity::takeEnergyDamage:from:becauseOf:weaponIdentifier:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resumePostProximityAlert

- (void) resumePostProximityAlert

Definition at line 5947 of file ShipEntity.m.

5948{
5949 if (!previousCondition)
5950 return;
5951
5952 behaviour = [previousCondition oo_intForKey:@"behaviour"];
5953 [_primaryTarget release];
5954 _primaryTarget = [[previousCondition objectForKey:@"primaryTarget"] weakRetain];
5955 [self startTrackingCurve];
5956 desired_range = [previousCondition oo_floatForKey:@"desired_range"];
5957 desired_speed = [previousCondition oo_floatForKey:@"desired_speed"];
5958 _destination = [previousCondition oo_hpvectorForKey:@"destination"];
5959
5960 [previousCondition release];
5962 frustration = 0.0;
5963
5965
5966 //[shipAI message:@"RESTART_DOCKING"]; // if docking, start over, other AIs will ignore this message
5967}

References _destination, _primaryTarget, _proximityAlert, behaviour, desired_range, desired_speed, DESTROY, frustration, nil, previousCondition, resumePostProximityAlert, and startTrackingCurve.

Referenced by behaviour_avoid_collision:, reactionTime, and resumePostProximityAlert.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rightVector

- (Vector) rightVector

Definition at line 1174 of file ShipEntity.m.

1175{
1176 return v_right;
1177}

References rightVector, and v_right.

Referenced by rightVector, totalBoundingBox, and OOExhaustPlumeEntity::update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ roleSet

References roleSet.

◆ rollD:

- (void) rollD: (NSString*) die_number
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1965 of file ShipEntityAI.m.

1965 :(NSString*)die_number
1966{
1967 int die_sides = [die_number intValue];
1968 if (die_sides > 0) {
1969 int die_roll = 1 + (ranrot_rand() % die_sides);
1970 NSString* result = [NSString stringWithFormat:@"ROLL_%d", die_roll];
1971 [shipAI reactToMessage:result context:@"rollD:"];
1972 } else {
1973 OOLog(@"ai.rollD.invalidValue", @"***** ERROR: invalid value supplied to rollD: '%@'.", die_number);
1974 }
1975}

◆ rollToMatchUp:rotating:

- (GLfloat) rollToMatchUp: (Vector) up_vec
rotating: (GLfloat) match_roll 

Definition at line 9602 of file ShipEntity.m.

9602 :(Vector)up_vec rotating:(GLfloat)match_roll
9603{
9604 GLfloat cosTheta = dot_product(up_vec, v_up); // == cos of angle between up vectors
9605 GLfloat sinTheta = dot_product(up_vec, v_right);
9606
9607 if (!isPlayer) {
9608 match_roll = -match_roll; // make necessary corrections for a different viewpoint
9609 sinTheta = -sinTheta;
9610 }
9611
9612 if (cosTheta < 0.0f) {
9613 cosTheta = -cosTheta;
9614 sinTheta = -sinTheta;
9615 }
9616
9617 if (sinTheta > 0.0f) {
9618 // increase roll rate
9619 return cosTheta * cosTheta * match_roll + sinTheta * sinTheta * max_flight_roll;
9620 } else {
9621 // decrease roll rate
9622 return cosTheta * cosTheta * match_roll - sinTheta * sinTheta * max_flight_roll;
9623 }
9624}

References dot_product(), Entity::isPlayer, max_flight_roll, v_right, and v_up.

Referenced by trackDestination:retreat:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ safeScriptActionOnTarget:

- (void) safeScriptActionOnTarget: (NSString*) action
implementation

Provided by category ShipEntity(PureAI).

Definition at line 2271 of file ShipEntityAI.m.

2271 :(NSString*)action
2272{
2273 PlayerEntity* player = PLAYER;
2274 ShipEntity* targEnt = [self primaryTarget];
2275 ShipEntity* oldTarget = nil;
2276
2277 if ([targEnt isShip]) {
2278 oldTarget = [player scriptTarget];
2279 [player setScriptTarget:(ShipEntity*)targEnt];
2280 [player runUnsanitizedScriptActions:[NSArray arrayWithObject:action]
2282 withContextName:[NSString stringWithFormat:@"<AI \"%@\" state %@ - safeScriptActionOnTarget:>", [[self getAI] name], [[self getAI] state]]
2283 forTarget:targEnt];
2284 [player setScriptTarget:oldTarget];
2285 }
2286}
void runUnsanitizedScriptActions:allowingAIMethods:withContextName:forTarget:(NSArray *unsanitizedActions,[allowingAIMethods] BOOL allowAIMethods,[withContextName] NSString *contextName,[forTarget] ShipEntity *target)
void setScriptTarget:(ShipEntity *ship)

◆ savedShipDictionaryWithContext:

- (NSDictionary *) savedShipDictionaryWithContext: (NSMutableDictionary*) context

Provided by category ShipEntity(LoadRestore).

Definition at line 75 of file ShipEntityLoadRestore.m.

75 :(NSMutableDictionary*)context
76{
77 NSMutableDictionary* result = [NSMutableDictionary dictionary];
78 if (context == nil)
79 context = [NSMutableDictionary dictionary];
80
81 [result setObject:_shipKey forKey:KEY_SHIP_KEY];
82
83 NSMutableDictionary* updatedShipInfo = [NSMutableDictionary dictionaryWithDictionary:shipinfoDictionary];
84
85 [updatedShipInfo setObject:[[self roleSet] roleString] forKey:KEY_ROLES];
86 [updatedShipInfo oo_setUnsignedInteger:fuel forKey:KEY_FUEL];
87 [updatedShipInfo oo_setUnsignedLongLong:bounty forKey:KEY_BOUNTY];
88 [updatedShipInfo setObject:OOStringFromWeaponType(forward_weapon_type) forKey:KEY_FORWARD_WEAPON];
89 [updatedShipInfo setObject:OOStringFromWeaponType(aft_weapon_type) forKey:KEY_AFT_WEAPON];
90 [updatedShipInfo setObject:OOStringFromScanClass(scanClass) forKey:KEY_SCAN_CLASS];
91
92 NSArray* deletes = nil;
93 [self simplifyShipdata:updatedShipInfo andGetDeletes:&deletes];
94
95 [result setObject:updatedShipInfo forKey:KEY_SHIPDATA_OVERRIDES];
96 if (deletes != nil)
97 [result setObject:deletes forKey:KEY_SHIPDATA_DELETES];
98
100 [result oo_setHPVector:[self position] forKey:KEY_POSITION];
101 }
103 [result oo_setQuaternion:[self normalOrientation] forKey:KEY_ORIENTATION];
104 }
105
106 if (energy != maxEnergy)
107 [result oo_setFloat:energy / maxEnergy forKey:KEY_ENERGY_LEVEL];
108
109 [result setObject:[self primaryRole] forKey:KEY_PRIMARY_ROLE];
110
111 // Add equipment.
112 NSArray* equipment = [[self equipmentEnumerator] allObjects];
113 if ([equipment count] != 0)
114 [result setObject:equipment forKey:KEY_EQUIPMENT];
115
116 // Add missiles.
117 if (missiles > 0) {
118 NSMutableArray* missileArray = [NSMutableArray array];
119 unsigned i;
120 for (i = 0; i < missiles; i++) {
121 NSString* missileType = [missile_list[i] identifier];
122 if (missileType != nil)
123 [missileArray addObject:missileType];
124 }
125 [result setObject:missileArray forKey:KEY_MISSILES];
126 }
127
128 // Add groups.
129 if (_group != nil) {
130 [result oo_setUnsignedInteger:GroupIDForGroup(_group, context) forKey:KEY_GROUP_ID];
131 if ([_group leader] == self)
132 [result oo_setBool:YES forKey:KEY_IS_GROUP_LEADER];
133 NSString* groupName = [_group name];
134 if (groupName != nil) {
135 [result setObject:groupName forKey:KEY_GROUP_NAME];
136 }
137 }
138 if (_escortGroup != nil) {
139 [result oo_setUnsignedInteger:GroupIDForGroup(_escortGroup, context) forKey:KEY_ESCORT_GROUP_ID];
140 }
141 /* Eric:
142 The escortGroup property is removed from the lead ship, on entering witchspace.
143 But it is needed in the save file to correctly restore an escorted group.
144 */
145 else if (_group != nil && [_group leader] == self) {
146 [result oo_setUnsignedInteger:GroupIDForGroup(_group, context) forKey:KEY_ESCORT_GROUP_ID];
147 }
148
149 // FIXME: AI.
150 // Eric: I think storing the AI name should be enough. On entering a wormhole, the stack is cleared so there are no preserved AI states.
151 // Also the AI restarts itself with the GLOBAL state, so no need to store any old state.
152 if ([[[self getAI] name] isEqualToString:@"nullAI.plist"]) {
153 // might be a JS version
154 [result setObject:[[self getAI] associatedJS] forKey:KEY_AI];
155 // if there isn't, loading nullAI.js will load nullAI.plist anyway
156 } else {
157 [result setObject:[[self getAI] name] forKey:KEY_AI];
158 }
159
160 return result;
161}
OOINLINE bool HPvector_equal(HPVector a, HPVector b) INLINE_CONST_FUNC
Definition OOHPVector.h:250
OOINLINE bool quaternion_equal(Quaternion a, Quaternion b) INLINE_CONST_FUNC

◆ scanClass

- (OOScanClass) scanClass
implementation

Reimplemented from Entity.

Definition at line 1849 of file ShipEntity.m.

1850{
1852 return CLASS_NO_DRAW;
1853 return scanClass;
1854}

References cloaking_device_active, and scanClass.

Referenced by PlayerEntity::addRoleForAggression:, Universe::addShipAt:withRole:withinRadius:, Universe::addShips:withRole:atPosition:withCoordinateSystem:, AuthorityPredicate, avoidCollision, StationEntity::becomeExplosion, behaviour_idle:, behaviour_intercept_target:, behaviour_track_as_turret:, broadcastHitByLaserFrom:, canAcceptEscort:, canScoop:, cascadeIfAppropriateWithDamageAmount:cascadeOwner:, PlayerEntity::collectBountyFor:, ShipEntity(PureAI)::fightOrFleeMissile, fireDirectLaserDefensiveShot, fireMissileWithIdentifier:andTarget:, interpretAIMessage:, isFriendlyTo:, isPolice, isThargoid, isUnpiloted, PlayerEntity::isValidTarget:, isValidTarget:, StationEntity::launchDefenseShip, StationEntity::launchIndependentShip:, StationEntity::launchPatrol, StationEntity::launchPolice, StationEntity::launchShipWithRole:, legalStatus, markAsOffender:withReason:, scanClass, scanDescription, ShipEntity(PureAI)::scanForFormationLeader, ShipEntity(OOAIPrivate)::scanForNearestShipWithPredicate:parameter:, ShipEntity(PureAI)::scanForOffenders, scannerDisplayColorForShip:isHostile:flash:scannerDisplayColor1:scannerDisplayColor2:scannerDisplayColorH1:scannerDisplayColorH2:, setAccuracy:, setBounty:withReason:, setCommsMessageColor, PlayerEntity::setUpAndConfirmOK:saveGame:, setUpShipFromDictionary:, trackPrimaryTarget:retreat:, trackSideTarget:leftside:, update:, and StationEntity::update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scanDescription

- (NSString *) scanDescription

Definition at line 6198 of file ShipEntity.m.

6199{
6200 if (scan_description != nil) {
6201 return scan_description;
6202 } else {
6203 NSString* desc = nil;
6204 switch ([self scanClass]) {
6205 case CLASS_NEUTRAL: {
6206 int legal = [self legalStatus];
6207 int legal_i = 0;
6208 if (legal > 0) {
6209 legal_i = (legal <= 50) ? 1 : 2;
6210 }
6211 desc = [[[UNIVERSE descriptions] oo_arrayForKey:@"legal_status"] oo_stringAtIndex:legal_i];
6212 } break;
6213
6214 case CLASS_THARGOID:
6215 desc = DESC(@"legal-desc-alien");
6216 break;
6217
6218 case CLASS_POLICE:
6219 desc = DESC(@"legal-desc-system-vessel");
6220 break;
6221
6222 case CLASS_MILITARY:
6223 desc = DESC(@"legal-desc-military-vessel");
6224 break;
6225
6226 default:
6227 break;
6228 }
6229 return desc;
6230 }
6231}

References DESC, legalStatus, nil, scan_description, scanClass, and scanDescription.

Referenced by displayName, HeadUpDisplay::hudDrawReticleOnTarget, and scanDescription.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scanDescriptionForScripting

- (NSString *) scanDescriptionForScripting

Definition at line 6193 of file ShipEntity.m.

6194{
6195 return scan_description;
6196}

References scan_description, and scanDescriptionForScripting.

Referenced by displayName, scanDescriptionForScripting, ShipGetProperty(), and ShipGetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scanForFormationLeader

- (void) scanForFormationLeader
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1621 of file ShipEntityAI.m.

1622{
1623 //-- Locates the nearest suitable formation leader in range --//
1625 [self checkScannerIgnoringUnpowered];
1626 unsigned i;
1627 GLfloat found_d2 = scannerRange * scannerRange;
1628 for (i = 0; i < n_scanned_ships; i++) {
1629 ShipEntity* ship = scanned_ships[i];
1630 if ((ship != self) && (!ship->isPlayer) && (ship->scanClass == scanClass) && [ship primaryTarget] != self && ![ship isCloaked]) // look for alike
1631 {
1632 GLfloat d2 = distance2_scanned_ships[i];
1633 if ((d2 < found_d2) && [ship canAcceptEscort:self]) {
1634 found_d2 = d2;
1635 [self setFoundTarget:ship];
1636 }
1637 }
1638 }
1639
1640 if ([self foundTarget] != nil)
1641 [shipAI message:@"TARGET_FOUND"];
1642 else {
1643 [shipAI message:@"NOTHING_FOUND"];
1644 if ([self hasPrimaryRole:@"wingman"]) {
1645 // become free-lance police :)
1646 [self setAITo:@"route1patrolAI.plist"]; // use this to avoid referencing a released AI
1647 [self setPrimaryRole:@"police"]; // other wingman can now select this ship as leader.
1648 }
1649 }
1650}

◆ scanForHostiles

- (void) scanForHostiles

Provided by category ShipEntity(AI).

Definition at line 293 of file ShipEntityAI.m.

294{
295 /*-- Locates all the ships in range targeting the receiver and chooses the nearest --*/
297
298 [self checkScanner];
299 unsigned i;
300 GLfloat found_d2 = scannerRange * scannerRange;
301 for (i = 0; i < n_scanned_ships; i++) {
302 ShipEntity* thing = scanned_ships[i];
303 GLfloat d2 = distance2_scanned_ships[i];
304 if ((d2 < found_d2)
305 && ([thing isThargoid] || (([thing primaryTarget] == self) && [thing hasHostileTarget]) || [thing isDefenseTarget:self])
306 && ![thing isCloaked]) {
307 [self setFoundTarget:thing];
308 found_d2 = d2;
309 }
310 }
311
312 [self checkFoundTarget];
313}

Referenced by PlayerEntity(Scripting)::targetNearestHostile.

Here is the caller graph for this function:

◆ scanForLoot

- (void) scanForLoot
implementation

Provided by category ShipEntity(PureAI).

Definition at line 937 of file ShipEntityAI.m.

938{
939 /*-- Locates the nearest debris in range --*/
940 if (!isStation) {
941 if (![self hasCargoScoop]) {
942 [shipAI message:@"NOTHING_FOUND"]; // can't collect loot if you have no scoop!
943 return;
944 }
945 if ([cargo count] >= [self maxAvailableCargoSpace]) {
946 if (max_cargo)
947 [shipAI message:@"HOLD_FULL"]; // can't collect loot if holds are full!
948 [shipAI message:@"NOTHING_FOUND"]; // can't collect loot if holds are full!
949 return;
950 }
951 } else {
952 if (magnitude2([self velocity])) {
953 [shipAI message:@"NOTHING_FOUND"]; // can't collect loot if you're a moving station
954 return;
955 }
956 }
957
958 [self checkScanner];
959
960 double found_d2 = scannerRange * scannerRange;
962 unsigned i;
963 for (i = 0; i < n_scanned_ships; i++) {
964 ShipEntity* other = (ShipEntity*)scanned_ships[i];
965 if ([other scanClass] == CLASS_CARGO && [other cargoType] != CARGO_NOT_CARGO && [other status] != STATUS_BEING_SCOOPED) {
966 if ((![self isPolice]) || ([[other commodityType] isEqualToString:@"slaves"])) // police only rescue lifepods and slaves
967 {
968 GLfloat d2 = distance2_scanned_ships[i];
969 if (d2 < found_d2) {
970 found_d2 = d2;
971 [self setFoundTarget:other];
972 }
973 }
974 }
975 }
976 [self checkFoundTarget];
977}

◆ scanForNearestIncomingMissile

- (void) scanForNearestIncomingMissile

Provided by category ShipEntity(AI).

Definition at line 555 of file ShipEntityAI.m.

556{
557 BinaryOperationPredicateParameter param = {
558 HasScanClassPredicate, [NSNumber numberWithInt:CLASS_MISSILE],
560 };
561 [self scanForNearestShipWithPredicate:ANDPredicate parameter:&param];
562}
BOOL HasScanClassPredicate(Entity *entity, void *parameter)
BOOL IsHostileAgainstTargetPredicate(Entity *ship, void *parameter)

Referenced by PlayerEntity(Scripting)::targetNearestIncomingMissile.

Here is the caller graph for this function:

◆ scanForNearestMerchantman

- (void) scanForNearestMerchantman
implementation

Provided by category ShipEntity(PureAI).

Definition at line 884 of file ShipEntityAI.m.

885{
886 float d2, found_d2;
887 unsigned i;
888 ShipEntity* ship = nil;
889
890 //-- Locates the nearest merchantman in range.
891 [self checkScannerIgnoringUnpowered];
892
893 found_d2 = scannerRange * scannerRange;
895
896 for (i = 0; i < n_scanned_ships; i++) {
897 ship = scanned_ships[i];
898 if ([ship isPirateVictim] && ([ship status] != STATUS_DEAD) && ([ship status] != STATUS_DOCKED) && ![ship isCloaked]) {
900 if (PIRATES_PREFER_PLAYER && (d2 < desired_range * desired_range) && ship->isPlayer && [self isPirate]) {
901 d2 = 0.0;
902 } else
904 if (d2 < found_d2) {
905 found_d2 = d2;
906 [self setFoundTarget:ship];
907 }
908 }
909 }
910 [self checkFoundTarget];
911}
#define PIRATES_PREFER_PLAYER
Definition ShipEntity.h:42
BOOL isPirate()
BOOL isPirateVictim()

◆ scanForNearestShipHavingAnyRole:

- (void) scanForNearestShipHavingAnyRole: (NSString*) scanRoles
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1993 of file ShipEntityAI.m.

1993 :(NSString*)scanRoles
1994{
1995 NSSet* set = [NSSet setWithArray:ScanTokensFromString(scanRoles)];
1996 [self scanForNearestShipWithPredicate:HasRoleInSetPredicate parameter:set];
1997}

◆ scanForNearestShipHavingRole:

- (void) scanForNearestShipHavingRole: (NSString*) scanRole
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1982 of file ShipEntityAI.m.

1982 :(NSString*)scanRole
1983{
1984 [self scanForNearestShipWithPredicate:HasRolePredicate parameter:scanRole];
1985}

Referenced by ShipEntity(PureAI)::thargonCheckMother.

Here is the caller graph for this function:

◆ scanForNearestShipMatchingPredicate:

- (void) scanForNearestShipMatchingPredicate: (NSString*) predicateExpression
implementation

Provided by category ShipEntity(PureAI).

Definition at line 2033 of file ShipEntityAI.m.

2033 :(NSString*)predicateExpression
2034{
2035 /* Takes a boolean-valued JS expression where "ship" is the ship being
2036 evaluated and "this" is our ship's ship script. the expression is
2037 turned into a JS function of the form:
2038
2039 function _oo_AIScanPredicate(ship)
2040 {
2041 return $expression;
2042 }
2043
2044 Examples of expressions:
2045 ship.isWeapon
2046 this.someComplicatedPredicate(ship)
2047 function (ship) { ...do something complicated... } ()
2048 */
2049
2050 static NSMutableDictionary* scriptCache = nil;
2051 NSString* aiName = nil;
2052 NSString* key = nil;
2053 OOJSFunction* function = nil;
2054 JSContext* context = NULL;
2055
2056 context = OOJSAcquireContext();
2057
2058 if (predicateExpression == nil)
2059 predicateExpression = @"false";
2060
2061 aiName = [[self getAI] name];
2062#ifndef NDEBUG
2063 /* In debug/test release builds, scripts are cached per AI in order to be
2064 able to report errors correctly. For end-user releases, we only cache
2065 one copy of each predicate, potentially leading to error messages for
2066 the wrong AI.
2067 */
2068 key = [NSString stringWithFormat:@"%@\n%@", aiName, predicateExpression];
2069#else
2070 key = predicateExpression;
2071#endif
2072
2073 // Look for cached function
2074 function = [scriptCache objectForKey:key];
2075 if (function == nil) {
2076 NSString* predicateCode = nil;
2077 const char* argNames[] = { "ship" };
2078
2079 // Stuff expression in a function.
2080 predicateCode = [NSString stringWithFormat:@"return %@;", predicateExpression];
2081 function = [[OOJSFunction alloc] initWithName:@"_oo_AIScanPredicate"
2082#if OOJS_QUICKJS
2083 scope:JS_UNDEFINED
2084#else
2085 scope:NULL
2086#endif
2087 code:predicateCode
2088 argumentCount:1
2089 argumentNames:argNames
2090 fileName:aiName
2091 lineNumber:0
2092 context:context];
2093 [function autorelease];
2094
2095 // Cache function.
2096 if (function != nil) {
2097 if (scriptCache == nil)
2098 scriptCache = [[NSMutableDictionary alloc] init];
2099 [scriptCache setObject:function forKey:key];
2100 }
2101 }
2102
2103 if (function != nil) {
2104#if OOJS_QUICKJS
2105 JSValue jsThis = OOJSObjectFromNativeObject(context, self); // Owned.
2106 JSFunctionPredicateParameter param = {
2107 .context = context,
2108 .function = [function function], // Borrowed.
2109 .jsThis = jsThis
2110 };
2111 [self scanForNearestShipWithPredicate:JSFunctionPredicate parameter:&param];
2112 JS_FreeValue(context, jsThis);
2113#else
2114 JSFunctionPredicateParameter param = {
2115 .context = context,
2116 .function = [function functionValue],
2117 .jsThis = OOJSObjectFromNativeObject(context, self)
2118 };
2119 [self scanForNearestShipWithPredicate:JSFunctionPredicate parameter:&param];
2120#endif
2121 } else {
2122 // Report error (once per occurrence)
2123 static NSMutableSet* errorCache = nil;
2124
2125 if (![errorCache containsObject:key]) {
2126 OOLog(@"ai.scanForNearestShipMatchingPredicate.compile.failed", @"Could not compile JavaScript predicate \"%@\" for AI %@.", predicateExpression, [[self getAI] name]);
2127 if (errorCache == nil)
2128 errorCache = [[NSMutableSet alloc] init];
2129 [errorCache addObject:key];
2130 }
2131
2132 // Select nothing
2134 [[self getAI] message:@"NOTHING_FOUND"];
2135 }
2136
2138 OOJSRelinquishContext(context);
2139}
JSObject * OOJSObjectFromNativeObject(JSContext *context, id object)
OOINLINE void OOJSReportPendingException(JSContext *context)

◆ scanForNearestShipNotHavingAnyRole:

- (void) scanForNearestShipNotHavingAnyRole: (NSString*) scanRoles
implementation

Provided by category ShipEntity(PureAI).

Definition at line 2021 of file ShipEntityAI.m.

2021 :(NSString*)scanRoles
2022{
2023 NSSet* set = [NSSet setWithArray:ScanTokensFromString(scanRoles)];
2024 [self scanForNearestShipWithNegatedPredicate:HasRoleInSetPredicate parameter:set];
2025}

◆ scanForNearestShipNotHavingRole:

- (void) scanForNearestShipNotHavingRole: (NSString*) scanRole
implementation

Provided by category ShipEntity(PureAI).

Definition at line 2010 of file ShipEntityAI.m.

2010 :(NSString*)scanRole
2011{
2012 [self scanForNearestShipWithNegatedPredicate:HasRolePredicate parameter:scanRole];
2013}

◆ scanForNearestShipWithAnyPrimaryRole:

- (void) scanForNearestShipWithAnyPrimaryRole: (NSString*) scanRoles
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1987 of file ShipEntityAI.m.

1987 :(NSString*)scanRoles
1988{
1989 NSSet* set = [NSSet setWithArray:ScanTokensFromString(scanRoles)];
1990 [self scanForNearestShipWithPredicate:HasPrimaryRoleInSetPredicate parameter:set];
1991}

◆ scanForNearestShipWithNegatedPredicate:parameter:

- (void) scanForNearestShipWithNegatedPredicate: (EntityFilterPredicate) predicate
parameter: (void*) parameter 
implementation

Provided by category ShipEntity(OOAIPrivate).

Definition at line 2507 of file ShipEntityAI.m.

2507 :(EntityFilterPredicate)predicate parameter:(void*)parameter
2508{
2509 ChainedEntityPredicateParameter param = { predicate, parameter };
2510 [self scanForNearestShipWithPredicate:NOTPredicate parameter:&param];
2511}
BOOL(* EntityFilterPredicate)(Entity *entity, void *parameter)
Definition Universe.h:51

Referenced by ShipEntity(PureAI)::scanForNearestShipNotHavingAnyRole:, ShipEntity(PureAI)::scanForNearestShipNotHavingRole:, ShipEntity(PureAI)::scanForNearestShipWithoutAnyPrimaryRole:, ShipEntity(PureAI)::scanForNearestShipWithoutPrimaryRole:, and ShipEntity(PureAI)::scanForNearestShipWithoutScanClass:.

Here is the caller graph for this function:

◆ scanForNearestShipWithoutAnyPrimaryRole:

- (void) scanForNearestShipWithoutAnyPrimaryRole: (NSString*) scanRoles
implementation

Provided by category ShipEntity(PureAI).

Definition at line 2015 of file ShipEntityAI.m.

2015 :(NSString*)scanRoles
2016{
2017 NSSet* set = [NSSet setWithArray:ScanTokensFromString(scanRoles)];
2018 [self scanForNearestShipWithNegatedPredicate:HasPrimaryRoleInSetPredicate parameter:set];
2019}

◆ scanForNearestShipWithoutPrimaryRole:

- (void) scanForNearestShipWithoutPrimaryRole: (NSString*) scanRole
implementation

Provided by category ShipEntity(PureAI).

Definition at line 2005 of file ShipEntityAI.m.

2005 :(NSString*)scanRole
2006{
2007 [self scanForNearestShipWithNegatedPredicate:HasPrimaryRolePredicate parameter:scanRole];
2008}

◆ scanForNearestShipWithoutScanClass:

- (void) scanForNearestShipWithoutScanClass: (NSString*) scanScanClass
implementation

Provided by category ShipEntity(PureAI).

Definition at line 2027 of file ShipEntityAI.m.

2027 :(NSString*)scanScanClass
2028{
2029 NSNumber* parameter = [NSNumber numberWithInt:OOScanClassFromString(scanScanClass)];
2030 [self scanForNearestShipWithNegatedPredicate:HasScanClassPredicate parameter:parameter];
2031}

◆ scanForNearestShipWithPredicate:parameter:

- (void) scanForNearestShipWithPredicate: (EntityFilterPredicate) predicate
parameter: (void*) parameter 
implementation

Provided by category ShipEntity(OOAIPrivate).

Definition at line 2481 of file ShipEntityAI.m.

2481 :(EntityFilterPredicate)predicate parameter:(void*)parameter
2482{
2483 // Locates all the ships in range for which predicate returns YES, and chooses the nearest.
2484 unsigned i;
2485 ShipEntity* candidate;
2486 float d2, found_d2 = scannerRange * scannerRange;
2487
2489 [self checkScanner];
2490
2491 if (predicate == NULL)
2492 return;
2493
2494 for (i = 0; i < n_scanned_ships; i++) {
2495 candidate = scanned_ships[i];
2497 if ((d2 < found_d2) && (candidate->scanClass != CLASS_CARGO) && ([candidate status] != STATUS_DOCKED)
2498 && predicate(candidate, parameter) && ![candidate isCloaked]) {
2499 [self setFoundTarget:candidate];
2500 found_d2 = d2;
2501 }
2502 }
2503
2504 [self checkFoundTarget];
2505}

Referenced by ShipEntity(AI)::scanForNearestIncomingMissile, ShipEntity(PureAI)::scanForNearestShipHavingAnyRole:, ShipEntity(PureAI)::scanForNearestShipHavingRole:, ShipEntity(PureAI)::scanForNearestShipMatchingPredicate:, ShipEntity(PureAI)::scanForNearestShipWithAnyPrimaryRole:, ShipEntity(OOAIPrivate)::scanForNearestShipWithNegatedPredicate:parameter:, ShipEntity(PureAI)::scanForNearestShipWithPrimaryRole:, and ShipEntity(PureAI)::scanForNearestShipWithScanClass:.

Here is the caller graph for this function:

◆ scanForNearestShipWithPrimaryRole:

- (void) scanForNearestShipWithPrimaryRole: (NSString*) scanRole
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1977 of file ShipEntityAI.m.

1977 :(NSString*)scanRole
1978{
1979 [self scanForNearestShipWithPredicate:HasPrimaryRolePredicate parameter:scanRole];
1980}

Referenced by ShipEntity(PureAI)::scanForThargoid.

Here is the caller graph for this function:

◆ scanForNearestShipWithScanClass:

- (void) scanForNearestShipWithScanClass: (NSString*) scanScanClass
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1999 of file ShipEntityAI.m.

1999 :(NSString*)scanScanClass
2000{
2001 NSNumber* parameter = [NSNumber numberWithInt:OOScanClassFromString(scanScanClass)];
2002 [self scanForNearestShipWithPredicate:HasScanClassPredicate parameter:parameter];
2003}

◆ scanForNonThargoid

- (void) scanForNonThargoid
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1466 of file ShipEntityAI.m.

1467{
1468 /*-- Locates all the non thargoid ships in range and chooses the nearest --*/
1470
1471 [self checkScanner];
1472 unsigned i;
1473 GLfloat found_d2 = scannerRange * scannerRange;
1474 for (i = 0; i < n_scanned_ships; i++) {
1475 ShipEntity* thing = scanned_ships[i];
1476 GLfloat d2 = distance2_scanned_ships[i];
1477 if (([thing scanClass] != CLASS_CARGO) && ([thing status] != STATUS_DOCKED) && ![thing isThargoid] && ![thing isCloaked] && (d2 < found_d2)) {
1478 [self setFoundTarget:thing];
1479 if ([thing isPlayer])
1480 d2 = 0.0; // prefer the player
1481 found_d2 = d2;
1482 }
1483 }
1484
1485 [self checkFoundTarget];
1486}

◆ scanForOffenders

- (void) scanForOffenders
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1351 of file ShipEntityAI.m.

1352{
1353 /*-- Locates all the ships in range and compares their legal status or bounty against ranrot_rand() & 255 - chooses the worst offender --*/
1354 NSDictionary* systeminfo = [UNIVERSE currentSystemData];
1355 float gov_factor = 0.4 * [(NSNumber*)[systeminfo objectForKey:KEY_GOVERNMENT] intValue]; // 0 .. 7 (0 anarchic .. 7 most stable) --> [0.0, 0.4, 0.8, 1.2, 1.6, 2.0, 2.4, 2.8]
1356 //
1357 if ([UNIVERSE sun] == nil)
1358 gov_factor = 1.0;
1359 //
1361
1362 // find the worst offender on the scanner
1363 //
1364 [self checkScanner];
1365 unsigned i;
1366 float worst_legal_factor = 0;
1367 GLfloat found_d2 = scannerRange * scannerRange;
1368 OOShipGroup* group = [self group];
1369 for (i = 0; i < n_scanned_ships; i++) {
1370 ShipEntity* ship = scanned_ships[i];
1371 if ((ship->scanClass != CLASS_CARGO) && ([ship status] != STATUS_DEAD) && ([ship status] != STATUS_DOCKED) && ![ship isCloaked]) {
1372 GLfloat d2 = distance2_scanned_ships[i];
1373 float legal_factor = [ship legalStatus] * gov_factor;
1374 int random_factor = ranrot_rand() & 255; // 25% chance of spotting a fugitive in 15s
1375 if ((d2 < found_d2) && (random_factor < legal_factor) && (legal_factor > worst_legal_factor)) {
1376 if (group == nil || group != [ship group]) // fellows with bounty can't be offenders
1377 {
1378 [self setFoundTarget:ship];
1379 worst_legal_factor = legal_factor;
1380 }
1381 }
1382 }
1383 }
1384
1385 [self checkFoundTarget];
1386}

◆ scanForRandomLoot

- (void) scanForRandomLoot
implementation

Provided by category ShipEntity(PureAI).

Definition at line 979 of file ShipEntityAI.m.

980{
981 /*-- Locates the all debris in range and chooses a piece at random from the first sixteen found --*/
982 if (![self isStation] && ![self hasCargoScoop]) {
983 [shipAI message:@"NOTHING_FOUND"]; // can't collect loot if you have no scoop!
984 return;
985 }
986 //
987 [self checkScanner];
988 //
989 ShipEntity* thing_uids_found[16];
990 unsigned things_found = 0;
992 unsigned i;
993 for (i = 0; (i < n_scanned_ships) && (things_found < 16); i++) {
994 ShipEntity* other = scanned_ships[i];
995 if ([other scanClass] == CLASS_CARGO && [other cargoType] != CARGO_NOT_CARGO && [other status] != STATUS_BEING_SCOOPED) {
996 thing_uids_found[things_found++] = other;
997 }
998 }
999
1000 if (things_found != 0) {
1001 [self setFoundTarget:thing_uids_found[ranrot_rand() % things_found]];
1002 [shipAI message:@"TARGET_FOUND"];
1003 } else
1004 [shipAI message:@"NOTHING_FOUND"];
1005}

◆ scanForRandomMerchantman

- (void) scanForRandomMerchantman
implementation

Provided by category ShipEntity(PureAI).

Definition at line 913 of file ShipEntityAI.m.

914{
915 unsigned n_found, i;
916
917 //-- Locates one of the merchantman in range.
918 [self checkScannerIgnoringUnpowered];
919 ShipEntity* ids_found[n_scanned_ships];
920
921 n_found = 0;
923 for (i = 0; i < n_scanned_ships; i++) {
924 ShipEntity* ship = scanned_ships[i];
925 if (([ship status] != STATUS_DEAD) && ([ship status] != STATUS_DOCKED) && [ship isPirateVictim] && ![ship isCloaked])
926 ids_found[n_found++] = ship;
927 }
928 if (n_found == 0) {
929 [shipAI message:@"NOTHING_FOUND"];
930 } else {
931 i = ranrot_rand() % n_found; // pick a number from 0 -> (n_found - 1)
932 [self setFoundTarget:ids_found[i]];
933 [shipAI message:@"TARGET_FOUND"];
934 }
935}

◆ scanForRocks

- (void) scanForRocks
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1871 of file ShipEntityAI.m.

1872{
1873 /*-- Locates the all boulders and asteroids in range and selects nearest --*/
1874
1875 // find boulders then asteroids within range
1876 //
1878 [self checkScanner];
1879 unsigned i;
1880 GLfloat found_d2 = scannerRange * scannerRange;
1881 for (i = 0; i < n_scanned_ships; i++) {
1882 ShipEntity* thing = scanned_ships[i];
1883 if ([thing isBoulder]) {
1884 GLfloat d2 = distance2_scanned_ships[i];
1885 if (d2 < found_d2) {
1886 [self setFoundTarget:thing];
1887 found_d2 = d2;
1888 }
1889 }
1890 }
1891 if ([self foundTarget] == nil) {
1892 for (i = 0; i < n_scanned_ships; i++) {
1893 ShipEntity* thing = scanned_ships[i];
1894 if ([thing hasRole:@"asteroid"]) {
1895 GLfloat d2 = distance2_scanned_ships[i];
1896 if (d2 < found_d2) {
1897 [self setFoundTarget:thing];
1898 found_d2 = d2;
1899 }
1900 }
1901 }
1902 }
1903
1904 [self checkFoundTarget];
1905}

◆ scanForThargoid

- (void) scanForThargoid
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1461 of file ShipEntityAI.m.

1462{
1463 return [self scanForNearestShipWithPrimaryRole:@"thargoid"];
1464}

◆ scannedShips

- (ShipEntity **) scannedShips

Definition at line 8537 of file ShipEntity.m.

8538{
8539 scanned_ships[n_scanned_ships] = nil; // terminate array
8540 return scanned_ships;
8541}

References nil, scanned_ships, and scannedShips.

Referenced by maxFlightSpeed, and scannedShips.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scannerDisplayColor1

- (OOColor *) scannerDisplayColor1

Definition at line 5717 of file ShipEntity.m.

5718{
5719 return [[scanner_display_color1 retain] autorelease];
5720}

References scannerDisplayColor1.

Referenced by HeadUpDisplay(Private)::drawScanner:, reactionTime, scannerDisplayColor1, scannerDisplayColorForShip:isHostile:flash:scannerDisplayColor1:scannerDisplayColor2:scannerDisplayColorH1:scannerDisplayColorH2:, ShipGetProperty(), and ShipGetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scannerDisplayColor2

- (OOColor *) scannerDisplayColor2

Definition at line 5722 of file ShipEntity.m.

5723{
5724 return [[scanner_display_color2 retain] autorelease];
5725}

References scannerDisplayColor2.

Referenced by HeadUpDisplay(Private)::drawScanner:, reactionTime, scannerDisplayColor2, scannerDisplayColorForShip:isHostile:flash:scannerDisplayColor1:scannerDisplayColor2:scannerDisplayColorH1:scannerDisplayColorH2:, ShipGetProperty(), and ShipGetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scannerDisplayColorForShip:isHostile:flash:scannerDisplayColor1:scannerDisplayColor2:scannerDisplayColorH1:scannerDisplayColorH2:

- (GLfloat *) scannerDisplayColorForShip: (ShipEntity*) otherShip
isHostile: (BOOL) isHostile
flash: (BOOL) flash
scannerDisplayColor1: (OOColor*) scannerDisplayColor1
scannerDisplayColor2: (OOColor*) scannerDisplayColor2
scannerDisplayColorH1: (OOColor*) scannerDisplayColorH1
scannerDisplayColorH2: (OOColor*) scannerDisplayColorH2 

Definition at line 5601 of file ShipEntity.m.

5601 :(ShipEntity*)otherShip isHostile:(BOOL)isHostile flash:(BOOL)flash scannerDisplayColor1:(OOColor*)scannerDisplayColor1 scannerDisplayColor2:(OOColor*)scannerDisplayColor2 scannerDisplayColorH1:(OOColor*)scannerDisplayColorH1 scannerDisplayColorH2:(OOColor*)scannerDisplayColorH2
5602{
5603 if (isHostile) {
5604 /* if there are any scripted scanner hostile display colours
5605 * for the ship, use them - otherwise fall through to the
5606 * normal scripted colours, then the scan class colours */
5607 if (scannerDisplayColorH1 || scannerDisplayColorH2) {
5608 if (scannerDisplayColorH1 && !scannerDisplayColorH2) {
5609 [scannerDisplayColorH1 getRed:&scripted_color[0] green:&scripted_color[1] blue:&scripted_color[2] alpha:&scripted_color[3]];
5610 }
5611
5612 if (!scannerDisplayColorH1 && scannerDisplayColorH2) {
5613 [scannerDisplayColorH2 getRed:&scripted_color[0] green:&scripted_color[1] blue:&scripted_color[2] alpha:&scripted_color[3]];
5614 }
5615
5616 if (scannerDisplayColorH1 && scannerDisplayColorH2) {
5617 if (flash)
5618 [scannerDisplayColorH1 getRed:&scripted_color[0] green:&scripted_color[1] blue:&scripted_color[2] alpha:&scripted_color[3]];
5619 else
5620 [scannerDisplayColorH2 getRed:&scripted_color[0] green:&scripted_color[1] blue:&scripted_color[2] alpha:&scripted_color[3]];
5621 }
5622
5623 return scripted_color;
5624 }
5625 }
5626
5627 // if there are any scripted scanner display colors for the ship, use them
5630 [scannerDisplayColor1 getRed:&scripted_color[0] green:&scripted_color[1] blue:&scripted_color[2] alpha:&scripted_color[3]];
5631 }
5632
5634 [scannerDisplayColor2 getRed:&scripted_color[0] green:&scripted_color[1] blue:&scripted_color[2] alpha:&scripted_color[3]];
5635 }
5636
5638 if (flash)
5639 [scannerDisplayColor1 getRed:&scripted_color[0] green:&scripted_color[1] blue:&scripted_color[2] alpha:&scripted_color[3]];
5640 else
5641 [scannerDisplayColor2 getRed:&scripted_color[0] green:&scripted_color[1] blue:&scripted_color[2] alpha:&scripted_color[3]];
5642 }
5643
5644 return scripted_color;
5645 }
5646
5647 // no scripted scanner display colors defined, proceed as per standard
5648 if ([self isJammingScanning]) {
5649 if (![otherShip hasMilitaryScannerFilter])
5650 return jammed_color;
5651 else {
5652 if (flash)
5653 return mascem_color1;
5654 else {
5655 if (isHostile)
5656 return hostile_color;
5657 else
5658 return mascem_color2;
5659 }
5660 }
5661 }
5662
5663 switch (scanClass) {
5664 case CLASS_ROCK:
5665 case CLASS_CARGO:
5666 return cargo_color;
5667 case CLASS_THARGOID:
5668 if (flash)
5669 return hostile_color;
5670 else
5671 return friendly_color;
5672 case CLASS_MISSILE:
5673 return missile_color;
5674 case CLASS_STATION:
5675 return friendly_color;
5676 case CLASS_BUOY:
5677 if (flash)
5678 return friendly_color;
5679 else
5680 return neutral_color;
5681 case CLASS_POLICE:
5682 case CLASS_MILITARY:
5683 if ((isHostile) && (flash))
5684 return police_color2;
5685 else
5686 return police_color1;
5687 case CLASS_MINE:
5688 if (flash)
5689 return neutral_color;
5690 else
5691 return hostile_color;
5692 default:
5693 if (isHostile)
5694 return hostile_color;
5695 }
5696 return neutral_color;
5697}
static GLfloat scripted_color[4]
static GLfloat mascem_color1[4]
static GLfloat neutral_color[4]
static GLfloat cargo_color[4]
static GLfloat hostile_color[4]
static GLfloat missile_color[4]
static GLfloat police_color1[4]
static GLfloat mascem_color2[4]
static GLfloat jammed_color[4]
static GLfloat friendly_color[4]
static GLfloat police_color2[4]
void getRed:green:blue:alpha:(float *red,[green] float *green,[blue] float *blue,[alpha] float *alpha)
Definition OOColor.m:344
OOColor * scannerDisplayColor2()
OOColor * scannerDisplayColor1()

References cargo_color, friendly_color, OOColor::getRed:green:blue:alpha:, hasMilitaryScannerFilter, hostile_color, isJammingScanning, jammed_color, mascem_color1, mascem_color2, missile_color, neutral_color, police_color1, police_color2, scanClass, scannerDisplayColor1, scannerDisplayColor2, and scripted_color.

Referenced by HeadUpDisplay(Private)::drawScanner:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scannerDisplayColorHostile1

- (OOColor *) scannerDisplayColorHostile1

Definition at line 5745 of file ShipEntity.m.

5746{
5747 return [[scanner_display_color_hostile1 retain] autorelease];
5748}

References scannerDisplayColorHostile1.

Referenced by HeadUpDisplay(Private)::drawScanner:, reactionTime, scannerDisplayColorHostile1, ShipGetProperty(), and ShipGetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scannerDisplayColorHostile2

- (OOColor *) scannerDisplayColorHostile2

Definition at line 5750 of file ShipEntity.m.

5751{
5752 return [[scanner_display_color_hostile2 retain] autorelease];
5753}

References scannerDisplayColorHostile2.

Referenced by HeadUpDisplay(Private)::drawScanner:, reactionTime, scannerDisplayColorHostile2, ShipGetProperty(), and ShipGetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scannerRange

- (GLfloat) scannerRange

References scannerRange.

◆ scoopIn:

- (void) scoopIn: (ShipEntity*) other

Definition at line 11244 of file ShipEntity.m.

11244 :(ShipEntity*)other
11245{
11246 [other getTractoredBy:self];
11247}
void getTractoredBy:(ShipEntity *other)

Referenced by collideWithShip:.

Here is the caller graph for this function:

◆ scoopUp:

- (void) scoopUp: (ShipEntity*) other

Definition at line 11253 of file ShipEntity.m.

11253 :(ShipEntity*)other
11254{
11255 [self scoopUpProcess:other processEvents:YES processMessages:YES];
11256}

References scoopUpProcess:processEvents:processMessages:.

Referenced by behaviour_tractored:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scoopUpProcess:processEvents:processMessages:

- (void) scoopUpProcess: (ShipEntity*) other
processEvents: (BOOL) proc_events
processMessages: (BOOL) proc_messages 

Definition at line 11258 of file ShipEntity.m.

11258 :(ShipEntity*)other processEvents:(BOOL)procEvents processMessages:(BOOL)procMessages
11259{
11260 if (other == nil)
11261 return;
11262
11263 OOCommodityType co_type = nil;
11264 OOCargoQuantity co_amount;
11265
11266 // don't even think of trying to scoop if the cargo hold is already full
11267 if (max_cargo && [cargo count] >= [self maxAvailableCargoSpace]) {
11268 [other setStatus:STATUS_IN_FLIGHT];
11269 return;
11270 }
11271
11272 switch ([other cargoType]) {
11273 case CARGO_RANDOM:
11274 co_type = [other commodityType];
11275 co_amount = [other commodityAmount];
11276 break;
11277
11278 case CARGO_SCRIPTED_ITEM: {
11279 // scripting
11280 PlayerEntity* player = PLAYER;
11281 [player setScriptTarget:self];
11282 if (procEvents) {
11283 [other doScriptEvent:OOJSID("shipWasScooped") withArgument:self];
11284 }
11285
11286 if ([other commodityType] != nil) {
11287 co_type = [other commodityType];
11288 co_amount = [other commodityAmount];
11289 // don't show scoop message now, will happen later.
11290 } else {
11291 if (isPlayer && [other showScoopMessage] && procMessages) {
11292 [UNIVERSE clearPreviousMessage];
11293 NSString* shipName = [other displayName];
11294 [UNIVERSE addMessage:OOExpandKey(@"scripted-item-scooped", shipName) forCount:4];
11295 }
11296 [other setCommodityForPod:nil andAmount:0];
11297 co_amount = 0;
11298 co_type = nil;
11299 }
11300 } break;
11301
11302 default:
11303 co_amount = 0;
11304 co_type = nil;
11305 break;
11306 }
11307
11308 /* Bug: docking failed due to NSRangeException while looking for element
11309 NSNotFound of cargo mainfest in -[PlayerEntity unloadCargoPods].
11310 Analysis: bad cargo pods being generated due to
11311 -[Universe commodityForName:] looking in wrong place for names.
11312 Fix 1: fix -[Universe commodityForName:].
11313 Fix 2: catch NSNotFound here and substitute random cargo type.
11314 -- Ahruman 20070714
11315 */
11316 if (co_type == nil && co_amount > 0) {
11317 co_type = [UNIVERSE getRandomCommodity];
11318 co_amount = [UNIVERSE getRandomAmountOfCommodity:co_type];
11319 }
11320
11321 if (co_amount > 0) {
11322 [other setCommodity:co_type andAmount:co_amount]; // belt and braces setting this!
11324
11325 if (isPlayer) {
11326 if ([other crew]) {
11327 if ([other showScoopMessage] && procMessages) {
11328 [UNIVERSE clearPreviousMessage];
11329 unsigned i;
11330 for (i = 0; i < [[other crew] count]; i++) {
11331 OOCharacter* rescuee = [[other crew] objectAtIndex:i];
11332 NSString* characterName = [rescuee name];
11333 if ([rescuee legalStatus]) {
11334 [UNIVERSE addMessage:OOExpandKey(@"scoop-captured-character", characterName) forCount:4.5];
11335 } else if ([rescuee insuranceCredits]) {
11336 [UNIVERSE addMessage:OOExpandKey(@"scoop-rescued-character", characterName) forCount:4.5];
11337 } else {
11338 [UNIVERSE addMessage:DESC(@"scoop-got-slave") forCount:4.5];
11339 }
11340 }
11341 }
11342 if (procEvents) {
11344 }
11345 } else {
11346 if ([other showScoopMessage] && procMessages) {
11347 [UNIVERSE clearPreviousMessage];
11348 [UNIVERSE addMessage:[UNIVERSE describeCommodity:co_type amount:co_amount] forCount:4.5];
11349 }
11350 }
11351 }
11352 [cargo insertObject:other atIndex:0]; // places most recently scooped object at eject position
11353 [other setStatus:STATUS_IN_HOLD];
11354 [other performTumble];
11355 [shipAI message:@"CARGO_SCOOPED"];
11356 if (max_cargo && [cargo count] >= [self maxAvailableCargoSpace])
11357 [shipAI message:@"HOLD_FULL"];
11358 }
11359 if (procEvents) {
11360 [self doScriptEvent:OOJSID("shipScoopedOther") withArgument:other]; // always fire, even without commodity.
11361 }
11362
11363 // if shipScoopedOther does something strange to the object, we must
11364 // then remove it from the hold, or it will be over-retained
11365 if ([other status] != STATUS_IN_HOLD) {
11366 if ([cargo containsObject:other]) {
11367 [cargo removeObject:other];
11368 }
11369 }
11370
11371 [[other collisionArray] removeObject:self]; // so it can't be scooped twice!
11372 // make sure other ships trying to scoop it lose it
11373 // probably already happened, but some may have acquired it
11374 // after the scooping started, and they might get stuck in a scooping
11375 // attempt as a result
11376 [self checkScannerIgnoringUnpowered];
11377 unsigned i;
11378 ShipEntity* scooper;
11379 for (i = 0; i < n_scanned_ships; i++) {
11380 scooper = (ShipEntity*)scanned_ships[i];
11381 if (self != scooper && (id)other == [scooper primaryTargetWithoutValidityCheck]) {
11382 [scooper noteLostTarget];
11383 }
11384 }
11385
11386 [self suppressTargetLost];
11387 [UNIVERSE removeEntity:other];
11388}
@ CARGO_RANDOM
Definition OOTypes.h:66
@ CARGO_SCRIPTED_ITEM
Definition OOTypes.h:67
@ CARGO_FLAG_CANISTERS
Definition OOTypes.h:107
NSMutableArray * collisionArray()
Definition Entity.m:845
NSString * name()
void setStatus:(OOEntityStatus stat)
void performTumble()
void setCommodityForPod:andAmount:(OOCommodityType co_type,[andAmount] OOCargoQuantity co_amount)
BOOL showScoopMessage()

References cargo, cargo_flag, CARGO_FLAG_CANISTERS, CARGO_RANDOM, CARGO_SCRIPTED_ITEM, cargoType, checkScannerIgnoringUnpowered, Entity::collisionArray, commodityType, count, crew, doScriptEvent:withArgument:, Entity::isPlayer, legalStatus, max_cargo, maxAvailableCargoSpace, AI::message:, n_scanned_ships, OOCharacter::name, nil, noteLostTarget, PLAYER, primaryTargetWithoutValidityCheck, scanned_ships, PlayerEntity::setScriptTarget:, Entity::setStatus:, showScoopMessage, Entity::status, and suppressTargetLost.

Referenced by scoopUp:, ShipAddCargoEntity(), and ShipAddCargoEntity().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ script

References script.

◆ scriptActionOnTarget:

- (void) scriptActionOnTarget: (NSString*) action
implementation

Provided by category ShipEntity(PureAI).

Definition at line 2242 of file ShipEntityAI.m.

2242 :(NSString*)action
2243{
2244 PlayerEntity* player = PLAYER;
2245 ShipEntity* targEnt = [self primaryTarget];
2246 ShipEntity* oldTarget = nil;
2247
2248#ifndef NDEBUG
2249 static BOOL deprecationWarning = NO;
2250
2251 if (!deprecationWarning) {
2252 deprecationWarning = YES;
2253 OOLog(@"script.deprecated.scriptActionOnTarget", @"----- WARNING in AI %@: the AI method scriptActionOnTarget: is deprecated and should not be used. It is slow and has unpredictable side effects. The recommended alternative is to use sendScriptMessage: to call a function in a ship's JavaScript ship script instead. scriptActionOnTarget: should not be used at all from scripts. An alternative is safeScriptActionOnTarget:, which is similar to scriptActionOnTarget: but has less side effects.", [AI currentlyRunningAIDescription]);
2254 } else {
2255 OOLog(@"script.deprecated.scriptActionOnTarget.repeat", @"----- WARNING in AI %@: the AI method scriptActionOnTarget: is deprecated and should not be used.", [AI currentlyRunningAIDescription]);
2256 }
2257#endif
2258
2259 if ([targEnt isShip]) {
2260 oldTarget = [player scriptTarget];
2261 [player setScriptTarget:(ShipEntity*)targEnt];
2262 [player runUnsanitizedScriptActions:[NSArray arrayWithObject:action]
2264 withContextName:[NSString stringWithFormat:@"<AI \"%@\" state %@ - scriptActionOnTarget:>", [[self getAI] name], [[self getAI] state]]
2265 forTarget:targEnt];
2266 [player checkScript]; // react immediately to any changes this makes
2267 [player setScriptTarget:oldTarget];
2268 }
2269}

◆ scriptedMisjump

- (BOOL) scriptedMisjump

Definition at line 1179 of file ShipEntity.m.

1180{
1181 return scripted_misjump;
1182}
unsigned scripted_misjump
Definition ShipEntity.h:267

References scripted_misjump, and scriptedMisjump.

Referenced by PlayerEntity::enterWitchspace, PlayerEntity::enterWormhole:, enterWormhole:replacing:, scriptedMisjump, and scriptInfo.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scriptedMisjumpRange

- (GLfloat) scriptedMisjumpRange

Definition at line 1189 of file ShipEntity.m.

1190{
1191 return _scriptedMisjumpRange;
1192}
GLfloat _scriptedMisjumpRange
Definition ShipEntity.h:273

References _scriptedMisjumpRange, and scriptedMisjumpRange.

Referenced by PlayerEntity::enterWitchspace, PlayerEntity::enterWormhole:, enterWormhole:replacing:, scriptedMisjumpRange, and scriptInfo.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scriptInfo

- (NSDictionary *) scriptInfo

References entityForShaderProperties, scriptedMisjump, scriptedMisjumpRange, and scriptInfo.

Here is the call graph for this function:

◆ selectMissile

- (OOEquipmentType *) selectMissile

Definition at line 3433 of file ShipEntity.m.

3434{
3435 OOEquipmentType* missileType = nil;
3436 NSString* role = nil;
3437 double chance = randf();
3438 BOOL thargoidMissile = NO;
3439
3440 if ([self isThargoid]) {
3441 if (_missileRole != nil)
3442 missileType = [self verifiedMissileTypeFromRole:_missileRole];
3443 if (missileType == nil) {
3444 _missileRole = @"EQ_THARGON"; // no valid missile_role defined, use thargoid fallback from now on.
3445 missileType = [self verifiedMissileTypeFromRole:_missileRole];
3446 }
3447 } else {
3448 // All other ships: random role 10% of the cases when auto weapons is set, if a missile_role is defined.
3449 // Without auto weapons, never random.
3450 float randomSelectionChance = chance;
3451 if (![self hasAutoWeapons])
3452 randomSelectionChance = 0.0f;
3453 if (randomSelectionChance < 0.9f && _missileRole != nil) {
3454 missileType = [self verifiedMissileTypeFromRole:_missileRole];
3455 }
3456
3457 if (missileType == nil) // the random 10% , or no valid missile_role defined
3458 {
3459 if (chance < 0.9f && _missileRole != nil) // no valid missile_role defined?
3460 {
3461 _missileRole = nil; // use generic ship fallback from now on.
3462 }
3463
3464 // assign random missiles 20% of the time without missile_role (or 10% with valid missile_role)
3465 if (chance > 0.8f)
3466 role = @"missile";
3467 // otherwise use the standard role
3468 else
3469 role = @"EQ_MISSILE";
3470
3471 missileType = [self verifiedMissileTypeFromRole:role];
3472 }
3473 }
3474
3475 if (missileType == nil)
3476 OOLogERR(@"ship.setUp.missiles", @"could not resolve missile / mine type for ship \"%@\". Original missile role:\"%@\".", [self name], _missileRole);
3477
3478 role = [[missileType identifier] lowercaseString];
3479 thargoidMissile = [self isThargoid] && ([role hasSuffix:@"thargon"] || [role hasPrefix:@"thargon"]);
3480
3481 if (thargoidMissile || (!thargoidMissile && [missileType isMissileOrMine])) {
3482 return missileType;
3483 } else {
3484 OOLogWARN(@"ship.setUp.missiles", @"missile_role \"%@\" is not a valid missile / mine type for ship \"%@\".%@", [missileType identifier], [self name], @" No missile selected.");
3485 return nil;
3486 }
3487}
BOOL hasAutoWeapons()
NSString * _missileRole
Definition ShipEntity.h:310

References _missileRole, hasAutoWeapons, OOEquipmentType::identifier, isThargoid, name, nil, OOLogERR, OOLogWARN, randf(), selectMissile, and verifiedMissileTypeFromRole:.

Referenced by isFrangible, selectMissile, setUpShipFromDictionary:, ShipSelectNewMissile(), and ShipSelectNewMissile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendAIMessage:

- (void) sendAIMessage: (NSString*) message

Definition at line 12864 of file ShipEntity.m.

12864 :(NSString*)message
12865{
12866 [shipAI message:message];
12867}

References AI::message:.

Referenced by DockEntity::abortAllDockings, StationEntity::abortDockingForShip:, ShipEntity(PureAI)::messageSelf:, DockEntity::pruneAndCountShipsOnApproach, ShipSendAIMessage(), and ShipSendAIMessage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendExpandedMessage:toShip:

- (void) sendExpandedMessage: (NSString*) message_text
toShip: (ShipEntity*) other_ship 

Definition at line 12337 of file ShipEntity.m.

12337 :(NSString*)message_text toShip:(ShipEntity*)other_ship
12338{
12339 if (!other_ship || !crew)
12340 return; // nobody to receive or send the signal
12341 if ((lastRadioMessage) && (messageTime > 0.0) && [message_text isEqual:lastRadioMessage])
12342 return; // don't send the same message too often
12343 [lastRadioMessage autorelease];
12344 lastRadioMessage = [message_text retain];
12345
12346 double d2 = HPdistance2(position, [other_ship position]);
12347 if (d2 > scannerRange * scannerRange) {
12348 // out of comms range
12349 return;
12350 }
12351
12352 Random_Seed very_random_seed;
12353 very_random_seed.a = rand() & 255;
12354 very_random_seed.b = rand() & 255;
12355 very_random_seed.c = rand() & 255;
12356 very_random_seed.d = rand() & 255;
12357 very_random_seed.e = rand() & 255;
12358 very_random_seed.f = rand() & 255;
12359 seed_RNG_only_for_planet_description(very_random_seed);
12360
12361 NSDictionary* specials = [NSDictionary dictionaryWithObjectsAndKeys:
12362 [self displayName], @"[self:name]",
12363 [other_ship identFromShip:self], @"[target:name]",
12364 nil];
12365 NSString* expandedMessage = OOExpandDescriptionString(OOStringExpanderDefaultRandomSeed(), message_text, specials, nil, nil, kOOExpandNoOptions);
12366
12367 [self sendMessage:expandedMessage toShip:other_ship withUnpilotedOverride:NO];
12368}
@ kOOExpandNoOptions
Random_Seed OOStringExpanderDefaultRandomSeed(void)
NSString * OOExpandDescriptionString(Random_Seed seed, NSString *string, NSDictionary *overrides, NSDictionary *legacyLocals, NSString *systemName, OOExpandOptions options)
NSString * identFromShip:(ShipEntity *otherShip)

References Random_Seed::a, Random_Seed::b, Random_Seed::c, crew, Random_Seed::d, displayName, Random_Seed::e, Random_Seed::f, HPdistance2(), identFromShip:, kOOExpandNoOptions, lastRadioMessage, messageTime, nil, OOExpandDescriptionString(), OOStringExpanderDefaultRandomSeed(), Entity::position, scannerRange, seed_RNG_only_for_planet_description(), and sendMessage:toShip:withUnpilotedOverride:.

Referenced by DockEntity::abortAllDockings, StationEntity::abortAllDockings, DockEntity::abortDockingForShip:, StationEntity::acceptDockingClearanceRequestFrom:, DockEntity(OOPrivate)::addShipToShipsOnApproach:, ShipEntity(AI)::broadcastDistressMessageWithDumping:, DockEntity::dockingInstructionsForShip:, StationEntity(OOPrivate)::holdPositionInstructionForShip:, interpretAIMessage:, StationEntity::noteDockedShip:, ShipEntity(AI)::requestDockingCoordinates, ShipEntity(PureAI)::sendTargetCommsMessage:, and StationEntity::update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendMessage:toShip:withUnpilotedOverride:

- (void) sendMessage: (NSString*) message_text
toShip: (ShipEntity*) other_ship
withUnpilotedOverride: (BOOL) unpilotedOverride 

Definition at line 12315 of file ShipEntity.m.

12315 :(NSString*)message_text toShip:(ShipEntity*)other_ship withUnpilotedOverride:(BOOL)unpilotedOverride
12316{
12317 if (!other_ship || !message_text)
12318 return;
12319 if (!crew && !unpilotedOverride)
12320 return;
12321
12322 double d2 = HPdistance2(position, [other_ship position]);
12323 if (d2 > scannerRange * scannerRange)
12324 return; // out of comms range
12325
12326 NSString* expandedMessage = OOExpand(message_text); // consistent with broadcast message.
12327
12328 if (other_ship->isPlayer) {
12329 [self setCommsMessageColor];
12330 [(PlayerEntity*)other_ship receiveCommsMessage:expandedMessage from:self];
12331 messageTime = 6.0;
12332 [UNIVERSE resetCommsLogColor];
12333 } else
12334 [other_ship receiveCommsMessage:expandedMessage from:self];
12335}
void receiveCommsMessage:from:(NSString *message_text,[from] ShipEntity *other)

References crew, HPdistance2(), Entity::isPlayer, messageTime, OOExpand, Entity::position, PlayerEntity::receiveCommsMessage:from:, receiveCommsMessage:from:, scannerRange, and setCommsMessageColor.

Referenced by sendExpandedMessage:toShip:, ShipCommsMessage(), and ShipCommsMessage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendScriptMessage:

- (void) sendScriptMessage: (NSString*) message
implementation

Provided by category ShipEntity(PureAI).

Definition at line 2289 of file ShipEntityAI.m.

2289 :(NSString*)message
2290{
2291 NSArray* components = ScanTokensFromString(message);
2292
2293 if ([components count] == 1) {
2294 [self doScriptEvent:OOJSIDFromString(message)];
2295 } else {
2296 NSString* function = [components objectAtIndex:0];
2297 components = [components subarrayWithRange:NSMakeRange(1, [components count] - 1)];
2298 [self doScriptEvent:OOJSIDFromString(function) withArgument:components];
2299 }
2300}

◆ sendTargetCommsMessage:

- (void) sendTargetCommsMessage: (NSString*) message
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1804 of file ShipEntityAI.m.

1804 :(NSString*)message
1805{
1806 ShipEntity* ship = [self primaryTarget];
1807 if ((ship == nil) || ([ship status] == STATUS_DEAD) || ([ship status] == STATUS_DOCKED)) {
1808 [self noteLostTarget];
1809 return;
1810 }
1811 [self sendExpandedMessage:message toShip:[self primaryTarget]];
1812}

◆ serializeShipSubEntities

- (NSString *) serializeShipSubEntities

Definition at line 753 of file ShipEntity.m.

754{
755 NSMutableString* result = [NSMutableString stringWithCapacity:4];
756 NSEnumerator* subEnum = nil;
757 ShipEntity* se = nil;
758 NSUInteger diff, i = 0;
759
760 for (subEnum = [self shipSubEntityEnumerator]; (se = [subEnum nextObject]);) {
761 diff = [se subIdx] - i;
762 i += diff + 1;
763 [result appendString:[self repeatString:@"0" times:diff]];
764 [result appendString:@"1"];
765 }
766 // add trailing zeroes
767 [result appendString:[self repeatString:@"0" times:[self maxShipSubEntities] - i]];
768 return result;
769}

References maxShipSubEntities, nil, repeatString:times:, serializeShipSubEntities, shipSubEntityEnumerator, and subIdx.

Referenced by PlayerEntity::commanderDataDictionary, serializeShipSubEntities, and subEntities.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setAccuracy:

- (void) setAccuracy: (GLfloat) new_accuracy

Definition at line 1126 of file ShipEntity.m.

1126 :(GLfloat)new_accuracy
1127{
1128 if (new_accuracy < 0.0f && scanClass == CLASS_MISSILE) {
1129 new_accuracy = 0.0;
1130 } else if (new_accuracy < -5.0f) {
1131 new_accuracy = -5.0;
1132 } else if (new_accuracy > 10.0f) {
1133 new_accuracy = 10.0;
1134 }
1135 accuracy = new_accuracy;
1136 pitch_tolerance = 0.01 * (85.0f + accuracy);
1137 // especially against small targets, less good pilots will waste some shots
1138 aim_tolerance = 240.0 - (18.0f * accuracy);
1139
1141 missile_load_time = 2.0; // smart enough not to waste all missiles on 1 ECM!
1142 }
1143}

References accuracy, aim_tolerance, COMBAT_AI_ISNT_AWFUL, missile_load_time, pitch_tolerance, and scanClass.

Referenced by setUpShipFromDictionary:, ShipSetProperty(), and ShipSetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setAfterburnerFactor:

- (void) setAfterburnerFactor: (GLfloat) new

Definition at line 3671 of file ShipEntity.m.

3671 :(GLfloat)new
3672{
3674}

References afterburner_speed_factor.

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setAfterburnerRate:

- (void) setAfterburnerRate: (GLfloat) new

Definition at line 3676 of file ShipEntity.m.

3676 :(GLfloat)new
3677{
3678 afterburner_rate = new;
3679}

References afterburner_rate.

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setAI:

- (void) setAI: (AI*) ai

Definition at line 6907 of file ShipEntity.m.

6907 :(AI*)ai
6908{
6909 [ai retain];
6910 if (shipAI) {
6911 [shipAI clearAllData];
6912 [shipAI autorelease];
6913 }
6914 shipAI = ai;
6915}

References AI::clearAllData, and shipAI.

Here is the call graph for this function:

◆ setAIScript:

- (void) setAIScript: (NSString*) aiString

Provided by category ShipEntity(AI).

Definition at line 268 of file ShipEntityAI.m.

268 :(NSString*)aiString
269{
270 NSMutableDictionary* properties = nil;
271
272 properties = [NSMutableDictionary dictionary];
273 [properties setObject:self forKey:@"ship"];
274
275 [aiScript autorelease];
276 aiScript = [OOScript jsAIScriptFromFileNamed:aiString properties:properties];
277 if (aiScript == nil) {
278 OOLog(@"ai.load.failed.unknownAI", @"Unable to load JS AI %@ for ship %@ (%@ for role %@)", aiString, self, [self shipDataKey], [self primaryRole]);
279 aiScript = [OOScript jsAIScriptFromFileNamed:@"oolite-nullAI.js" properties:properties];
280 } else {
282 haveStartedJSAI = NO;
283 }
284 [aiScript retain];
285}
id jsAIScriptFromFileNamed:properties:(NSString *fileName,[properties] NSDictionary *properties)
Definition OOScript.m:202
unsigned haveStartedJSAI
Definition ShipEntity.h:269

Referenced by AI::restorePreviousStateMachine, and ShipEntity(AI)::setAITo:.

Here is the caller graph for this function:

◆ setAIScriptWakeTime:

- (void) setAIScriptWakeTime: (OOTimeAbsolute) t

Definition at line 1286 of file ShipEntity.m.

1286 :(OOTimeAbsolute)t
1287{
1288 aiScriptWakeTime = t;
1289}
double OOTimeAbsolute
Definition OOTypes.h:192

References aiScriptWakeTime.

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setAITo:

- (void) setAITo: (NSString*) aiString

Provided by category ShipEntity(AI).

Definition at line 245 of file ShipEntityAI.m.

245 :(NSString*)aiString
246{
247 // don't try to load real AIs if the game hasn't started yet
248 if (![PLAYER scriptsLoaded]) {
249 aiString = @"oolite-nullAI.js";
250 }
251 if ([aiString hasSuffix:@".plist"]) {
252 [[self getAI] setStateMachine:aiString withJSScript:@"oolite-nullAI.js"];
253 [self setAIScript:@"oolite-nullAI.js"];
254 } else if ([aiString hasSuffix:@".js"]) {
255 [[self getAI] setStateMachine:@"nullAI.plist" withJSScript:aiString];
256 [self setAIScript:aiString];
257 } else {
258 NSString* path = [ResourceManager pathForFileNamed:[aiString stringByAppendingString:@".js"] inFolder:@"AIs"];
259 if (path == nil) // no js, use plist
260 {
261 [self setAITo:[aiString stringByAppendingString:@".plist"]];
262 } else {
263 [self setAITo:[aiString stringByAppendingString:@".js"]];
264 }
265 }
266}
NSString * pathForFileNamed:inFolder:(NSString *fileName,[inFolder] NSString *folderName)

Referenced by abandonShip, ShipEntity(PureAI)::becomeUncontrolledThargon, deployEscorts, dockEscorts, getTractoredBy:, Universe::newShipWithRole:, PlayerEntity::resetAutopilotAI, ShipEntity(PureAI)::scanForFormationLeader, PlayerEntity(Scripting)::sendAllShipsAway, ShipEntity(AI)::setAITo:, ShipEntity(PureAI)::setPlanetPatrolCoordinates, setStateMachine:, setUpShipFromDictionary:, ShipEntity(LoadRestore)::shipRestoredFromDictionary:useFallback:context:, ShipSetAI(), ShipSetAI(), PlayerEntity::showShipModelWithKey:shipData:personality:factorX:factorY:factorZ:inContext:, and ShipEntity(AI)::switchAITo:.

Here is the caller graph for this function:

◆ setAutoCloak:

- (void) setAutoCloak: (BOOL) automatic

Definition at line 5778 of file ShipEntity.m.

5778 :(BOOL)automatic
5779{
5780 cloakAutomatic = !!automatic;
5781}

References cloakAutomatic.

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setBeaconCode:

- (void) setBeaconCode: (NSString*) bcode
implementation

Reimplemented from <OOBeaconEntity>.

Definition at line 1410 of file ShipEntity.m.

1410 :(NSString*)bcode
1411{
1412 if ([bcode length] == 0)
1413 bcode = nil;
1414
1415 if (_beaconCode != bcode) {
1416 [_beaconCode release];
1417 _beaconCode = [bcode copy];
1418
1420 }
1421 // if not blanking code and label is currently blank, default label to code
1422 if (bcode != nil && (_beaconLabel == nil || [_beaconLabel length] == 0)) {
1423 [self setBeaconLabel:bcode];
1424 }
1425}

References _beaconCode, _beaconDrawable, _beaconLabel, DESTROY, nil, and setBeaconLabel:.

Referenced by WormholeEntity::disgorgeShips, setUpShipFromDictionary:, ShipSetProperty(), and ShipSetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setBeaconLabel:

- (void) setBeaconLabel: (NSString*) blabel
implementation

Reimplemented from <OOBeaconEntity>.

Definition at line 1432 of file ShipEntity.m.

1432 :(NSString*)blabel
1433{
1434 if ([blabel length] == 0)
1435 blabel = nil;
1436
1437 if (_beaconLabel != blabel) {
1438 [_beaconLabel release];
1439 _beaconLabel = [OOExpand(blabel) retain];
1440 }
1441}

References _beaconLabel, and nil.

Referenced by setBeaconCode:, setUpShipFromDictionary:, ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setBehaviour:

- (void) setBehaviour: (OOBehaviour) cond

Definition at line 8835 of file ShipEntity.m.

8835 :(OOBehaviour)cond
8836{
8837 if (cond != behaviour) {
8838 frustration = 0.0; // change is a GOOD thing
8839 behaviour = cond;
8840 }
8841}
OOBehaviour
Definition ShipEntity.h:147

References behaviour, and frustration.

Referenced by launchCascadeMine, PlayerEntity::launchMine:, PlayerEntity(Scripting)::processSceneString:atOffset:, setUpOneStandardSubentity:asTurret:, and takeEnergyDamage:from:becauseOf:weaponIdentifier:.

Here is the caller graph for this function:

◆ setBounty:

- (void) setBounty: (OOCreditsQuantity) amount

Reimplemented in PlayerEntity.

Definition at line 7106 of file ShipEntity.m.

7106 :(OOCreditsQuantity)amount
7107{
7108 [self setBounty:amount withReason:kOOLegalStatusReasonUnknown];
7109}
uint64_t OOCreditsQuantity
Definition OOTypes.h:160

References setBounty:withReason:.

Here is the call graph for this function:

◆ setBounty:withReason:

- (void) setBounty: (OOCreditsQuantity) amount
withReason: (OOLegalStatusReason) reason 

Reimplemented in PlayerEntity.

Definition at line 7111 of file ShipEntity.m.

7111 :(OOCreditsQuantity)amount withReason:(OOLegalStatusReason)reason
7112{
7113 if ([self isSubEntity]) {
7114 [[self parentEntity] setBounty:amount withReason:reason];
7115 } else {
7116 if ((scanClass == CLASS_THARGOID || scanClass == CLASS_STATION) && reason != kOOLegalStatusReasonSetup && reason != kOOLegalStatusReasonByScript) {
7117 return; // no standard bounties for Thargoids / Stations
7118 }
7119 if (scanClass == CLASS_POLICE && amount != 0) {
7120 return; // police never have bounties
7121 }
7122 NSString* nReason = OOStringFromLegalStatusReason(reason);
7123 [self setBounty:amount withReasonAsString:nReason];
7124 }
7125}
NSString * OOStringFromLegalStatusReason(OOLegalStatusReason reason)

References Entity::isSubEntity, OOStringFromLegalStatusReason(), Entity::parentEntity, scanClass, setBounty:withReason:, and setBounty:withReasonAsString:.

Referenced by Universe::addShipAt:withRole:withinRadius:, becomeExplosion, WormholeEntity::disgorgeShips, interpretAIMessage:, StationEntity::launchIndependentShip:, StationEntity::launchPatrol, StationEntity::launchPirateShip, StationEntity::launchPolice, Universe::newShipWithRole:, setBounty:, setBounty:withReason:, ShipEntity(Private)::setUpOneEscort:inGroup:withRole:atPosition:andCount:, setUpShipFromDictionary:, ShipSetProperty(), ShipSetProperty(), update:, and Universe::witchspaceShipWithPrimaryRole:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setBounty:withReasonAsString:

- (void) setBounty: (OOCreditsQuantity) amount
withReasonAsString: (NSString*) reason 

Reimplemented in PlayerEntity.

Definition at line 7127 of file ShipEntity.m.

7127 :(OOCreditsQuantity)amount withReasonAsString:(NSString*)reason
7128{
7129 if ([self isSubEntity]) {
7130 [[self parentEntity] setBounty:amount withReasonAsString:reason];
7131 } else {
7132 JSContext* context = OOJSAcquireContext();
7133
7134 OOJSVal amountVal = OOJSValueFromDouble(context, (int)amount - (int)bounty);
7135
7136 bounty = amount; // can't set the new bounty until the size of the change is known
7137
7138 OOJSVal reasonVal = OOJSValueFromNativeObject(context, reason);
7139
7140 ShipScriptEvent(context, self, "shipBountyChanged", amountVal, reasonVal);
7141
7142 OOJSRelinquishContext(context);
7143 }
7144}

References bounty, Entity::isSubEntity, OOJSAcquireContext(), OOJSRelinquishContext(), OOJSValueFromDouble(), OOJSValueFromNativeObject(), Entity::parentEntity, setBounty:withReasonAsString:, and ShipScriptEvent.

Referenced by setBounty:withReason:, setBounty:withReasonAsString:, ShipSetBounty(), and ShipSetBounty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setCargo:

- (void) setCargo: (NSArray*) some_cargo

Definition at line 7278 of file ShipEntity.m.

7278 :(NSArray*)some_cargo
7279{
7280 [cargo removeAllObjects];
7281 [cargo addObjectsFromArray:some_cargo];
7282}

Referenced by setCargoFlag:.

Here is the caller graph for this function:

◆ setCargoFlag:

- (void) setCargoFlag: (OOCargoFlag) flag

Definition at line 7332 of file ShipEntity.m.

7332 :(OOCargoFlag)flag
7333{
7334 if (cargo_flag != flag) {
7335 cargo_flag = flag;
7336 NSArray* newCargo = nil;
7337 unsigned num = 0;
7338 if (likely_cargo > 0) {
7339 num = likely_cargo * (0.5 + randf());
7340 if (num > [self maxAvailableCargoSpace]) {
7341 num = [self maxAvailableCargoSpace];
7342 }
7343 } else {
7344 num = [self maxAvailableCargoSpace];
7345 }
7346 if (num > 200) {
7347 num = 200;
7348 /* no core NPC ship carries this much when generated (the
7349 * Anaconda could, but doesn't): let's not waste time generating
7350 * thousands of pods - even if they are semi-virtual - for some
7351 * massive OXP ship */
7352 }
7353 if (num > 0) {
7354 switch (cargo_flag) {
7356 newCargo = [UNIVERSE getContainersOfCommodity:[shipinfoDictionary oo_stringForKey:@"cargo_carried"] how_much:num];
7357 break;
7359 newCargo = [UNIVERSE getContainersOfGoods:num scarce:NO legal:YES];
7360 break;
7362 newCargo = [UNIVERSE getContainersOfGoods:num scarce:YES legal:YES];
7363 break;
7365 newCargo = [UNIVERSE getContainersOfCommodity:@"Narcotics" how_much:num];
7366 break;
7368 newCargo = [UNIVERSE getContainersOfGoods:num scarce:YES legal:NO];
7369 break;
7370 case CARGO_FLAG_PIRATE:
7371 newCargo = [UNIVERSE getContainersOfGoods:(Ranrot() % (1 + num / 2)) scarce:YES legal:NO];
7372 break;
7374 // TODO: allow passengers to survive
7375 case CARGO_FLAG_NONE:
7376 default:
7377 break;
7378 }
7379 }
7380 [self setCargo:newCargo];
7381 }
7382}
OOCargoFlag
Definition OOTypes.h:99
@ CARGO_FLAG_FULL_CONTRABAND
Definition OOTypes.h:104
@ CARGO_FLAG_FULL_SCARCE
Definition OOTypes.h:102
@ CARGO_FLAG_FULL_PLENTIFUL
Definition OOTypes.h:101
@ CARGO_FLAG_PIRATE
Definition OOTypes.h:105
@ CARGO_FLAG_FULL_UNIFORM
Definition OOTypes.h:106
@ CARGO_FLAG_FULL_MEDICAL
Definition OOTypes.h:103
@ CARGO_FLAG_FULL_PASSENGERS
Definition OOTypes.h:108
@ CARGO_FLAG_NONE
Definition OOTypes.h:100

References cargo_flag, CARGO_FLAG_FULL_CONTRABAND, CARGO_FLAG_FULL_MEDICAL, CARGO_FLAG_FULL_PASSENGERS, CARGO_FLAG_FULL_PLENTIFUL, CARGO_FLAG_FULL_SCARCE, CARGO_FLAG_FULL_UNIFORM, CARGO_FLAG_NONE, CARGO_FLAG_PIRATE, likely_cargo, maxAvailableCargoSpace, nil, randf(), and setCargo:.

Referenced by Universe::addShipAt:withRole:withinRadius:, StationEntity::launchEscort, StationEntity::launchIndependentShip:, PlanetEntity::launchShuttle, StationEntity::launchShuttle, ShipSetCargoType(), ShipSetCargoType(), and Universe::witchspaceShipWithPrimaryRole:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setCloaked:

- (void) setCloaked: (BOOL) cloak

Definition at line 5765 of file ShipEntity.m.

5765 :(BOOL)cloak
5766{
5767 if (cloak)
5768 [self activateCloakingDevice];
5769 else
5770 [self deactivateCloakingDevice];
5771}

References activateCloakingDevice, and deactivateCloakingDevice.

Referenced by removeEquipmentItem:, ShipSetProperty(), and ShipSetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setCommodity:andAmount:

- (void) setCommodity: (OOCommodityType) co_type
andAmount: (OOCargoQuantity) co_amount 

Definition at line 7164 of file ShipEntity.m.

7164 :(OOCommodityType)co_type andAmount:(OOCargoQuantity)co_amount
7165{
7166 if (co_type != nil) {
7167 /* The tmp variable is needed as scoopUp can cause the method
7168 * to be passed a reference to self.commodity_type, so DESTROY
7169 * then copying the parameter segfaults */
7170 NSString* tmp = [co_type copy];
7172 commodity_type = tmp;
7173 commodity_amount = co_amount;
7174 }
7175}

References commodity_amount, commodity_type, DESTROY, and nil.

Referenced by PlayerEntity(ScriptMethods)::awardCommodityType:amount:, becomeExplosion, Universe::cargoPodFromTemplate:, PlayerEntity::createCargoPodWithType:andAmount:, Universe::fillCargopodWithRandomCargo:, ShipEntity(Private)::launchPodWithCrew:, PlayerEntity::loadCargoPodsForType:amount:, setCommodityForPod:andAmount:, Universe(OOPrivate)::setUpCargoPods, and PlayerEntity::unloadCargoPodsForType:amount:.

Here is the caller graph for this function:

◆ setCommodityForPod:andAmount:

- (void) setCommodityForPod: (OOCommodityType) co_type
andAmount: (OOCargoQuantity) co_amount 

Definition at line 7177 of file ShipEntity.m.

7177 :(OOCommodityType)co_type andAmount:(OOCargoQuantity)co_amount
7178{
7179 // can be nil for pods
7180 if (co_type == nil) {
7182 commodity_amount = 0;
7183 return;
7184 }
7185 // pod content should never be greater than 1 ton or this will give cargo counting problems elsewhere in the code.
7186 // so do first a mass check for cargo added by script/plist.
7187 OOMassUnit unit = [[UNIVERSE commodityMarket] massUnitForGood:co_type];
7188 if (unit == UNITS_TONS && co_amount > 1)
7189 co_amount = 1;
7190 else if (unit == UNITS_KILOGRAMS && co_amount > 1000)
7191 co_amount = 1000;
7192 else if (unit == UNITS_GRAMS && co_amount > 1000000)
7193 co_amount = 1000000;
7194 [self setCommodity:co_type andAmount:co_amount];
7195}
OOMassUnit
Definition OOTypes.h:111
@ UNITS_TONS
Definition OOTypes.h:112
@ UNITS_GRAMS
Definition OOTypes.h:114
@ UNITS_KILOGRAMS
Definition OOTypes.h:113

References commodity_amount, commodity_type, DESTROY, nil, setCommodity:andAmount:, UNITS_GRAMS, UNITS_KILOGRAMS, and UNITS_TONS.

Referenced by setUpShipFromDictionary:, ShipSetCargo(), and ShipSetCargo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setCommsMessageColor

- (void) setCommsMessageColor

Definition at line 12408 of file ShipEntity.m.

12409{
12410 float hue = 0.0625f * (universalID & 15);
12411 [[UNIVERSE commLogGUI] setTextColor:[OOColor colorWithHue:hue saturation:0.375f brightness:1.0f alpha:1.0f]];
12412 if (scanClass == CLASS_THARGOID)
12413 [[UNIVERSE commLogGUI] setTextColor:[OOColor greenColor]];
12414 if (scanClass == CLASS_POLICE)
12415 [[UNIVERSE commLogGUI] setTextColor:[OOColor cyanColor]];
12416}
OOColor * cyanColor()
Definition OOColor.m:274
OOColor * greenColor()
Definition OOColor.m:264
OOColor * colorWithHue:saturation:brightness:alpha:(float hue,[saturation] float saturation,[brightness] float brightness,[alpha] float alpha)
Definition OOColor.m:100

References OOColor::colorWithHue:saturation:brightness:alpha:, OOColor::cyanColor, OOColor::greenColor, scanClass, setCommsMessageColor, and Entity::universalID.

Referenced by broadcastMessage:withUnpilotedOverride:, sendMessage:toShip:withUnpilotedOverride:, setCommsMessageColor, and sunGlareFilter.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setCoordinate:

- (void) setCoordinate: (HPVector) coord

Definition at line 8853 of file ShipEntity.m.

8853 :(HPVector)coord // The name "setCoordinates" is already used by AI scripting.
8854{
8855 coordinates = coord;
8856}

References coordinates.

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setCoordinates:

- (void) setCoordinates: (NSString*) system_x_y_z
implementation

Provided by category ShipEntity(PureAI).

Definition at line 2141 of file ShipEntityAI.m.

2141 :(NSString*)system_x_y_z
2142{
2143 NSArray* tokens = ScanTokensFromString(system_x_y_z);
2144 NSString* systemString = nil;
2145 NSString* xString = nil;
2146 NSString* yString = nil;
2147 NSString* zString = nil;
2148
2149 if ([tokens count] != 4) {
2150 OOLog(@"ai.syntax.setCoordinates", @"***** ERROR: cannot setCoordinates: '%@'.", system_x_y_z);
2151 return;
2152 }
2153
2154 systemString = (NSString*)[tokens objectAtIndex:0];
2155 xString = (NSString*)[tokens objectAtIndex:1];
2156 if ([xString hasPrefix:@"rand:"])
2157 xString = [NSString stringWithFormat:@"%.3f", bellf([(NSString*)[[xString componentsSeparatedByString:@":"] objectAtIndex:1] intValue])];
2158 yString = (NSString*)[tokens objectAtIndex:2];
2159 if ([yString hasPrefix:@"rand:"])
2160 yString = [NSString stringWithFormat:@"%.3f", bellf([(NSString*)[[yString componentsSeparatedByString:@":"] objectAtIndex:1] intValue])];
2161 zString = (NSString*)[tokens objectAtIndex:3];
2162 if ([zString hasPrefix:@"rand:"])
2163 zString = [NSString stringWithFormat:@"%.3f", bellf([(NSString*)[[zString componentsSeparatedByString:@":"] objectAtIndex:1] intValue])];
2164
2165 HPVector posn = make_HPvector([xString floatValue], [yString floatValue], [zString floatValue]);
2166 GLfloat scalar = 1.0;
2167
2168 coordinates = [UNIVERSE coordinatesForPosition:posn withCoordinateSystem:systemString returningScalar:&scalar];
2169
2170 [shipAI message:@"APPROACH_COORDINATES"];
2171}

◆ setCoordinatesFromPosition

- (void) setCoordinatesFromPosition
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1070 of file ShipEntityAI.m.

1071{
1073}

◆ setCourseToPlanet

- (void) setCourseToPlanet
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1144 of file ShipEntityAI.m.

1145{
1146 /*- selects the nearest planet it can find -*/
1147 OOPlanetEntity* the_planet = [self findNearestPlanetExcludingMoons];
1148 if (the_planet) {
1149 double variation = (aegis_status == AEGIS_NONE ? 0.5 : 0.2); // more random deviation when far from planet.
1150 HPVector p_pos = the_planet->position;
1151 double p_cr = the_planet->collision_radius; // the surface
1152 HPVector p1 = HPvector_between(p_pos, position);
1153 p1 = HPvector_normal(p1); // vector towards ship
1154 p1.x += variation * (randf() - variation);
1155 p1.y += variation * (randf() - variation);
1156 p1.z += variation * (randf() - variation);
1157 p1 = HPvector_normal(p1);
1158 _destination = HPvector_add(p_pos, HPvector_multiply_scalar(p1, p_cr)); // on surface
1159 desired_range = collision_radius + 100.0; // +100m from the destination
1160 } else {
1161 [shipAI message:@"NO_PLANET_FOUND"];
1162 }
1163}

◆ setCourseToWitchpoint

- (void) setCourseToWitchpoint
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1388 of file ShipEntityAI.m.

1389{
1390 if (UNIVERSE) {
1391 _destination = [UNIVERSE getWitchspaceExitPosition];
1392 desired_range = 10000.0; // 10km away
1393 }
1394}

◆ setCrew:

- (void) setCrew: (NSArray*) crewArray

Definition at line 6865 of file ShipEntity.m.

6865 :(NSArray*)crewArray
6866{
6867 if ([self isExplicitlyUnpiloted]) {
6868 // unpiloted ships cannot have crew
6869 // but may have crew before isExplicitlyUnpiloted set, so force *that* to clear too
6870 [crew autorelease];
6871 crew = nil;
6872 return;
6873 }
6874 // do not set to hulk here when crew is nil (or 0). Some things like missiles have no crew.
6875 [crew autorelease];
6876 crew = [crewArray copy];
6877}
BOOL isExplicitlyUnpiloted()

References crew, isExplicitlyUnpiloted, and nil.

Referenced by Universe::addShipAt:withRole:withinRadius:, Universe::addShipWithRole:launchPos:rfactor:, launchEscapeCapsule, ShipEntity(Private)::launchPodWithCrew:, PlayerEntity(Contracts)::processEscapePods, setSingleCrewWithRole:, setUpShipFromDictionary:, ShipSetCrew(), ShipSetCrew(), and Universe::witchspaceShipWithPrimaryRole:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setDemoShip:

- (void) setDemoShip: (OOScalar) demoRate

Definition at line 12750 of file ShipEntity.m.

12750 :(OOScalar)rate
12751{
12753 demoRate = rate;
12754 isDemoShip = YES;
12755 [self setPitch:0.0f];
12756 [self setRoll:0.0f];
12757}
Quaternion demoStartOrientation
Definition ShipEntity.h:482
OOScalar demoRate
Definition ShipEntity.h:480

References demoRate, demoStartOrientation, isDemoShip, Entity::orientation, setPitch:, and setRoll:.

Referenced by Universe::makeDemoShipWithRole:spinning:, Universe::setupIntroFirstGo:, PlayerEntity::showShipModelWithKey:shipData:personality:factorX:factorY:factorZ:inContext:, and Universe::update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setDemoStartTime:

- (void) setDemoStartTime: (OOTimeAbsolute) time

Definition at line 12764 of file ShipEntity.m.

12764 :(OOTimeAbsolute)time
12765{
12766 demoStartTime = time;
12767}

References demoStartTime.

Referenced by Universe::setupIntroFirstGo:, PlayerEntity::showShipModelWithKey:shipData:personality:factorX:factorY:factorZ:inContext:, and Universe::update:.

Here is the caller graph for this function:

◆ setDesiredRange:

- (void) setDesiredRange: (double) amount

Definition at line 7404 of file ShipEntity.m.

7404 :(double)amount
7405{
7406 desired_range = amount;
7407}

References desired_range.

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setDesiredRangeForWaypoint

- (void) setDesiredRangeForWaypoint
implementation

Provided by category ShipEntity(PureAI).

Definition at line 813 of file ShipEntityAI.m.

814{
815 desired_range = fmax(maxFlightSpeed / max_flight_pitch / 6, 50.0); // some ships need a longer range to reach a waypoint.
816}

◆ setDesiredRangeTo:

- (void) setDesiredRangeTo: (NSString*) rangeString
implementation

Provided by category ShipEntity(PureAI).

Definition at line 808 of file ShipEntityAI.m.

808 :(NSString*)rangeString
809{
810 desired_range = [rangeString doubleValue];
811}

◆ setDesiredSpeed:

- (void) setDesiredSpeed: (double) amount

Definition at line 7389 of file ShipEntity.m.

7389 :(double)amount
7390{
7391 desired_speed = amount;
7392}

References desired_speed.

Referenced by PlayerEntity::launchEscapeCapsule, DockEntity::launchShip:, ShipSetProperty(), ShipSetProperty(), and takeEnergyDamage:from:becauseOf:weaponIdentifier:.

Here is the caller graph for this function:

◆ setDestination:

- (void) setDestination: (HPVector) dest

Definition at line 11903 of file ShipEntity.m.

11903 :(HPVector)dest
11904{
11905 _destination = dest;
11906 frustration = 0.0; // new destination => no frustration!
11907}

References _destination, and frustration.

Referenced by Universe::setupIntroFirstGo:, and Universe::update:.

Here is the caller graph for this function:

◆ setDestinationFromCoordinates

- (void) setDestinationFromCoordinates
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1065 of file ShipEntityAI.m.

1066{
1068}

◆ setDestinationSystem:

- (void) setDestinationSystem: (OOSystemID) s

Definition at line 6840 of file ShipEntity.m.

6840 :(OOSystemID)s
6841{
6843}

References destination_system.

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setDestinationToCurrentLocation

- (void) setDestinationToCurrentLocation
implementation

Provided by category ShipEntity(PureAI).

Definition at line 795 of file ShipEntityAI.m.

796{
797 // randomly add a .5m variance
799}
HPVector OOHPVectorRandomSpatial(OOHPScalar maxLength)
Definition OOHPVector.m:75

◆ setDestinationToDockingAbort

- (void) setDestinationToDockingAbort
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1907 of file ShipEntityAI.m.

1908{
1909 Entity* the_target = [self targetStation];
1910 if (!the_target) {
1911 /* Probably the player trying to dock with docking computer
1912 * from out of scanner range */
1913 the_target = [UNIVERSE station];
1914 }
1915 double bo_distance = 8000; // 8km back off
1916 HPVector v0 = position;
1917 HPVector d0 = (the_target) ? the_target->position : kZeroHPVector;
1918 v0.x += (randf() - 0.5) * collision_radius;
1919 v0.y += (randf() - 0.5) * collision_radius;
1920 v0.z += (randf() - 0.5) * collision_radius;
1921 v0.x -= d0.x;
1922 v0.y -= d0.y;
1923 v0.z -= d0.z;
1924 v0 = HPvector_normal_or_fallback(v0, make_HPvector(0, 0, -1));
1925
1926 v0.x *= bo_distance;
1927 v0.y *= bo_distance;
1928 v0.z *= bo_distance;
1929 v0.x += d0.x;
1930 v0.y += d0.y;
1931 v0.z += d0.z;
1932 coordinates = v0;
1933 _destination = v0;
1934}
OOINLINE HPVector HPvector_normal_or_fallback(HPVector vec, HPVector fallback) INLINE_CONST_FUNC
Definition OOHPVector.h:265

◆ setDestinationToJinkPosition

- (void) setDestinationToJinkPosition
implementation

Provided by category ShipEntity(PureAI).

Definition at line 801 of file ShipEntityAI.m.

802{
805 pitching_over = YES; // don't complete roll first, but immediately start with pitching.
806}
Vector OOVectorRandomSpatial(OOScalar maxLength)
Definition OOVector.m:89

◆ setDestinationToStationBeacon

- (void) setDestinationToStationBeacon
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1401 of file ShipEntityAI.m.

1402{
1403 if ([UNIVERSE station]) {
1404 _destination = [[UNIVERSE station] beaconPosition];
1405 }
1406}

◆ setDestinationToTarget

- (void) setDestinationToTarget
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1236 of file ShipEntityAI.m.

1237{
1238 Entity* the_target = [self primaryTarget];
1239 if (the_target)
1240 _destination = the_target->position;
1241}

◆ setDestinationToWitchpoint

- (void) setDestinationToWitchpoint
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1396 of file ShipEntityAI.m.

1397{
1398 _destination = [UNIVERSE getWitchspaceExitPosition];
1399}

◆ setDestinationWithinTarget

- (void) setDestinationWithinTarget
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1243 of file ShipEntityAI.m.

1244{
1245 Entity* the_target = [self primaryTarget];
1246 if (the_target) {
1247 HPVector pos = the_target->position;
1248 Quaternion q;
1251 GLfloat d = (randf() - randf()) * the_target->collision_radius;
1252 _destination = make_HPvector(pos.x + d * v.x, pos.y + d * v.y, pos.z + d * v.z);
1253 }
1254}

◆ setDisplayName:

- (void) setDisplayName: (NSString*) inName

Definition at line 6251 of file ShipEntity.m.

6251 :(NSString*)inName
6252{
6253 [displayName release];
6254 displayName = [inName copy];
6255}

References displayName.

Referenced by setUpOneStandardSubentity:asTurret:, ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setEnergyRechargeRate:

- (void) setEnergyRechargeRate: (GLfloat) new

Definition at line 6491 of file ShipEntity.m.

6491 :(GLfloat)new
6492{
6494}

References energy_recharge_rate.

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setEntityPersonalityInt:

- (void) setEntityPersonalityInt: (uint16_t) value

Definition at line 8429 of file ShipEntity.m.

8429 :(uint16_t)value
8430{
8431 if (value <= ENTITY_PERSONALITY_MAX) {
8432 entity_personality = value;
8433 [[self mesh] rebindMaterials];
8434 }
8435}

References entity_personality, ENTITY_PERSONALITY_MAX, mesh, and OOMesh::rebindMaterials.

Referenced by PlayerEntity(Contracts)::buySelectedShip, PlayerEntity(LoadSave)::loadPlayerFromFile:asNew:, MissionRunScreen(), MissionRunScreen(), PlayerReplaceShip(), PlayerReplaceShip(), PlayerEntity(Contracts)::replaceShipWithNamedShip:, setUpOneStandardSubentity:asTurret:, ShipSetProperty(), ShipSetProperty(), and PlayerEntity::showShipModelWithKey:shipData:personality:factorX:factorY:factorZ:inContext:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setEscortDestination:

- (void) setEscortDestination: (HPVector) dest

Definition at line 11909 of file ShipEntity.m.

11909 :(HPVector)dest
11910{
11911 _destination = dest; // don't reset frustration for escorts.
11912}

References _destination.

Referenced by ShipSetProperty(), ShipSetProperty(), and update:.

Here is the caller graph for this function:

◆ setEscortGroup:

- (void) setEscortGroup: (OOShipGroup*) group

Definition at line 6010 of file ShipEntity.m.

6010 :(OOShipGroup*)group
6011{
6012 if (group != _escortGroup) {
6013 [_escortGroup release];
6014 _escortGroup = [group retain];
6015 [group setLeader:self]; // A ship is always leader of its own escort group.
6016 [self updateEscortFormation];
6017 }
6018}
void setLeader:(ShipEntity *leader)

References _escortGroup, group, OOShipGroup::setLeader:, and updateEscortFormation.

Referenced by ShipEntity(LoadRestore)::shipRestoredFromDictionary:useFallback:context:, and update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setEvasiveJink:

- (void) setEvasiveJink: (GLfloat) z

Definition at line 8989 of file ShipEntity.m.

8989 :(GLfloat)z
8990{
8992 jink = kZeroVector;
8993 } else {
8994 jink.x = (ranrot_rand() % 256) - 128.0;
8995 jink.y = (ranrot_rand() % 256) - 128.0;
8996 jink.z = z;
8997
8998 // make sure we don't accidentally have near-zero jink
8999 if (jink.x < 0.0) {
9000 jink.x -= 128.0;
9001 } else {
9002 jink.x += 128.0;
9003 }
9004 if (jink.y < 0) {
9005 jink.y -= 128.0;
9006 } else {
9007 jink.y += 128.0;
9008 }
9009 }
9010}

References accuracy, COMBAT_AI_ISNT_AWFUL, jink, kZeroVector, and ranrot_rand.

Referenced by behaviour_attack_broadside_target:leftside:, behaviour_attack_fly_from_target:, behaviour_attack_fly_to_target:, behaviour_attack_sniper:, behaviour_attack_target:, behaviour_evasive_action:, ShipEntity(AI)::performFlee, and trackPrimaryTarget:retreat:.

Here is the caller graph for this function:

◆ setExhaustEmissiveColor:

- (void) setExhaustEmissiveColor: (OOColor*) color

Definition at line 10153 of file ShipEntity.m.

10153 :(OOColor*)color
10154{
10155 if (color) {
10156 [exhaust_emissive_color release];
10157 exhaust_emissive_color = [color retain];
10158 }
10159}

References exhaust_emissive_color.

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setFoundTarget:

- (void) setFoundTarget: (Entity*) targetEntity

Reimplemented in PlayerEntity.

Definition at line 8558 of file ShipEntity.m.

8558 :(Entity*)targetEntity
8559{
8560 [_foundTarget release];
8561 _foundTarget = [targetEntity weakRetain];
8562}

References _foundTarget, and OOWeakRefObject::weakRetain.

Referenced by ShipEntity(OOAIPrivate)::acceptDistressMessageFrom:, broadcastEnergyBlastImminent, broadcastHitByLaserFrom:, enterWormhole:replacing:, ShipEntity(PureAI)::fightOrFleeHostiles, ShipEntity(PureAI)::fightOrFleeMissile, fireSubentityLaserShot:, ShipEntity(AI)::groupAttackTarget, ShipEntity(OOAIPrivate)::performHyperSpaceExitReplace:toSystem:, ShipEntity(PureAI)::recallStoredTarget, ShipEntity(PureAI)::requestNewTarget, respondToAttackFrom:becauseOf:, ShipEntity(PureAI)::scanForFormationLeader, ShipEntity(AI)::scanForHostiles, ShipEntity(PureAI)::scanForLoot, ShipEntity(PureAI)::scanForNearestMerchantman, ShipEntity(OOAIPrivate)::scanForNearestShipWithPredicate:parameter:, ShipEntity(PureAI)::scanForNonThargoid, ShipEntity(PureAI)::scanForOffenders, ShipEntity(PureAI)::scanForRandomLoot, ShipEntity(PureAI)::scanForRandomMerchantman, ShipEntity(PureAI)::scanForRocks, ShipSetProperty(), ShipSetProperty(), takeEnergyDamage:from:becauseOf:weaponIdentifier:, and StationEntity::takeEnergyDamage:from:becauseOf:weaponIdentifier:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setFuel:

- (void) setFuel: (OOFuelQuantity) amount

Definition at line 6997 of file ShipEntity.m.

6997 :(OOFuelQuantity)amount
6998{
6999 if (amount > [self fuelCapacity])
7000 amount = [self fuelCapacity];
7001
7002 fuel = amount;
7003}
uint16_t OOFuelQuantity
Definition OOTypes.h:158

References fuel, and fuelCapacity.

Referenced by ShipEntity(PureAI)::addFuel:, PlayerEntity(Scripting)::awardEquipment:, PlayerEntity(Scripting)::awardFuel:, PlayerEntity::doBookkeeping:, StationEntity::launchIndependentShip:, Universe::makeSunSkimmer:andSetAI:, PlayerEntity(Contracts)::newShipCommonSetup:yardInfo:baseInfo:, PlayerEntity(Scripting)::sendAllShipsAway, PlayerEntity(Scripting)::setFuelLeak:, ShipSetProperty(), ShipSetProperty(), and update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setGroup:

- (void) setGroup: (OOShipGroup*) group

Definition at line 5984 of file ShipEntity.m.

5984 :(OOShipGroup*)group
5985{
5986 if (group != _group) {
5987 if (_escortGroup != _group) {
5988 if (self == [_group leader])
5989 [_group setLeader:nil];
5990 [_group removeShip:self];
5991 }
5992 [_group release];
5993 [group addShip:self];
5994 _group = [group retain];
5995
5996 [[group leader] updateEscortFormation];
5997 }
5998}
BOOL addShip:(ShipEntity *ship)
ShipEntity * leader()
void updateEscortFormation()

References _escortGroup, _group, OOShipGroup::addShip:, group, OOShipGroup::leader, OOShipGroup::removeShip:, OOShipGroup::setLeader:, and updateEscortFormation.

Referenced by abandonShip, acceptAsEscort:, Universe::addShipsAt:withRole:quantity:withinRadius:asGroup:, ShipEntity(PureAI)::becomeUncontrolledThargon, deployEscorts, dockEscorts, ShipEntity(PureAI)::escortCheckMother, fireMissileWithIdentifier:andTarget:, StationEntity::launchDefenseShip, StationEntity::launchIndependentShip:, StationEntity::launchMiner, StationEntity::launchPatrol, StationEntity::launchPirateShip, StationEntity::launchPolice, StationEntity::launchScavenger, StationEntity::launchShipWithRole:, OOShipGroup::removeShip:, setUpEscorts, ShipEntity(Private)::setUpMixedEscorts, ShipEntity(Private)::setUpOneEscort:inGroup:withRole:atPosition:andCount:, StationEntity::setUpShipFromDictionary:, ShipGroupAddShip(), ShipGroupAddShip(), ShipEntity(LoadRestore)::shipRestoredFromDictionary:useFallback:context:, ShipSetProperty(), ShipSetProperty(), ShipEntity(AI)::suggestEscortTo:, and ShipEntity(PureAI)::thargonCheckMother.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setHeatInsulation:

- (void) setHeatInsulation: (GLfloat) value

◆ setHomeSystem:

- (void) setHomeSystem: (OOSystemID) s

Definition at line 6835 of file ShipEntity.m.

6835 :(OOSystemID)s
6836{
6837 home_system = s;
6838}

References home_system.

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setHulk:

- (void) setHulk: (BOOL) isNowHulk

Definition at line 7716 of file ShipEntity.m.

7716 :(BOOL)isNowHulk
7717{
7718 if (![self isSubEntity]) {
7719 isHulk = isNowHulk;
7720 }
7721}
unsigned isHulk

References isHulk, and Entity::isSubEntity.

Referenced by launchEscapeCapsule, and setUpShipFromDictionary:.

Here is the caller graph for this function:

◆ setHyperspaceSpinTime:

- (void) setHyperspaceSpinTime: (float) new

Definition at line 2874 of file ShipEntity.m.

2874 :(float)new
2875{
2877}

References hyperspaceMotorSpinTime.

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setIsBoulder:

- (void) setIsBoulder: (BOOL) flag

Definition at line 1504 of file ShipEntity.m.

1504 :(BOOL)flag
1505{
1506 if (flag)
1507 [self addRole:kBoulderRole];
1508 else
1509 [self removeRole:kBoulderRole];
1510}

References addRole:, and removeRole:.

Referenced by becomeExplosion, ShipSetProperty(), and ShipSetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setIsMissileFlag:

- (void) setIsMissileFlag: (BOOL) newValue

Definition at line 10707 of file ShipEntity.m.

10707 :(BOOL)newValue
10708{
10709 isMissile = !!newValue; // set the isMissile flag, used for tracking submunitions and preventing collisions at launch.
10710}

References isMissile.

Referenced by fireMissileWithIdentifier:andTarget:, and ShipEntity(ScriptMethods)::spawnShipsWithRole:count:.

Here is the caller graph for this function:

◆ setIsWreckage:

- (void) setIsWreckage: (BOOL) isw

Definition at line 7890 of file ShipEntity.m.

7890 :(BOOL)isw
7891{
7892 isWreckage = isw;
7893}

References isWreckage.

Referenced by Universe::addWreckageFrom:withRole:at:scale:lifetime:.

Here is the caller graph for this function:

◆ setLaserColor:

- (void) setLaserColor: (OOColor*) color

Definition at line 10145 of file ShipEntity.m.

10145 :(OOColor*)color
10146{
10147 if (color) {
10148 [laser_color release];
10149 laser_color = [color retain];
10150 }
10151}

References laser_color.

Referenced by setWeaponDataFromType:.

Here is the caller graph for this function:

◆ setLastAegisLock:

- (void) setLastAegisLock: (Entity<OOStellarBody>*) lastAegisLock

Definition at line 6819 of file ShipEntity.m.

6819 :(Entity<OOStellarBody>*)lastAegisLock
6820{
6821 [_lastAegisLock release];
6822 _lastAegisLock = [lastAegisLock weakRetain];
6823}

References _lastAegisLock.

Referenced by checkForAegis, and PlayerEntity::completeSetUpAndSetTarget:.

Here is the caller graph for this function:

◆ setLastEscortTarget:

- (void) setLastEscortTarget: (Entity*) targetEntity

Definition at line 8590 of file ShipEntity.m.

8590 :(Entity*)targetEntity
8591{
8592 [_lastEscortTarget release];
8593 _lastEscortTarget = [targetEntity weakRetain];
8594}

References _lastEscortTarget, and OOWeakRefObject::weakRetain.

Referenced by deployEscorts.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setLaunchDelay:

- (void) setLaunchDelay: (double) delay

Definition at line 6855 of file ShipEntity.m.

6855 :(double)delay
6856{
6857 launch_delay = delay;
6858}
double launch_delay
Definition ShipEntity.h:334

References launch_delay.

Referenced by DockEntity::launchShip:.

Here is the caller graph for this function:

◆ setMaxAvailableCargoSpace:

- (void) setMaxAvailableCargoSpace: (OOCargoQuantity) new

Definition at line 7212 of file ShipEntity.m.

7212 :(OOCargoQuantity)new
7213{
7215}

References equipment_weight, and max_cargo.

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setMaxEscortCount:

- (void) setMaxEscortCount: (uint8_t) newCount

Definition at line 6080 of file ShipEntity.m.

6080 :(uint8_t)newCount
6081{
6082 _maxEscortCount = newCount;
6083}

References _maxEscortCount.

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setMaxFlightPitch:

- (void) setMaxFlightPitch: (GLfloat) new

Reimplemented in PlayerEntity.

Definition at line 7534 of file ShipEntity.m.

7534 :(GLfloat)new
7535{
7536 max_flight_pitch = new;
7537}

References max_flight_pitch.

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setMaxFlightRoll:

- (void) setMaxFlightRoll: (GLfloat) new

Reimplemented in PlayerEntity.

Definition at line 7544 of file ShipEntity.m.

7544 :(GLfloat)new
7545{
7546 max_flight_roll = new;
7547}

References max_flight_roll.

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setMaxFlightSpeed:

- (void) setMaxFlightSpeed: (GLfloat) new

Definition at line 7539 of file ShipEntity.m.

7539 :(GLfloat)new
7540{
7541 maxFlightSpeed = new;
7542}

References maxFlightSpeed.

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setMaxFlightYaw:

- (void) setMaxFlightYaw: (GLfloat) new

Reimplemented in PlayerEntity.

Definition at line 7549 of file ShipEntity.m.

7549 :(GLfloat)new
7550{
7551 max_flight_yaw = new;
7552}

References max_flight_yaw.

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setMaxThrust:

- (void) setMaxThrust: (GLfloat) new

Definition at line 3686 of file ShipEntity.m.

3686 :(GLfloat)new
3687{
3688 max_thrust = new;
3689}

References max_thrust.

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setMesh:

- (void) setMesh: (OOMesh*) mesh

Definition at line 1150 of file ShipEntity.m.

1150 :(OOMesh*)mesh
1151{
1152 if (mesh != [self mesh]) {
1153 [self setDrawable:mesh];
1154 [octree autorelease];
1155 octree = [[mesh octree] retain];
1156 }
1157}
Octree * octree
Definition OOMesh.m:631

References mesh, OOMesh::octree, octree, and OOEntityWithDrawable::setDrawable:.

Referenced by PlayerEntity::doBookkeeping:, PlayerEntity::launchEscapeCapsule, ShipEntity(Private)::rescaleBy:writeToCache:, ShipSetMaterialsInternal(), and ShipSetMaterialsInternal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setMessageTime:

- (void) setMessageTime: (double) value

Definition at line 5974 of file ShipEntity.m.

5974 :(double)value
5975{
5976 messageTime = value;
5977}

References messageTime.

Referenced by HeadUpDisplay::refreshLastTransmitter.

Here is the caller graph for this function:

◆ setMissileLoadTime:

- (void) setMissileLoadTime: (OOTimeDelta) newMissileLoadTime

Definition at line 10717 of file ShipEntity.m.

10717 :(OOTimeDelta)newMissileLoadTime
10718{
10719 missile_load_time = fmax(0.0, newMissileLoadTime);
10720}

References missile_load_time.

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setName:

- (void) setName: (NSString*) inName

Reimplemented in PlayerEntity.

Definition at line 6233 of file ShipEntity.m.

6233 :(NSString*)inName
6234{
6235 [name release];
6236 name = [inName copy];
6237}

References name.

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setNextBeacon:

- (void) setNextBeacon: (Entity<OOBeaconEntity>*) beaconShip
implementation

Reimplemented from <OOBeaconEntity>.

Definition at line 1494 of file ShipEntity.m.

1494 :(Entity<OOBeaconEntity>*)beaconShip
1495{
1496 if (beaconShip != [self nextBeacon]) {
1497 [_nextBeacon release];
1498 _nextBeacon = [beaconShip weakRetain];
1499 }
1500}
Entity< OOBeaconEntity > * nextBeacon()
OOWeakReference * _nextBeacon
Definition ShipEntity.h:473

References _nextBeacon, and nextBeacon.

Referenced by PlayerEntity::setNextCompassMode, and PlayerEntity::setPrevCompassMode.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setOwner:

- (void) setOwner: (Entity*) who_owns_entity
implementation

Reimplemented from Entity.

Definition at line 5803 of file ShipEntity.m.

5803 :(Entity*)who_owns_entity
5804{
5805 [super setOwner:who_owns_entity];
5806
5807 /* Reset shader binding target so that bind-to-super works.
5808 This is necessary since we don't know about the owner in
5809 setUpShipFromDictionary:, when the mesh is initially set up.
5810 -- Ahruman 2008-04-19
5811 */
5812 if (isSubEntity) {
5813 [[self drawable] setBindingTarget:self];
5814 }
5815}

References OOEntityWithDrawable::drawable, Entity::isSubEntity, OODrawable::setBindingTarget:, and Entity::setOwner:.

Referenced by abandonShip, ShipEntity(Private)::addSubEntity:, behaviour_tractored:, dockEscorts, dumpItem:, ShipEntity(PureAI)::escortCheckMother, fireMissileWithIdentifier:andTarget:, getTractoredBy:, launchCascadeMine, StationEntity::launchDefenseShip, PlayerEntity::launchEscapeCapsule, StationEntity::launchIndependentShip:, PlayerEntity::launchMine:, StationEntity::launchPirateShip, ShipEntity(Private)::launchPodWithCrew:, releaseCargoPodsDebris, OOShipGroup::removeShip:, ShipEntity(Private)::setUpOneEscort:inGroup:withRole:atPosition:andCount:, setUpShipFromDictionary:, ShipEntity(LoadRestore)::shipRestoredFromDictionary:useFallback:context:, ShipEntity(ScriptMethods)::spawnShipsWithRole:count:, ShipEntity(Private)::subEntityDied:, ShipEntity(AI)::suggestEscortTo:, ShipEntity(PureAI)::thargonCheckMother, and update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPendingEscortCount:

- (void) setPendingEscortCount: (uint8_t) count

Definition at line 6070 of file ShipEntity.m.

6070 :(uint8_t)count
6071{
6073}

References _maxEscortCount, _pendingEscortCount, count, and MIN.

Referenced by StationEntity::launchIndependentShip:, DockEntity::launchShip:, Universe::makeDemoShipWithRole:spinning:, Universe::setupIntroFirstGo:, and PlayerEntity::showShipModelWithKey:shipData:personality:factorX:factorY:factorZ:inContext:.

Here is the caller graph for this function:

◆ setPitch:

- (void) setPitch: (double) amount

Definition at line 7086 of file ShipEntity.m.

7086 :(double)amount
7087{
7088 flightPitch = amount * M_PI / 2.0;
7089}
#define M_PI
Definition OOMaths.h:54

References flightPitch, and M_PI.

Referenced by WormholeEntity::disgorgeShips, dumpItem:, launchCascadeMine, DockEntity::launchShip:, PlayerEntity(Scripting)::processSceneString:atOffset:, setDemoShip:, and Universe::setUpSpace.

Here is the caller graph for this function:

◆ setPlanetPatrolCoordinates

- (void) setPlanetPatrolCoordinates
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1670 of file ShipEntityAI.m.

1671{
1672 // check we've arrived near the last given coordinates
1674 if (HPmagnitude2(r_pos) < 1000000 || patrol_counter == 0) {
1675 Entity* the_sun = [UNIVERSE sun];
1676 ShipEntity* the_station = [[self group] leader];
1677 if (!the_station || ![the_station isStation])
1678 the_station = [UNIVERSE station];
1679 if ((!the_sun) || (!the_station))
1680 return;
1681 HPVector sun_pos = the_sun->position;
1682 HPVector stn_pos = the_station->position;
1683 HPVector sun_dir = HPvector_subtract(sun_pos, stn_pos);
1684 Vector vSun = make_vector(0, 0, 1);
1685 if (sun_dir.x || sun_dir.y || sun_dir.z)
1686 vSun = HPVectorToVector(HPvector_normal(sun_dir));
1687 Vector v0 = [the_station forwardVector];
1688 Vector v1 = cross_product(v0, vSun);
1689 Vector v2 = cross_product(v0, v1);
1690 switch (patrol_counter) {
1691 case 0: // first go to 5km ahead of the station
1692 coordinates = make_HPvector(stn_pos.x + 5000 * v0.x, stn_pos.y + 5000 * v0.y, stn_pos.z + 5000 * v0.z);
1693 desired_range = 250.0;
1694 break;
1695 case 1: // go to 25km N of the station
1696 coordinates = make_HPvector(stn_pos.x + 25000 * v1.x, stn_pos.y + 25000 * v1.y, stn_pos.z + 25000 * v1.z);
1697 desired_range = 250.0;
1698 break;
1699 case 2: // go to 25km E of the station
1700 coordinates = make_HPvector(stn_pos.x + 25000 * v2.x, stn_pos.y + 25000 * v2.y, stn_pos.z + 25000 * v2.z);
1701 desired_range = 250.0;
1702 break;
1703 case 3: // go to 25km S of the station
1704 coordinates = make_HPvector(stn_pos.x - 25000 * v1.x, stn_pos.y - 25000 * v1.y, stn_pos.z - 25000 * v1.z);
1705 desired_range = 250.0;
1706 break;
1707 case 4: // go to 25km W of the station
1708 coordinates = make_HPvector(stn_pos.x - 25000 * v2.x, stn_pos.y - 25000 * v2.y, stn_pos.z - 25000 * v2.z);
1709 desired_range = 250.0;
1710 break;
1711 default: // We should never come here
1712 coordinates = make_HPvector(stn_pos.x + 5000 * v0.x, stn_pos.y + 5000 * v0.y, stn_pos.z + 5000 * v0.z);
1713 desired_range = 250.0;
1714 break;
1715 }
1717 if (patrol_counter > 4) {
1718 if (randf() < .25) {
1719 // consider docking
1720 [self setTargetStation:the_station];
1721 [self setAITo:@"dockingAI.plist"];
1722 return;
1723 } else {
1724 // go around again
1725 patrol_counter = 1;
1726 }
1727 }
1728 }
1729 [shipAI message:@"APPROACH_COORDINATES"];
1730}
int patrol_counter
Definition ShipEntity.h:340

◆ setPrevBeacon:

- (void) setPrevBeacon: (Entity<OOBeaconEntity>*) beaconShip
implementation

Reimplemented from <OOBeaconEntity>.

Definition at line 1486 of file ShipEntity.m.

1486 :(Entity<OOBeaconEntity>*)beaconShip
1487{
1488 if (beaconShip != [self prevBeacon]) {
1489 [_prevBeacon release];
1490 _prevBeacon = [beaconShip weakRetain];
1491 }
1492}
OOWeakReference * _prevBeacon
Definition ShipEntity.h:472
Entity< OOBeaconEntity > * prevBeacon()

References _prevBeacon, and prevBeacon.

Here is the call graph for this function:

◆ setPrimaryAggressor:

- (void) setPrimaryAggressor: (Entity*) targetEntity

Definition at line 8574 of file ShipEntity.m.

8574 :(Entity*)targetEntity
8575{
8576 [_primaryAggressor release];
8577 _primaryAggressor = [targetEntity weakRetain];
8578}

References _primaryAggressor, and OOWeakRefObject::weakRetain.

Referenced by ShipEntity(PureAI)::fightOrFleeHostiles, ShipEntity(PureAI)::fightOrFleeMissile, fireMissileWithIdentifier:andTarget:, fireSubentityLaserShot:, respondToAttackFrom:becauseOf:, ShipSetProperty(), ShipSetProperty(), takeEnergyDamage:from:becauseOf:weaponIdentifier:, and StationEntity::takeEnergyDamage:from:becauseOf:weaponIdentifier:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPrimaryRole:

◆ setProximityAlert:

- (void) setProximityAlert: (ShipEntity*) targetEntity

Definition at line 6107 of file ShipEntity.m.

6107 :(ShipEntity*)other
6108{
6109 if (!other) {
6111 return;
6112 }
6113
6114 if ([other mass] < 2000) // we are not alerted by small objects. (a cargopod has a mass of about 1000)
6115 return;
6116
6117 if (isStation) // stations don't worry about colliding with things
6118 return;
6119
6120 /* Ignore station collision warnings if launching or docking */
6121 if ((other->isStation) && ([self status] == STATUS_LAUNCHING || dockingInstructions != nil)) {
6122 return;
6123 }
6124
6125 if (!crew) // Ships without pilot (cargo, rocks, missiles, buoys etc) will not get alarmed. (escape-pods have pilots)
6126 return;
6127
6128 // check vectors
6129 Vector vdiff = HPVectorToVector(HPvector_between(position, other->position));
6130 GLfloat d_forward = dot_product(vdiff, v_forward);
6131 GLfloat d_up = dot_product(vdiff, v_up);
6132 GLfloat d_right = dot_product(vdiff, v_right);
6133 if ((d_forward > 0.0) && (flightSpeed > 0.0)) // it's ahead of us and we're moving forward
6134 d_forward *= 0.25 * maxFlightSpeed / flightSpeed; // extend the collision zone forward up to 400%
6135 double d2 = d_forward * d_forward + d_up * d_up + d_right * d_right;
6136 double cr2 = collision_radius * 2.0 + other->collision_radius;
6137 cr2 *= cr2; // check with twice the combined radius
6138
6139 if (d2 > cr2) // we're okay
6140 return;
6141
6142 if (behaviour == BEHAVIOUR_AVOID_COLLISION) // already avoiding something
6143 {
6144 ShipEntity* prox = (ShipEntity*)[self proximityAlert];
6145 if ((prox) && (prox != other)) {
6146 // check which subtends the greatest angle
6147 GLfloat sa_prox = prox->collision_radius * prox->collision_radius / HPdistance2(position, prox->position);
6148 GLfloat sa_other = other->collision_radius * other->collision_radius / HPdistance2(position, other->position);
6149 if (sa_prox < sa_other)
6150 return;
6151 }
6152 }
6153 [_proximityAlert release];
6154 _proximityAlert = [other weakRetain];
6155}

References _proximityAlert, behaviour, Entity::collision_radius, crew, DESTROY, dockingInstructions, dot_product(), flightSpeed, HPdistance2(), HPvector_between, HPVectorToVector(), Entity::isStation, Entity::mass, maxFlightSpeed, nil, Entity::position, proximityAlert, Entity::status, v_forward, v_right, v_up, and OOWeakRefObject::weakRetain.

Referenced by CollisionRegion::findCollisions.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setRacepointsFromTarget

- (void) setRacepointsFromTarget
implementation

Provided by category ShipEntity(PureAI).

Definition at line 2362 of file ShipEntityAI.m.

2363{
2364 // two point - one at z - cr one at z + cr
2365 ShipEntity* ship = [self primaryTarget];
2366 if (ship == nil) {
2367 [shipAI message:@"NOTHING_FOUND"];
2368 return;
2369 }
2370 Vector k = ship->v_forward;
2371 GLfloat c = ship->collision_radius;
2372 HPVector o = ship->position;
2373 navpoints[0] = make_HPvector(o.x - c * k.x, o.y - c * k.y, o.z - c * k.z);
2374 navpoints[1] = make_HPvector(o.x + c * k.x, o.y + c * k.y, o.z + c * k.z);
2375 navpoints[2] = make_HPvector(o.x + 2.0 * c * k.x, o.y + 2.0 * c * k.y, o.z + 2.0 * c * k.z);
2379 [shipAI message:@"RACEPOINTS_SET"];
2380}

◆ setRawRoll:

- (void) setRawRoll: (double) amount

Definition at line 7081 of file ShipEntity.m.

7081 :(double)amount
7082{
7083 flightRoll = amount;
7084}

References flightRoll.

Referenced by StationSetProperty(), and StationSetProperty().

Here is the caller graph for this function:

◆ setReactionTime:

- (void) setReactionTime: (float) newReactionTime

Definition at line 5416 of file ShipEntity.m.

5416 :(float)newReactionTime
5417{
5418 reactionTime = newReactionTime;
5419}

References reactionTime.

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setReference:

- (void) setReference: (Vector) v

Definition at line 6531 of file ShipEntity.m.

6531 :(Vector)v
6532{
6533 reference = v;
6534}

References reference.

Referenced by setUpOneStandardSubentity:asTurret:.

Here is the caller graph for this function:

◆ setRememberedShip:

- (void) setRememberedShip: (Entity*) targetEntity

Definition at line 8622 of file ShipEntity.m.

8622 :(Entity*)targetEntity
8623{
8624 [_rememberedShip release];
8625 _rememberedShip = [targetEntity weakRetain];
8626}

References _rememberedShip, and OOWeakRefObject::weakRetain.

Referenced by ShipEntity(PureAI)::storeTarget.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setReportAIMessages:

- (void) setReportAIMessages: (BOOL) yn

Definition at line 6541 of file ShipEntity.m.

6541 :(BOOL)yn
6542{
6543 reportAIMessages = yn;
6544}

References reportAIMessages.

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setRoll:

- (void) setRoll: (double) amount

Definition at line 7076 of file ShipEntity.m.

7076 :(double)amount
7077{
7078 flightRoll = amount * M_PI / 2.0;
7079}

References flightRoll, and M_PI.

Referenced by Universe::addEntity:, WormholeEntity::disgorgeShips, dumpItem:, launchCascadeMine, PlayerEntity::launchEscapeCapsule, DockEntity::launchShip:, PlayerEntity(Scripting)::processSceneString:atOffset:, and setDemoShip:.

Here is the caller graph for this function:

◆ setScanDescription:

- (void) setScanDescription: (NSString*) inName

Definition at line 6257 of file ShipEntity.m.

6257 :(NSString*)inName
6258{
6259 [scan_description release];
6260 scan_description = [inName copy];
6261}

References scan_description.

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setScannerDisplayColor1:

- (void) setScannerDisplayColor1: (OOColor*) color1

Definition at line 5699 of file ShipEntity.m.

5699 :(OOColor*)color
5700{
5702
5703 if (color == nil)
5704 color = [OOColor colorWithDescription:[[self shipInfoDictionary] objectForKey:@"scanner_display_color1"]];
5705 scanner_display_color1 = [color retain];
5706}
OOColor * colorWithDescription:(id description)
Definition OOColor.m:135

References OOColor::colorWithDescription:, DESTROY, nil, scanner_display_color1, and shipInfoDictionary.

Referenced by setUpShipFromDictionary:, ShipSetProperty(), and ShipSetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setScannerDisplayColor2:

- (void) setScannerDisplayColor2: (OOColor*) color2

Definition at line 5708 of file ShipEntity.m.

5708 :(OOColor*)color
5709{
5711
5712 if (color == nil)
5713 color = [OOColor colorWithDescription:[[self shipInfoDictionary] objectForKey:@"scanner_display_color2"]];
5714 scanner_display_color2 = [color retain];
5715}

References OOColor::colorWithDescription:, DESTROY, nil, scanner_display_color2, and shipInfoDictionary.

Referenced by setUpShipFromDictionary:, ShipSetProperty(), and ShipSetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setScannerDisplayColorHostile1:

- (void) setScannerDisplayColorHostile1: (OOColor*) color1

Definition at line 5727 of file ShipEntity.m.

5727 :(OOColor*)color
5728{
5730
5731 if (color == nil)
5732 color = [OOColor colorWithDescription:[[self shipInfoDictionary] objectForKey:@"scanner_hostile_display_color1"]];
5733 scanner_display_color_hostile1 = [color retain];
5734}

References OOColor::colorWithDescription:, DESTROY, nil, scanner_display_color_hostile1, and shipInfoDictionary.

Referenced by setUpShipFromDictionary:, ShipSetProperty(), and ShipSetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setScannerDisplayColorHostile2:

- (void) setScannerDisplayColorHostile2: (OOColor*) color2

Definition at line 5736 of file ShipEntity.m.

5736 :(OOColor*)color
5737{
5739
5740 if (color == nil)
5741 color = [OOColor colorWithDescription:[[self shipInfoDictionary] objectForKey:@"scanner_hostile_display_color2"]];
5742 scanner_display_color_hostile2 = [color retain];
5743}

References OOColor::colorWithDescription:, DESTROY, nil, scanner_display_color_hostile2, and shipInfoDictionary.

Referenced by setUpShipFromDictionary:, ShipSetProperty(), and ShipSetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setScannerRange:

- (void) setScannerRange: (GLfloat) value

Definition at line 6521 of file ShipEntity.m.

6521 :(GLfloat)value
6522{
6523 scannerRange = value;
6524}

References scannerRange.

◆ setScriptedMisjump:

- (void) setScriptedMisjump: (BOOL) newValue

Definition at line 1184 of file ShipEntity.m.

1184 :(BOOL)newValue
1185{
1186 scripted_misjump = !!newValue;
1187}

References scripted_misjump.

Referenced by enterWormhole:replacing:, PlayerEntity(OOPrivate)::performWitchspaceExitUpdates:, ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setScriptedMisjumpRange:

- (void) setScriptedMisjumpRange: (GLfloat) newValue

Definition at line 1194 of file ShipEntity.m.

1194 :(GLfloat)newValue
1195{
1196 _scriptedMisjumpRange = newValue;
1197}

References _scriptedMisjumpRange.

Referenced by enterWormhole:replacing:, PlayerEntity(OOPrivate)::performWitchspaceExitUpdates:, ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setShipClassName:

- (void) setShipClassName: (NSString*) inName

Definition at line 6245 of file ShipEntity.m.

6245 :(NSString*)inName
6246{
6247 [shipClassName release];
6248 shipClassName = [inName copy];
6249}

References shipClassName.

Referenced by PlayerEntity(Contracts)::newShipCommonSetup:yardInfo:baseInfo:, PlayerEntity::setCommanderDataFromDictionary:, ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setShipDataKey:

- (void) setShipDataKey: (NSString*) key

Definition at line 1784 of file ShipEntity.m.

1784 :(NSString*)key
1785{
1787 _shipKey = [key copy];
1788}

References _shipKey, and DESTROY.

Referenced by PlayerEntity(Contracts)::newShipCommonSetup:yardInfo:baseInfo:, PlayerEntity::setCommanderDataFromDictionary:, and PlayerEntity::setUpAndConfirmOK:saveGame:.

Here is the caller graph for this function:

◆ setShipHitByLaser:

- (void) setShipHitByLaser: (ShipEntity*) ship
implementation

Provided by category ShipEntity(Private).

Definition at line 8775 of file ShipEntity.m.

8775 :(ShipEntity*)ship
8776{
8777 if (ship != [self shipHitByLaser]) {
8778 [_shipHitByLaser release];
8779 _shipHitByLaser = [ship weakRetain];
8780 }
8781}
OOWeakReference * _shipHitByLaser
Definition ShipEntity.h:467
ShipEntity * shipHitByLaser()

References OOWeakRefObject::weakRetain.

Referenced by fireDirectLaserShotAt:, fireLaserShotInDirection:weaponIdentifier:, and fireSubentityLaserShot:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setShipScript:

- (void) setShipScript: (NSString*) script_name

Definition at line 6937 of file ShipEntity.m.

6937 :(NSString*)script_name
6938{
6939 NSMutableDictionary* properties = nil;
6940 NSArray* actions = nil;
6941
6942 properties = [NSMutableDictionary dictionary];
6943 [properties setObject:self forKey:@"ship"];
6944
6945 [script autorelease];
6946 script = [OOScript jsScriptFromFileNamed:script_name properties:properties];
6947
6948 if (script == nil) {
6949 actions = [shipinfoDictionary oo_arrayForKey:@"launch_actions"];
6950 if (actions) {
6951 OOStandardsDeprecated([NSString stringWithFormat:@"The launch_actions ship key is deprecated on %@.", [self displayName]]);
6952 if (!OOEnforceStandards()) {
6953 [properties setObject:actions forKey:@"legacy_launchActions"];
6954 }
6955 }
6956
6957 actions = [shipinfoDictionary oo_arrayForKey:@"script_actions"];
6958 if (actions) {
6959 OOStandardsDeprecated([NSString stringWithFormat:@"The script_actions ship key is deprecated on %@.", [self displayName]]);
6960 if (!OOEnforceStandards()) {
6961 [properties setObject:actions forKey:@"legacy_scriptActions"];
6962 }
6963 }
6964
6965 actions = [shipinfoDictionary oo_arrayForKey:@"death_actions"];
6966 if (actions) {
6967 OOStandardsDeprecated([NSString stringWithFormat:@"The death_actions ship key is deprecated on %@.", [self displayName]]);
6968 if (!OOEnforceStandards()) {
6969 [properties setObject:actions forKey:@"legacy_deathActions"];
6970 }
6971 }
6972
6973 actions = [shipinfoDictionary oo_arrayForKey:@"setup_actions"];
6974 if (actions) {
6975 OOStandardsDeprecated([NSString stringWithFormat:@"The setup_actions ship key is deprecated on %@.", [self displayName]]);
6976 if (!OOEnforceStandards()) {
6977 [properties setObject:actions forKey:@"legacy_setupActions"];
6978 }
6979 }
6980
6981 script = [OOScript jsScriptFromFileNamed:@"oolite-default-ship-script.js"
6982 properties:properties];
6983 }
6984 [script retain];
6985}
BOOL OOEnforceStandards(void)
id jsScriptFromFileNamed:properties:(NSString *fileName,[properties] NSDictionary *properties)
Definition OOScript.m:177

References displayName, OOScript::jsScriptFromFileNamed:properties:, nil, OOEnforceStandards(), OOStandardsDeprecated(), and script.

Referenced by setUpShipFromDictionary:, ShipSetScript(), and ShipSetScript().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setShipUniqueName:

- (void) setShipUniqueName: (NSString*) inName

Definition at line 6239 of file ShipEntity.m.

6239 :(NSString*)inName
6240{
6241 [shipUniqueName release];
6242 shipUniqueName = [inName copy];
6243}

References shipUniqueName.

Referenced by PlayerEntity(Contracts)::newShipCommonSetup:yardInfo:baseInfo:, PlayerEntity::setCommanderDataFromDictionary:, ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setSingleCrewWithRole:

- (void) setSingleCrewWithRole: (NSString*) crewRole

Convenience to set the crew to a single character of the given role, originating in the ship's home system. Does nothing if unpiloted.

Definition at line 6879 of file ShipEntity.m.

6879 :(NSString*)crewRole
6880{
6881 if (![self isUnpiloted]) {
6882 OOCharacter* crewMember = [OOCharacter randomCharacterWithRole:crewRole
6883 andOriginalSystem:[self homeSystem]];
6884 [self setCrew:[NSArray arrayWithObject:crewMember]];
6885 }
6886}
BOOL isUnpiloted()

References homeSystem, isUnpiloted, OOCharacter::randomCharacterWithRole:andOriginalSystem:, and setCrew:.

Referenced by StationEntity::launchDefenseShip, StationEntity::launchEscort, StationEntity::launchIndependentShip:, StationEntity::launchMiner, StationEntity::launchPatrol, StationEntity::launchPirateShip, StationEntity::launchPolice, StationEntity::launchScavenger, StationEntity::launchShipWithRole:, PlanetEntity::launchShuttle, StationEntity::launchShuttle, ShipEntity(Private)::setUpOneEscort:inGroup:withRole:atPosition:andCount:, and StationEntity::setUpShipFromDictionary:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setSpeed:

- (void) setSpeed: (double) amount

Definition at line 7384 of file ShipEntity.m.

7384 :(double)amount
7385{
7386 flightSpeed = amount;
7387}

References flightSpeed.

Referenced by ShipEntity(PureAI)::becomeUncontrolledThargon, WormholeEntity::disgorgeShips, fireMissileWithIdentifier:andTarget:, launchCascadeMine, PlayerEntity::launchEscapeCapsule, and DockEntity::launchShip:.

Here is the caller graph for this function:

◆ setSpeedFactorTo:

- (void) setSpeedFactorTo: (NSString*) speedString
implementation

Provided by category ShipEntity(PureAI).

Definition at line 823 of file ShipEntityAI.m.

823 :(NSString*)speedString
824{
825 desired_speed = maxFlightSpeed * [speedString doubleValue];
826}

◆ setSpeedTo:

- (void) setSpeedTo: (NSString*) speedString
implementation

Provided by category ShipEntity(PureAI).

Definition at line 818 of file ShipEntityAI.m.

818 :(NSString*)speedString
819{
820 desired_speed = [speedString doubleValue];
821}

◆ setSpeedToCruiseSpeed

- (void) setSpeedToCruiseSpeed
implementation

Provided by category ShipEntity(PureAI).

Definition at line 828 of file ShipEntityAI.m.

829{
831}

◆ setStateMachine:

- (void) setStateMachine: (NSString*) ai_desc

Definition at line 6902 of file ShipEntity.m.

6902 :(NSString*)smName
6903{
6904 [self setAITo:smName];
6905}

References setAITo:.

Here is the call graph for this function:

◆ setStateTo:

- (void) setStateTo: (NSString*) state
implementation

Provided by category ShipEntity(PureAI).

Definition at line 752 of file ShipEntityAI.m.

752 :(NSString*)state
753{
754 [[self getAI] setState:state];
755}

◆ setStatus:

- (void) setStatus: (OOEntityStatus) stat
implementation

Reimplemented from Entity.

Definition at line 6845 of file ShipEntity.m.

6845 :(OOEntityStatus)stat
6846{
6847 if ([self status] == stat)
6848 return;
6849 [super setStatus:stat];
6850 if (stat == STATUS_LAUNCHING) {
6851 launch_time = [UNIVERSE getTime];
6852 }
6853}
double launch_time
Definition ShipEntity.h:333

References launch_time, Entity::setStatus:, and Entity::status.

Referenced by Universe::addEntity:, DockEntity::addShipToLaunchQueue:withPriority:, PlayerEntity(ScriptMethods)::awardCommodityType:amount:, ballTrackLeadingTarget:atTarget:, becomeExplosion, becomeLargeExplosion:, PlayerEntity(Controls)::beginWitchspaceCountdown:, behaviour_tractored:, PlayerEntity(Contracts)::buySelectedShip, PlayerEntity(Controls)::cancelWitchspaceCountdown, PlayerEntity(Scripting)::checkScript, PlayerEntity::createCargoPodWithType:andAmount:, PlayerEntity::deferredInit, PlayerEntity::disengageAutopilot, PlayerEntity::doBookkeeping:, PlayerEntity::docked, PlayerEntity::endScenario:, PlayerEntity::engageAutopilotToStation:, PlayerEntity::enterDock:, PlayerEntity::enterGalacticWitchspace, PlayerEntity::enterWitchspace, PlayerEntity::enterWormhole:, getTractoredBy:, Universe::handleOoliteException:, Universe::initWithGameView:, initWithKey:definition:, PlayerEntity::interpretAIMessage:, PlayerEntity::isDocked, PlayerEntity::launchEscapeCapsule, PlayerEntity(Scripting)::launchFromStation, DockEntity::launchShip:, PlayerEntity::leaveWitchspace, PlayerEntity::loadCargoPodsForType:amount:, Universe::makeDemoShipWithRole:spinning:, noteKilledBy:damageType:, PlayerEntity(OOPrivate)::performLaunchingUpdates:, PlayerEntity(OOPrivate)::performWitchspaceCountdownUpdates:, PlayerEntity(OOPrivate)::performWitchspaceExitUpdates:, PlayerShipBeginGalacticHyperspaceCountdown(), PlayerShipBeginGalacticHyperspaceCountdown(), PlayerEntity(OOControlsPrivate)::pollFlightControls:, PlayerEntity(Scripting)::processSceneString:atOffset:, Universe::reinitAndShowDemo:, PlayerEntity::setDockedAtMainStation, PlayerEntity::setUpAndConfirmOK:saveGame:, Universe::setupIntroFirstGo:, setUpOneStandardSubentity:asTurret:, Universe::setUpSpace, PlayerEntity::showShipModelWithKey:shipData:personality:factorX:factorY:factorZ:inContext:, WormholeEntity::suckInShip:, update:, Universe::update:, PlayerEntity::witchJumpChecklist:, and witchspaceLeavingEffects.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setSubEntityRotationalVelocity:

- (void) setSubEntityRotationalVelocity: (Quaternion) rv

Definition at line 1085 of file ShipEntity.m.

1085 :(Quaternion)rv
1086{
1088}
Quaternion subentityRotationalVelocity
Definition ShipEntity.h:208

References subentityRotationalVelocity.

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setSubEntityTakingDamage:

- (void) setSubEntityTakingDamage: (ShipEntity*) sub

Definition at line 1252 of file ShipEntity.m.

1252 :(ShipEntity*)sub
1253{
1254#ifndef NDEBUG
1255 // Sanity checks: sub must be a ship subentity of self, or nil.
1256 if (sub != nil) {
1257 if (![self hasSubEntity:sub]) {
1258 OOLog(@"ship.subentity.sanityCheck.failed.details", @"Attempt to set subentity taking damage of %@ to %@, which is not a subentity.", [self shortDescription], sub);
1259 sub = nil;
1260 } else if (![sub isShip]) {
1261 OOLog(@"ship.subentity.sanityCheck.failed", @"Attempt to set subentity taking damage of %@ to %@, which is not a ship.", [self shortDescription], sub);
1262 sub = nil;
1263 }
1264 }
1265#endif
1266
1267 [_subEntityTakingDamage release];
1268 _subEntityTakingDamage = [sub weakRetain];
1269}
OOWeakReference * _subEntityTakingDamage
Definition ShipEntity.h:443

References _subEntityTakingDamage, Entity::isShip, nil, OOLog, and OOWeakRefObject::weakRetain.

Referenced by dealloc, Universe::firstShipHitByLaserFromShip:inDirection:offset:gettingRangeFound:, ShipEntity(Private)::subEntityDied:, ShipEntity(Private)::subEntityReallyDied:, and subEntityTakingDamage.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setSubIdx:

- (void) setSubIdx: (NSUInteger) value

Definition at line 724 of file ShipEntity.m.

724 :(NSUInteger)value
725{
726 _subIdx = value;
727}
NSUInteger _subIdx
Definition ShipEntity.h:331

References _subIdx.

Referenced by setUpOneStandardSubentity:asTurret:.

Here is the caller graph for this function:

◆ setSunGlareFilter:

- (void) setSunGlareFilter: (GLfloat) newValue

Definition at line 1116 of file ShipEntity.m.

1116 :(GLfloat)newValue
1117{
1118 sunGlareFilter = OOClamp_0_1_f(newValue);
1119}

References OOClamp_0_1_f(), and sunGlareFilter.

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setSunSkimEndCoordinates

- (void) setSunSkimEndCoordinates
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1749 of file ShipEntityAI.m.

1750{
1751 if ([UNIVERSE sun] == nil) {
1752 [shipAI message:@"NO_SUN_FOUND"];
1753 return;
1754 }
1755
1756 coordinates = [UNIVERSE getSunSkimEndPositionForShip:self];
1757 [shipAI message:@"APPROACH_COORDINATES"];
1758}

◆ setSunSkimExitCoordinates

- (void) setSunSkimExitCoordinates
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1760 of file ShipEntityAI.m.

1761{
1762 Entity* the_sun = [UNIVERSE sun];
1763 if (the_sun == nil)
1764 return;
1765 HPVector v1 = [UNIVERSE getSunSkimEndPositionForShip:self];
1766 HPVector vs = the_sun->position;
1767 HPVector vout = HPvector_subtract(v1, vs);
1768 if (vout.x || vout.y || vout.z)
1769 vout = HPvector_normal(vout);
1770 else
1771 vout.z = 1.0;
1772 v1.x += 10000 * vout.x;
1773 v1.y += 10000 * vout.y;
1774 v1.z += 10000 * vout.z;
1775 coordinates = v1;
1776 [shipAI message:@"APPROACH_COORDINATES"];
1777}

◆ setSunSkimStartCoordinates

- (void) setSunSkimStartCoordinates
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1732 of file ShipEntityAI.m.

1733{
1734 if ([UNIVERSE sun] == nil) {
1735 [shipAI message:@"NO_SUN_FOUND"];
1736 return;
1737 }
1738
1739 HPVector v0 = [UNIVERSE getSunSkimStartPositionForShip:self];
1740
1741 if (!HPvector_equal(v0, kZeroHPVector)) {
1742 coordinates = v0;
1743 [shipAI message:@"APPROACH_COORDINATES"];
1744 } else {
1745 [shipAI message:@"WAIT_FOR_SUN"];
1746 }
1747}

◆ setSuppressExplosion:

- (void) setSuppressExplosion: (BOOL) suppress

Definition at line 8437 of file ShipEntity.m.

8437 :(BOOL)suppress
8438{
8439 suppressExplosion = !!suppress;
8440}

References suppressExplosion.

Referenced by becomeExplosion, becomeLargeExplosion:, and deserializeShipSubEntitiesFrom:.

Here is the caller graph for this function:

◆ setTakeOffFromPlanet

- (void) setTakeOffFromPlanet
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1165 of file ShipEntityAI.m.

1166{
1167 /*- selects the nearest planet it can find -*/
1168 OOPlanetEntity* the_planet = [self findNearestPlanet];
1169 if (the_planet) {
1170 _destination = HPvector_add([the_planet position], HPvector_multiply_scalar(HPvector_normal(HPvector_subtract([the_planet position], position)), -10000.0 - the_planet->collision_radius)); // 10km straight up
1171 desired_range = 50.0;
1172 } else {
1173 OOLog(@"ai.setTakeOffFromPlanet.noPlanet", @"%@", @"***** Error. Planet not found during take off!");
1174 }
1175}

◆ setTargetForScript: [1/2]

- (void) setTargetForScript: (ShipEntity*) target

Provided by category ShipEntity(OOJavaScriptExtensions).

Definition at line 118 of file EntityOOJavaScriptExtensions.m.

118 :(ShipEntity*)target
119{
120 ShipEntity* me = self;
121
122 // Ensure coherence by not fiddling with subentities.
123 while ([me isSubEntity]) {
124 if (me == [me owner] || [me owner] == nil)
125 break;
126 me = (ShipEntity*)[me owner];
127 }
128 while ([target isSubEntity]) {
129 if (target == [target owner] || [target owner] == nil)
130 break;
131 target = (ShipEntity*)[target owner];
132 }
133 if (![me isKindOfClass:[ShipEntity class]])
134 return;
135 if (target != nil) {
136 [me addTarget:target];
137 } else
138 [me removeTarget:[me primaryTarget]];
139}

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setTargetForScript: [2/2]

- (void) setTargetForScript: (ShipEntity *) target

Provided by category ShipEntity(OOJavaScriptExtensions).

◆ setTargetStation:

- (void) setTargetStation: (Entity*) targetEntity

Definition at line 8638 of file ShipEntity.m.

8638 :(Entity*)targetEntity
8639{
8640 [_targetStation release];
8641 _targetStation = [targetEntity weakRetain];
8642}
OOWeakReference * _targetStation
Definition ShipEntity.h:427

References _targetStation, and OOWeakRefObject::weakRetain.

Referenced by PlayerEntity::disengageAutopilot, dockEscorts, PlayerEntity::engageAutopilotToStation:, ShipEntity(AI)::recallDockingInstructions, ShipEntity(PureAI)::setPlanetPatrolCoordinates, ShipEntity(PureAI)::setTargetToLastStation, setTargetToNearestStationIncludingHostiles:, ShipEntity(PureAI)::setTargetToRandomStation, and setTargetToSystemStation.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setTargetToFoundTarget

- (void) setTargetToFoundTarget
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1007 of file ShipEntityAI.m.

1008{
1009 if ([self foundTarget] != nil) {
1010 [self addTarget:[self foundTarget]];
1011 } else {
1012 [shipAI message:@"TARGET_LOST"]; // to prevent the ship going for a wrong, previous target. Should not be a reactToMessage.
1013 }
1014}

◆ setTargetToLastStation

- (void) setTargetToLastStation
implementation

Provided by category ShipEntity(PureAI).

Definition at line 2225 of file ShipEntityAI.m.

2226{
2227 Entity* station = [self targetStation];
2228
2229 if (station != nil && [station isStation]) {
2230 [self addTarget:station];
2231 } else {
2232 [shipAI message:@"NO_STATION_FOUND"];
2233 [self setTargetStation:nil];
2234 }
2235}

◆ setTargetToNearestFriendlyStation

- (void) setTargetToNearestFriendlyStation

Definition at line 12191 of file ShipEntity.m.

12192{
12193 [self setTargetToNearestStationIncludingHostiles:NO];
12194}

References setTargetToNearestFriendlyStation, and setTargetToNearestStationIncludingHostiles:.

Referenced by coordinates, and setTargetToNearestFriendlyStation.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setTargetToNearestStation

- (void) setTargetToNearestStation

Definition at line 12197 of file ShipEntity.m.

12198{
12199 [self setTargetToNearestStationIncludingHostiles:YES];
12200}

References setTargetToNearestStation, and setTargetToNearestStationIncludingHostiles:.

Referenced by coordinates, and setTargetToNearestStation.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setTargetToNearestStationIncludingHostiles:

- (void) setTargetToNearestStationIncludingHostiles: (BOOL) includeHostiles
implementation

Definition at line 12147 of file ShipEntity.m.

12147 :(BOOL)includeHostiles
12148{
12149 // check if the groupID (parent ship) points to a station...
12150 Entity* mother = [[self group] leader];
12151 if ([mother isStation]) {
12152 [self addTarget:mother];
12153 [self setTargetStation:mother];
12154 return; // head for mother!
12155 }
12156
12157 /*- selects the nearest station it can find -*/
12158 if (!UNIVERSE)
12159 return;
12160 int ent_count = UNIVERSE->n_entities;
12161 Entity** uni_entities = UNIVERSE->sortedEntities; // grab the public sorted list
12162 Entity* my_entities[ent_count];
12163 int i;
12164 int station_count = 0;
12165 for (i = 0; i < ent_count; i++)
12166 if (uni_entities[i]->isStation)
12167 my_entities[station_count++] = [uni_entities[i] retain]; // retained
12168 //
12169 StationEntity *thing = nil, *station = nil;
12170 double range2, nearest2 = SCANNER_MAX_RANGE2 * 1000000.0; // 1000x typical scanner range (25600 km), squared.
12171 for (i = 0; i < station_count; i++) {
12172 thing = (StationEntity*)my_entities[i];
12173 range2 = HPdistance2(position, thing->position);
12174 if (range2 < nearest2 && (includeHostiles || ![thing isHostileTo:self])) {
12175 station = thing;
12176 nearest2 = range2;
12177 }
12178 }
12179 for (i = 0; i < station_count; i++)
12180 [my_entities[i] release]; // released
12181 //
12182 if (station) {
12183 [self addTarget:station];
12184 [self setTargetStation:station];
12185 } else {
12186 [shipAI message:@"NO_STATION_FOUND"];
12187 }
12188}

References addTarget:, group, HPdistance2(), Entity::isStation, OOShipGroup::leader, AI::message:, nil, Entity::position, SCANNER_MAX_RANGE2, setTargetStation:, and UNIVERSE.

Referenced by setTargetToNearestFriendlyStation, and setTargetToNearestStation.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setTargetToPrimaryAggressor

- (void) setTargetToPrimaryAggressor
implementation

Provided by category ShipEntity(PureAI).

Definition at line 838 of file ShipEntityAI.m.

839{
840 Entity* primeAggressor = [self primaryAggressor];
841 if (!primeAggressor)
842 return;
843 if ([self primaryTarget] == primeAggressor)
844 return;
845
846 // a more considered approach here:
847 // if we're already busy attacking a target we don't necessarily want to break off
848 //
849 if ([self hasHostileTarget] && randf() < 0.75) // if I'm attacking, ignore 75% of new aggressor's attacks
850 {
851 // but add them as a secondary target anyway
852 [self addDefenseTarget:(ShipEntity*)primeAggressor];
853 return;
854 }
855 // react only if the primary aggressor is not a friendly ship, else ignore it
856 if ([primeAggressor isShip] && ![(ShipEntity*)primeAggressor isFriendlyTo:self]) {
857 // inform our old target of our new target
858 //
859 Entity* primeTarget = [self primaryTarget];
860 if ((primeTarget) && (primeTarget->isShip)) {
861 ShipEntity* currentShip = [self primaryTarget];
862 [[currentShip getAI] message:[NSString stringWithFormat:@"%@ %d %d", AIMS_AGGRESSOR_SWITCHED_TARGET, universalID, [[self primaryAggressor] universalID]]];
863 [currentShip doScriptEvent:OOJSID("shipAttackerDistracted") withArgument:[self primaryAggressor]];
864 }
865
866 // okay, so let's now target the aggressor
867 [self addTarget:[self primaryAggressor]];
868 }
869}

◆ setTargetToRandomStation

- (void) setTargetToRandomStation
implementation

Provided by category ShipEntity(PureAI).

Definition at line 2181 of file ShipEntityAI.m.

2182{
2183 /*- selects the nearest station it can find -*/
2184 int ent_count = UNIVERSE->n_entities;
2185 Entity** uni_entities = UNIVERSE->sortedEntities; // grab the public sorted list
2186 Entity* my_entities[ent_count];
2187 StationEntity *station = nil, *my_station = nil;
2188 double maxRange2 = desired_range * desired_range;
2189 int i;
2190 int station_count = 0;
2191
2192 for (i = 0; i < ent_count; i++) {
2193 // find stations within range but exclude carriers.
2194 if (uni_entities[i]->isStation) {
2195 my_station = (StationEntity*)uni_entities[i];
2196 if ([my_station maxFlightSpeed] == 0 && [my_station hasNPCTraffic] && HPdistance2(position, [my_station position]) < maxRange2) {
2197 my_entities[station_count++] = [uni_entities[i] retain]; // retained
2198 }
2199 }
2200 }
2201
2202 if (station_count != 0) {
2203 // select a random station
2204 station = (StationEntity*)my_entities[ranrot_rand() % station_count];
2205 // if more than one candidate do not select main station
2206 if (station == [UNIVERSE station] && station_count > 1) {
2207 while (station == [UNIVERSE station]) {
2208 station = (StationEntity*)my_entities[ranrot_rand() % station_count];
2209 }
2210 }
2211 }
2212
2213 for (i = 0; i < station_count; i++)
2214 [my_entities[i] release]; // released
2215 //
2216 if (station) {
2217 [self addTarget:station];
2218 [self setTargetStation:station];
2219 [shipAI message:@"STATION_FOUND"];
2220 } else {
2221 [shipAI message:@"NO_STATION_IN_RANGE"];
2222 }
2223}

◆ setTargetToSystemStation

- (void) setTargetToSystemStation

Definition at line 12203 of file ShipEntity.m.

12204{
12205 StationEntity* system_station = [UNIVERSE station];
12206
12207 if (!system_station) {
12208 [shipAI message:@"NOTHING_FOUND"];
12209 [shipAI message:@"NO_STATION_FOUND"];
12211 [self setTargetStation:nil];
12212 return;
12213 }
12214
12215 if (!system_station->isStation) {
12216 [shipAI message:@"NOTHING_FOUND"];
12217 [shipAI message:@"NO_STATION_FOUND"];
12219 [self setTargetStation:nil];
12220 return;
12221 }
12222
12223 [self addTarget:system_station];
12224 [self setTargetStation:system_station];
12225 return;
12226}

References _primaryTarget, addTarget:, DESTROY, Entity::isStation, AI::message:, setTargetStation:, and setTargetToSystemStation.

Referenced by coordinates, and setTargetToSystemStation.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setTemperature:

- (void) setTemperature: (GLfloat) value

Definition at line 7566 of file ShipEntity.m.

7566 :(GLfloat)value
7567{
7568 ship_temperature = value;
7569}

References ship_temperature.

Referenced by Universe::addWreckageFrom:withRole:at:scale:lifetime:, becomeExplosion, dumpItem:, ShipEntity(Private)::launchPodWithCrew:, releaseCargoPodsDebris, ShipSetProperty(), ShipSetProperty(), and ShipEntity(ScriptMethods)::spawnShipsWithRole:count:.

Here is the caller graph for this function:

◆ setThankedShip:

- (void) setThankedShip: (Entity*) targetEntity

Definition at line 8606 of file ShipEntity.m.

8606 :(Entity*)targetEntity
8607{
8608 [_thankedShip release];
8609 _thankedShip = [targetEntity weakRetain];
8610}

References _thankedShip, and OOWeakRefObject::weakRetain.

Referenced by interpretAIMessage:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setThrust:

- (void) setThrust: (double) amount

Definition at line 7096 of file ShipEntity.m.

7096 :(double)amount
7097{
7098 thrust = amount;
7099}

References thrust.

Referenced by behaviour_tractored:, dumpItem:, PlayerEntity::launchEscapeCapsule, releaseCargoPodsDebris, ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setThrustFactorTo:

- (void) setThrustFactorTo: (NSString*) thrustFactorString
implementation

Provided by category ShipEntity(PureAI).

Definition at line 833 of file ShipEntityAI.m.

833 :(NSString*)thrustFactorString
834{
835 thrust = OOClamp_0_1_f([thrustFactorString doubleValue]) * max_thrust;
836}

◆ setThrustForDemo:

- (void) setThrustForDemo: (float) factor

Definition at line 7101 of file ShipEntity.m.

7101 :(float)factor
7102{
7103 flightSpeed = factor * maxFlightSpeed;
7104}

References flightSpeed, and maxFlightSpeed.

◆ setTotalVelocity:

- (void) setTotalVelocity: (Vector) vel

Definition at line 11177 of file ShipEntity.m.

11177 :(Vector)vel
11178{
11179 [self setVelocity:vector_subtract(vel, [self thrustVector])];
11180}

References Entity::setVelocity:, and thrustVector.

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setTrackCloseContacts:

- (void) setTrackCloseContacts: (BOOL) value

Definition at line 12552 of file ShipEntity.m.

12552 :(BOOL)value
12553{
12554 if (value == (BOOL)trackCloseContacts)
12555 return;
12556
12557 trackCloseContacts = value;
12558 [closeContactsInfo release];
12559
12560 if (trackCloseContacts) {
12561 closeContactsInfo = [[NSMutableDictionary alloc] init];
12562 } else {
12564 }
12565}

References closeContactsInfo, nil, and trackCloseContacts.

Referenced by dealloc, setUpShipFromDictionary:, ShipSetProperty(), and ShipSetProperty().

Here is the caller graph for this function:

◆ setUpCargoType:

- (void) setUpCargoType: (NSString*) cargoString

Definition at line 937 of file ShipEntity.m.

937 :(NSString*)cargoString
938{
939 cargo_type = StringToCargoType(cargoString);
940
941 switch (cargo_type) {
942 case CARGO_SLAVES:
945 commodity_type = @"slaves";
946 cargo_type = CARGO_RANDOM; // not realy random, but it tells that cargo is selected.
947 break;
948
949 case CARGO_ALLOY:
952 commodity_type = @"alloys";
954 break;
955
956 case CARGO_MINERALS:
959 commodity_type = @"minerals";
961 break;
962
963 case CARGO_THARGOID:
966 commodity_type = @"alien_items";
968 break;
969
971 commodity_amount = 1; // value > 0 is needed to be recognised as cargo by scripts;
972 DESTROY(commodity_type); // will be defined elsewhere when needed.
973 break;
974
975 case CARGO_RANDOM:
976 // Could already be set by the cargo_carried key. If not, ensure at least one.
977 if (commodity_amount == 0)
979 break;
980
981 default:
982 break;
983 }
984}
OOCargoType StringToCargoType(NSString *string) PURE_FUNC
@ CARGO_THARGOID
Definition OOTypes.h:65
@ CARGO_SLAVES
Definition OOTypes.h:62
@ CARGO_ALLOY
Definition OOTypes.h:63
@ CARGO_MINERALS
Definition OOTypes.h:64

References CARGO_ALLOY, CARGO_MINERALS, CARGO_RANDOM, CARGO_SCRIPTED_ITEM, CARGO_SLAVES, CARGO_THARGOID, cargo_type, commodity_amount, commodity_type, DESTROY, and StringToCargoType().

Referenced by setUpShipFromDictionary:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setUpEscorts

- (void) setUpEscorts

Definition at line 1532 of file ShipEntity.m.

1533{
1534 // Ensure that we do not try to create escorts if we are an escort ship ourselves.
1535 // This could lead to circular reference memory overflows (e.g. "boa-mk2" trying to create 4 "boa-mk2"
1536 // escorts or the case of two ships specifying eachother as escorts) - Nikos 20090510
1537 if ([self isEscort]) {
1538 OOLogWARN(@"ship.setUp.escortShipCircularReference",
1539 @"Ship %@ requested escorts, when it is an escort ship itself. Avoiding possible circular reference overflow by ignoring escort setup.", self);
1540 return;
1541 }
1542
1543 if ([shipinfoDictionary objectForKey:@"escort_roles"] != nil) {
1544 [self setUpMixedEscorts];
1545 return;
1546 }
1547
1548 NSString* defaultRole = @"escort";
1549 NSString* escortRole = nil;
1550 NSString* escortShipKey = nil;
1551
1552 if (_pendingEscortCount == 0)
1553 return;
1554
1556 if ([self hasPrimaryRole:@"police"] || [self hasPrimaryRole:@"hunter"]) {
1557 _maxEscortCount = MAX_ESCORTS; // police and hunters get up to MAX_ESCORTS, overriding the 'escorts' key.
1558 [self updateEscortFormation];
1559 } else {
1560 _pendingEscortCount = _maxEscortCount; // other ships can only get what's defined inside their 'escorts' key.
1561 }
1562 }
1563
1564 if ([self isPolice])
1565 defaultRole = @"wingman";
1566
1567 escortRole = [shipinfoDictionary oo_stringForKey:@"escort_role" defaultValue:nil];
1568 if (escortRole == nil)
1569 escortRole = [shipinfoDictionary oo_stringForKey:@"escort-role" defaultValue:defaultRole];
1570 if (![escortRole isEqualToString:defaultRole]) {
1571 if (![[UNIVERSE newShipWithRole:escortRole] autorelease]) {
1572 escortRole = defaultRole;
1573 }
1574 }
1575
1576 escortShipKey = [shipinfoDictionary oo_stringForKey:@"escort_ship" defaultValue:nil];
1577 if (escortShipKey == nil)
1578 escortShipKey = [shipinfoDictionary oo_stringForKey:@"escort-ship"];
1579
1580 if (escortShipKey != nil) {
1581 if (![[UNIVERSE newShipWithName:escortShipKey] autorelease]) {
1582 escortShipKey = nil;
1583 } else {
1584 escortRole = [NSString stringWithFormat:@"[%@]", escortShipKey];
1585 }
1586 }
1587
1588 OOShipGroup* escortGroup = [self escortGroup];
1589 if ([self group] == nil) {
1590 [self setGroup:escortGroup]; // should probably become a copy of the escortGroup post NMSR.
1591 }
1592 [escortGroup setLeader:self];
1593
1594 [self refreshEscortPositions];
1595
1596 uint8_t currentEscortCount = [escortGroup count] - 1; // always at least 0.
1597
1598 while (_pendingEscortCount > 0 && ([self isThargoid] || currentEscortCount < _maxEscortCount)) {
1599 // The following line adds escort 1 in position 1, etc... up to MAX_ESCORTS.
1600 HPVector ex_pos = [self coordinatesForEscortPosition:currentEscortCount];
1601
1602 ShipEntity* escorter = nil;
1603
1604 escorter = [UNIVERSE newShipWithRole:escortRole]; // retained
1605
1606 if (escorter == nil)
1607 break;
1608 [self setUpOneEscort:escorter inGroup:escortGroup withRole:escortRole atPosition:ex_pos andCount:currentEscortCount];
1609
1610 [escorter release];
1611
1613 currentEscortCount = [escortGroup count] - 1;
1614 }
1615 // done assigning escorts
1617}

References _maxEscortCount, _pendingEscortCount, coordinatesForEscortPosition:, OOShipGroup::count, escortGroup, group, isEscort, isPolice, isThargoid, MAX_ESCORTS, nil, OOLogWARN, refreshEscortPositions, setGroup:, OOShipGroup::setLeader:, setUpEscorts, setUpMixedEscorts, setUpOneEscort:inGroup:withRole:atPosition:andCount:, shipinfoDictionary, UNIVERSE, and updateEscortFormation.

Referenced by StationEntity::launchIndependentShip:, octree, setUpEscorts, and wasAddedToUniverse.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setUpFromDictionary:

- (BOOL) setUpFromDictionary: (NSDictionary*) shipDict

Definition at line 235 of file ShipEntity.m.

235 :(NSDictionary*)shipDict
236{
238
239 // Settings shared by players & NPCs.
240 //
241 // In order for default values to work and float values to not be junk,
242 // replace nil with empty dictionary. -- Ahruman 2008-04-28
243 shipinfoDictionary = [shipDict copy];
244 if (shipinfoDictionary == nil)
245 shipinfoDictionary = [[NSDictionary alloc] init];
246 shipDict = shipinfoDictionary; // Ensure no mutation.
247
248 // set these flags explicitly.
250 haveStartedJSAI = NO;
251 scripted_misjump = NO;
253 being_fined = NO;
256 isMissile = NO;
258 _lightsActive = YES;
259
260 // set things from dictionary from here out - default values might require adjustment -- Kaks 20091130
261 _scaleFactor = [shipDict oo_floatForKey:@"model_scale_factor" defaultValue:1.0f];
262
263 float defaultSpeed = isStation ? 0.0f : 160.0f;
264 maxFlightSpeed = [shipDict oo_floatForKey:@"max_flight_speed" defaultValue:defaultSpeed];
265 max_flight_roll = [shipDict oo_floatForKey:@"max_flight_roll" defaultValue:2.0f];
266 max_flight_pitch = [shipDict oo_floatForKey:@"max_flight_pitch" defaultValue:1.0f];
267 max_flight_yaw = [shipDict oo_floatForKey:@"max_flight_yaw" defaultValue:max_flight_pitch]; // Note by default yaw == pitch
269
270 max_thrust = [shipDict oo_floatForKey:@"thrust" defaultValue:15.0f];
272
273 afterburner_rate = [shipDict oo_floatForKey:@"injector_burn_rate" defaultValue:AFTERBURNER_BURNRATE];
274 afterburner_speed_factor = [shipDict oo_floatForKey:@"injector_speed_factor" defaultValue:7.0f];
275 if (afterburner_speed_factor < 1.0) {
276 OOLog(@"ship.setup.injectorSpeed", @"injector_speed_factor cannot be lower than 1.0 for %@", self);
278 }
279#if OO_VARIABLE_TORUS_SPEED
281 OOLog(@"ship.setup.injectorSpeed", @"injector_speed_factor cannot be higher than minimum torus speed factor (%f) for %@.", MIN_HYPERSPEED_FACTOR, self);
283 }
284#else
286 OOLog(@"ship.setup.injectorSpeed", @"injector_speed_factor cannot be higher than torus speed factor (%f) for %@.", HYPERSPEED_FACTOR, self);
288 }
289#endif
290
291 maxEnergy = [shipDict oo_floatForKey:@"max_energy" defaultValue:200.0f];
292 energy_recharge_rate = [shipDict oo_floatForKey:@"energy_recharge_rate" defaultValue:1.0f];
293
294 _showDamage = [shipDict oo_boolForKey:@"show_damage" defaultValue:(energy_recharge_rate > 0)];
295 // Each new ship should start in seemingly good operating condition, unless specifically told not to - this does not affect the ship's energy levels
296 [self setThrowSparks:[shipDict oo_boolForKey:@"throw_sparks" defaultValue:NO]];
297
298 weapon_facings = [shipDict oo_intForKey:@"weapon_facings" defaultValue:VALID_WEAPON_FACINGS] & VALID_WEAPON_FACINGS;
300 forward_weapon_type = OOWeaponTypeFromString([shipDict oo_stringForKey:@"forward_weapon_type" defaultValue:@"EQ_WEAPON_NONE"]);
302 aft_weapon_type = OOWeaponTypeFromString([shipDict oo_stringForKey:@"aft_weapon_type" defaultValue:@"EQ_WEAPON_NONE"]);
304 port_weapon_type = OOWeaponTypeFromString([shipDict oo_stringForKey:@"port_weapon_type" defaultValue:@"EQ_WEAPON_NONE"]);
306 starboard_weapon_type = OOWeaponTypeFromString([shipDict oo_stringForKey:@"starboard_weapon_type" defaultValue:@"EQ_WEAPON_NONE"]);
307
310 cloakPassive = [shipDict oo_boolForKey:@"cloak_passive" defaultValue:YES]; // Nikos - switched passive cloak default to YES 20120523
311 cloakAutomatic = [shipDict oo_boolForKey:@"cloak_automatic" defaultValue:YES];
312
313 missiles = [shipDict oo_intForKey:@"missiles" defaultValue:0];
314 /* TODO: The following initializes the missile list to be blank, which prevents a crash caused by hasOneEquipmentItem trying to access a missile list
315 previously initialized but then released. See issue #204. We need to investigate further the cause of the missile list being released.
316 - kanthoney 10/03/2017
317 Update 20170818: The issue seems to have been resolved properly using the fix below and the problem was apparently an access of the
318 missile_list array elements before their initialization and while we were checking whether equipment can be added or not. There is
319 probably not much more that can be done here, unless someone would like to have a go at refactoring the entire ship initialization
320 code. In any case, the crash is no more and the applied solution is both simple and logical - Nikos
321 */
322 unsigned i;
323 for (i = 0; i < missiles; i++) {
324 missile_list[i] = nil;
325 }
326 max_missiles = [shipDict oo_intForKey:@"max_missiles" defaultValue:missiles];
331 missile_load_time = fmax(0.0, [shipDict oo_doubleForKey:@"missile_load_time" defaultValue:0.0]); // no negative load times
332 missile_launch_time = [UNIVERSE getTime] + missile_load_time;
333
334 // upgrades:
336 if ([shipDict oo_fuzzyBooleanForKey:@"has_ecm"])
337 [self addEquipmentItem:@"EQ_ECM" inContext:@"npc"];
338 if ([shipDict oo_fuzzyBooleanForKey:@"has_scoop"])
339 [self addEquipmentItem:@"EQ_FUEL_SCOOPS" inContext:@"npc"];
340 if ([shipDict oo_fuzzyBooleanForKey:@"has_escape_pod"])
341 [self addEquipmentItem:@"EQ_ESCAPE_POD" inContext:@"npc"];
342 if ([shipDict oo_fuzzyBooleanForKey:@"has_cloaking_device"])
343 [self addEquipmentItem:@"EQ_CLOAKING_DEVICE" inContext:@"npc"];
344 if ([shipDict oo_floatForKey:@"has_energy_bomb"] > 0) {
345 /* NOTE: has_energy_bomb actually refers to QC mines.
346
347 max_missiles for NPCs is a newish addition, and ships have
348 traditionally not needed to reserve a slot for a Q-mine added this
349 way. If has_energy_bomb is possible, and max_missiles is not
350 explicit, we add an extra missile slot to compensate.
351 -- Ahruman 2011-03-25
352 */
353 if ([shipDict oo_fuzzyBooleanForKey:@"has_energy_bomb"]) {
354 if (max_missiles == missiles && max_missiles < SHIPENTITY_MAX_MISSILES && [shipDict objectForKey:@"max_missiles"] == nil) {
355 max_missiles++;
356 }
357 [self addEquipmentItem:@"EQ_QC_MINE" inContext:@"npc"];
358 }
359 }
360
361 if ([shipDict oo_fuzzyBooleanForKey:@"has_fuel_injection"])
362 [self addEquipmentItem:@"EQ_FUEL_INJECTION" inContext:@"npc"];
363
364#if USEMASC
365 if ([shipDict oo_fuzzyBooleanForKey:@"has_military_jammer"])
366 [self addEquipmentItem:@"EQ_MILITARY_JAMMER" inContext:@"npc"];
367 if ([shipDict oo_fuzzyBooleanForKey:@"has_military_scanner_filter"])
368 [self addEquipmentItem:@"EQ_MILITARY_SCANNER_FILTER" inContext:@"npc"];
369#endif
370
371 // can it be 'mined' for alloys?
372 canFragment = [shipDict oo_fuzzyBooleanForKey:@"fragment_chance" defaultValue:0.9];
373 isWreckage = NO;
374
375 // can subentities be destroyed separately?
376 isFrangible = [shipDict oo_boolForKey:@"frangible" defaultValue:YES];
377
378 max_cargo = [shipDict oo_unsignedIntForKey:@"max_cargo"];
379 extra_cargo = [shipDict oo_unsignedIntForKey:@"extra_cargo" defaultValue:15];
380
381 hyperspaceMotorSpinTime = [shipDict oo_floatForKey:@"hyperspace_motor_spin_time" defaultValue:DEFAULT_HYPERSPACE_SPIN_TIME];
382 if (![shipDict oo_boolForKey:@"hyperspace_motor" defaultValue:YES])
384
385 [name autorelease];
386 name = [[shipDict oo_stringForKey:@"name" defaultValue:@"?"] copy];
387
388 [shipUniqueName autorelease];
389 shipUniqueName = [[shipDict oo_stringForKey:@"ship_name" defaultValue:@""] copy];
390
391 [shipClassName autorelease];
392 shipClassName = [[shipDict oo_stringForKey:@"ship_class_name" defaultValue:name] copy];
393
394 [displayName autorelease];
395 displayName = [[shipDict oo_stringForKey:@"display_name" defaultValue:nil] copy];
396
397 // Load the model (must be before subentities)
398 NSString* modelName = [shipDict oo_stringForKey:@"model"];
399 if (modelName != nil) {
400 OOMesh* mesh = nil;
401
402 mesh = [OOMesh meshWithName:modelName
403 cacheKey:[NSString stringWithFormat:@"%@-%.3f", _shipKey, _scaleFactor]
404 materialDictionary:[shipDict oo_dictionaryForKey:@"materials"]
405 shadersDictionary:[shipDict oo_dictionaryForKey:@"shaders"]
406 smooth:[shipDict oo_boolForKey:@"smooth" defaultValue:NO]
407 shaderMacros:OODefaultShipShaderMacros()
409 scaleFactor:_scaleFactor
410 cacheWriteable:YES];
411
412 if (mesh == nil)
413 return NO;
414 [self setMesh:mesh];
415 }
416
417 float density = [shipDict oo_floatForKey:@"density" defaultValue:1.0f];
418 if (octree)
419 mass = (GLfloat)(density * 20.0f * [octree volume]);
420
422 default_laser_color = [[OOColor brightColorWithDescription:[shipDict objectForKey:@"laser_color"]] retain];
423
424 if (default_laser_color == nil) {
425 [self setLaserColor:[OOColor redColor]];
426 } else {
427 [self setLaserColor:default_laser_color];
428 }
429 // exhaust emissive color
430 OORGBAComponents defaultExhaustEmissiveColorComponents; // pale blue is exhaust default color
431 defaultExhaustEmissiveColorComponents.r = 0.7f;
432 defaultExhaustEmissiveColorComponents.g = 0.9f;
433 defaultExhaustEmissiveColorComponents.b = 1.0f;
434 defaultExhaustEmissiveColorComponents.a = 0.9f;
435 OOColor* color = [OOColor brightColorWithDescription:[shipDict objectForKey:@"exhaust_emissive_color"]];
436 if (color == nil)
437 color = [OOColor colorWithRGBAComponents:defaultExhaustEmissiveColorComponents];
438 [self setExhaustEmissiveColor:color];
439
440 [self clearSubEntities];
441 [self setUpSubEntities];
442
443 // correctly initialise weaponRange, etc. (must be after subentity setup)
445 OOWeaponType weapon_type = nil;
446 BOOL hasTurrets = NO;
447 NSEnumerator* subEnum = [self shipSubEntityEnumerator];
448 ShipEntity* se = nil;
449 while (isWeaponNone(weapon_type) && (se = [subEnum nextObject])) {
450 weapon_type = se->forward_weapon_type;
451 if (se->behaviour == BEHAVIOUR_TRACK_AS_TURRET) {
452 hasTurrets = YES;
453 }
454 }
455 if (isWeaponNone(weapon_type) && hasTurrets) { /* safety for ships only equipped with turrets
456 note: this was hard-coded to 10000.0, although turrets have a notably
457 shorter range. We are using a multiplier of 1.667 in order to not change
458 something that already works, but probably it would be best to use
459 TURRET_SHOT_RANGE * COMBAT_WEAPON_RANGE_FACTOR here
460 */
462 } else {
463 [self setWeaponDataFromType:weapon_type];
464 }
465 } else {
466 [self setWeaponDataFromType:forward_weapon_type];
467 }
468
469 // rotating subentities
471 if ([shipDict objectForKey:@"rotational_velocity"]) {
472 subentityRotationalVelocity = [shipDict oo_quaternionForKey:@"rotational_velocity"];
473 }
474
475 // set weapon offsets
476 NSString* weaponMountMode = [shipDict oo_stringForKey:@"weapon_mount_mode" defaultValue:@"single"];
477 _multiplyWeapons = [weaponMountMode isEqualToString:@"multiply"];
478 forwardWeaponOffset = [[self getWeaponOffsetFrom:shipDict withKey:@"weapon_position_forward" inMode:weaponMountMode] retain];
479 aftWeaponOffset = [[self getWeaponOffsetFrom:shipDict withKey:@"weapon_position_aft" inMode:weaponMountMode] retain];
480 portWeaponOffset = [[self getWeaponOffsetFrom:shipDict withKey:@"weapon_position_port" inMode:weaponMountMode] retain];
481 starboardWeaponOffset = [[self getWeaponOffsetFrom:shipDict withKey:@"weapon_position_starboard" inMode:weaponMountMode] retain];
482
483 tractor_position = vector_multiply_scalar([shipDict oo_vectorForKey:@"scoop_position"], _scaleFactor);
484
485 // sun glare filter - default is high filter, both for HDR and SDR
486 [self setSunGlareFilter:[shipDict oo_floatForKey:@"sun_glare_filter" defaultValue:0.97f]];
487
488 // Get scriptInfo dictionary, containing arbitrary stuff scripts might be interested in.
489 scriptInfo = [[shipDict oo_dictionaryForKey:@"script_info" defaultValue:nil] retain];
490
491 explosionType = [[shipDict oo_arrayForKey:@"explosion_type" defaultValue:nil] retain];
492
493 isDemoShip = NO;
494
495 return YES;
496
498}
#define VALID_WEAPON_FACINGS
Definition OOTypes.h:206
#define HYPERSPEED_FACTOR
#define SHIPENTITY_MAX_MISSILES
Definition ShipEntity.h:79
OOWeaponType OOWeaponTypeFromString(NSString *string) PURE_FUNC
OOColor * colorWithRGBAComponents:(OORGBAComponents components)
Definition OOColor.m:119
OOColor * brightColorWithDescription:(id description)
Definition OOColor.m:202
OOColor * redColor()
Definition OOColor.m:259
OOWeaponFacingSet weapon_facings
Definition ShipEntity.h:293
unsigned _showDamage
Definition ShipEntity.h:259
unsigned haveExecutedSpawnAction
Definition ShipEntity.h:268

References _scriptedMisjumpRange, being_fined, haveExecutedSpawnAction, haveStartedJSAI, isNearPlanetSurface, nil, OOJS_PROFILE_ENTER, scripted_misjump, and shipinfoDictionary.

◆ setUpMixedEscorts

- (void) setUpMixedEscorts
implementation

Provided by category ShipEntity(Private).

Definition at line 1619 of file ShipEntity.m.

1620{
1621 NSArray* escortRoles = [shipinfoDictionary oo_arrayForKey:@"escort_roles" defaultValue:nil];
1622 if (escortRoles == nil) {
1623 OOLogWARN(@"eship.setUp.escortShipRoles",
1624 @"Ship %@ has bad escort_roles definition.", self);
1625 return;
1626 }
1627 NSDictionary* escortDefinition = nil;
1628 NSDictionary* systeminfo = nil;
1629 OOGovernmentID government;
1630
1631 systeminfo = [UNIVERSE currentSystemData];
1632 government = [systeminfo oo_unsignedCharForKey:KEY_GOVERNMENT];
1633
1634 OOShipGroup* escortGroup = [self escortGroup];
1635 if ([self group] == nil) {
1636 [self setGroup:escortGroup]; // should probably become a copy of the escortGroup post NMSR.
1637 }
1638 [escortGroup setLeader:self];
1640 [self refreshEscortPositions];
1641
1642 uint8_t currentEscortCount = [escortGroup count] - 1; // always at least 0
1643
1644 _maxEscortCount = 0;
1645 int8_t i = 0;
1646 foreach (escortDefinition, escortRoles) {
1647 if (currentEscortCount >= MAX_ESCORTS) {
1648 break;
1649 }
1650 // int rather than uint because, at least for min, there is a
1651 // use to giving a negative value
1652 int8_t min = [escortDefinition oo_intForKey:@"min" defaultValue:0];
1653 int8_t max = [escortDefinition oo_intForKey:@"max" defaultValue:2];
1654 NSString* escortRole = [escortDefinition oo_stringForKey:@"role" defaultValue:@"escort"];
1655 int8_t desired = max;
1656 if (min < desired) {
1657 for (i = min; i < max; i++) {
1658 if (Ranrot() % 11 < government + 2) {
1659 desired--;
1660 }
1661 }
1662 }
1663 for (i = 0; i < desired; i++) {
1664 if (currentEscortCount >= MAX_ESCORTS) {
1665 break;
1666 }
1667 if (![escortRole isEqualToString:@""]) {
1668 HPVector ex_pos = [self coordinatesForEscortPosition:currentEscortCount];
1669 ShipEntity* escorter = [UNIVERSE newShipWithRole:escortRole]; // retained
1670 if (escorter == nil) {
1671 break;
1672 }
1673 [self setUpOneEscort:escorter inGroup:escortGroup withRole:escortRole atPosition:ex_pos andCount:currentEscortCount];
1674 [escorter release];
1675 }
1676 currentEscortCount++;
1678 }
1679 }
1680 // done assigning escorts
1682}
uint8_t OOGovernmentID
Definition OOTypes.h:179

References coordinatesForEscortPosition:, OOShipGroup::count, escortGroup, MAX_ESCORTS, nil, OOLogWARN, Ranrot(), refreshEscortPositions, setGroup:, OOShipGroup::setLeader:, ShipEntity(Private)::setUpMixedEscorts, and setUpOneEscort:inGroup:withRole:atPosition:andCount:.

Referenced by ShipEntity(Private)::drawDebugStuff, setUpEscorts, and ShipEntity(Private)::setUpMixedEscorts.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setUpOneEscort:inGroup:withRole:atPosition:andCount:

- (void) setUpOneEscort: (ShipEntity*) escorter
inGroup: (OOShipGroup*) escortGroup
withRole: (NSString*) escortRole
atPosition: (HPVector) ex_pos
andCount: (uint8_t) currentEscortCount 
implementation

Provided by category ShipEntity(Private).

Definition at line 1684 of file ShipEntity.m.

1684 :(ShipEntity*)escorter inGroup:(OOShipGroup*)escortGroup withRole:(NSString*)escortRole atPosition:(HPVector)ex_pos andCount:(uint8_t)currentEscortCount
1685{
1686 NSString* autoAI = nil;
1687 NSString* pilotRole = nil;
1688 NSDictionary* autoAIMap = nil;
1689 NSDictionary* escortShipDict = nil;
1690 AI* escortAI = nil;
1691 NSString* defaultRole = @"escort";
1692
1693 if ([self isPolice]) {
1694 defaultRole = @"wingman";
1695 pilotRole = @"police"; // police are always insured.
1696 } else {
1697 pilotRole = bounty ? @"pirate" : @"hunter"; // hunters have insurancies, pirates not.
1698 }
1699
1700 double dd = escorter->collision_radius;
1701
1702 if (EXPECT(currentEscortCount < (uint8_t)MAX_ESCORTS)) {
1703 // spread them around a little randomly
1704 ex_pos.x += dd * 6.0 * (randf() - 0.5);
1705 ex_pos.y += dd * 6.0 * (randf() - 0.5);
1706 ex_pos.z += dd * 6.0 * (randf() - 0.5);
1707 } else {
1708 // Thargoid armada(!) Add more distance between the 'escorts'.
1709 ex_pos.x += dd * 12.0 * (randf() - 0.5);
1710 ex_pos.y += dd * 12.0 * (randf() - 0.5);
1711 ex_pos.z += dd * 12.0 * (randf() - 0.5);
1712 }
1713
1714 [escorter setPosition:ex_pos]; // minimise lollipop flash
1715
1716 if ([escorter crew] == nil) {
1717 [escorter setSingleCrewWithRole:pilotRole];
1718 }
1719
1720 [escorter setPrimaryRole:defaultRole]; // for mothership
1721 // in case this hasn't yet been set, make sure escorts get a real scan class
1722 // shouldn't happen very often, but is possible
1723 if (scanClass == CLASS_NOT_SET) {
1724 scanClass = CLASS_NEUTRAL;
1725 }
1726 [escorter setScanClass:scanClass]; // you are the same as I
1727
1728 if ([self bounty] == 0)
1729 [escorter setBounty:0 withReason:kOOLegalStatusReasonSetup]; // Avoid dirty escorts for clean mothers
1730
1731 // find the right autoAI.
1732 escortShipDict = [escorter shipInfoDictionary];
1733 autoAIMap = [ResourceManager dictionaryFromFilesNamed:@"autoAImap.plist" inFolder:@"Config" andMerge:YES];
1734 autoAI = [autoAIMap oo_stringForKey:defaultRole];
1735 if (autoAI == nil) // no 'wingman' defined in autoAImap?
1736 {
1737 autoAI = [autoAIMap oo_stringForKey:@"escort" defaultValue:@"nullAI.plist"];
1738 }
1739
1740 escortAI = [escorter getAI];
1741
1742 // Let the populator decide which AI to use, unless we have a working alternative AI & we specify auto_ai = NO !
1743 if ((escortRole && [escortShipDict oo_fuzzyBooleanForKey:@"auto_ai" defaultValue:YES])
1744 || ([[escortAI name] isEqualToString:@"nullAI.plist"] && ![autoAI isEqualToString:@"nullAI.plist"])) {
1745 [escorter switchAITo:autoAI];
1746 }
1747
1748 [escorter setGroup:escortGroup];
1749 [escorter setOwner:self]; // mark self as group leader
1750
1751 if ([self status] == STATUS_DOCKED) {
1752 [[self owner] addShipToLaunchQueue:escorter withPriority:NO];
1753 } else {
1754 [UNIVERSE addEntity:escorter]; // STATUS_IN_FLIGHT, AI state GLOBAL
1755 [escortAI setState:@"FLYING_ESCORT"]; // Begin escort flight. (If the AI doesn't define FLYING_ESCORT, this has no effect.)
1756 [escorter doScriptEvent:OOJSID("spawnedAsEscort") withArgument:self];
1757 }
1758
1759 if ([escorter heatInsulation] < [self heatInsulation])
1760 [escorter setHeatInsulation:[self heatInsulation]]; // give escorts same protection as mother.
1761 if (([escorter maxFlightSpeed] < cruiseSpeed) && ([escorter maxFlightSpeed] > cruiseSpeed * 0.3))
1762 cruiseSpeed = [escorter maxFlightSpeed] * 0.99; // adapt patrolSpeed to the slowest escort but ignore the very slow ones.
1763
1764 if (bounty) {
1765 int extra = 1 | (ranrot_rand() & 15);
1766 // if mothership is offender, make sure escorter is too.
1767 [escorter markAsOffender:extra withReason:kOOLegalStatusReasonSetup];
1768 } else {
1769 // otherwise force the escort to be clean
1770 [escorter setBounty:0 withReason:kOOLegalStatusReasonSetup];
1771 }
1772}
void setState:(NSString *stateName)
Definition AI.m:303
NSDictionary * dictionaryFromFilesNamed:inFolder:andMerge:(NSString *fileName,[inFolder] NSString *folderName,[andMerge] BOOL mergeFiles)
void setSingleCrewWithRole:(NSString *crewRole)
void setPrimaryRole:(NSString *role)

References Entity::collision_radius, ResourceManager::dictionaryFromFilesNamed:inFolder:andMerge:, doScriptEvent:withArgument:, EXPECT, getAI, heatInsulation, markAsOffender:withReason:, MAX_ESCORTS, maxFlightSpeed, nil, Entity::owner, randf(), ranrot_rand, setBounty:withReason:, setGroup:, setHeatInsulation:, setOwner:, Entity::setPosition:, setPrimaryRole:, Entity::setScanClass:, setSingleCrewWithRole:, AI::setState:, shipInfoDictionary, switchAITo:, HPVector::x, HPVector::y, and HPVector::z.

Referenced by setUpEscorts, and ShipEntity(Private)::setUpMixedEscorts.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setUpOneFlasher:

- (BOOL) setUpOneFlasher: (NSDictionary*) subentDict
implementation

Provided by category ShipEntity(Private).

Definition at line 851 of file ShipEntity.m.

851 :(NSDictionary*)subentDict
852{
853 OOFlasherEntity* flasher = [OOFlasherEntity flasherWithDictionary:subentDict];
854 [flasher setPosition:HPvector_multiply_scalar([subentDict oo_hpvectorForKey:@"position"], _scaleFactor)];
855 [flasher rescaleBy:_scaleFactor];
856 [self addSubEntity:flasher];
857 return YES;
858}
instancetype flasherWithDictionary:(NSDictionary *dictionary)
void rescaleBy:(GLfloat factor)

References addSubEntity:, OOFlasherEntity::flasherWithDictionary:, OOFlasherEntity::rescaleBy:, and Entity::setPosition:.

Referenced by ShipEntity(Private)::setUpOneSubentity:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setUpOneStandardSubentity:asTurret:

- (BOOL) setUpOneStandardSubentity: (NSDictionary*) subentDict
asTurret: (BOOL) asTurret 

Definition at line 860 of file ShipEntity.m.

860 :(NSDictionary*)subentDict asTurret:(BOOL)asTurret
861{
862 ShipEntity* subentity = nil;
863 NSString* subentKey = nil;
864 HPVector subPosition;
865 Quaternion subOrientation;
866
867 subentKey = [subentDict oo_stringForKey:@"subentity_key"];
868 if (subentKey == nil) {
869 OOLog(@"setup.ship.badEntry.subentities", @"Failed to set up entity - no subentKey in %@", subentDict);
870 return NO;
871 }
872
873 if (!asTurret && [self isStation] && [subentDict oo_boolForKey:@"is_dock"]) {
874 subentity = [UNIVERSE newDockWithName:subentKey andScaleFactor:_scaleFactor];
875 } else {
876 subentity = [UNIVERSE newSubentityWithName:subentKey andScaleFactor:_scaleFactor];
877 }
878 if (subentity == nil) {
879 OOLog(@"setup.ship.badEntry.subentities", @"Failed to set up entity %@", subentKey);
880 return NO;
881 }
882
883 subPosition = HPvector_multiply_scalar([subentDict oo_hpvectorForKey:@"position"], _scaleFactor);
884 subOrientation = [subentDict oo_quaternionForKey:@"orientation"];
885
886 [subentity setPosition:subPosition];
887 [subentity setOrientation:subOrientation];
888 [subentity setReference:vector_forward_from_quaternion(subOrientation)];
889 // subentities inherit parent personality
890 [subentity setEntityPersonalityInt:[self entityPersonalityInt]];
891
892 if (asTurret) {
893 [subentity setBehaviour:BEHAVIOUR_TRACK_AS_TURRET];
894 [subentity setWeaponRechargeRate:[subentDict oo_floatForKey:@"fire_rate" defaultValue:TURRET_SHOT_FREQUENCY]];
895 [subentity setWeaponEnergy:[subentDict oo_floatForKey:@"weapon_energy" defaultValue:TURRET_TYPICAL_ENERGY]];
896 [subentity setWeaponRange:[subentDict oo_floatForKey:@"weapon_range" defaultValue:TURRET_SHOT_RANGE]];
897 [subentity setStatus:STATUS_ACTIVE];
898 } else {
899 [subentity setStatus:STATUS_INACTIVE];
900 }
901
902 [subentity overrideScriptInfo:[subentDict oo_dictionaryForKey:@"script_info"]];
903
904 [self addSubEntity:subentity];
905 [subentity setSubIdx:_maxShipSubIdx];
907
908 // update subentities
909 BoundingBox sebb = [subentity findSubentityBoundingBox];
912
913 if (!asTurret && [self isStation] && [subentDict oo_boolForKey:@"is_dock"]) {
914 BOOL allow_docking = [subentDict oo_boolForKey:@"allow_docking" defaultValue:YES];
915 BOOL ddc = [subentDict oo_boolForKey:@"disallowed_docking_collides" defaultValue:NO];
916 BOOL allow_launching = [subentDict oo_boolForKey:@"allow_launching" defaultValue:YES];
917 // do not include this key in OOShipRegistry; should never be set by shipdata
918 BOOL virtual_dock = [subentDict oo_boolForKey:@"_is_virtual_dock" defaultValue:NO];
919 if (virtual_dock) {
921 }
922
923 [(DockEntity*)subentity setDimensionsAndCorridor:allow_docking ddc:ddc launching:allow_launching];
924 [subentity setDisplayName:[subentDict oo_stringForKey:@"dock_label" defaultValue:@"the docking bay"]];
925 }
926
927 [subentity release];
928
929 return YES;
930}
OOINLINE void bounding_box_add_vector(BoundingBox *box, Vector vec) ALWAYS_INLINE_FUNC NONNULL_FUNC
void setDimensionsAndCorridor:ddc:launching:(BOOL docking,[ddc] BOOL ddc,[launching] BOOL launching)
void setVirtual()
Definition DockEntity.m:189
void setWeaponEnergy:(float value)
void setDisplayName:(NSString *inName)
void setWeaponRange:(GLfloat value)
void setWeaponRechargeRate:(float value)
void setEntityPersonalityInt:(uint16_t value)
void setSubIdx:(NSUInteger value)
Definition ShipEntity.m:724
void overrideScriptInfo:(NSDictionary *override)
BoundingBox findSubentityBoundingBox()
void setReference:(Vector v)

References _maxShipSubIdx, _scaleFactor, addSubEntity:, bounding_box_add_vector(), entityPersonalityInt, findSubentityBoundingBox, HPvector_multiply_scalar(), Entity::isStation, BoundingBox::max, BoundingBox::min, nil, OOLog, overrideScriptInfo:, setBehaviour:, DockEntity::setDimensionsAndCorridor:ddc:launching:, setDisplayName:, setEntityPersonalityInt:, Entity::setOrientation:, Entity::setPosition:, setReference:, setStatus:, setSubIdx:, DockEntity::setVirtual, setWeaponEnergy:, setWeaponRange:, setWeaponRechargeRate:, and totalBoundingBox.

Referenced by ShipEntity(Private)::setUpOneSubentity:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setUpOneSubentity:

- (BOOL) setUpOneSubentity: (NSDictionary*) subentDict
implementation

Provided by category ShipEntity(Private).

Definition at line 835 of file ShipEntity.m.

835 :(NSDictionary*)subentDict
836{
838
839 NSString* type = nil;
840
841 type = [subentDict oo_stringForKey:@"type"];
842 if ([type isEqualToString:@"flasher"]) {
843 return [self setUpOneFlasher:subentDict];
844 } else {
845 return [self setUpOneStandardSubentity:subentDict asTurret:[type isEqualToString:@"ball_turret"]];
846 }
847
849}

References nil, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, setUpOneFlasher:, and setUpOneStandardSubentity:asTurret:.

Referenced by setUpSubEntities.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setUpShipFromDictionary:

- (BOOL) setUpShipFromDictionary: (NSDictionary*) shipDict

Reimplemented in DockEntity, PlayerEntity, and StationEntity.

Definition at line 500 of file ShipEntity.m.

500 :(NSDictionary*)shipDict
501{
503
504 if (![self setUpFromDictionary:shipDict])
505 return NO;
506
507 // NPC-only settings.
508 //
514 reference = v_forward; // reference vector for (* turrets *)
515
516 isShip = YES;
517
518 // scan class settings. 'scanClass' is in common usage, but we could also have a more standard 'scan_class' key with higher precedence. Kaks 20090810
519 // let's see if scan_class is set...
520 scanClass = OOScanClassFromString([shipDict oo_stringForKey:@"scan_class" defaultValue:@"CLASS_NOT_SET"]);
521
522 // if not, try 'scanClass'. NOTE: non-standard capitalization is documented and entrenched.
523 if (scanClass == CLASS_NOT_SET) {
524 scanClass = OOScanClassFromString([shipDict oo_stringForKey:@"scanClass" defaultValue:@"CLASS_NOT_SET"]);
525 }
526
527 [scan_description autorelease];
528 scan_description = [[shipDict oo_stringForKey:@"scan_description" defaultValue:nil] copy];
529
530 // FIXME: give NPCs shields instead.
531
532 if ([shipDict oo_fuzzyBooleanForKey:@"has_shield_booster"])
533 [self addEquipmentItem:@"EQ_SHIELD_BOOSTER" inContext:@"npc"];
534 if ([shipDict oo_fuzzyBooleanForKey:@"has_shield_enhancer"])
535 [self addEquipmentItem:@"EQ_SHIELD_ENHANCER" inContext:@"npc"];
536
537 // Start with full energy banks.
539 weapon_temp = 0.0f;
540 forward_weapon_temp = 0.0f;
541 aft_weapon_temp = 0.0f;
542 port_weapon_temp = 0.0f;
544
545 // setWeaponDataFromType inside setUpFromDictionary should set weapon_damage from the front laser.
546 // no weapon_damage? It's a missile: set weapon_damage from shipdata!
547 if (weapon_damage == 0.0) {
548 weapon_damage_override = weapon_damage = [shipDict oo_floatForKey:@"weapon_energy" defaultValue:0]; // any damage value for missiles/bombs
549 } else {
551 }
552
553 scannerRange = [shipDict oo_floatForKey:@"scanner_range" defaultValue:(float)SCANNER_MAX_RANGE];
554
555 fuel = [shipDict oo_unsignedShortForKey:@"fuel"]; // Does it make sense that this defaults to 0? Should it not be 70? -- Ahruman
556
557 fuel_accumulator = 1.0;
558
559 [self setBounty:[shipDict oo_unsignedIntForKey:@"bounty" defaultValue:0] withReason:kOOLegalStatusReasonSetup];
560
561 [shipAI autorelease];
562 shipAI = [[AI alloc] init];
563 [shipAI setOwner:self];
564 [self setAITo:[shipDict oo_stringForKey:@"ai_type" defaultValue:@"nullAI.plist"]];
565
566 likely_cargo = [shipDict oo_unsignedIntForKey:@"likely_cargo"];
567 noRocks = [shipDict oo_fuzzyBooleanForKey:@"no_boulders"];
568
571 NSString* cargoString = [shipDict oo_stringForKey:@"cargo_carried"];
572 if (cargoString != nil) {
573 if ([cargoString isEqualToString:@"SCARCE_GOODS"]) {
575 } else if ([cargoString isEqualToString:@"PLENTIFUL_GOODS"]) {
577 } else {
579
580 OOCommodityType c_commodity = nil;
581 int c_amount = 1;
582 NSScanner* scanner = [NSScanner scannerWithString:cargoString];
583 if ([scanner scanInt:&c_amount]) {
584 [scanner ooliteScanCharactersFromSet:[NSCharacterSet whitespaceCharacterSet] intoString:NULL]; // skip whitespace
585 c_commodity = [[scanner string] substringFromIndex:[scanner scanLocation]];
586 if ([[UNIVERSE commodities] goodDefined:c_commodity]) {
587 [self setCommodityForPod:c_commodity andAmount:c_amount];
588 } else {
589 c_commodity = [[UNIVERSE commodities] goodNamed:c_commodity];
590 if ([[UNIVERSE commodities] goodDefined:c_commodity]) {
591 [self setCommodityForPod:c_commodity andAmount:c_amount];
592 }
593 }
594 } else {
595 c_amount = 1;
596 c_commodity = [shipDict oo_stringForKey:@"cargo_carried"];
597 if ([[UNIVERSE commodities] goodDefined:c_commodity]) {
598 [self setCommodityForPod:c_commodity andAmount:c_amount];
599 } else {
600 c_commodity = [[UNIVERSE commodities] goodNamed:c_commodity];
601 if ([[UNIVERSE commodities] goodDefined:c_commodity]) {
602 [self setCommodityForPod:c_commodity andAmount:c_amount];
603 }
604 }
605 }
606 }
607 }
608
609 cargoString = [shipDict oo_stringForKey:@"cargo_type"];
610 if (cargoString) {
611 if (cargo != nil)
612 [cargo autorelease];
613 cargo = [[NSMutableArray alloc] initWithCapacity:max_cargo]; // alloc retains;
614
615 [self setUpCargoType:cargoString];
616 } else if (scanClass != CLASS_CARGO) {
617 if (cargo != nil)
618 [cargo autorelease];
619 cargo = [[NSMutableArray alloc] initWithCapacity:max_cargo]; // alloc retains;
620 // if not CLASS_CARGO, and no cargo type set, default to CARGO_NOT_CARGO
622 }
623
624 hasScoopMessage = [shipDict oo_boolForKey:@"has_scoop_message" defaultValue:YES];
625
626 [roleSet release];
627 roleSet = [[[OORoleSet roleSetWithString:[shipDict oo_stringForKey:@"roles"]] roleSetWithRemovedRole:@"player"] retain];
628 [primaryRole release];
630
631 [self setOwner:self];
632 [self setHulk:[shipDict oo_boolForKey:@"is_hulk"]];
633
634 // these are the colors used for the "lollipop" of the ship. Any of the two (or both, for flash effect) can be defined. nil means use default from shipData.
635 [self setScannerDisplayColor1:nil];
636 [self setScannerDisplayColor2:nil];
637 // and the same for the "hostile" colours
638 [self setScannerDisplayColorHostile1:nil];
639 [self setScannerDisplayColorHostile2:nil];
640
641 // Populate the missiles here. Must come after scanClass.
642 _missileRole = [shipDict oo_stringForKey:@"missile_role"];
643 unsigned i, j;
644 for (i = 0, j = 0; i < missiles; i++) {
645 missile_list[i] = [self selectMissile];
646 // could loop forever (if missile_role is badly defined, selectMissile might return nil in some cases) . Try 3 times, and if no luck, skip
647 if (missile_list[i] == nil && j < 3) {
648 j++;
649 i--;
650 } else {
651 j = 0;
652 if (missile_list[i] == nil) {
653 missiles--;
654 }
655 }
656 }
657
658 // accuracy. Must come after scanClass, because we are using scanClass to determine if this is a missile.
659
660 // missiles: range 0 to +10
661 // ships: range -5 to +10, but randomly only -5 <= accuracy < +5
662 // enables "better" AIs at +5 and above
663 // police and military always have positive accuracy
664
665 accuracy = [shipDict oo_floatForKey:@"accuracy" defaultValue:-100.0f]; // Out-of-range default
667 accuracy = (randf() * 10.0) - 5.0;
668
669 if (accuracy < 0.0f && (scanClass == CLASS_MILITARY || scanClass == CLASS_POLICE)) { // police and military pilots have a better average skill.
671 }
672 }
673 if (scanClass == CLASS_MISSILE) { // missile accuracy range is 0 to 10
675 }
676 [self setAccuracy:accuracy]; // set derived variables
677 _missed_shots = 0;
678
679 // escorts
680 _maxEscortCount = MIN([shipDict oo_unsignedCharForKey:@"escorts" defaultValue:0], (uint8_t)MAX_ESCORTS);
682 if (_pendingEscortCount == 0 && [shipDict oo_arrayForKey:@"escort_roles" defaultValue:nil] != nil) {
683 // mostly ignored by setUpMixedEscorts, but needs to be high
684 // enough that it doesn't end up at zero (e.g. by governmental
685 // reductions in [Universe addShipAt]
687 }
688
689 // beacons
690 [self setBeaconCode:[shipDict oo_stringForKey:@"beacon"]];
691 [self setBeaconLabel:[shipDict oo_stringForKey:@"beacon_label" defaultValue:[shipDict oo_stringForKey:@"beacon"]]];
692
693 // contact tracking entities
694 [self setTrackCloseContacts:[shipDict oo_boolForKey:@"track_contacts" defaultValue:NO]];
695
696 // ship skin insulation factor (1.0 is normal)
697 [self setHeatInsulation:[shipDict oo_floatForKey:@"heat_insulation" defaultValue:[self hasHeatShield] ? 2.0 : 1.0]];
698
699 // unpiloted (like missiles asteroids etc.)
700 _explicitlyUnpiloted = [shipDict oo_fuzzyBooleanForKey:@"unpiloted"];
702 [self setCrew:nil];
703 } else {
704 // crew and passengers
705 NSDictionary* cdict = [[UNIVERSE characters] objectForKey:[shipDict oo_stringForKey:@"pilot"]];
706 if (cdict != nil) {
707 OOCharacter* pilot = [OOCharacter characterWithDictionary:cdict];
708 [self setCrew:[NSArray arrayWithObject:pilot]];
709 }
710 }
711
712 [self setShipScript:[shipDict oo_stringForKey:@"script"]];
713
714 home_system = [UNIVERSE currentSystemID];
715 destination_system = [UNIVERSE currentSystemID];
716
717 reactionTime = [shipDict oo_floatForKey:@"reaction_time" defaultValue:COMBAT_AI_STANDARD_REACTION_TIME];
718
719 return YES;
720
722}
OOScanClass OOScanClassFromString(NSString *string) PURE_FUNC
OOINLINE float OOClamp_0_max_f(float value, float max) INLINE_CONST_FUNC
const OOMatrix kIdentityMatrix
Definition OOMatrix.m:28
Definition AI.h:35
OOCharacter * characterWithDictionary:(NSDictionary *c_dict)
instancetype roleSetWithString:(NSString *roleString)
Definition OORoleSet.m:42
unsigned hasScoopMessage
Definition ShipEntity.h:264
GLfloat weapon_damage_override
Definition ShipEntity.h:299

References _explicitlyUnpiloted, _maxEscortCount, _missed_shots, _missileRole, _pendingEscortCount, accuracy, addEquipmentItem:inContext:, aft_weapon_temp, cargo, cargo_flag, CARGO_FLAG_FULL_PLENTIFUL, CARGO_FLAG_FULL_SCARCE, CARGO_FLAG_FULL_UNIFORM, CARGO_NOT_CARGO, cargo_type, OOCharacter::characterWithDictionary:, commodity_amount, commodity_type, destination_system, Entity::energy, forward_weapon_temp, fuel, fuel_accumulator, hasHeatShield, hasScoopMessage, home_system, Entity::isShip, kBasisXVector, kBasisYVector, kBasisZVector, kIdentityMatrix, kIdentityQuaternion, likely_cargo, MAX_ESCORTS, Entity::maxEnergy, MIN, missile_list, missiles, nil, noRocks, OOClamp_0_max_f(), OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOScanClassFromString(), Entity::orientation, port_weapon_temp, primaryRole, randf(), reactionTime, reference, roleSet, OORoleSet::roleSetWithString:, Entity::rotMatrix, scan_description, scanClass, scannerRange, selectMissile, setAccuracy:, setAITo:, setBeaconCode:, setBeaconLabel:, setBounty:withReason:, setCommodityForPod:andAmount:, setCrew:, setHeatInsulation:, setHulk:, AI::setOwner:, setOwner:, setScannerDisplayColor1:, setScannerDisplayColor2:, setScannerDisplayColorHostile1:, setScannerDisplayColorHostile2:, setShipScript:, setTrackCloseContacts:, setUpCargoType:, shipAI, starboard_weapon_temp, UNIVERSE, v_forward, v_right, v_up, weapon_damage, weapon_damage_override, and weapon_temp.

Here is the call graph for this function:

◆ setUpSubEntities

- (BOOL) setUpSubEntities

Reimplemented in StationEntity.

Definition at line 790 of file ShipEntity.m.

791{
793
794 unsigned int i;
795 NSDictionary* shipDict = [self shipInfoDictionary];
796 NSArray* plumes = [shipDict oo_arrayForKey:@"exhaust"];
797
799 _maxShipSubIdx = 0;
800
801 for (i = 0; i < [plumes count]; i++) {
802 NSArray* definition = ScanTokensFromString([plumes oo_stringAtIndex:i]);
803 OOExhaustPlumeEntity* exhaust = [OOExhaustPlumeEntity exhaustForShip:self withDefinition:definition andScale:_scaleFactor];
804 [self addSubEntity:exhaust];
805 }
806
807 NSArray* subs = [shipDict oo_arrayForKey:@"subentities"];
808
810
811 for (i = 0; i < [subs count]; i++) {
812 [self setUpOneSubentity:[subs oo_dictionaryAtIndex:i]];
813 }
814
816
817 return YES;
818
820}
#define NO_DRAW_DISTANCE_FACTOR
Definition Entity.h:49
id exhaustForShip:withDefinition:andScale:(ShipEntity *ship,[withDefinition] NSArray *definition,[andScale] float scale)

References _maxShipSubIdx, _profileRadius, addSubEntity:, Entity::boundingBox, Entity::collision_radius, OOExhaustPlumeEntity::exhaustForShip:withDefinition:andScale:, Entity::no_draw_distance, NO_DRAW_DISTANCE_FACTOR, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, ScanTokensFromString(), setUpOneSubentity:, setUpSubEntities, shipInfoDictionary, and totalBoundingBox.

Referenced by PlayerEntity(Contracts)::newShipCommonSetup:yardInfo:baseInfo:, octree, setUpSubEntities, ShipRestoreSubEntities(), ShipRestoreSubEntities(), and PlayerEntity(OOPrivate)::tryBuyingItem:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setWeaponDataFromType:

- (void) setWeaponDataFromType: (OOWeaponType) weapon_type

Definition at line 6470 of file ShipEntity.m.

6470 :(OOWeaponType)weapon_type
6471{
6472 weaponRange = getWeaponRangeFromType(weapon_type);
6473 weapon_energy_use = [weapon_type weaponEnergyUse];
6476 weapon_damage = [weapon_type weaponDamage];
6477
6478 if (default_laser_color == nil) {
6479 OOColor* wcol = [weapon_type weaponColor];
6480 if (wcol != nil) {
6481 [self setLaserColor:wcol];
6482 }
6483 }
6484}
GLfloat weaponShotTemperature()
OOColor * weaponColor()
GLfloat weaponRechargeRate()

References default_laser_color, getWeaponRangeFromType(), nil, setLaserColor:, weapon_damage, weapon_energy_use, weapon_recharge_rate, weapon_shot_temperature, OOEquipmentType::weaponColor, OOEquipmentType::weaponDamage, OOEquipmentType::weaponEnergyUse, weaponRange, OOEquipmentType::weaponRechargeRate, and OOEquipmentType::weaponShotTemperature.

Referenced by behaviour_attack_broadside:, behaviour_close_to_broadside_range:, PlayerEntity::currentWeaponStats, fireAftWeapon:, fireMainWeapon:, firePortWeapon:, fireStarboardWeapon:, fireSubentityLaserShot:, and PlayerEntity::setCommanderDataFromDictionary:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setWeaponEnergy:

- (void) setWeaponEnergy: (float) value

Definition at line 6506 of file ShipEntity.m.

6506 :(float)value
6507{
6508 weapon_damage = value;
6509}

References weapon_damage.

Referenced by setUpOneStandardSubentity:asTurret:.

Here is the caller graph for this function:

◆ setWeaponMount:toWeapon:

- (BOOL) setWeaponMount: (OOWeaponFacing) facing
toWeapon: (NSString*) eqKey 

Reimplemented in PlayerEntity.

Definition at line 3137 of file ShipEntity.m.

3137 :(OOWeaponFacing)facing toWeapon:(NSString*)eqKey
3138{
3139 // sets WEAPON_NONE if not recognised
3140 if (weapon_facings & facing) {
3142 switch (facing) {
3144 forward_weapon_type = chosen_weapon;
3145 break;
3146
3147 case WEAPON_FACING_AFT:
3148 aft_weapon_type = chosen_weapon;
3149 break;
3150
3151 case WEAPON_FACING_PORT:
3152 port_weapon_type = chosen_weapon;
3153 break;
3154
3156 starboard_weapon_type = chosen_weapon;
3157 break;
3158
3159 case WEAPON_FACING_NONE:
3160 break;
3161 }
3162
3163 return YES;
3164 } else {
3165 return NO;
3166 }
3167}

References aft_weapon_type, forward_weapon_type, OOWeaponTypeFromEquipmentIdentifierStrict(), port_weapon_type, starboard_weapon_type, WEAPON_FACING_AFT, WEAPON_FACING_FORWARD, WEAPON_FACING_NONE, WEAPON_FACING_PORT, WEAPON_FACING_STARBOARD, and weapon_facings.

Referenced by ShipSetProperty(), and ShipSetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setWeaponRange:

- (void) setWeaponRange: (GLfloat) value

Definition at line 6465 of file ShipEntity.m.

6465 :(GLfloat)value
6466{
6467 weaponRange = value;
6468}

References weaponRange.

Referenced by setUpOneStandardSubentity:asTurret:.

Here is the caller graph for this function:

◆ setWeaponRechargeRate:

- (void) setWeaponRechargeRate: (float) value

Definition at line 6501 of file ShipEntity.m.

6501 :(float)value
6502{
6503 weapon_recharge_rate = value;
6504}

References weapon_recharge_rate.

Referenced by setUpOneStandardSubentity:asTurret:.

Here is the caller graph for this function:

◆ setYaw:

- (void) setYaw: (double) amount

Definition at line 7091 of file ShipEntity.m.

7091 :(double)amount
7092{
7093 flightYaw = amount * M_PI / 2.0;
7094}

References flightYaw, and M_PI.

Referenced by DockEntity::launchShip:.

Here is the caller graph for this function:

◆ shieldBoostFactor

- (float) shieldBoostFactor

Definition at line 3628 of file ShipEntity.m.

3629{
3630 float boostFactor = 1.0f;
3631 if ([self hasShieldBooster])
3632 boostFactor += 1.0f;
3633 if ([self hasMilitaryShieldEnhancer])
3634 boostFactor += 1.0f;
3635
3636 return boostFactor;
3637}
BOOL hasMilitaryShieldEnhancer()
BOOL hasShieldBooster()

References hasMilitaryShieldEnhancer, hasShieldBooster, and shieldBoostFactor.

Referenced by isFrangible, maxAftShieldLevel, maxForwardShieldLevel, and shieldBoostFactor.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shieldRechargeRate

- (float) shieldRechargeRate

Definition at line 3651 of file ShipEntity.m.

3652{
3653 return [self hasMilitaryShieldEnhancer] ? 3.0f : 2.0f;
3654}

References hasMilitaryShieldEnhancer, and shieldRechargeRate.

Referenced by isFrangible, and shieldRechargeRate.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shipAIScript

- (OOScript *) shipAIScript

Definition at line 1276 of file ShipEntity.m.

1277{
1278 return aiScript;
1279}

References aiScript, and shipAIScript.

Referenced by shipAIScript, ShipGetProperty(), and ShipGetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shipAIScriptWakeTime

- (OOTimeAbsolute) shipAIScriptWakeTime

Definition at line 1281 of file ShipEntity.m.

1282{
1283 return aiScriptWakeTime;
1284}

References aiScriptWakeTime, and shipAIScriptWakeTime.

Referenced by shipAIScriptWakeTime.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shipClassName

- (NSString *) shipClassName

References shipClassName.

◆ shipDataKey

◆ shipDataKeyAutoRole

- (NSString *) shipDataKeyAutoRole

Definition at line 1779 of file ShipEntity.m.

1780{
1781 return [[[NSString alloc] initWithFormat:@"[%@]", [self shipDataKey]] autorelease];
1782}

References shipDataKey, and shipDataKeyAutoRole.

Referenced by hasRole:, octree, and shipDataKeyAutoRole.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shipHitByLaser

- (ShipEntity *) shipHitByLaser

Definition at line 8770 of file ShipEntity.m.

8771{
8772 return [_shipHitByLaser weakRefUnderlyingObject];
8773}

References shipHitByLaser, and OOWeakReference::weakRefUnderlyingObject.

Referenced by maxFlightSpeed, PlayerEntity(OOControlsPrivate)::pollFlightControls:, and shipHitByLaser.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shipInfoDictionary

- (NSDictionary *) shipInfoDictionary

Definition at line 1790 of file ShipEntity.m.

1791{
1792 return shipinfoDictionary;
1793}

References shipInfoDictionary, and shipinfoDictionary.

Referenced by Universe::addEntity:, becomeExplosion, clearSubEntities, PlayerEntity::commanderDataDictionary, countsAsKill, hasAutoAI, hasAutoWeapons, octree, ShipEntity(Private)::rescaleBy:writeToCache:, setScannerDisplayColor1:, setScannerDisplayColor2:, setScannerDisplayColorHostile1:, setScannerDisplayColorHostile2:, ShipEntity(Private)::setUpOneEscort:inGroup:withRole:atPosition:andCount:, setUpSubEntities, shipInfoDictionary, ShipSetMaterialsInternal(), and ShipSetMaterialsInternal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shipRestoredFromDictionary:useFallback:context:

+ (id) shipRestoredFromDictionary: (NSDictionary*) dictionary
useFallback: (BOOL) fallback
context: (NSMutableDictionary*) context 

Provided by category ShipEntity(LoadRestore).

Definition at line 163 of file ShipEntityLoadRestore.m.

163 :(NSDictionary*)dict
164 useFallback:(BOOL)fallback
165 context:(NSMutableDictionary*)context
166{
167 if (dict == nil)
168 return nil;
169 if (context == nil)
170 context = [NSMutableDictionary dictionary];
171
172 ShipEntity* ship = nil;
173
174 NSString* shipKey = [dict oo_stringForKey:KEY_SHIP_KEY];
175 NSDictionary* shipData = [[OOShipRegistry sharedRegistry] shipInfoForKey:shipKey];
176
177 if (shipData != nil) {
178 NSMutableDictionary* mergedData = [NSMutableDictionary dictionaryWithDictionary:shipData];
179
180 StripIgnoredKeys(mergedData);
181 NSArray* deletes = [dict oo_arrayForKey:KEY_SHIPDATA_DELETES];
182 if (deletes != nil)
183 [mergedData removeObjectsForKeys:deletes];
184 [mergedData addEntriesFromDictionary:[dict oo_dictionaryForKey:KEY_SHIPDATA_OVERRIDES]];
185 [mergedData oo_setBool:NO forKey:@"auto_ai"];
186 [mergedData oo_setUnsignedInteger:0 forKey:@"escorts"];
187
188 Class shipClass = [UNIVERSE shipClassForShipDictionary:mergedData];
189 ship = [[[shipClass alloc] initWithKey:shipKey definition:mergedData] autorelease];
190
191 // FIXME: restore AI.
192 [ship setAITo:[dict oo_stringForKey:KEY_AI defaultValue:@"nullAI.plist"]];
193
194 [ship setPrimaryRole:[dict oo_stringForKey:KEY_PRIMARY_ROLE]];
195
196 } else {
197 // Unknown ship; fall back on role if desired and possible.
198 NSString* shipPrimaryRole = [dict oo_stringForKey:KEY_PRIMARY_ROLE];
199 if (!fallback || shipPrimaryRole == nil)
200 return nil;
201
202 ship = [[UNIVERSE newShipWithRole:shipPrimaryRole] autorelease];
203 if (ship == nil)
204 return nil;
205 }
206
207 // The following stuff is deliberately set up the same way even if using role fallback.
208 [ship setPosition:[dict oo_hpvectorForKey:KEY_POSITION]];
209 [ship setNormalOrientation:[dict oo_quaternionForKey:KEY_ORIENTATION]];
210
211 float energyLevel = [dict oo_floatForKey:KEY_ENERGY_LEVEL defaultValue:1.0f];
212 [ship setEnergy:energyLevel * [ship maxEnergy]];
213
214 [ship removeAllEquipment];
215 NSString* eqKey = nil;
216 foreach (eqKey, [dict oo_arrayForKey:KEY_EQUIPMENT]) {
217 [ship addEquipmentItem:eqKey withValidation:NO inContext:@"loading"];
218 }
219
220 [ship removeMissiles];
221 foreach (eqKey, [dict oo_arrayForKey:KEY_MISSILES]) {
222 [ship addEquipmentItem:eqKey withValidation:NO inContext:@"loading"];
223 }
224
225 // Groups.
226 NSUInteger groupID = [dict oo_integerForKey:KEY_GROUP_ID defaultValue:NSNotFound];
227 if (groupID != NSNotFound) {
228 OOShipGroup* group = GroupForGroupID(groupID, context);
229 [ship setGroup:group]; // Handles adding to group
230 if ([dict oo_boolForKey:KEY_IS_GROUP_LEADER])
231 [group setLeader:ship];
232 NSString* groupName = [dict oo_stringForKey:KEY_GROUP_NAME];
233 if (groupName != nil)
234 [group setName:groupName];
235 if ([ship hasPrimaryRole:@"escort"] && ship != [group leader]) {
236 [ship setOwner:[group leader]];
237 }
238 }
239
240 groupID = [dict oo_integerForKey:KEY_ESCORT_GROUP_ID defaultValue:NSNotFound];
241 if (groupID != NSNotFound) {
242 OOShipGroup* group = GroupForGroupID(groupID, context);
243 [group setLeader:ship];
244 [group setName:@"escort group"];
245 [ship setEscortGroup:group];
246 }
247
248 return ship;
249}
#define KEY_EQUIPMENT
#define KEY_MISSILES
static void StripIgnoredKeys(NSMutableDictionary *dict)
#define KEY_IS_GROUP_LEADER
static OOShipGroup * GroupForGroupID(NSUInteger groupID, NSMutableDictionary *context)
void setNormalOrientation:(Quaternion quat)
Definition Entity.m:692
void setName:(NSString *name)
NSDictionary * shipInfoForKey:(NSString *key)
BOOL addEquipmentItem:withValidation:inContext:(NSString *equipmentKey,[withValidation] BOOL validateAddition,[inContext] NSString *context)
OOCreditsQuantity removeMissiles()
void removeAllEquipment()
void setEscortGroup:(OOShipGroup *group)

Referenced by WormholeEntity::initWithDict:.

Here is the caller graph for this function:

◆ shipScript

- (OOScript *) shipScript

Definition at line 1271 of file ShipEntity.m.

1272{
1273 return script;
1274}

References script, and shipScript.

Referenced by ShipGetProperty(), ShipGetProperty(), and shipScript.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shipSubEntityEnumerator

- (NSEnumerator *) shipSubEntityEnumerator

Definition at line 1219 of file ShipEntity.m.

1220{
1221 return [[self subEntities] objectEnumeratorFilteredWithSelector:@selector(isShip)];
1222}

References shipSubEntityEnumerator, and subEntities.

Referenced by addTarget:, becomeExplosion, becomeLargeExplosion:, behaviour_attack_target:, PlayerEntity::canAddEquipment:inContext:, deserializeShipSubEntitiesFrom:, PlayerEntity::doesHitLine:v1:hitEntity:, doesHitLine:v1:hitEntity:, fireMainWeapon:, fireWeapon:direction:range:, hasPrimaryWeapon:, laserHeatLevelForward, PlayerEntity(Contracts)::missingSubEntitiesAdjustment, removeTarget:, serializeShipSubEntities, StationEntity::setUpSubEntities, shipSubEntityEnumerator, subEntities, ShipEntity(OOJavaScriptExtensions)::subEntitiesForScript, switchLightsOff, switchLightsOn, turretCount, and weaponTypeIDForFacing:strict:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shipUniqueName

- (NSString *) shipUniqueName

References shipUniqueName.

◆ shortDescriptionComponents

- (NSString *) shortDescriptionComponents
implementation

Definition at line 1106 of file ShipEntity.m.

1107{
1108 return [NSString stringWithFormat:@"\"%@\"", [self name]];
1109}

References name, and shortDescriptionComponents.

Referenced by shortDescriptionComponents.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shotTime

- (OOTimeDelta) shotTime

Definition at line 10084 of file ShipEntity.m.

10085{
10086 return shot_time;
10087}

References shot_time, and shotTime.

Referenced by canCollide, coordinates, fireSubentityLaserShot:, fireTurretCannon:, fireWeapon:direction:range:, shotTime, and weaponRecoveryTime.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ showDamage

- (BOOL) showDamage

Definition at line 7895 of file ShipEntity.m.

7896{
7897 return _showDamage;
7898}

References _showDamage, and showDamage.

Referenced by maxFlightSpeed, and showDamage.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ showScoopMessage

- (BOOL) showScoopMessage

Definition at line 7322 of file ShipEntity.m.

7323{
7324 return hasScoopMessage;
7325}

References hasScoopMessage, and showScoopMessage.

Referenced by cargo, scoopUpProcess:processEvents:processMessages:, and showScoopMessage.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ simplifyShipdata:andGetDeletes:

- (void) simplifyShipdata: (NSMutableDictionary*) data
andGetDeletes: (NSArray**) deletes 
implementation

Provided by category ShipEntity(LoadRestoreInternal).

Definition at line 251 of file ShipEntityLoadRestore.m.

251 :(NSMutableDictionary*)data andGetDeletes:(NSArray**)deletes
252{
253 NSParameterAssert(data != nil && deletes != NULL);
254 *deletes = nil;
255
256 // Get original ship data.
257 NSMutableDictionary* referenceData = [NSMutableDictionary dictionaryWithDictionary:[[OOShipRegistry sharedRegistry] shipInfoForKey:[self shipDataKey]]];
258
259 // Discard stuff that we handle separately.
260 StripIgnoredKeys(referenceData);
261 StripIgnoredKeys(data);
262
263 // Note items that are in referenceData, but not data.
264 NSMutableArray* foundDeletes = [NSMutableArray array];
265 NSString* key = nil;
266 foreachkey(key, referenceData)
267 {
268 if ([data objectForKey:key] == nil) {
269 [foundDeletes addObject:key];
270 }
271 }
272 if ([foundDeletes count] != 0)
273 *deletes = foundDeletes;
274
275 // after rev3010 this loop was using cycles without doing anything - commenting this whole loop out for now. -- kaks 20100207
276 /*
277 // Discard anything that hasn't changed.
278 for (enumerator = [data keyEnumerator]; (key = [enumerator nextObject]); )
279 {
280 id referenceVal = [referenceData objectForKey:key];
281 id myVal = [data objectForKey:key];
282 if ([referenceVal isEqual:myVal])
283 {
284 // [data removeObjectForKey:key];
285 }
286 }
287 */
288}
#define foreachkey(VAR, DICT)

References count, foreachkey, nil, OOShipRegistry::sharedRegistry, shipDataKey, OOShipRegistry::shipInfoForKey:, and StripIgnoredKeys().

Referenced by ShipEntity(LoadRestore)::savedShipDictionaryWithContext:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ spawn:

- (void) spawn: (NSString*) roles_number

Definition at line 12487 of file ShipEntity.m.

12487 :(NSString*)roles_number
12488{
12489 NSArray* tokens = ScanTokensFromString(roles_number);
12490 NSString* roleString = nil;
12491 NSString* numberString = nil;
12492 NSUInteger number;
12493
12494 if ([tokens count] != 2) {
12495 OOLog(kOOLogSyntaxAddShips, @"***** Could not spawn: \"%@\" (must be two tokens, role and number)", roles_number);
12496 return;
12497 }
12498
12499 roleString = [tokens oo_stringAtIndex:0];
12500 numberString = [tokens oo_stringAtIndex:1];
12501
12502 number = [numberString intValue];
12503
12504 [self spawnShipsWithRole:roleString count:number];
12505}
static NSString *const kOOLogSyntaxAddShips

References count, kOOLogSyntaxAddShips, nil, OOLog, ScanTokensFromString(), and spawnShipsWithRole:count:.

Here is the call graph for this function:

◆ spawnShipsWithRole:count:

- (NSArray *) spawnShipsWithRole: (NSString*) role
count: (NSUInteger) count 

Provided by category ShipEntity(ScriptMethods).

Definition at line 60 of file ShipEntityScriptMethods.m.

60 :(NSString*)role count:(NSUInteger)count
61{
62 ShipEntity* ship = [self rootShipEntity]; // FIXME: (EMMSTRAN) implement an -absolutePosition method, use that in spawnShipWithRole:near:, and use self instead of root.
63 ShipEntity* spawned = nil;
64 NSMutableArray* result = nil;
65
66 if (count == 0)
67 return [NSArray array];
68
69 OOLog(kOOLogNoteAddShips, @"Spawning %zu x '%@' near %@ %d", count, role, [self shortDescription], [self universalID]);
70
71 result = [NSMutableArray arrayWithCapacity:count];
72
73 do {
74 spawned = [UNIVERSE spawnShipWithRole:role near:ship];
75 if (spawned != nil) {
76 [spawned setTemperature:[self randomEjectaTemperature]];
77 if ([self isMissileFlagSet] && [[spawned shipInfoDictionary] oo_boolForKey:@"is_submunition"]) {
78 [spawned setOwner:[self owner]];
79 [spawned addTarget:[self primaryTarget]];
80 [spawned setIsMissileFlag:YES];
81 }
82 if ([spawned isMine]) {
83 [spawned setOwner:self];
84 }
85 [result addObject:spawned];
86 }
87 } while (--count);
88
89 return result;
90}
static NSString *const kOOLogNoteAddShips

Referenced by ShipSpawn(), ShipSpawn(), and spawn:.

Here is the caller graph for this function:

◆ speedFactor

- (GLfloat) speedFactor

Definition at line 7554 of file ShipEntity.m.

7555{
7556 if (maxFlightSpeed <= 0.0)
7557 return 0.0;
7558 return flightSpeed / maxFlightSpeed;
7559}

References flightSpeed, maxFlightSpeed, and speedFactor.

Referenced by maxFlightSpeed, speedFactor, and OOExhaustPlumeEntity::update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ starboardWeaponOffset

- (NSArray *) starboardWeaponOffset

References hasAutoWeapons, and starboardWeaponOffset.

Here is the call graph for this function:

◆ startTrackingCurve

- (void) startTrackingCurve

Definition at line 5434 of file ShipEntity.m.

5435{
5436 Entity* target = [self primaryTarget];
5437 if (target == nil) {
5438 return;
5439 }
5440 OOTimeAbsolute now = [UNIVERSE getTime];
5441 trackingCurvePositions[0] = [target position];
5442 trackingCurvePositions[1] = [target position];
5443 trackingCurvePositions[2] = [target position];
5444 trackingCurvePositions[3] = [target position];
5445 trackingCurveTimes[0] = now;
5446 trackingCurveTimes[1] = now - reactionTime / 3.0;
5447 trackingCurveTimes[2] = now - reactionTime * 2.0 / 3.0;
5449 [self calculateTrackingCurve];
5450 return;
5451}

References calculateTrackingCurve, nil, Entity::position, primaryTarget, reactionTime, startTrackingCurve, trackingCurvePositions, and trackingCurveTimes.

Referenced by addTarget:, reactionTime, resumePostProximityAlert, and startTrackingCurve.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stationGroup

- (OOShipGroup *) stationGroup

Definition at line 6027 of file ShipEntity.m.

6028{
6029 if (_group == nil) {
6030 _group = [[OOShipGroup alloc] initWithName:@"station group"];
6031 [_group setLeader:self];
6032 }
6033
6034 return _group;
6035}

References _group, nil, OOShipGroup::setLeader:, and stationGroup.

Referenced by StationEntity::launchDefenseShip, StationEntity::launchMiner, StationEntity::launchPatrol, StationEntity::launchPirateShip, StationEntity::launchPolice, StationEntity::launchScavenger, StationEntity::launchShipWithRole:, messageTime, StationEntity::setUpShipFromDictionary:, and stationGroup.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ storeTarget

- (void) storeTarget
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1838 of file ShipEntityAI.m.

1839{
1840 Entity* target = [self primaryTarget];
1841
1842 if (target) {
1843 [self setRememberedShip:target];
1844 } else {
1846 }
1847}

◆ subEntities

- (NSArray *) subEntities

References clearSubEntities, exhaustEnumerator, flasherEnumerator, maxShipSubEntities, serializeShipSubEntities, shipSubEntityEnumerator, subEntities, subEntityCount, subEntityEnumerator, subEntityRotationalVelocity, subEntityTakingDamage, and subIdx.

Here is the call graph for this function:

◆ subEntitiesForScript [1/2]

- (NSArray *) subEntitiesForScript

Provided by category ShipEntity(OOJavaScriptExtensions).

Definition at line 113 of file EntityOOJavaScriptExtensions.m.

114{
115 return [[self shipSubEntityEnumerator] allObjects];
116}

Referenced by ShipGetProperty(), ShipGetProperty(), ShipRestoreSubEntities(), and ShipRestoreSubEntities().

Here is the caller graph for this function:

◆ subEntitiesForScript [2/2]

- (NSArray *) subEntitiesForScript

Provided by category ShipEntity(OOJavaScriptExtensions).

◆ subEntityCount

- (NSUInteger) subEntityCount

Definition at line 1204 of file ShipEntity.m.

1205{
1206 return [subEntities count];
1207}

References subEntityCount.

Referenced by drawImmediate:translucent:, subEntities, subEntityCount, and update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ subEntityDied:

- (void) subEntityDied: (ShipEntity*) sub
implementation

Provided by category ShipEntity(Private).

Definition at line 8194 of file ShipEntity.m.

8194 :(ShipEntity*)sub
8195{
8196 if ([self subEntityTakingDamage] == sub)
8197 [self setSubEntityTakingDamage:nil];
8198
8199 [sub setOwner:nil];
8200 // TODO? Recalculating collision radius should increase collision testing efficiency,
8201 // but for most ship models the difference would be marginal. -- Kaks 20110429
8202 mass -= [sub mass]; // missing subents affect fuel charge rate, etc..
8203 [subEntities removeObject:sub];
8204}

References Entity::mass, setOwner:, and setSubEntityTakingDamage:.

Referenced by becomeExplosion.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ subEntityEnumerator

- (NSEnumerator *) subEntityEnumerator

Definition at line 1214 of file ShipEntity.m.

1215{
1216 return [[self subEntities] objectEnumerator];
1217}

References subEntities, and subEntityEnumerator.

Referenced by subEntities, and subEntityEnumerator.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ subEntityReallyDied:

- (void) subEntityReallyDied: (ShipEntity*) sub
implementation

Reimplemented from Entity.

Provided by category ShipEntity(Private).

Definition at line 8206 of file ShipEntity.m.

8206 :(ShipEntity*)sub
8207{
8208 if ([self subEntityTakingDamage] == sub)
8209 [self setSubEntityTakingDamage:nil];
8210
8211 if ([self hasSubEntity:sub]) {
8212 OOLogERR(@"shipEntity.bug.subEntityRetainUnderflow", @"Subentity of %@ died while still in subentity list! This is bad. Leaking subentity list to avoid crash. %@", self, @"This is an internal error, please report it.");
8213
8214 // Leak subentity list.
8215 subEntities = nil;
8216 }
8217}

References nil, OOLogERR, and setSubEntityTakingDamage:.

Referenced by dealloc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ subEntityRotationalVelocity

- (Quaternion) subEntityRotationalVelocity

Definition at line 1080 of file ShipEntity.m.

1081{
1083}

References subEntityRotationalVelocity, and subentityRotationalVelocity.

Referenced by subEntities, and subEntityRotationalVelocity.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ subEntityTakingDamage

- (ShipEntity *) subEntityTakingDamage

Definition at line 1234 of file ShipEntity.m.

1235{
1236 ShipEntity* result = [_subEntityTakingDamage weakRefUnderlyingObject];
1237
1238#ifndef NDEBUG
1239 // Sanity check - there have been problems here, see fireLaserShotInDirection:
1240 // -parentEntity will take care of reporting insanity.
1241 if ([result parentEntity] != self)
1242 result = nil;
1243#endif
1244
1245 // Clear the weakref if the subentity is dead.
1246 if (result == nil)
1247 [self setSubEntityTakingDamage:nil];
1248
1249 return result;
1250}

References nil, Entity::parentEntity, setSubEntityTakingDamage:, subEntityTakingDamage, and OOWeakReference::weakRefUnderlyingObject.

Referenced by fireDirectLaserShotAt:, fireLaserShotInDirection:weaponIdentifier:, fireSubentityLaserShot:, subEntities, and subEntityTakingDamage.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ subIdx

- (NSUInteger) subIdx

Definition at line 729 of file ShipEntity.m.

730{
731 return _subIdx;
732}

References _subIdx, and subIdx.

Referenced by deserializeShipSubEntitiesFrom:, serializeShipSubEntities, subEntities, and subIdx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ suggestEscort

- (void) suggestEscort
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1585 of file ShipEntityAI.m.

1586{
1587 ShipEntity* mother = [self primaryTarget];
1588 [self suggestEscortTo:mother];
1589}

◆ suggestEscortTo:

- (BOOL) suggestEscortTo: (ShipEntity*) mother

Provided by category ShipEntity(AI).

Definition at line 641 of file ShipEntityAI.m.

641 :(ShipEntity*)mother
642{
643 if (mother) {
644#ifdef OO_DEBUG_MONITOR_ENABLED
645 if (reportAIMessages) {
646 OOLog(@"ai.suggestEscort", @"DEBUG: %@ suggests escorting %@", self, mother);
647 }
648#endif
649
650 if ([mother acceptAsEscort:self]) {
651 // copy legal status across
652 if (([mother legalStatus] > 0) && (bounty <= 0)) {
653 int extra = 1 | (ranrot_rand() & 15);
654 // [mother setBounty: [mother legalStatus] + extra withReason:kOOLegalStatusReasonAssistingOffender];
655 [self markAsOffender:extra withReason:kOOLegalStatusReasonAssistingOffender];
656 // bounty += extra; // obviously we're dodgier than we thought!
657 }
658
659 [self setOwner:mother];
660 [self setGroup:[mother escortGroup]];
661 [shipAI message:@"ESCORTING"];
662 return YES;
663 }
664
665#ifdef OO_DEBUG_MONITOR_ENABLED
666 if (reportAIMessages) {
667 OOLog(@"ai.suggestEscort.refused", @"DEBUG: %@ refused by %@", self, mother);
668 }
669#endif
670 }
671 [self setOwner:self];
672 [shipAI message:@"NOT_ESCORTING"];
673 [self doScriptEvent:OOJSID("escortRejected") withArgument:mother];
674 return NO;
675}

Referenced by ShipEntity(PureAI)::suggestEscort.

Here is the caller graph for this function:

◆ sunGlareFilter

- (GLfloat) sunGlareFilter

References checkShipsInVicinityForWitchJumpExit, int(), isMining, markedForFines, markForFines, setCommsMessageColor, and sunGlareFilter.

Here is the call graph for this function:

◆ suppressFlightNotifications

- (BOOL) suppressFlightNotifications

Definition at line 1844 of file ShipEntity.m.

1845{
1846 return suppressAegisMessages;
1847}

References suppressAegisMessages, and suppressFlightNotifications.

Referenced by isFrangible, and suppressFlightNotifications.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ suppressTargetLost

- (void) suppressTargetLost
implementation

Reimplemented in PlayerEntity.

Definition at line 11249 of file ShipEntity.m.

11250{
11251}

References suppressTargetLost.

Referenced by scoopUpProcess:processEvents:processMessages:, and suppressTargetLost.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SurfaceDistanceSqared

+ (float) SurfaceDistanceSqared (Entity *) reference
(Entity< OOStellarBody > *) stellar 
implementation

Definition at line 6577 of file ShipEntity.m.

6578{
6579 return SurfaceDistanceSqaredV([reference position], stellar);
6580}

References Entity::position, reference, and SurfaceDistanceSqaredV.

Referenced by findNearestStellarBody.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SurfaceDistanceSqaredV

+ (float) SurfaceDistanceSqaredV (HPVector) reference
(Entity< OOStellarBody > *) stellar 
implementation

Definition at line 6567 of file ShipEntity.m.

6568{
6569 float centerDistance = HPmagnitude2(HPvector_subtract([stellar position], reference));
6570 float r = [stellar radius];
6571 /* 1.35: empirical value used to help determine proximity when non-nested
6572 planets are close to each other
6573 */
6574 return centerDistance - 1.35 * r * r;
6575}

References HPmagnitude2(), HPvector_subtract(), Entity::position, and reference.

Referenced by ComparePlanetsBySurfaceDistance, findNearestPlanet, and SurfaceDistanceSqared.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ switchAITo:

◆ switchLightsOff

- (void) switchLightsOff

Definition at line 11883 of file ShipEntity.m.

11884{
11885 OOFlasherEntity* se = nil;
11886 ShipEntity* sub = nil;
11887
11888 _lightsActive = NO;
11889
11890 foreach (se, [self flasherEnumerator]) {
11891 [se setActive:NO];
11892 }
11893 foreach (sub, [self shipSubEntityEnumerator]) {
11894 [sub switchLightsOff];
11895 }
11896}
void setActive:(BOOL active)
NSEnumerator * flasherEnumerator()
void switchLightsOff()

References _lightsActive, flasherEnumerator, nil, shipSubEntityEnumerator, and switchLightsOff.

Referenced by coordinates, StationEntity::launchPatrol, ShipSetProperty(), ShipSetProperty(), and switchLightsOff.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ switchLightsOn

- (void) switchLightsOn

Definition at line 11867 of file ShipEntity.m.

11868{
11869 OOFlasherEntity* se = nil;
11870 ShipEntity* sub = nil;
11871
11872 _lightsActive = YES;
11873
11874 foreach (se, [self flasherEnumerator]) {
11875 [se setActive:YES];
11876 }
11877 foreach (sub, [self shipSubEntityEnumerator]) {
11878 [sub switchLightsOn];
11879 }
11880}
void switchLightsOn()

References _lightsActive, flasherEnumerator, nil, shipSubEntityEnumerator, and switchLightsOn.

Referenced by coordinates, ShipSetProperty(), ShipSetProperty(), and switchLightsOn.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ takeEnergyDamage:from:becauseOf:weaponIdentifier:

- (void) takeEnergyDamage: (double) amount
from: (Entity*) ent
becauseOf: (Entity*) other
weaponIdentifier: (NSString*) weaponIdentifier 
implementation

Reimplemented from Entity.

Reimplemented in DockEntity, PlayerEntity, and StationEntity.

Definition at line 11427 of file ShipEntity.m.

11427 :(double)amount from:(Entity*)ent becauseOf:(Entity*)other weaponIdentifier:(NSString*)weaponIdentifier
11428{
11429 if ([self status] == STATUS_DEAD)
11430 return;
11431 if (amount <= 0.0)
11432 return;
11433
11434 BOOL energyMine = [ent isCascadeWeapon];
11435 BOOL cascade = NO;
11436 if (energyMine) {
11437 cascade = [self cascadeIfAppropriateWithDamageAmount:amount cascadeOwner:[ent owner]];
11438 }
11439
11440 energy -= amount;
11441 /* Heat increase from energy impacts will never directly cause
11442 * overheating - too easy for missile hits to cause an uncredited
11443 * death by overheating - CIM */
11448 }
11449 }
11450
11451 being_mined = NO;
11452 ShipEntity* hunter = nil;
11453
11454 hunter = [other rootShipEntity];
11455 if (hunter == nil && [other isShip])
11456 hunter = (ShipEntity*)other;
11457
11458 // must check for this before potentially deleting 'other' for cloaking
11459 if ((other) && ([other isShip])) {
11461 }
11462
11463 if (hunter != nil && [self owner] != hunter) // our owner could be the same entity as the one responsible for our taking damage in the case of submunitions
11464 {
11465 if ([hunter isCloaked]) {
11466 [self doScriptEvent:OOJSID("shipBeingAttackedByCloaked") andReactToAIMessage:@"ATTACKED_BY_CLOAKED"];
11467
11468 // lose it!
11469 other = nil;
11470 hunter = nil;
11471 }
11472 } else {
11473 hunter = nil;
11474 }
11475
11476 // if the other entity is a ship note it as an aggressor
11477 if (hunter != nil) {
11478 BOOL iAmTheLaw = [self isPolice];
11479 BOOL uAreTheLaw = [hunter isPolice];
11480
11481 DESTROY(_lastEscortTarget); // we're being attacked, escorts can scramble!
11482
11483 [self setPrimaryAggressor:hunter];
11484 [self setFoundTarget:hunter];
11485
11486 // firing on an innocent ship is an offence
11487 [self broadcastHitByLaserFrom:hunter];
11488
11489 // tell ourselves we've been attacked
11490 if (energy > 0) {
11491 [self respondToAttackFrom:ent becauseOf:hunter];
11492 }
11493
11494 OOShipGroup* group = [self group];
11495 // JSAIs manage group notifications themselves
11496 if (![self hasNewAI]) {
11497 // additionally, tell our group we've been attacked
11498 if (group != nil && group != [hunter group] && !(iAmTheLaw || uAreTheLaw)) {
11499 if ([self isTrader] || [self isEscort]) {
11500 ShipEntity* groupLeader = [group leader];
11501 if (groupLeader != self) {
11502 [groupLeader setFoundTarget:hunter];
11503 [groupLeader setPrimaryAggressor:hunter];
11504 [groupLeader respondToAttackFrom:ent becauseOf:hunter];
11505 // unsetting group leader for carriers can break stuff
11506 }
11507 }
11508 if ([self isPirate]) {
11509 NSEnumerator* groupEnum = nil;
11510 ShipEntity* otherPirate = nil;
11511
11512 for (groupEnum = [group mutationSafeEnumerator]; (otherPirate = [groupEnum nextObject]);) {
11513 if (otherPirate != self && randf() < 0.5) // 50% chance they'll help
11514 {
11515 [otherPirate setFoundTarget:hunter];
11516 [otherPirate setPrimaryAggressor:hunter];
11517 [otherPirate respondToAttackFrom:ent becauseOf:hunter];
11518 }
11519 }
11520 } else if (iAmTheLaw) {
11521 NSEnumerator* groupEnum = nil;
11522 ShipEntity* otherPolice = nil;
11523
11524 for (groupEnum = [group mutationSafeEnumerator]; (otherPolice = [groupEnum nextObject]);) {
11525 if (otherPolice != self) {
11526 [otherPolice setFoundTarget:hunter];
11527 [otherPolice setPrimaryAggressor:hunter];
11528 [otherPolice respondToAttackFrom:ent becauseOf:hunter];
11529 }
11530 }
11531 }
11532 }
11533 }
11534
11535 // if I'm a copper and you're not, then mark the other as an offender!
11536 if (iAmTheLaw && !uAreTheLaw) {
11537 // JSAI's can choose not to do this for friendly fire purposes
11538 if (![self hasNewAI]) {
11539 [hunter markAsOffender:64 withReason:kOOLegalStatusReasonAttackedPolice];
11540 }
11541 }
11542
11543 if ((group != nil && [hunter group] == group) || (iAmTheLaw && uAreTheLaw)) {
11544 // avoid shooting each other
11545 if ([hunter behaviour] == BEHAVIOUR_ATTACK_FLY_TO_TARGET) // avoid me please!
11546 {
11547 [hunter setBehaviour:BEHAVIOUR_ATTACK_FLY_FROM_TARGET];
11548 [hunter setDesiredSpeed:[hunter maxFlightSpeed]];
11549 }
11550 }
11551 }
11552
11553 OOShipDamageType damageType = kOODamageTypeEnergy;
11555 damageType = kOODamageTypeRemoved;
11556 else if (energyMine)
11557 damageType = kOODamageTypeCascadeWeapon;
11558
11559 if (!suppressExplosion) {
11560 [self noteTakingDamage:amount from:other type:damageType];
11561 if (cascade)
11562 energy = 0.0; // explicit set energy to zero in case an oxp raised the energy in previous line.
11563 }
11564
11565 // die if I'm out of energy
11566 if (energy <= 0.0) {
11567 // backup check just in case scripts have reduced energy
11568 if (self != [UNIVERSE station]) {
11569 if (hunter != nil)
11570 [hunter noteTargetDestroyed:self];
11571 [self getDestroyedBy:other damageType:damageType];
11572 }
11573 } else {
11574 // warn if I'm low on energy
11575 if (energy < maxEnergy * 0.25) {
11576 [self doScriptEvent:OOJSID("shipEnergyIsLow") andReactToAIMessage:@"ENERGY_LOW"];
11577 }
11578 if ((energy < maxEnergy * 0.125 || (energy < 64 && energy < amount * 2)) && [self hasEscapePod] && (ranrot_rand() & 3) == 0) // 25% chance he gets to an escape pod
11579 {
11580 [self abandonShip];
11581 }
11582 }
11583}
#define SHIP_ENERGY_DAMAGE_TO_HEAT_FACTOR
Definition ShipEntity.h:67
ShipEntity * rootShipEntity()
Definition Entity.m:566
void setDesiredSpeed:(double amount)
BOOL isTrader()
void noteTargetDestroyed:(ShipEntity *target)

References _lastEscortTarget, abandonShip, behaviour, being_mined, broadcastHitByLaserFrom:, cascadeIfAppropriateWithDamageAmount:cascadeOwner:, DESTROY, doScriptEvent:andReactToAIMessage:, Entity::energy, getDestroyedBy:damageType:, group, hasEscapePod, hasNewAI, heatInsulation, Entity::isCascadeWeapon, isCloaked, isEscort, isMining, isPirate, isPolice, Entity::isShip, isTrader, OOShipGroup::leader, markAsOffender:withReason:, Entity::maxEnergy, maxFlightSpeed, nil, noteTakingDamage:from:type:, noteTargetDestroyed:, Entity::owner, randf(), ranrot_rand, respondToAttackFrom:becauseOf:, Entity::rootShipEntity, setBehaviour:, setDesiredSpeed:, setFoundTarget:, setPrimaryAggressor:, SHIP_ENERGY_DAMAGE_TO_HEAT_FACTOR, SHIP_MAX_CABIN_TEMP, ship_temperature, Entity::status, suppressExplosion, and UNIVERSE.

Referenced by deserializeShipSubEntitiesFrom:, fireDirectLaserShotAt:, fireLaserShotInDirection:weaponIdentifier:, fireSubentityLaserShot:, DockEntity::takeEnergyDamage:from:becauseOf:weaponIdentifier:, and StationEntity::takeEnergyDamage:from:becauseOf:weaponIdentifier:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ takeHeatDamage:

- (void) takeHeatDamage: (double) amount

Reimplemented in PlayerEntity, and StationEntity.

Definition at line 11687 of file ShipEntity.m.

11687 :(double)amount
11688{
11689 if ([self status] == STATUS_DEAD)
11690 return;
11691
11692 if ([self isSubEntity]) {
11693 ShipEntity* owner = [self owner];
11694 if (![owner isFrangible]) {
11695 return;
11696 }
11697 }
11698
11699 energy -= amount;
11700 throw_sparks = YES;
11701
11702 [self noteTakingDamage:amount from:nil type:kOODamageTypeHeat];
11703
11704 // oops we're burning up!
11705 if (energy <= 0.0) {
11706 [self getDestroyedBy:nil damageType:kOODamageTypeHeat];
11707 } else {
11708 // warn if I'm low on energy
11709 if (energy < maxEnergy * 0.25) {
11710 [self doScriptEvent:OOJSID("shipEnergyIsLow") andReactToAIMessage:@"ENERGY_LOW"];
11711 }
11712 }
11713}
unsigned throw_sparks
Definition Entity.h:97

References doScriptEvent:andReactToAIMessage:, Entity::energy, getDestroyedBy:damageType:, isFrangible, Entity::isSubEntity, Entity::maxEnergy, noteTakingDamage:from:type:, Entity::owner, Entity::status, and Entity::throw_sparks.

Referenced by PlayerEntity::takeHeatDamage:, StationEntity::takeHeatDamage:, and update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ takeScrapeDamage:from:

- (void) takeScrapeDamage: (double) amount
from: (Entity*) ent 

Reimplemented in PlayerEntity, and StationEntity.

Definition at line 11650 of file ShipEntity.m.

11650 :(double)amount from:(Entity*)ent
11651{
11652 if ([self status] == STATUS_DEAD)
11653 return;
11654
11655 if ([self status] == STATUS_LAUNCHING || [ent status] == STATUS_LAUNCHING) {
11656 // no collisions during launches please
11657 return;
11658 }
11659
11660 energy -= amount;
11661 [self noteTakingDamage:amount from:ent type:kOODamageTypeScrape];
11662
11663 // oops we hit too hard!!!
11664 if (energy <= 0.0) {
11665 float frag_chance = [ent mass] * 10 / [self mass];
11666 /* impacts from heavier entities produce fragments
11667 * impacts from lighter entities might do but not always
11668 * asteroid-asteroid impacts likely to fragment
11669 * ship-asteroid impacts might, or might just vaporise it
11670 * projectile weapons just get the default chance
11671 */
11672 if (randf() < frag_chance) {
11673 being_mined = YES; // same as using a mining laser
11674 }
11675 if ([ent isShip]) {
11677 }
11678 [self getDestroyedBy:ent damageType:kOODamageTypeScrape];
11679 } else {
11680 // warn if I'm low on energy
11681 if (energy < maxEnergy * 0.25) {
11682 [self doScriptEvent:OOJSID("shipEnergyIsLow") andReactToAIMessage:@"ENERGY_LOW"];
11683 }
11684 }
11685}

References being_mined, doScriptEvent:andReactToAIMessage:, Entity::energy, getDestroyedBy:damageType:, Entity::isShip, Entity::mass, Entity::maxEnergy, noteTakingDamage:from:type:, noteTargetDestroyed:, randf(), and Entity::status.

Referenced by collideWithShip:, DockEntity::shipIsInDockingCorridor:, PlayerEntity::takeScrapeDamage:from:, and StationEntity::takeScrapeDamage:from:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ targetFirstBeaconWithCode:

- (void) targetFirstBeaconWithCode: (NSString*) code
implementation

Provided by category ShipEntity(PureAI).

Definition at line 2321 of file ShipEntityAI.m.

2321 :(NSString*)code
2322{
2323 NSArray* all_beacons = [UNIVERSE listBeaconsWithCode:code];
2324 if ([all_beacons count]) {
2325 [self addTarget:(ShipEntity*)[all_beacons objectAtIndex:0]];
2326 [shipAI message:@"TARGET_FOUND"];
2327 } else
2328 [shipAI message:@"NOTHING_FOUND"];
2329}

◆ targetNextBeaconWithCode:

- (void) targetNextBeaconWithCode: (NSString*) code
implementation

Provided by category ShipEntity(PureAI).

Definition at line 2331 of file ShipEntityAI.m.

2331 :(NSString*)code
2332{
2333 NSArray* all_beacons = [UNIVERSE listBeaconsWithCode:code];
2334 ShipEntity* current_beacon = [self primaryTarget];
2335
2336 if ((!current_beacon) || (![current_beacon isBeacon])) {
2337 [shipAI message:@"NO_CURRENT_BEACON"];
2338 [shipAI message:@"NOTHING_FOUND"];
2339 return;
2340 }
2341
2342 // find the current beacon in the list..
2343 NSUInteger i = [all_beacons indexOfObject:current_beacon];
2344
2345 if (i == NSNotFound) {
2346 [shipAI message:@"NOTHING_FOUND"];
2347 return;
2348 }
2349
2350 i++; // next index
2351
2352 if (i < [all_beacons count]) {
2353 // locate current target in list
2354 [self addTarget:(ShipEntity*)[all_beacons objectAtIndex:i]];
2355 [shipAI message:@"TARGET_FOUND"];
2356 } else {
2357 [shipAI message:@"LAST_BEACON"];
2358 [shipAI message:@"NOTHING_FOUND"];
2359 }
2360}
BOOL isBeacon()

◆ targetStation

- (StationEntity *) targetStation

Definition at line 8628 of file ShipEntity.m.

8629{
8630 StationEntity* result = [_targetStation weakRefUnderlyingObject];
8631 if (result == nil || ![self isValidTarget:result]) {
8633 return nil;
8634 }
8635 return result;
8636}

References _targetStation, DESTROY, nil, targetStation, and OOWeakReference::weakRefUnderlyingObject.

Referenced by behaviour_fly_to_destination:, PlayerEntity::cancelDockingRequest:, PlayerEntity::engageAutopilotToStation:, maxFlightSpeed, PlayerEntity::performDockingRequest:, ShipEntity(AI)::requestDockingCoordinates, ShipEntity(PureAI)::setDestinationToDockingAbort, ShipEntity(PureAI)::setTargetToLastStation, targetStation, and trackDestination:retreat:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ temperature

- (GLfloat) temperature

Definition at line 7561 of file ShipEntity.m.

7562{
7563 return ship_temperature;
7564}

References ship_temperature, and temperature.

Referenced by PlayerEntity::createDoppelganger, maxFlightSpeed, randomEjectaTemperatureWithMaxFactor:, temperature, and update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ thankedShip

- (Entity *) thankedShip

Definition at line 8596 of file ShipEntity.m.

8597{
8598 Entity* result = [_thankedShip weakRefUnderlyingObject];
8599 if (result == nil || ![self isValidTarget:result]) {
8601 return nil;
8602 }
8603 return result;
8604}

References _thankedShip, DESTROY, nil, thankedShip, and OOWeakReference::weakRefUnderlyingObject.

Referenced by interpretAIMessage:, maxFlightSpeed, and thankedShip.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ thargonCheckMother

- (void) thargonCheckMother
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1488 of file ShipEntityAI.m.

1489{
1490 ShipEntity* mother = [self owner];
1491 if (mother == nil && [self group])
1492 mother = [[self group] leader];
1493
1494 double maxRange2 = scannerRange * scannerRange;
1495
1496 if (mother && mother != self && HPdistance2(mother->position, position) < maxRange2) {
1497 [shipAI message:@"TARGET_FOUND"]; // no need for scanning, we still have our mother.
1498 } else {
1499 // we lost the old mother, search for a new one
1500 [self scanForNearestShipHavingRole:@"thargoid-mothership"]; // the scan will send further AI messages.
1501 if ([self foundTarget] != nil) {
1502 mother = (ShipEntity*)[self foundTarget];
1503 [self setOwner:mother];
1504 if ([mother group] != [mother escortGroup]) // avoid adding thargon to an escort group.
1505 {
1506 [self setGroup:[mother group]];
1507 }
1508 };
1509 }
1510}

◆ throwSparks

- (void) throwSparks
implementation

Reimplemented from Entity.

Definition at line 10498 of file ShipEntity.m.

10499{
10500 Vector offset = {
10501 randf() * (boundingBox.max.x - boundingBox.min.x) + boundingBox.min.x,
10502 randf() * (boundingBox.max.y - boundingBox.min.y) + boundingBox.min.y,
10503 randf() * boundingBox.max.z + boundingBox.min.z // rear section only
10504 };
10506
10507 float w = boundingBox.max.x - boundingBox.min.x;
10508 float h = boundingBox.max.y - boundingBox.min.y;
10509 float m = (w < h) ? 0.25 * w : 0.25 * h;
10510
10511 float sz = m * (1 + randf() + randf()); // half minimum dimension on average
10512
10514
10515 OOColor* color = [OOColor colorWithHue:0.08 + 0.17 * randf() saturation:1.0 brightness:1.0 alpha:1.0];
10516
10517 OOSparkEntity* spark = [[OOSparkEntity alloc] initWithPosition:origin
10518 velocity:vel
10519 duration:2.0 + 3.0 * randf()
10520 size:sz
10521 color:color];
10522
10523 [spark setOwner:self];
10524 [UNIVERSE addEntity:spark];
10525 [spark release];
10526
10528}
double next_spark_time
Definition ShipEntity.h:373

References Entity::boundingBox, OOColor::colorWithHue:saturation:brightness:alpha:, HPvector_add(), HPvector_subtract(), HPVectorToVector(), next_spark_time, Entity::normalOrientation, Entity::position, quaternion_rotate_vector(), randf(), Entity::setOwner:, throwSparks, vector_multiply_scalar(), and vectorToHPVector().

Referenced by throwSparks, and update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ thrust

- (float) thrust

References thrust.

◆ thrustVector

- (Vector) thrustVector

Definition at line 11167 of file ShipEntity.m.

11168{
11170}

References flightSpeed, thrustVector, v_forward, and vector_multiply_scalar().

Referenced by cruiseSpeed, setTotalVelocity:, thrustVector, and velocity.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ totalBoundingBox

References forwardVector, rightVector, totalBoundingBox, and upVector.

Here is the call graph for this function:

◆ trackCloseContacts

References trackCloseContacts.

◆ trackDestination:retreat:

- (double) trackDestination: (double) delta_t
retreat: (BOOL) retreat 

Definition at line 9459 of file ShipEntity.m.

9459 :(double)delta_t retreat:(BOOL)retreat
9460{
9461 Vector relPos;
9462 GLfloat d_forward, d_up, d_right;
9463
9464 BOOL we_are_docking = (nil != dockingInstructions);
9465
9466 stick_roll = 0.0; // desired roll and pitch
9467 stick_pitch = 0.0;
9468 stick_yaw = 0.0;
9469
9470 double reverse = 1.0;
9471 double reversePlayer = 1.0;
9472
9473 double min_d = 0.004;
9474 double max_cos = MAX_COS; // should match default value of max_cos in behaviour_fly_to_destination!
9475 double precision = we_are_docking ? 0.25 : 0.9025; // lower values force a direction closer to the target. (resp. 50% and 95% within range)
9476
9477 if (retreat)
9478 reverse = -reverse;
9479
9480 if (isPlayer) {
9481 reverse = -reverse;
9482 reversePlayer = -1;
9483 }
9484
9486 double range2 = magnitude2(relPos);
9487 double desired_range2 = desired_range * desired_range;
9488
9489 /* 2009-7-18 Eric: We need to aim well inide the desired_range sphere round the target and not at the surface of the sphere.
9490 Because of the framerate most ships normally overshoot the target and they end up flying clearly on a path
9491 through the sphere. Those ships give no problems, but ships with a very low turnrate will aim close to the surface and will than
9492 have large trouble with reaching their destination. When those ships enter the slowdown range, they have almost no speed vector
9493 in the direction of the target. I now used 95% of desired_range to aim at, but a smaller value might even be better.
9494 */
9495 if (range2 > desired_range2) {
9496 max_cos = sqrt(1 - precision * desired_range2 / range2); // Head for a point within 95% of desired_range.
9497 if (max_cos >= 0.99999) {
9498 max_cos = 0.99999;
9499 }
9500 }
9501
9502 if (!vector_equal(relPos, kZeroVector))
9503 relPos = vector_normal(relPos);
9504 else
9505 relPos.z = 1.0;
9506
9507 d_right = dot_product(relPos, v_right);
9508 d_up = dot_product(relPos, v_up);
9509 d_forward = dot_product(relPos, v_forward); // == cos of angle between v_forward and vector to target
9510
9511 // begin rule-of-thumb manoeuvres
9512 stick_pitch = 0.0;
9513 stick_roll = 0.0;
9514
9515 // pitching_over is currently only set in behaviour_formation_form_up, for escorts and in avoidCollision.
9516 // This allows for immediate pitch corrections instead of first waiting untill roll has completed.
9517 if (pitching_over) {
9518 if (reverse * d_up > 0) // pitch up
9520 else
9522 pitching_over = (reverse * d_forward < 0.707);
9523 }
9524
9525 // check if we are flying toward (or away from) the destination..
9526 if ((d_forward < max_cos) || (retreat)) // not on course so we must adjust controls..
9527 {
9528
9529 if (d_forward <= -max_cos || (retreat && d_forward >= max_cos)) // hack to avoid just flying away from the destination
9530 {
9531 d_up = min_d * 2.0;
9532 }
9533
9534 if (d_up > min_d) {
9535 int factor = sqrt(fabs(d_right) / fabs(min_d));
9536 if (factor > 8)
9537 factor = 8;
9538 if (d_right > min_d)
9539 stick_roll = -max_flight_roll * reversePlayer * 0.125 * factor; // only reverse sign for the player;
9540 if (d_right < -min_d)
9541 stick_roll = +max_flight_roll * reversePlayer * 0.125 * factor;
9542 if (fabs(d_right) < fabs(stick_roll) * delta_t)
9543 stick_roll = fabs(d_right) / delta_t * (stick_roll < 0 ? -1 : 1); // don't overshoot heading
9544 }
9545
9546 if (d_up < -min_d) {
9547 int factor = sqrt(fabs(d_right) / fabs(min_d));
9548 if (factor > 8)
9549 factor = 8;
9550 if (d_right > min_d)
9551 stick_roll = +max_flight_roll * reversePlayer * 0.125 * factor; // only reverse sign for the player;
9552 if (d_right < -min_d)
9553 stick_roll = -max_flight_roll * reversePlayer * 0.125 * factor;
9554 if (fabs(d_right) < fabs(stick_roll) * delta_t)
9555 stick_roll = fabs(d_right) / delta_t * (stick_roll < 0 ? -1 : 1); // don't overshoot heading
9556 }
9557
9558 if (stick_roll == 0.0) {
9559 int factor = sqrt(fabs(d_up) / fabs(min_d));
9560 if (factor > 8)
9561 factor = 8;
9562 if (d_up > min_d)
9563 stick_pitch = -max_flight_pitch * reverse * 0.125 * factor; // pitch_pitch * reverse;
9564 if (d_up < -min_d)
9565 stick_pitch = +max_flight_pitch * reverse * 0.125 * factor;
9566 if (fabs(d_up) < fabs(stick_pitch) * delta_t)
9567 stick_pitch = fabs(d_up) / delta_t * (stick_pitch < 0 ? -1 : 1); // don't overshoot heading
9568 }
9569
9570 if (stick_pitch == 0.0) {
9571 // not sufficiently on course yet, but min_d is too high
9572 // turn anyway slightly to adjust
9573 stick_pitch = 0.01;
9574 }
9575 }
9576
9577 if (we_are_docking && docking_match_rotation && (d_forward > max_cos)) {
9578 /* we are docking and need to consider the rotation/orientation of the docking port */
9579 StationEntity* station_for_docking = (StationEntity*)[self targetStation];
9580
9581 if ((station_for_docking) && (station_for_docking->isStation)) {
9582 stick_roll = [self rollToMatchUp:[station_for_docking portUpVectorForShip:self] rotating:[station_for_docking flightRoll]];
9583 }
9584 }
9585
9586 // end rule-of-thumb manoeuvres
9587
9588 [self applySticks:delta_t];
9589
9590 if (retreat)
9591 d_forward *= d_forward; // make positive AND decrease granularity
9592
9593 if (d_forward < 0.0)
9594 return 0.0;
9595
9596 if ((!flightRoll) && (!flightPitch)) // no correction
9597 return 1.0;
9598
9599 return d_forward;
9600}
Vector portUpVectorForShip:(ShipEntity *ship)

References _destination, applySticks:, desired_range, docking_match_rotation, dockingInstructions, dot_product(), flightPitch, flightRoll, HPvector_subtract(), HPVectorToVector(), Entity::isPlayer, Entity::isStation, kZeroVector, magnitude2(), MAX_COS, max_flight_pitch, max_flight_roll, nil, pitching_over, StationEntity::portUpVectorForShip:, Entity::position, rollToMatchUp:rotating:, stick_pitch, stick_roll, stick_yaw, targetStation, v_forward, v_right, v_up, vector_equal(), vector_normal(), and Vector::z.

Referenced by behaviour_avoid_collision:, behaviour_face_destination:, behaviour_fly_from_destination:, behaviour_fly_thru_navpoints:, behaviour_fly_to_destination:, behaviour_fly_to_target_six:, behaviour_formation_form_up:, behaviour_intercept_target:, and behaviour_land_on_planet:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ trackOntoTarget:withDForward:

- (void) trackOntoTarget: (double) delta_t
withDForward: (GLfloat) dp 

Definition at line 8879 of file ShipEntity.m.

8879 :(double)delta_t withDForward:(GLfloat)dp
8880{
8881 Vector vector_to_target;
8882 Quaternion q_minarc;
8883 //
8884 Entity* target = [self primaryTarget];
8885 //
8886 if (!target)
8887 return;
8888
8889 vector_to_target = [self vectorTo:target];
8890 //
8891 GLfloat range2 = magnitude2(vector_to_target);
8892 GLfloat targetRadius = 0.75 * target->collision_radius;
8893 GLfloat max_cos = sqrt(1 - targetRadius * targetRadius / range2);
8894
8895 if (dp > max_cos)
8896 return; // ON TARGET!
8897
8898 if (vector_to_target.x || vector_to_target.y || vector_to_target.z)
8899 vector_to_target = vector_normal(vector_to_target);
8900 else
8901 vector_to_target.z = 1.0;
8902
8903 q_minarc = quaternion_rotation_between(v_forward, vector_to_target);
8904
8906 [self orientationChanged];
8907
8908 flightRoll = 0.0;
8909 flightPitch = 0.0;
8910 flightYaw = 0.0;
8911 stick_roll = 0.0;
8912 stick_pitch = 0.0;
8913 stick_yaw = 0.0;
8914}

References Entity::collision_radius, flightPitch, flightRoll, flightYaw, magnitude2(), Entity::orientation, orientationChanged, primaryTarget, quaternion_multiply(), quaternion_rotation_between(), stick_pitch, stick_roll, stick_yaw, v_forward, vector_normal(), Entity::vectorTo:, Vector::x, Vector::y, and Vector::z.

Here is the call graph for this function:

◆ trackPrimaryTarget:retreat:

- (double) trackPrimaryTarget: (double) delta_t
retreat: (BOOL) retreat 

Definition at line 9043 of file ShipEntity.m.

9043 :(double)delta_t retreat:(BOOL)retreat
9044{
9045 Entity* target = [self primaryTarget];
9046
9047 if (!target) // leave now!
9048 {
9049 [self noteLostTargetAndGoIdle]; // NOTE: was AI message: rather than reactToMessage:
9050 return 0.0;
9051 }
9052
9053 if (![self canStillTrackPrimaryTarget]) {
9054 [self noteLostTargetAndGoIdle]; // NOTE: was AI message: rather than reactToMessage:
9055 return 0.0;
9056 }
9057
9058 /* 1.81 change: do the above check first: if a missile can't be
9059 * fired outside scanner range it should self-destruct if the
9060 * target gets far enough away (it's going to miss anyway) -
9061 * CIM */
9062 if (scanClass == CLASS_MISSILE)
9063 return [self missileTrackPrimaryTarget:delta_t];
9064
9065 GLfloat d_forward, d_up, d_right;
9066
9068
9069 double range2 = HPmagnitude2(HPvector_subtract([target position], position));
9070
9071 // jink if retreating
9072 if (retreat) // calculate jink position when flying away from target.
9073 {
9074 Vector vx, vy, vz;
9075 if (target->isShip) {
9076 ShipEntity* targetShip = (ShipEntity*)target;
9077 vx = targetShip->v_right;
9078 vy = targetShip->v_up;
9079 vz = targetShip->v_forward;
9080 } else {
9081 Quaternion q = target->orientation;
9085 }
9086
9087 BOOL avoidCollision = NO;
9088 if (range2 < collision_radius * target->collision_radius * 100.0) // Check direction within 10 * collision radius.
9089 {
9090 Vector targetDirection = kBasisZVector;
9091 if (!vector_equal(relPos, kZeroVector))
9092 targetDirection = vector_normal(relPos);
9093 avoidCollision = (dot_product(targetDirection, v_forward) > -0.1); // is flying toward target or only slightly outward.
9094 }
9095
9096 GLfloat dist_adjust_factor = 1.0;
9098 double range = magnitude(relPos);
9099 if (range > 2000.0) {
9100 dist_adjust_factor = range / 2000.0;
9102 dist_adjust_factor *= 3;
9103 }
9104 }
9105 if (jink.x == 0.0 && behaviour != BEHAVIOUR_RUNNING_DEFENSE) { // test for zero jink and correct
9106 [self setEvasiveJink:400.0];
9107 }
9108 }
9109
9110 if (!avoidCollision) // it is safe to jink
9111 {
9112 relPos.x += (jink.x * vx.x + jink.y * vy.x + jink.z * vz.x) * dist_adjust_factor;
9113 relPos.y += (jink.x * vx.y + jink.y * vy.y + jink.z * vz.y) * dist_adjust_factor;
9114 relPos.z += (jink.x * vx.z + jink.y * vy.z + jink.z * vz.z);
9115 }
9116 }
9117
9118 if (!vector_equal(relPos, kZeroVector))
9119 relPos = vector_normal(relPos);
9120 else
9121 relPos.z = 1.0;
9122
9123 double max_cos = [self currentAimTolerance];
9124
9125 stick_roll = 0.0; // desired roll and pitch
9126 stick_pitch = 0.0;
9127
9128 double reverse = (retreat) ? -1.0 : 1.0;
9129
9130 double min_d = 0.004; // ~= 40m at 10km
9131 int max_factor = 8;
9132 double r_max_factor = 0.125;
9133 if (!retreat) {
9135 // much greater precision in combat
9136 if (max_flight_pitch > 1.0) {
9137 max_factor = floor(max_flight_pitch / 0.125);
9138 r_max_factor = 1.0 / max_factor;
9139 }
9140 min_d = 0.0004; // 10 times more precision ~= 4m at 10km
9141 max_factor *= 3;
9142 r_max_factor /= 3.0;
9143 } else if (accuracy >= COMBAT_AI_ISNT_AWFUL) {
9144 // slowly improve precision to target, but only if missing
9145 min_d -= 0.0001 * [self missedShots];
9146 if (min_d < 0.001) {
9147 min_d = 0.001;
9148 max_factor *= 2;
9149 r_max_factor /= 2.0;
9150 }
9151 }
9152 }
9153
9154 d_right = dot_product(relPos, v_right);
9155 d_up = dot_product(relPos, v_up);
9156 d_forward = dot_product(relPos, v_forward); // == cos of angle between v_forward and vector to target
9157
9158 if (d_forward * reverse > max_cos) // on_target!
9159 {
9160 return d_forward;
9161 }
9162
9163 // begin rule-of-thumb manoeuvres
9164 stick_pitch = 0.0;
9165 stick_roll = 0.0;
9166
9167 if ((reverse * d_forward < -0.5) && !pitching_over) // we're going the wrong way!
9168 pitching_over = YES;
9169
9170 if (pitching_over) {
9171 if (reverse * d_up > 0) // pitch up
9173 else
9175 pitching_over = (reverse * d_forward < 0.707);
9176 }
9177
9178 // check if we are flying toward the destination..
9179 if ((d_forward < max_cos) || (retreat)) // not on course so we must adjust controls..
9180 {
9181 if (d_forward < -max_cos) // hack to avoid just flying away from the destination
9182 {
9183 d_up = min_d * 2.0;
9184 }
9185
9186 if (d_up > min_d) {
9187 int factor = sqrt(fabs(d_right) / fabs(min_d));
9188 if (factor > max_factor)
9189 factor = max_factor;
9190 if (d_right > min_d)
9191 stick_roll = -max_flight_roll * r_max_factor * factor; // note#
9192 if (d_right < -min_d)
9193 stick_roll = +max_flight_roll * r_max_factor * factor; // note#
9194 }
9195 if (d_up < -min_d) {
9196 int factor = sqrt(fabs(d_right) / fabs(min_d));
9197 if (factor > max_factor)
9198 factor = max_factor;
9199 if (d_right > min_d)
9200 stick_roll = +max_flight_roll * r_max_factor * factor; // note#
9201 if (d_right < -min_d)
9202 stick_roll = -max_flight_roll * r_max_factor * factor; // note#
9203 }
9204
9205 if (stick_roll == 0.0) {
9206 int factor = sqrt(fabs(d_up) / fabs(min_d));
9207 if (factor > max_factor)
9208 factor = max_factor;
9209 if (d_up > min_d)
9210 stick_pitch = -max_flight_pitch * reverse * r_max_factor * factor;
9211 if (d_up < -min_d)
9212 stick_pitch = +max_flight_pitch * reverse * r_max_factor * factor;
9213 }
9214
9216 // don't overshoot target (helps accuracy at low frame rates)
9217 if (fabs(d_right) < fabs(stick_roll) * delta_t) {
9218 stick_roll = fabs(d_right) / delta_t * (stick_roll < 0 ? -1 : 1);
9219 }
9220 if (fabs(d_up) < fabs(stick_pitch) * delta_t) {
9221 stick_pitch = fabs(d_up) / delta_t * (stick_pitch < 0 ? -0.9 : 0.9);
9222 }
9223 }
9224 }
9225 /* # note
9226 Eric 9-9-2010: Removed the "reverse" variable from the stick_roll calculation. This was mathematical wrong and
9227 made the ship roll in the wrong direction, preventing the ship to fly away in a straight line from the target.
9228 This means all the places were a jink was set, this jink never worked correctly. The main reason a ship still
9229 managed to turn at close range was probably by the fail-safe mechanisme with the "pitching_over" variable.
9230 The jink was programmed to do nothing within 500 meters of the ship and just fly away in direct line from the target
9231 in that range. Because of the bug the ships always rolled to the wrong side needed to fly away in direct line
9232 resulting in making it a difficult target.
9233 After fixing the bug, the ship realy flew away in direct line during the first 500 meters, making it a easy target
9234 for the player. All jink settings are retested and changed to give a turning behaviour that felt like the old
9235 situation, but now more deliberately set.
9236 */
9237
9238 // end rule-of-thumb manoeuvres
9239 stick_yaw = 0.0;
9240
9241 [self applySticks:delta_t];
9242
9243 if (retreat)
9244 d_forward *= d_forward; // make positive AND decrease granularity
9245
9246 if (d_forward < 0.0)
9247 return 0.0;
9248
9249 if ((!flightRoll) && (!flightPitch)) // no correction
9250 return 1.0;
9251
9252 return d_forward;
9253}
void avoidCollision()

References accuracy, applySticks:, avoidCollision, behaviour, calculateTargetPosition, canStillTrackPrimaryTarget, Entity::collision_radius, COMBAT_AI_FLEES_BETTER, COMBAT_AI_FLEES_BETTER_2, COMBAT_AI_ISNT_AWFUL, COMBAT_AI_TRACKS_CLOSER, currentAimTolerance, dot_product(), flightPitch, flightRoll, HPmagnitude2(), HPvector_subtract(), HPVectorToVector(), Entity::isShip, jink, kBasisZVector, kZeroVector, magnitude(), max_flight_pitch, max_flight_roll, missedShots, missileTrackPrimaryTarget:, noteLostTargetAndGoIdle, Entity::orientation, pitching_over, Entity::position, primaryTarget, scanClass, setEvasiveJink:, stick_pitch, stick_roll, stick_yaw, v_forward, v_right, v_up, vector_equal(), vector_forward_from_quaternion(), vector_normal(), vector_right_from_quaternion(), vector_up_from_quaternion(), Vector::x, Vector::y, and Vector::z.

Referenced by behaviour_attack_break_off_target:, behaviour_attack_fly_from_target:, behaviour_attack_fly_to_target:, behaviour_attack_mining_target:, behaviour_attack_slow_dogfight:, behaviour_attack_sniper:, behaviour_flee_target:, behaviour_intercept_target:, behaviour_running_defense:, and behaviour_track_target:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ trackSideTarget:leftside:

- (double) trackSideTarget: (double) delta_t
leftside: (BOOL) leftside 

Definition at line 9255 of file ShipEntity.m.

9255 :(double)delta_t leftside:(BOOL)leftside
9256{
9257 Entity* target = [self primaryTarget];
9258
9259 if (!target) // leave now!
9260 {
9261 [self noteLostTargetAndGoIdle]; // NOTE: was AI message: rather than reactToMessage:
9262 return 0.0;
9263 }
9264
9265 if (![self canStillTrackPrimaryTarget]) {
9266 [self noteLostTargetAndGoIdle]; // NOTE: was AI message: rather than reactToMessage:
9267 return 0.0;
9268 }
9269
9270 if (scanClass == CLASS_MISSILE) // never?
9271 return [self missileTrackPrimaryTarget:delta_t];
9272
9273 GLfloat d_forward, d_up, d_right;
9274
9276
9277 if (!vector_equal(relPos, kZeroVector))
9278 relPos = vector_normal(relPos);
9279 else
9280 relPos.z = 1.0;
9281
9282 // worse shots with side lasers than fore/aft, in general
9283
9284 double max_cos = [self currentAimTolerance];
9285
9286 stick_roll = 0.0; // desired roll and pitch
9287 stick_pitch = 0.0;
9288 stick_yaw = 0.0;
9289
9290 double reverse = (leftside) ? -1.0 : 1.0;
9291
9292 double min_d = 0.004;
9294 min_d = 0.002;
9295 }
9296 int max_factor = 8;
9297 double r_max_factor = 0.125;
9298
9299 d_right = dot_product(relPos, v_right);
9300 d_up = dot_product(relPos, v_up);
9301 d_forward = dot_product(relPos, v_forward); // == cos of angle between v_forward and vector to target
9302
9303 if (d_right * reverse > max_cos) // on_target!
9304 {
9305 return d_right * reverse;
9306 }
9307
9308 // begin rule-of-thumb manoeuvres
9309 stick_pitch = 0.0;
9310 stick_roll = 0.0;
9311 stick_yaw = 0.0;
9312
9313 // check if we are flying toward the destination..
9314 if ((d_right * reverse < max_cos)) // not on course so we must adjust controls..
9315 {
9316 if (d_right < -max_cos) // hack to avoid just pointing away from the destination
9317 {
9318 d_forward = min_d * 2.0;
9319 }
9320
9321 if (d_forward > min_d) {
9322 int factor = sqrt(fabs(d_up) / fabs(min_d));
9323 if (factor > max_factor)
9324 factor = max_factor;
9325 if (d_up > min_d)
9326 stick_pitch = +max_flight_pitch * r_max_factor * factor; // note#
9327 if (d_up < -min_d)
9328 stick_pitch = -max_flight_pitch * r_max_factor * factor; // note#
9329 }
9330 if (d_forward < -min_d) {
9331 int factor = sqrt(fabs(d_up) / fabs(min_d));
9332 if (factor > max_factor)
9333 factor = max_factor;
9334 if (d_up > min_d)
9335 stick_pitch = +max_flight_pitch * r_max_factor * factor; // note#
9336 if (d_up < -min_d)
9337 stick_pitch = -max_flight_pitch * r_max_factor * factor; // note#
9338 }
9339
9340 if (fabs(stick_pitch) == 0.0 || fabs(d_forward) > 0.5) {
9341 stick_pitch = 0.0;
9342 int factor = sqrt(fabs(d_forward) / fabs(min_d));
9343 if (factor > max_factor)
9344 factor = max_factor;
9345 if (d_forward > min_d)
9346 stick_yaw = -max_flight_yaw * reverse * r_max_factor * factor;
9347 if (d_forward < -min_d) {
9348 if (factor < max_factor / 2.0) // compensate for forward thrust
9349 factor *= 2.0;
9350 stick_yaw = +max_flight_yaw * reverse * r_max_factor * factor;
9351 }
9352 }
9353 }
9354
9355 // end rule-of-thumb manoeuvres
9356
9357 [self applySticks:delta_t];
9358
9359 if ((!flightPitch) && (!flightYaw)) // no correction
9360 return 1.0;
9361
9362 return d_right * reverse;
9363}

References accuracy, applySticks:, calculateTargetPosition, canStillTrackPrimaryTarget, COMBAT_AI_TRACKS_CLOSER, currentAimTolerance, dot_product(), flightPitch, flightYaw, HPvector_subtract(), HPVectorToVector(), kZeroVector, max_flight_pitch, max_flight_yaw, missileTrackPrimaryTarget:, noteLostTargetAndGoIdle, Entity::position, primaryTarget, scanClass, stick_pitch, stick_roll, stick_yaw, v_forward, v_right, v_up, vector_equal(), vector_normal(), and Vector::z.

Referenced by behaviour_attack_broadside_target:leftside:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ transitionToAegisNone

- (void) transitionToAegisNone

Definition at line 6546 of file ShipEntity.m.

6547{
6549 Entity<OOStellarBody>* lastAegisLock = [self lastAegisLock];
6550 if (lastAegisLock != nil) {
6551 [self doScriptEvent:OOJSID("shipExitedPlanetaryVicinity") withArgument:lastAegisLock];
6552
6553 if (lastAegisLock == [UNIVERSE sun]) {
6554 [shipAI message:@"AWAY_FROM_SUN"];
6555 } else {
6556 [shipAI message:@"AWAY_FROM_PLANET"];
6557 }
6558 }
6559
6561 [shipAI message:@"AEGIS_NONE"];
6562 }
6563 }
6565}

References AEGIS_CLOSE_TO_ANY_PLANET, AEGIS_NONE, aegis_status, doScriptEvent:withArgument:, lastAegisLock, AI::message:, nil, suppressAegisMessages, transitionToAegisNone, and UNIVERSE.

Referenced by checkForAegis, reportAIMessages, transitionToAegisNone, and PlayerEntity(OOPrivate)::witchStart.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ turretCount

- (NSUInteger) turretCount

Definition at line 6085 of file ShipEntity.m.

6086{
6087 NSUInteger count = 0;
6088 NSEnumerator* subEnum = [self shipSubEntityEnumerator];
6089 ShipEntity* se = nil;
6090 while ((se = [subEnum nextObject])) {
6091 if ([se isTurret]) {
6092 count++;
6093 }
6094 }
6095 return count;
6096}
BOOL isTurret()

References count, isTurret, nil, shipSubEntityEnumerator, and turretCount.

Referenced by messageTime, OOShipLibraryTurrets(), and turretCount.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update:

- (void) update: (OOTimeDelta) delta_t
implementation

Reimplemented from Entity.

Reimplemented in DockEntity, PlayerEntity, and StationEntity.

Definition at line 2083 of file ShipEntity.m.

2083 :(OOTimeDelta)delta_t
2084{
2085 if (shipinfoDictionary == nil) {
2086 OOLog(@"shipEntity.notDict", @"Ship %@ was not set up from dictionary.", self);
2087 [UNIVERSE removeEntity:self];
2088 return;
2089 }
2090
2091 if (!isfinite(maxFlightSpeed)) {
2092 OOLog(@"ship.sanityCheck.failed", @"Ship %@ %@ infinite top speed, clamped to 300.", self, @"had");
2093 maxFlightSpeed = 300;
2094 }
2095
2096 bool isSubEnt = [self isSubEntity];
2097
2098 if (isDemoShip) {
2099 if (demoRate > 0) {
2100 OOScalar cos1 = cos(M_PI * ([UNIVERSE getTime] - demoStartTime) * demoRate / 11);
2101 OOScalar sin1 = sin(M_PI * ([UNIVERSE getTime] - demoStartTime) * demoRate / 11);
2102 OOScalar cos2 = cos(-M_PI * ([UNIVERSE getTime] - demoStartTime) * demoRate / 15);
2103 OOScalar sin2 = sin(-M_PI * ([UNIVERSE getTime] - demoStartTime) * demoRate / 15);
2104 Quaternion q1 = make_quaternion(cos1, sin1 * sqrt(3) / 2, sin1 / 2, 0);
2105 Quaternion q2 = make_quaternion(cos2, -sin2 * sqrt(4) / sqrt(5), 0, sin2 * sqrt(1) / sqrt(5));
2106 [self setOrientation:quaternion_multiply(q2, quaternion_multiply(q1, demoStartOrientation))];
2107 }
2108
2109 [super update:delta_t];
2110 if ([self subEntityCount] > 0) {
2111 // only copy the subent array if there are subentities
2112 ShipEntity* se = nil;
2113 foreach (se, [self subEntities]) {
2114 [se update:delta_t];
2115 if ([se isShip]) {
2116 BoundingBox sebb = [se findSubentityBoundingBox];
2119 }
2120 }
2121 }
2122 return;
2123 }
2124
2125 if (!isSubEnt) {
2126 if (scanClass == CLASS_NOT_SET) {
2127 scanClass = CLASS_NEUTRAL;
2128 OOLog(@"ship.sanityCheck.failed", @"Ship %@ %@ with scanClass CLASS_NOT_SET; forced to CLASS_NEUTRAL.", self, [self primaryRole]);
2129 }
2130
2131 [self updateTrackingCurve];
2132
2133 //
2134 // deal with collisions
2135 //
2136 [self manageCollisions];
2137
2138 // subentity collisions managed via parent entity
2139
2140 //
2141 // reset any inadvertant legal mishaps
2142 //
2143 if (scanClass == CLASS_POLICE) {
2144 if (bounty > 0) {
2145 [self setBounty:0 withReason:kOOLegalStatusReasonPoliceAreClean];
2146 }
2147 ShipEntity* target = [self primaryTarget];
2148 if ((target) && ([target scanClass] == CLASS_POLICE)) {
2149 [self noteLostTarget];
2150 }
2151 }
2152
2153 if (trackCloseContacts) {
2154 // in checkCloseCollisionWith: we check if some thing has come within touch range (origin within our collision_radius)
2155 // here we check if it has gone outside that range
2156 NSString* other_key = nil;
2157
2158 // create a temp copy to iterate over, since we may want to
2159 // change the original
2160 NSDictionary* closeContactsTemp = [[NSDictionary alloc] initWithDictionary:closeContactsInfo];
2161 foreachkey(other_key, closeContactsTemp)
2162 {
2163 ShipEntity* other = [UNIVERSE entityForUniversalID:[other_key intValue]];
2164 if ((other != nil) && (other->isShip)) {
2165 if (HPdistance2(position, other->position) > collision_radius * collision_radius) // moved beyond our sphere!
2166 {
2167 // calculate position with respect to our own position and orientation
2170 Vector pos0 = { 0, 0, 0 };
2171 ScanVectorFromString([closeContactsInfo objectForKey:other_key], &pos0);
2172 // send AI messages about the contact
2173 OOWeakReference* temp = _primaryTarget;
2174 _primaryTarget = [other weakRetain];
2175 if ((pos0.x < 0.0) && (pos1.x > 0.0)) {
2176 [self doScriptEvent:OOJSID("shipTraversePositiveX") withArgument:other andReactToAIMessage:@"POSITIVE X TRAVERSE"];
2177 }
2178 if ((pos0.x > 0.0) && (pos1.x < 0.0)) {
2179 [self doScriptEvent:OOJSID("shipTraverseNegativeX") withArgument:other andReactToAIMessage:@"NEGATIVE X TRAVERSE"];
2180 }
2181 if ((pos0.y < 0.0) && (pos1.y > 0.0)) {
2182 [self doScriptEvent:OOJSID("shipTraversePositiveY") withArgument:other andReactToAIMessage:@"POSITIVE Y TRAVERSE"];
2183 }
2184 if ((pos0.y > 0.0) && (pos1.y < 0.0)) {
2185 [self doScriptEvent:OOJSID("shipTraverseNegativeY") withArgument:other andReactToAIMessage:@"NEGATIVE Y TRAVERSE"];
2186 }
2187 if ((pos0.z < 0.0) && (pos1.z > 0.0)) {
2188 [self doScriptEvent:OOJSID("shipTraversePositiveZ") withArgument:other andReactToAIMessage:@"POSITIVE Z TRAVERSE"];
2189 }
2190 if ((pos0.z > 0.0) && (pos1.z < 0.0)) {
2191 [self doScriptEvent:OOJSID("shipTraverseNegativeZ") withArgument:other andReactToAIMessage:@"NEGATIVE Z TRAVERSE"];
2192 }
2193 _primaryTarget = temp;
2194 [closeContactsInfo removeObjectForKey:other_key];
2195 }
2196 } else {
2197 [closeContactsInfo removeObjectForKey:other_key];
2198 }
2199 }
2200 [closeContactsTemp release];
2201 } // end if trackCloseContacts
2202
2203 } // end if !isSubEntity
2204
2205#ifdef OO_DEBUG_MONITOR_ENABLED
2206 // DEBUGGING
2207 if (reportAIMessages && (debugLastBehaviour != behaviour)) {
2208 OOLog(kOOLogEntityBehaviourChanged, @"%@ behaviour is now %@", self, OOStringFromBehaviour(behaviour));
2209 debugLastBehaviour = behaviour;
2210 }
2211#endif
2212
2213 // cool all weapons.
2214 weapon_temp = fmaxf(weapon_temp - (float)(WEAPON_COOLING_FACTOR * delta_t), 0.0f);
2215 forward_weapon_temp = fmaxf(forward_weapon_temp - (float)(WEAPON_COOLING_FACTOR * delta_t), 0.0f);
2216 aft_weapon_temp = fmaxf(aft_weapon_temp - (float)(WEAPON_COOLING_FACTOR * delta_t), 0.0f);
2217 port_weapon_temp = fmaxf(port_weapon_temp - (float)(WEAPON_COOLING_FACTOR * delta_t), 0.0f);
2218 starboard_weapon_temp = fmaxf(starboard_weapon_temp - (float)(WEAPON_COOLING_FACTOR * delta_t), 0.0f);
2219
2220 // update time between shots
2221 shot_time += delta_t;
2222
2223 // handle radio message effects
2224 if (messageTime > 0.0) {
2225 messageTime -= delta_t;
2226 if (messageTime < 0.0)
2227 messageTime = 0.0;
2228 }
2229
2230 // temperature factors
2231 if (!isSubEnt) {
2232 double external_temp = 0.0;
2233 OOSunEntity* sun = [UNIVERSE sun];
2234 if (sun != nil) {
2235 // set the ambient temperature here
2236 double sun_zd = HPdistance2(position, [sun position]); // square of distance
2237 double sun_cr = sun->collision_radius;
2238 double alt1 = sun_cr * sun_cr / sun_zd;
2239 external_temp = SUN_TEMPERATURE * alt1;
2240 if ([sun goneNova])
2241 external_temp *= 100;
2242
2243 if ([self hasFuelScoop] && alt1 > 0.75 && [self fuel] < [self fuelCapacity]) {
2244 fuel_accumulator += (float)(delta_t * flightSpeed * 0.010 / [self fuelChargeRate]);
2245 // are we fast enough to collect any fuel?
2246 while (fuel_accumulator > 1.0f) {
2247 [self setFuel:[self fuel] + 1];
2248 fuel_accumulator -= 1.0f;
2249 [self doScriptEvent:OOJSID("shipScoopedFuel")];
2250 }
2251 }
2252 }
2253
2254 // work on the ship temperature
2255 //
2256 float heatThreshold = [self heatInsulation] * 100.0f;
2257 if (external_temp > heatThreshold && external_temp > ship_temperature)
2258 ship_temperature += (external_temp - ship_temperature) * delta_t * SHIP_INSULATION_FACTOR / [self heatInsulation];
2259 else {
2261 ship_temperature += (external_temp - heatThreshold - ship_temperature) * delta_t * SHIP_COOLING_FACTOR / [self heatInsulation];
2264 }
2265 }
2266 } else // subents
2267 {
2268 ship_temperature = [[self owner] temperature];
2269 }
2270
2272 [self takeHeatDamage:delta_t * ship_temperature];
2273
2274 // are we burning due to low energy
2275 if ((energy < maxEnergy * 0.20) && _showDamage) // prevents asteroid etc. from burning
2276 throw_sparks = YES;
2277
2278 // burning effects
2279 if (throw_sparks) {
2280 next_spark_time -= delta_t;
2281 if (next_spark_time < 0.0) {
2282 [self throwSparks];
2283 throw_sparks = NO; // until triggered again
2284 }
2285 }
2286
2287 if (!isSubEnt) {
2288
2289 // cloaking device
2290 if ([self hasCloakingDevice]) {
2294 [self deactivateCloakingDevice];
2295 if (energy < 0)
2296 energy = 0;
2297 }
2298 }
2299 }
2300
2301 // military_jammer
2302 if ([self hasMilitaryJammer]) {
2307 if (energy < 0)
2308 energy = 0;
2309 }
2310 } else {
2313 }
2314 }
2315
2316 // check outside factors
2317 /* aegis checks are expensive, so only do them once every km or so of flight
2318 * unlikely to be important otherwise. (every 100m if already close to
2319 * planet, to watch for surface)
2320
2321 * if have non-zero inertial velocity, need to check every frame,
2322 * as distanceTravelled does not include this component - CIM */
2324 aegis_status = [self checkForAegis]; // is a station or something nearby??
2325 if (aegis_status == AEGIS_NONE) {
2326 // in open space: check every km
2328 } else {
2329 // near planets: check every 100m
2331 }
2332 }
2333 } // end if !isSubEntity
2334
2335 // scripting
2337 // When crashing into a boulder, STATUS_LAUNCHING is sometimes skipped on scooping the resulting splinters.
2338 OOEntityStatus status = [self status];
2339 if (script != nil && (status == STATUS_IN_FLIGHT || status == STATUS_LAUNCHING || status == STATUS_BEING_SCOOPED || (status == STATUS_ACTIVE && self == [UNIVERSE station]))) {
2340 [PLAYER setScriptTarget:self];
2341 [self doScriptEvent:OOJSID("shipSpawned")];
2342 if ([self status] != STATUS_DEAD)
2343 [PLAYER doScriptEvent:OOJSID("shipSpawned") withArgument:self];
2344 }
2346 }
2347 /* No point in starting the AI if still launching */
2348 if (!haveStartedJSAI && [self status] != STATUS_LAUNCHING) {
2349 haveStartedJSAI = YES;
2350 [self doScriptEvent:OOJSID("aiStarted")];
2351 }
2352
2353 // behaviours according to status and behaviour
2354 //
2355 if ([self status] == STATUS_LAUNCHING) {
2356 if ([UNIVERSE getTime] > launch_time + launch_delay) // move for while before thinking
2357 {
2358 StationEntity* stationLaunchedFrom = [UNIVERSE nearestEntityMatchingPredicate:IsStationPredicate parameter:NULL relativeToEntity:self];
2359 [self setStatus:STATUS_IN_FLIGHT];
2360 // awaken JS-based AIs
2361 haveStartedJSAI = YES;
2362 [self doScriptEvent:OOJSID("aiStarted")];
2363 [self doScriptEvent:OOJSID("shipLaunchedFromStation") withArgument:stationLaunchedFrom];
2364 [shipAI reactToMessage:@"LAUNCHED OKAY" context:@"launched"];
2365 } else {
2366 // ignore behaviour just keep moving...
2367 flightYaw = 0.0;
2368 [self applyAttitudeChanges:delta_t];
2369 [self applyThrust:delta_t];
2370 if (energy < maxEnergy) {
2371 energy += energy_recharge_rate * delta_t;
2372 if (energy > maxEnergy) {
2373 energy = maxEnergy;
2374 [self doScriptEvent:OOJSID("shipEnergyBecameFull")];
2375 [shipAI message:@"ENERGY_FULL"];
2376 }
2377 }
2378
2379 if ([self subEntityCount] > 0) {
2380 // only copy the subent array if there are subentities
2381 ShipEntity* se = nil;
2382 foreach (se, [self subEntities]) {
2383 [se update:delta_t];
2384 }
2385 }
2386 // super update
2387 [super update:delta_t];
2388
2389 return;
2390 }
2391 }
2392 //
2393 // double check scooped behaviour
2394 //
2395 if ([self status] == STATUS_BEING_SCOOPED) {
2396 // if we are being tractored, but we have no owner, then we have a problem
2397 if (behaviour != BEHAVIOUR_TRACTORED || [self owner] == nil || [self owner] == self || [self owner] == NO_TARGET) {
2398 // escaped tractor beam
2399 [self setStatus:STATUS_IN_FLIGHT]; // should correct 'uncollidable objects' bug
2400 behaviour = BEHAVIOUR_IDLE;
2401 frustration = 0.0;
2402 [self setOwner:self];
2403 [shipAI exitStateMachineWithMessage:nil]; // Escapepods and others should continue their old AI here.
2404 }
2405 }
2406
2407 if ([self status] == STATUS_COCKPIT_DISPLAY) {
2408 flightYaw = 0.0;
2409 [self applyAttitudeChanges:delta_t];
2410 GLfloat range2 = 0.1 * HPdistance2(position, _destination) / (collision_radius * collision_radius);
2411 if ((range2 > 1.0) || (velocity.z > 0.0))
2412 range2 = 1.0;
2414 } else {
2415 [self processBehaviour:delta_t];
2416
2417 // manage energy
2418 if (energy < maxEnergy) {
2419 energy += energy_recharge_rate * delta_t;
2420 if (energy > maxEnergy) {
2421 energy = maxEnergy;
2422 [self doScriptEvent:OOJSID("shipEnergyBecameFull")];
2423 [shipAI message:@"ENERGY_FULL"];
2424 }
2425 }
2426
2427 if (!isSubEnt) {
2428 // update destination position for escorts
2429 [self refreshEscortPositions];
2430 if ([self hasEscorts]) {
2431 ShipEntity* escort = nil;
2432 unsigned i = 0;
2433 // Note: works on escortArray rather than escortEnumerator because escorts may be mutated.
2434 foreach (escort, [self escortArray]) {
2435 [escort setEscortDestination:[self coordinatesForEscortPosition:i++]];
2436 }
2437
2438 ShipEntity* leader = [[self escortGroup] leader];
2439 if (leader != nil && ([leader scanClass] != [self scanClass])) {
2440 OOLog(@"ship.sanityCheck.failed", @"Ship %@ escorting %@ with wrong scanclass!", self, leader);
2441 [[self escortGroup] removeShip:self];
2442 [self setEscortGroup:nil];
2443 }
2444 }
2445 }
2446 }
2447
2448 // rotational velocity
2451 qf.w *= (1.0 - delta_t);
2452 qf.x *= delta_t;
2453 qf.y *= delta_t;
2454 qf.z *= delta_t;
2455 [self setOrientation:quaternion_multiply(qf, orientation)];
2456 }
2457
2458 // reset totalBoundingBox
2460
2461 // super update
2462 [super update:delta_t];
2463
2464 // update subentities
2465
2466 if ([self subEntityCount] > 0) {
2467 // only copy the subent array if there are subentities
2468 ShipEntity* se = nil;
2469 foreach (se, [self subEntities]) {
2470 [se update:delta_t];
2471 if ([se isShip]) {
2472 BoundingBox sebb = [se findSubentityBoundingBox];
2475 }
2476 }
2477 }
2478
2479 if (aiScriptWakeTime > 0 && [PLAYER clockTimeAdjusted] > aiScriptWakeTime) {
2480 aiScriptWakeTime = 0;
2481 [self doScriptEvent:OOJSID("aiAwoken")];
2482 }
2483}
OOINLINE Quaternion make_quaternion(OOScalar qw, OOScalar qx, OOScalar qy, OOScalar qz) INLINE_CONST_FUNC
const Quaternion kZeroQuaternion
BOOL ScanVectorFromString(NSString *xyzString, Vector *outVector)
#define SHIP_COOLING_FACTOR
Definition ShipEntity.h:63
#define CLOAKING_DEVICE_MIN_ENERGY
Definition ShipEntity.h:50
#define MILITARY_JAMMER_ENERGY_RATE
Definition ShipEntity.h:53
#define CLOAKING_DEVICE_ENERGY_RATE
Definition ShipEntity.h:49
#define WEAPON_COOLING_FACTOR
Definition ShipEntity.h:115
#define MILITARY_JAMMER_MIN_ENERGY
Definition ShipEntity.h:54
#define SUN_TEMPERATURE
Definition ShipEntity.h:74
NSString * OOStringFromBehaviour(OOBehaviour behaviour) CONST_FUNC
#define SHIP_INSULATION_FACTOR
Definition ShipEntity.h:68
BOOL hasFuelScoop()
void setEscortDestination:(HPVector dest)
void update:(OOTimeDelta delta_t)
GLfloat fuelChargeRate()

References _destination, _nextAegisCheck, _primaryTarget, _showDamage, AEGIS_NONE, aegis_status, aft_weapon_temp, aiScriptWakeTime, applyAttitudeChanges:, applyThrust:, behaviour, bounding_box_add_vector(), Entity::boundingBox, bounty, checkForAegis, cloaking_device_active, CLOAKING_DEVICE_ENERGY_RATE, CLOAKING_DEVICE_MIN_ENERGY, closeContactsInfo, Entity::collision_radius, coordinatesForEscortPosition:, deactivateCloakingDevice, demoRate, demoStartTime, Entity::distanceTravelled, doScriptEvent:, doScriptEvent:withArgument:, doScriptEvent:withArgument:andReactToAIMessage:, dot_product(), Entity::energy, energy_recharge_rate, escortArray, escortGroup, AI::exitStateMachineWithMessage:, findSubentityBoundingBox, flightSpeed, flightYaw, foreachkey, forward_weapon_temp, frustration, fuel, fuel_accumulator, fuelCapacity, fuelChargeRate, hasCloakingDevice, hasEscorts, hasFuelScoop, hasMilitaryJammer, haveExecutedSpawnAction, haveStartedJSAI, heatInsulation, HPdistance2(), HPvector_add(), HPvector_between, HPVectorToVector(), isDemoShip, Entity::isShip, Entity::isSubEntity, kIdentityQuaternion, kZeroQuaternion, kZeroVector, launch_delay, launch_time, OOShipGroup::leader, M_PI, make_quaternion(), make_vector(), manageCollisions, BoundingBox::max, Entity::maxEnergy, maxFlightSpeed, AI::message:, messageTime, military_jammer_active, MILITARY_JAMMER_ENERGY_RATE, MILITARY_JAMMER_MIN_ENERGY, BoundingBox::min, next_spark_time, nil, NO_TARGET, noteLostTarget, OOLog, OOStringFromBehaviour(), Entity::owner, PLAYER, port_weapon_temp, Entity::position, primaryRole, primaryTarget, processBehaviour:, quaternion_equal(), AI::reactToMessage:context:, refreshEscortPositions, OOShipGroup::removeShip:, reportAIMessages, scanClass, ScanVectorFromString(), script, setBounty:withReason:, setEscortDestination:, setEscortGroup:, setFuel:, Entity::setOrientation:, setOwner:, setStatus:, SHIP_COOLING_FACTOR, SHIP_INSULATION_FACTOR, SHIP_MAX_CABIN_TEMP, SHIP_MIN_CABIN_TEMP, ship_temperature, shipinfoDictionary, shot_time, starboard_weapon_temp, Entity::status, subEntities, subEntityCount, subentityRotationalVelocity, SUN_TEMPERATURE, takeHeatDamage:, temperature, Entity::throw_sparks, throwSparks, totalBoundingBox, trackCloseContacts, UNIVERSE, Entity::update:, update:, updateTrackingCurve, v_forward, v_right, v_up, vector_equal(), vector_multiply_scalar(), vectorToHPVector(), velocity, Quaternion::w, OOWeakRefObject::weakRetain, WEAPON_COOLING_FACTOR, weapon_temp, Quaternion::x, Vector::x, Quaternion::y, Vector::y, Quaternion::z, and Vector::z.

Referenced by DockEntity::clearDockingCorridor, WormholeEntity::disgorgeShips, PlayerEntity::doBookkeeping:, DockEntity::update:, update:, and StationEntity::update:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateEscortFormation

- (void) updateEscortFormation

Definition at line 11995 of file ShipEntity.m.

11996{
11998}

References _escortPositionsValid, and updateEscortFormation.

Referenced by deployEscorts, octree, setEscortGroup:, setGroup:, setUpEscorts, and updateEscortFormation.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateTrackingCurve

- (void) updateTrackingCurve

Definition at line 5453 of file ShipEntity.m.

5454{
5455 Entity* target = [self primaryTarget];
5456 OOTimeAbsolute now = [UNIVERSE getTime];
5457 if (target == nil || reactionTime <= 0.0 || trackingCurveTimes[0] + reactionTime / 3.0 > now)
5458 return;
5462 if (EXPECT_NOT([target isShip] && [(ShipEntity*)target isCloaked])) {
5463 // if target is cloaked, introduce some more inaccuracy
5464 // 0.02 seems to be enough to give them slight difficulty on
5465 // a straight-line target and real trouble on anything better
5466 trackingCurvePositions[0] = HPvector_add([target position], OOHPVectorRandomSpatial([(ShipEntity*)target flightSpeed] * reactionTime * 0.02));
5467 } else {
5468 trackingCurvePositions[0] = [target position];
5469 }
5473 trackingCurveTimes[0] = now;
5474 [self calculateTrackingCurve];
5475 return;
5476}

References calculateTrackingCurve, EXPECT_NOT, flightSpeed, HPvector_add(), isCloaked, Entity::isShip, nil, OOHPVectorRandomSpatial(), Entity::position, primaryTarget, reactionTime, trackingCurvePositions, trackingCurveTimes, and updateTrackingCurve.

Referenced by reactionTime, update:, and updateTrackingCurve.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ upVector

- (Vector) upVector

Definition at line 1169 of file ShipEntity.m.

1170{
1171 return v_up;
1172}

References upVector, and v_up.

Referenced by behaviour_fly_to_destination:, OOExhaustPlumeEntity(Private)::saveToLastFrame, totalBoundingBox, OOExhaustPlumeEntity::update:, and upVector.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ validateDefenseTargets

- (void) validateDefenseTargets

Definition at line 9696 of file ShipEntity.m.

9697{
9698 if (_defenseTargets == nil) {
9699 return;
9700 }
9701 // get enumerator from array as we'll be modifying original during enumeration
9702 NSEnumerator* defTargets = [[self allDefenseTargets] objectEnumerator];
9703 Entity* target = nil;
9704 while ((target = [[defTargets nextObject] weakRefUnderlyingObject])) {
9705 if ([target status] == STATUS_DEAD) {
9706 [self removeDefenseTarget:target];
9707 }
9708 }
9709}

References _defenseTargets, allDefenseTargets, nil, removeDefenseTarget:, Entity::status, and validateDefenseTargets.

Referenced by isMissile, ShipGetProperty(), ShipGetProperty(), and validateDefenseTargets.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ validForAddToUniverse

- (BOOL) validForAddToUniverse
implementation

Reimplemented from Entity.

Reimplemented in PlayerEntity.

Definition at line 2074 of file ShipEntity.m.

2075{
2076 if (shipinfoDictionary == nil) {
2077 OOLog(@"shipEntity.notDict", @"Ship %@ was not set up from dictionary.", self);
2078 return NO;
2079 }
2080 return [super validForAddToUniverse];
2081}

References nil, OOLog, shipinfoDictionary, Entity::validForAddToUniverse, and validForAddToUniverse.

Referenced by validForAddToUniverse.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ velocity

◆ verifiedMissileTypeFromRole:

- (OOEquipmentType *) verifiedMissileTypeFromRole: (NSString*) role
implementation

Definition at line 3355 of file ShipEntity.m.

3355 :(NSString*)role
3356{
3357 NSString* eqRole = nil;
3358 NSString* shipKey = nil;
3359 ShipEntity* missile = nil;
3360 OOEquipmentType* missileType = nil;
3361 BOOL isRandomMissile = [role isEqualToString:@"missile"];
3362
3363 if (isRandomMissile) {
3364 while (!shipKey) {
3365 shipKey = [UNIVERSE randomShipKeyForRoleRespectingConditions:role];
3366 if (!shipKey) {
3367 OOLogWARN(@"ship.setUp.missiles", @"%@ \"%@\" used in ship \"%@\" needs a valid %@.plist entry.%@", @"random missile", shipKey, [self name], @"shipdata", @"Trying another missile.");
3368 }
3369 }
3370 } else {
3371 shipKey = [UNIVERSE randomShipKeyForRoleRespectingConditions:role];
3372 if (!shipKey) {
3373 OOLogWARN(@"ship.setUp.missiles", @"%@ \"%@\" used in ship \"%@\" needs a valid %@.plist entry.%@", @"missile_role", role, [self name], @"shipdata", @" Using defaults instead.");
3374 return nil;
3375 }
3376 }
3377
3378 eqRole = [OOEquipmentType getMissileRegistryRoleForShip:shipKey]; // eqRole != role for generic missiles.
3379
3380 if (eqRole == nil) {
3381 missile = [UNIVERSE newShipWithName:shipKey];
3382 if (!missile) {
3383 if (isRandomMissile)
3384 OOLogWARN(@"ship.setUp.missiles", @"%@ \"%@\" used in ship \"%@\" needs a valid %@.plist entry.%@", @"random missile", shipKey, [self name], @"shipdata", @"Trying another missile.");
3385 else
3386 OOLogWARN(@"ship.setUp.missiles", @"%@ \"%@\" used in ship \"%@\" needs a valid %@.plist entry.%@", @"missile_role", role, [self name], @"shipdata", @" Using defaults instead.");
3387
3388 [OOEquipmentType setMissileRegistryRole:@"" forShip:shipKey]; // no valid role for this shipKey
3389 if (isRandomMissile)
3390 return [self verifiedMissileTypeFromRole:role];
3391 else
3392 return nil;
3393 }
3394
3395 if (isRandomMissile) {
3396 id value;
3397
3398 foreach (value, [[missile roleSet] roles]) {
3399 role = (NSString*)value;
3400 missileType = [OOEquipmentType equipmentTypeWithIdentifier:role];
3401 // ensure that we have a missile or mine
3402 if ([missileType isMissileOrMine])
3403 break;
3404 }
3405
3406 if (![missileType isMissileOrMine]) {
3407 role = shipKey; // unique identifier to use in lieu of a valid equipment type if none are defined inside the generic missile roleset.
3408 }
3409 }
3410
3411 missileType = [OOEquipmentType equipmentTypeWithIdentifier:role];
3412
3413 if (!missileType) {
3414 OOLogWARN(@"ship.setUp.missiles", @"%@ \"%@\" used in ship \"%@\" needs a valid %@.plist entry.%@", (isRandomMissile ? @"random missile" : @"missile_role"), role, [self name], @"equipment", @" Enabling compatibility mode.");
3415 missileType = [self generateMissileEquipmentTypeFrom:role];
3416 }
3417
3419 [missile release];
3420 } else {
3421 if ([eqRole isEqualToString:@""]) {
3422 // wrong ship definition, already written to the log in a previous call.
3423 if (isRandomMissile)
3424 return [self verifiedMissileTypeFromRole:role]; // try and find a valid missile with role 'missile'.
3425 return nil;
3426 }
3427 missileType = [OOEquipmentType equipmentTypeWithIdentifier:eqRole];
3428 }
3429
3430 return missileType;
3431}
void setMissileRegistryRole:forShip:(NSString *roles,[forShip] NSString *shipKey)
NSString * getMissileRegistryRoleForShip:(NSString *shipKey)

References OOEquipmentType::equipmentTypeWithIdentifier:, generateMissileEquipmentTypeFrom:, OOEquipmentType::getMissileRegistryRoleForShip:, name, nil, OOLogWARN, roleSet, OOEquipmentType::setMissileRegistryRole:forShip:, and verifiedMissileTypeFromRole:.

Referenced by selectMissile, and verifiedMissileTypeFromRole:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ volume

- (float) volume

Definition at line 1309 of file ShipEntity.m.

1310{
1311 return [octree volume];
1312}

References Octree::volume, and volume.

Referenced by clearSubEntities, octree, PlayerEntity::setGuiToGameOptionsScreen, and volume.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wasAddedToUniverse

- (void) wasAddedToUniverse
implementation

Reimplemented from Entity.

Definition at line 1368 of file ShipEntity.m.

1369{
1370 [super wasAddedToUniverse];
1371
1372 // if we have a universal id then we can proceed to set up any
1373 // stuff that happens when we get added to the UNIVERSE
1374 if (universalID != NO_TARGET) {
1375 // set up escorts
1376 if (([self status] == STATUS_IN_FLIGHT || [self status] == STATUS_LAUNCHING) && _pendingEscortCount != 0) // just popped into existence
1377 {
1378 [self setUpEscorts];
1379 } else {
1380 /* Earlier there was a silly log message here because I thought
1381 this would never happen, but wasn't entirely sure. Turns out
1382 it did!
1383 -- Ahruman 2009-09-13
1384 */
1386 }
1387 }
1388
1389 // Tell subentities, too
1390 [subEntities makeObjectsPerformSelector:@selector(wasAddedToUniverse)];
1391
1392 [self resetExhaustPlumes];
1393}

References _pendingEscortCount, NO_TARGET, resetExhaustPlumes, setUpEscorts, Entity::status, Entity::universalID, Entity::wasAddedToUniverse, and wasAddedToUniverse.

Referenced by PlayerEntity::showShipModelWithKey:shipData:personality:factorX:factorY:factorZ:inContext:, and wasAddedToUniverse.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wasRemovedFromUniverse

- (void) wasRemovedFromUniverse
implementation

Reimplemented from Entity.

Definition at line 1395 of file ShipEntity.m.

1396{
1397 [subEntities makeObjectsPerformSelector:@selector(wasRemovedFromUniverse)];
1398}

References wasRemovedFromUniverse.

Referenced by wasRemovedFromUniverse.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ weaponFacings

- (OOWeaponFacingSet) weaponFacings

Definition at line 2901 of file ShipEntity.m.

2902{
2903 return weapon_facings;
2904}

References weapon_facings, and weaponFacings.

Referenced by PlayerEntity::availableFacings, isFrangible, OOShipLibraryWeapons(), PlayerEntity::setCommanderDataFromDictionary:, PlayerEntity::setGuiToEquipShipScreen:selectingFacingFor:, PlayerEntity::setWeaponMount:toWeapon:inContext:, and weaponFacings.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ weaponRange

- (GLfloat) weaponRange

References energyRechargeRate, weaponRange, and weaponRechargeRate.

Here is the call graph for this function:

◆ weaponRechargeRate

- (float) weaponRechargeRate

Definition at line 6496 of file ShipEntity.m.

6497{
6498 return weapon_recharge_rate;
6499}

References weapon_recharge_rate, and weaponRechargeRate.

Referenced by weaponRange, and weaponRechargeRate.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ weaponRecoveryTime

- (GLfloat) weaponRecoveryTime

Definition at line 8361 of file ShipEntity.m.

8362{
8364 return OOClamp_0_1_f(result);
8365}

References OOClamp_0_1_f(), shotTime, weapon_recharge_rate, and weaponRecoveryTime.

Referenced by maxFlightSpeed, and weaponRecoveryTime.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ weaponTypeForFacing:strict:

- (OOEquipmentType *) weaponTypeForFacing: (OOWeaponFacing) facing
strict: (BOOL) strict 

Reimplemented in PlayerEntity.

Definition at line 2943 of file ShipEntity.m.

2943 :(OOWeaponFacing)facing strict:(BOOL)strict
2944{
2945 // OOWeaponType weaponType = [self weaponTypeIDForFacing:facing strict:strict];
2946 // return [OOEquipmentType equipmentTypeWithIdentifier:OOEquipmentIdentifierFromWeaponType(weaponType)];
2947 return [self weaponTypeIDForFacing:facing strict:strict];
2948}

References weaponTypeIDForFacing:strict:.

Referenced by fireDirectLaserShotAt:, fireSubentityLaserShot:, ShipGetProperty(), and ShipGetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ weaponTypeIDForFacing:strict:

- (OOWeaponType) weaponTypeIDForFacing: (OOWeaponFacing) facing
strict: (BOOL) strict 

Definition at line 2906 of file ShipEntity.m.

2906 :(OOWeaponFacing)facing strict:(BOOL)strict
2907{
2908 OOWeaponType weaponType = nil;
2909
2910 if (facing & weapon_facings) {
2911 switch (facing) {
2913 weaponType = forward_weapon_type;
2914 // if no forward weapon, and not carrying out a strict check, see if subentities have forward weapons, return the first one found.
2915 if (isWeaponNone(weaponType) && !strict) {
2916 NSEnumerator* subEntEnum = [self shipSubEntityEnumerator];
2917 ShipEntity* subEntity = nil;
2918 while (isWeaponNone(weaponType) && (subEntity = [subEntEnum nextObject])) {
2919 weaponType = subEntity->forward_weapon_type;
2920 }
2921 }
2922 break;
2923
2924 case WEAPON_FACING_AFT:
2925 weaponType = aft_weapon_type;
2926 break;
2927
2928 case WEAPON_FACING_PORT:
2929 weaponType = port_weapon_type;
2930 break;
2931
2933 weaponType = starboard_weapon_type;
2934 break;
2935
2936 case WEAPON_FACING_NONE:
2937 break;
2938 }
2939 }
2940 return weaponType;
2941}

References aft_weapon_type, forward_weapon_type, isWeaponNone(), nil, port_weapon_type, shipSubEntityEnumerator, starboard_weapon_type, WEAPON_FACING_AFT, WEAPON_FACING_FORWARD, WEAPON_FACING_NONE, WEAPON_FACING_PORT, WEAPON_FACING_STARBOARD, and weapon_facings.

Referenced by weaponTypeForFacing:strict:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ witchspaceLeavingEffects

- (BOOL) witchspaceLeavingEffects

Definition at line 11809 of file ShipEntity.m.

11810{
11811 // all ships exiting witchspace will share the same orientation.
11812 orientation = [UNIVERSE getWitchspaceExitRotation];
11813 flightRoll = 0.0;
11814 stick_roll = 0.0;
11815 flightPitch = 0.0;
11816 stick_pitch = 0.0;
11817 flightYaw = 0.0;
11818 stick_yaw = 0.0;
11819 flightSpeed = 50.0; // constant speed same for all ships
11820 // was a quarter of max speed, so the Anaconda speeds up and most
11821 // others slow down - CIM
11822 // will be overridden if left witchspace via a genuine wormhole
11824 if (![UNIVERSE addEntity:self]) // AI and status get initialised here
11825 {
11826 return NO;
11827 }
11828 [self setStatus:STATUS_EXITING_WITCHSPACE];
11829 [shipAI message:@"EXITED_WITCHSPACE"];
11830
11831 [UNIVERSE addWitchspaceJumpEffectForShip:self];
11832 [self setStatus:STATUS_IN_FLIGHT];
11833 return YES;
11834}

References flightPitch, flightRoll, flightSpeed, flightYaw, kZeroVector, AI::message:, Entity::orientation, setStatus:, stick_pitch, stick_roll, stick_yaw, UNIVERSE, velocity, and witchspaceLeavingEffects.

Referenced by Universe::addShipAt:withRole:withinRadius:, coordinates, WormholeEntity::disgorgeShips, leaveWitchspace, and witchspaceLeavingEffects.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ withinStationAegis

- (BOOL) withinStationAegis

Definition at line 6803 of file ShipEntity.m.

6804{
6806}

References AEGIS_IN_DOCKING_RANGE, aegis_status, and withinStationAegis.

Referenced by AuthorityPredicate, reportAIMessages, and withinStationAegis.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wormholeEntireGroup

- (void) wormholeEntireGroup

Provided by category ShipEntity(AI).

Definition at line 635 of file ShipEntityAI.m.

636{
637 [self wormholeGroup];
638 [self wormholeEscorts];
639}

◆ wormholeEscorts

- (void) wormholeEscorts

Provided by category ShipEntity(AI).

Definition at line 609 of file ShipEntityAI.m.

610{
611 ShipEntity* ship = nil;
612 NSString* context = nil;
613 WormholeEntity* whole = nil;
614
615 whole = [self primaryTarget];
616 if (![whole isWormhole])
617 return;
618
619#ifndef NDEBUG
620 context = [NSString stringWithFormat:@"%@ wormholeEscorts", [self shortDescription]];
621#endif
622
623 foreach (ship, [self escortEnumerator]) {
624 [ship addTarget:whole];
625 [ship reactToAIMessage:@"ENTER WORMHOLE" context:context];
626 [ship doScriptEvent:OOJSID("wormholeSuggested") withArgument:whole];
627 }
628
629 // We now have no escorts..
630
631 [_escortGroup release];
633}

Referenced by enterWormhole:replacing:, and ShipEntity(AI)::wormholeEntireGroup.

Here is the caller graph for this function:

◆ wormholeGroup

- (void) wormholeGroup
implementation

Provided by category ShipEntity(PureAI).

Definition at line 1423 of file ShipEntityAI.m.

1424{
1425 ShipEntity* ship = nil;
1426 WormholeEntity* whole = nil;
1427
1428 whole = [self primaryTarget];
1429 if (![whole isWormhole])
1430 return;
1431
1432 foreach (ship, [[self group] mutationSafeEnumerator]) {
1433 [ship addTarget:whole];
1434 [ship reactToAIMessage:@"ENTER WORMHOLE" context:@"wormholeGroup"];
1435 [ship doScriptEvent:OOJSID("wormholeSuggested") withArgument:whole];
1436 }
1437}

Referenced by ShipEntity(AI)::wormholeEntireGroup.

Here is the caller graph for this function:

Member Data Documentation

◆ _beaconCode

- (NSString*) _beaconCode
private

Definition at line 470 of file ShipEntity.h.

Referenced by beaconCode, dealloc, and setBeaconCode:.

◆ _beaconDrawable

- (id<OOHUDBeaconIcon>) _beaconDrawable
private

Definition at line 474 of file ShipEntity.h.

Referenced by beaconDrawable, dealloc, and setBeaconCode:.

◆ _beaconLabel

- (NSString*) _beaconLabel
private

Definition at line 471 of file ShipEntity.h.

Referenced by beaconLabel, dealloc, setBeaconCode:, and setBeaconLabel:.

◆ _collisionExceptions

- (OOWeakSet*) _collisionExceptions
private

◆ _defenseTargets

- (OOWeakSet*) _defenseTargets
private

Definition at line 460 of file ShipEntity.h.

Referenced by addDefenseTarget:, dealloc, and validateDefenseTargets.

◆ _destination

◆ _equipment

◆ _escortGroup

◆ _escortPositions

- (Vector _escortPositions[MAX_ESCORTS])
private

Definition at line 457 of file ShipEntity.h.

◆ _escortPositionsValid

- (BOOL) _escortPositionsValid
private

Definition at line 458 of file ShipEntity.h.

Referenced by updateEscortFormation.

◆ _explicitlyUnpiloted

- (unsigned) _explicitlyUnpiloted
protected

Definition at line 263 of file ShipEntity.h.

Referenced by isExplicitlyUnpiloted, and setUpShipFromDictionary:.

◆ _foundTarget

- (OOWeakReference*) _foundTarget
protected

Definition at line 428 of file ShipEntity.h.

Referenced by foundTarget, PlayerEntity::setFoundTarget:, and setFoundTarget:.

◆ _group

- (OOShipGroup*) _group
private

◆ _heatInsulation

- (float) _heatInsulation
private

Definition at line 448 of file ShipEntity.h.

Referenced by heatInsulation, and setHeatInsulation:.

◆ _lastAegisLock

- (OOWeakReference*) _lastAegisLock
private

Definition at line 450 of file ShipEntity.h.

Referenced by dealloc, and setLastAegisLock:.

◆ _lastEscortTarget

- (OOWeakReference*) _lastEscortTarget
protected

◆ _lightsActive

- (unsigned) _lightsActive
protected

Definition at line 271 of file ShipEntity.h.

Referenced by lightsActive, switchLightsOff, and switchLightsOn.

◆ _maxEscortCount

- (uint8_t) _maxEscortCount
private

◆ _maxShipSubIdx

- (NSUInteger) _maxShipSubIdx
protected

◆ _missed_shots

- (int) _missed_shots
protected

Definition at line 365 of file ShipEntity.h.

Referenced by adjustMissedShots:, missedShots, and setUpShipFromDictionary:.

◆ _missileRole

- (NSString*) _missileRole
protected

Definition at line 310 of file ShipEntity.h.

Referenced by selectMissile, and setUpShipFromDictionary:.

◆ _multiplyWeapons

◆ _nextAegisCheck

- (double) _nextAegisCheck
private

Definition at line 476 of file ShipEntity.h.

Referenced by forceAegisCheck, initWithKey:definition:, and update:.

◆ _nextBeacon

- (OOWeakReference*) _nextBeacon
private

Definition at line 473 of file ShipEntity.h.

Referenced by setNextBeacon:.

◆ _pendingEscortCount

- (uint8_t) _pendingEscortCount
private

◆ _prevBeacon

- (OOWeakReference*) _prevBeacon
private

Definition at line 472 of file ShipEntity.h.

Referenced by setPrevBeacon:.

◆ _primaryAggressor

- (OOWeakReference*) _primaryAggressor
protected

Definition at line 426 of file ShipEntity.h.

Referenced by noteLostTarget, primaryAggressor, and setPrimaryAggressor:.

◆ _primaryTarget

◆ _profileRadius

- (GLfloat) _profileRadius
private

Definition at line 465 of file ShipEntity.h.

Referenced by clearSubEntities, frustumRadius, and setUpSubEntities.

◆ _proximityAlert

- (OOWeakReference*) _proximityAlert
protected

Definition at line 432 of file ShipEntity.h.

Referenced by proximityAlert, resumePostProximityAlert, and setProximityAlert:.

◆ _rememberedShip

- (OOWeakReference*) _rememberedShip
protected

Definition at line 431 of file ShipEntity.h.

Referenced by rememberedShip, and setRememberedShip:.

◆ _scaleFactor

◆ _scriptedMisjumpRange

- (GLfloat) _scriptedMisjumpRange
protected

◆ _shipHitByLaser

- (OOWeakReference*) _shipHitByLaser
private

Definition at line 467 of file ShipEntity.h.

◆ _shipKey

- (NSString*) _shipKey
private

Definition at line 445 of file ShipEntity.h.

Referenced by dealloc, initWithKey:definition:, setShipDataKey:, and shipDataKey.

◆ _showDamage

- (unsigned) _showDamage
protected

Definition at line 259 of file ShipEntity.h.

Referenced by showDamage, and update:.

◆ _subEntityTakingDamage

- (OOWeakReference*) _subEntityTakingDamage
private

Definition at line 443 of file ShipEntity.h.

Referenced by setSubEntityTakingDamage:.

◆ _subIdx

- (NSUInteger) _subIdx
protected

Definition at line 331 of file ShipEntity.h.

Referenced by setSubIdx:, and subIdx.

◆ _targetStation

- (OOWeakReference*) _targetStation
protected

Definition at line 427 of file ShipEntity.h.

Referenced by setTargetStation:, and targetStation.

◆ _thankedShip

- (OOWeakReference*) _thankedShip
protected

Definition at line 430 of file ShipEntity.h.

Referenced by setThankedShip:, and thankedShip.

◆ accuracy

◆ aegis_status

- (OOAegisStatus) aegis_status
protected

◆ aft_weapon_temp

◆ aft_weapon_type

◆ afterburner_rate

- (GLfloat) afterburner_rate
protected

◆ afterburner_speed_factor

- (GLfloat) afterburner_speed_factor
protected

Definition at line 281 of file ShipEntity.h.

Referenced by afterburnerFactor, and setAfterburnerFactor:.

◆ aftWeaponOffset

- (NSArray *) aftWeaponOffset
protected

◆ aim_tolerance

- (GLfloat) aim_tolerance
protected

◆ aiScript

- (OOJSScript*) aiScript
protected

Definition at line 212 of file ShipEntity.h.

Referenced by dealloc, and shipAIScript.

◆ aiScriptWakeTime

- (OOTimeAbsolute) aiScriptWakeTime
protected

◆ behaviour

◆ being_fined

- (unsigned) being_fined
protected

◆ being_mined

- (unsigned) being_mined
protected

◆ bounty

◆ canFragment

- (unsigned) canFragment
protected

Definition at line 257 of file ShipEntity.h.

Referenced by becomeExplosion.

◆ cargo

◆ cargo_dump_time

- (OOTimeAbsolute) cargo_dump_time
protected

Definition at line 347 of file ShipEntity.h.

Referenced by dumpCargoItem:, dumpItem:, and PlayerEntity::loadCargoPods.

◆ cargo_flag

- (OOCargoFlag) cargo_flag
protected

◆ cargo_type

- (OOCargoType) cargo_type
protected

Definition at line 287 of file ShipEntity.h.

Referenced by cargoType, setUpCargoType:, and setUpShipFromDictionary:.

◆ cloakAutomatic

◆ cloaking_device_active

◆ cloakPassive

◆ closeContactsInfo

- (NSMutableDictionary*) closeContactsInfo
protected

Definition at line 390 of file ShipEntity.h.

Referenced by checkCloseCollisionWith:, setTrackCloseContacts:, and update:.

◆ collision_vector

- (Vector) collision_vector
protected

Definition at line 375 of file ShipEntity.h.

◆ commodity_amount

- (OOCargoQuantity) commodity_amount
protected

◆ commodity_type

◆ coordinates

- (HPVector) coordinates
protected

Definition at line 8848 of file ShipEntity.m.

8849{
8850 return coordinates;
8851}

Referenced by coordinates, and setCoordinate:.

◆ crew

◆ cruiseSpeed

- (double) cruiseSpeed
protected

Definition at line 7409 of file ShipEntity.m.

7410{
7411 return cruiseSpeed;
7412}

Referenced by acceptAsEscort:, and cruiseSpeed.

◆ currentWeaponFacing

◆ default_laser_color

- (OOColor*) default_laser_color
protected

Definition at line 219 of file ShipEntity.h.

Referenced by dealloc, and setWeaponDataFromType:.

◆ demoRate

- (OOScalar) demoRate
private

Definition at line 480 of file ShipEntity.h.

Referenced by setDemoShip:, and update:.

◆ demoStartOrientation

- (Quaternion) demoStartOrientation
private

Definition at line 482 of file ShipEntity.h.

Referenced by setDemoShip:.

◆ demoStartTime

- (OOTimeAbsolute) demoStartTime
private

Definition at line 481 of file ShipEntity.h.

Referenced by getDemoStartTime, setDemoStartTime:, and update:.

◆ desired_range

◆ desired_speed

◆ destination_system

- (OOSystemID) destination_system
protected

Definition at line 369 of file ShipEntity.h.

Referenced by destinationSystem, setDestinationSystem:, and setUpShipFromDictionary:.

◆ displayName

- (NSString *) displayName
protected

Definition at line 6172 of file ShipEntity.m.

6173{
6174 if (displayName == nil || [displayName length] == 0) {
6175 if ([shipUniqueName length] == 0) {
6176 if (shipClassName == nil) {
6177 return name;
6178 } else {
6179 return shipClassName;
6180 }
6181 } else {
6182 if (shipClassName == nil) {
6183 return [NSString stringWithFormat:@"%@: %@", name, shipUniqueName];
6184 } else {
6185 return [NSString stringWithFormat:@"%@: %@", shipClassName, shipUniqueName];
6186 }
6187 }
6188 }
6189 return displayName;
6190}

Referenced by StationEntity::acceptDockingClearanceRequestFrom:, PlayerEntity(Scripting)::commanderShipDisplayName_string, dealloc, displayName, PlayerEntity(ScriptMethods)::dockedStationDisplayName, StationEntity::dumpSelfState, StationEntity::fitsInDock:andLogNoFit:, PlayerEntity(OOControlsPrivate)::handleAutopilotOn:, identFromShip:, StationEntity::launchDefenseShip, StationEntity::launchEscort, StationEntity::launchIndependentShip:, StationEntity::launchMiner, StationEntity::launchPatrol, StationEntity::launchPirateShip, StationEntity::launchPolice, StationEntity::launchScavenger, StationEntity::launchShipWithRole:, StationEntity::launchShuttle, PlayerEntity::marketScreenTitle, PlayerEntity::receiveCommsMessage:from:, sendExpandedMessage:toShip:, setDisplayName:, PlayerEntity::setGuiToInterfacesScreen:, PlayerEntity::setGuiToStatusScreen, setShipScript:, StationEntity::setUpSubEntities, ShipGetProperty(), ShipGetProperty(), PlayerEntity(Contracts)::showTradeInInformationFooter, and StationEntity::update:.

◆ distance2_scanned_ships

- (GLfloat distance2_scanned_ships[MAX_SCAN_NUMBER+1])
protected

Definition at line 402 of file ShipEntity.h.

Referenced by checkScanner, and checkScannerIgnoringUnpowered.

◆ docking_match_rotation

- (unsigned) docking_match_rotation
protected

◆ dockingInstructions

- (NSDictionary *) dockingInstructions
protected

◆ energy_recharge_rate

- (GLfloat) energy_recharge_rate
protected

◆ entity_personality

◆ equipment_weight

◆ exhaust_emissive_color

- (OOColor*) exhaust_emissive_color
protected

Definition at line 220 of file ShipEntity.h.

Referenced by dealloc, and setExhaustEmissiveColor:.

◆ explosionType

- (NSArray*) explosionType
protected

Definition at line 324 of file ShipEntity.h.

Referenced by becomeExplosion, and dealloc.

◆ extra_cargo

◆ flightPitch

◆ flightRoll

◆ flightSpeed

◆ flightYaw

◆ forward_weapon_temp

◆ forward_weapon_type

◆ forwardWeaponOffset

- (NSArray *) forwardWeaponOffset
protected

◆ frustration

◆ fuel

◆ fuel_accumulator

- (GLfloat) fuel_accumulator
protected

◆ hasScoopMessage

- (unsigned) hasScoopMessage
protected

Definition at line 264 of file ShipEntity.h.

Referenced by setUpShipFromDictionary:, and showScoopMessage.

◆ haveExecutedSpawnAction

- (unsigned) haveExecutedSpawnAction
protected

Definition at line 268 of file ShipEntity.h.

Referenced by setUpFromDictionary:, and update:.

◆ haveStartedJSAI

- (unsigned) haveStartedJSAI
protected

Definition at line 269 of file ShipEntity.h.

Referenced by setUpFromDictionary:, and update:.

◆ home_system

- (OOSystemID) home_system
protected

Definition at line 368 of file ShipEntity.h.

Referenced by homeSystem, setHomeSystem:, and setUpShipFromDictionary:.

◆ hyperspaceMotorSpinTime

- (float) hyperspaceMotorSpinTime
protected

Definition at line 236 of file ShipEntity.h.

Referenced by hasHyperspaceMotor, hyperspaceSpinTime, and setHyperspaceSpinTime:.

◆ isDemoShip

- (BOOL) isDemoShip
private

Definition at line 12759 of file ShipEntity.m.

12760{
12761 return isDemoShip;
12762}

Referenced by isDemoShip, setDemoShip:, and update:.

◆ isFrangible

- (BOOL) isFrangible
protected

◆ isHulk

- (BOOL) isHulk
protected

◆ isMissile

- (BOOL) isMissile
protected

◆ isNearPlanetSurface

- (unsigned) isNearPlanetSurface
protected

Definition at line 252 of file ShipEntity.h.

Referenced by checkForAegis, and setUpFromDictionary:.

◆ isWreckage

- (unsigned) isWreckage
protected

Definition at line 258 of file ShipEntity.h.

Referenced by becomeExplosion, canCollide, and setIsWreckage:.

◆ jink

◆ laser_color

- (OOColor*) laser_color
protected

Definition at line 218 of file ShipEntity.h.

Referenced by dealloc, and setLaserColor:.

◆ last_shot_time

- (OOTimeAbsolute) last_shot_time
protected

Definition at line 348 of file ShipEntity.h.

Referenced by fireLaserShotInDirection:weaponIdentifier:.

◆ lastRadioMessage

- (NSString*) lastRadioMessage
protected

Definition at line 392 of file ShipEntity.h.

Referenced by dealloc, and sendExpandedMessage:toShip:.

◆ launch_delay

- (double) launch_delay
protected

Definition at line 334 of file ShipEntity.h.

Referenced by setLaunchDelay:, and update:.

◆ launch_time

- (double) launch_time
protected

Definition at line 333 of file ShipEntity.h.

Referenced by setStatus:, and update:.

◆ likely_cargo

- (OOCargoQuantity) likely_cargo
protected

Definition at line 283 of file ShipEntity.h.

Referenced by becomeExplosion, setCargoFlag:, and setUpShipFromDictionary:.

◆ max_cargo

◆ max_flight_pitch

◆ max_flight_roll

◆ max_flight_yaw

◆ max_missiles

◆ max_thrust

- (GLfloat) max_thrust
protected

Definition at line 234 of file ShipEntity.h.

Referenced by PlayerEntity::doBookkeeping:, maxThrust, and setMaxThrust:.

◆ maxFlightSpeed

◆ messageTime

◆ military_jammer_active

- (unsigned) military_jammer_active
protected

Definition at line 238 of file ShipEntity.h.

Referenced by PlayerEntity::doBookkeeping:, isJammingScanning, and update:.

◆ missile_launch_time

- (OOTimeAbsolute) missile_launch_time
protected

Definition at line 312 of file ShipEntity.h.

Referenced by fireMissileWithIdentifier:andTarget:, and noticeECM.

◆ missile_list

◆ missile_load_time

- (OOTimeDelta) missile_load_time
protected

◆ missiles

◆ n_scanned_ships

◆ name

◆ navpoints

- (HPVector navpoints[32])
protected

Definition at line 406 of file ShipEntity.h.

Referenced by behaviour_fly_thru_navpoints:.

◆ next_navpoint_index

- (unsigned) next_navpoint_index
protected

Definition at line 407 of file ShipEntity.h.

Referenced by behaviour_fly_thru_navpoints:.

◆ next_spark_time

- (double) next_spark_time
protected

Definition at line 373 of file ShipEntity.h.

Referenced by throwSparks, and update:.

◆ noRocks

- (unsigned) noRocks
protected

Definition at line 270 of file ShipEntity.h.

Referenced by becomeExplosion, isMinable, and setUpShipFromDictionary:.

◆ number_of_navpoints

- (unsigned) number_of_navpoints
protected

Definition at line 408 of file ShipEntity.h.

Referenced by behaviour_fly_thru_navpoints:.

◆ octree

- (Octree *) octree
protected

Definition at line 1304 of file ShipEntity.m.

1305{
1306 return octree;
1307}

Referenced by clearSubEntities, dealloc, doOctreesCollide, octree, and setMesh:.

◆ patrol_counter

- (int) patrol_counter
protected

Definition at line 340 of file ShipEntity.h.

◆ pitch_tolerance

- (GLfloat) pitch_tolerance
protected

Definition at line 363 of file ShipEntity.h.

Referenced by missileTrackPrimaryTarget:, and setAccuracy:.

◆ pitching_over

◆ planetForLanding

- (OOUniversalID) planetForLanding
protected

Definition at line 335 of file ShipEntity.h.

◆ port_weapon_temp

◆ port_weapon_type

◆ portWeaponOffset

- (NSArray *) portWeaponOffset
protected

◆ previousCondition

- (NSMutableDictionary*) previousCondition
protected

Definition at line 342 of file ShipEntity.h.

Referenced by avoidCollision, dealloc, hasHostileTarget, and resumePostProximityAlert.

◆ primaryRole

◆ reactionTime

- (float) reactionTime
protected

◆ reference

- (Vector) reference
protected

◆ reportAIMessages

- (BOOL) reportAIMessages
protected

Definition at line 6536 of file ShipEntity.m.

6537{
6538 return reportAIMessages;
6539}

Referenced by landOnPlanet:, reportAIMessages, setReportAIMessages:, AI::takeAction:, and update:.

◆ roleSet

- (OORoleSet *) roleSet
protected

Definition at line 6276 of file ShipEntity.m.

6277{
6278 if (roleSet == nil)
6279 roleSet = [[OORoleSet alloc] initWithRoleString:primaryRole];
6280 return [[roleSet roleSetWithAddedRoleIfNotSet:primaryRole probability:1.0] roleSetWithAddedRoleIfNotSet:[self shipDataKeyAutoRole] probability:1.0];
6281}
NSString * shipDataKeyAutoRole()

Referenced by addRole:withProbability:, becomeExplosion, dealloc, HasRoleInSetPredicate(), removeRole:, roleSet, ShipEntity(LoadRestore)::savedShipDictionaryWithContext:, PlayerEntity::setUpShipFromDictionary:, setUpShipFromDictionary:, ShipGetProperty(), ShipGetProperty(), and verifiedMissileTypeFromRole:.

◆ rolling_over

- (unsigned) rolling_over
protected

Definition at line 243 of file ShipEntity.h.

◆ scan_description

- (NSString*) scan_description
protected

◆ scanned_ships

◆ scanner_display_color1

- (OOColor*) scanner_display_color1
protected

Definition at line 221 of file ShipEntity.h.

Referenced by dealloc, and setScannerDisplayColor1:.

◆ scanner_display_color2

- (OOColor*) scanner_display_color2
protected

Definition at line 222 of file ShipEntity.h.

Referenced by dealloc, and setScannerDisplayColor2:.

◆ scanner_display_color_hostile1

- (OOColor*) scanner_display_color_hostile1
protected

Definition at line 223 of file ShipEntity.h.

Referenced by dealloc, and setScannerDisplayColorHostile1:.

◆ scanner_display_color_hostile2

- (OOColor*) scanner_display_color_hostile2
protected

Definition at line 224 of file ShipEntity.h.

Referenced by dealloc, and setScannerDisplayColorHostile2:.

◆ scannerRange

◆ script

◆ scripted_misjump

- (unsigned) scripted_misjump
protected

◆ scriptInfo

- (NSDictionary *) scriptInfo
protected

Definition at line 12728 of file ShipEntity.m.

12729{
12730 return (scriptInfo != nil) ? scriptInfo : (NSDictionary*)[NSDictionary dictionary];
12731}

Referenced by overrideScriptInfo:, scriptInfo, ShipGetProperty(), and ShipGetProperty().

◆ ship_temperature

◆ shipAI

- (AI*) shipAI
protected

◆ shipClassName

- (NSString *) shipClassName
protected

◆ shipinfoDictionary

- (NSDictionary*) shipinfoDictionary
protected

◆ shipUniqueName

- (NSString *) shipUniqueName
protected

◆ shot_counter

- (int) shot_counter
protected

Definition at line 346 of file ShipEntity.h.

◆ shot_time

◆ starboard_weapon_temp

◆ starboard_weapon_type

◆ starboardWeaponOffset

- (NSArray *) starboardWeaponOffset
protected

◆ stick_pitch

◆ stick_roll

◆ stick_yaw

◆ subEntities

◆ subentityRotationalVelocity

- (Quaternion) subentityRotationalVelocity
protected

Definition at line 208 of file ShipEntity.h.

Referenced by setSubEntityRotationalVelocity:, subEntityRotationalVelocity, and update:.

◆ success_factor

◆ sunGlareFilter

- (GLfloat) sunGlareFilter
protected

Definition at line 1111 of file ShipEntity.m.

1112{
1113 return sunGlareFilter;
1114}

Referenced by currentAimTolerance, setSunGlareFilter:, and sunGlareFilter.

◆ suppressAegisMessages

- (unsigned) suppressAegisMessages
protected

◆ suppressExplosion

- (unsigned) suppressExplosion
protected

◆ thrust

◆ totalBoundingBox

◆ trackCloseContacts

- (BOOL) trackCloseContacts
protected

Definition at line 12547 of file ShipEntity.m.

12548{
12549 return trackCloseContacts;
12550}

Referenced by checkCloseCollisionWith:, setTrackCloseContacts:, trackCloseContacts, and update:.

◆ trackingCurveCoeffs

- (HPVector trackingCurveCoeffs[3])
protected

Definition at line 440 of file ShipEntity.h.

Referenced by calculateTargetPosition, and calculateTrackingCurve.

◆ trackingCurvePositions

- (HPVector trackingCurvePositions[4])
protected

Definition at line 438 of file ShipEntity.h.

Referenced by calculateTrackingCurve, startTrackingCurve, and updateTrackingCurve.

◆ trackingCurveTimes

- (OOTimeAbsolute trackingCurveTimes[4])
protected

◆ tractor_position

- (Vector) tractor_position
protected

Definition at line 395 of file ShipEntity.h.

Referenced by absoluteTractorPosition.

◆ v_forward

◆ v_right

◆ v_up

◆ weapon_damage

◆ weapon_damage_override

- (GLfloat) weapon_damage_override
protected

Definition at line 299 of file ShipEntity.h.

Referenced by setUpShipFromDictionary:.

◆ weapon_energy_use

- (GLfloat) weapon_energy_use
protected

◆ weapon_facings

- (OOWeaponFacingSet) weapon_facings
protected

Definition at line 293 of file ShipEntity.h.

Referenced by setWeaponMount:toWeapon:, weaponFacings, and weaponTypeIDForFacing:strict:.

◆ weapon_recharge_rate

◆ weapon_shot_temperature

- (GLfloat) weapon_shot_temperature
protected

◆ weapon_temp

◆ weaponRange


The documentation for this class was generated from the following files: