Adding ability to use custom sounds for specific lasers (#342)

This commit is contained in:
phkb 2020-08-18 15:26:49 +10:00 committed by GitHub
parent 83ba610bbf
commit 662bf77ae8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 152 additions and 49 deletions

View File

@ -1276,13 +1276,13 @@ MA 02110-1301, USA.
} }
- (void) takeEnergyDamage:(double)amount from:(Entity *)ent becauseOf:(Entity *)other - (void) takeEnergyDamage:(double)amount from:(Entity *)ent becauseOf:(Entity *)other weaponIdentifier:(NSString *)weaponIdentifier
{ {
if (virtual_dock) // can't be damaged if (virtual_dock) // can't be damaged
{ {
return; return;
} }
[super takeEnergyDamage:amount from:ent becauseOf:other]; [super takeEnergyDamage:amount from:ent becauseOf:other weaponIdentifier:weaponIdentifier];
} }

View File

@ -270,7 +270,7 @@ enum OOScanClass
- (void) applyVelocity:(OOTimeDelta)delta_t; - (void) applyVelocity:(OOTimeDelta)delta_t;
- (BOOL) checkCloseCollisionWith:(Entity *)other; - (BOOL) checkCloseCollisionWith:(Entity *)other;
- (void) takeEnergyDamage:(double)amount from:(Entity *)ent becauseOf:(Entity *)other; - (void) takeEnergyDamage:(double)amount from:(Entity *)ent becauseOf:(Entity *)other weaponIdentifier:(NSString *)weaponIdentifier;
- (void) dumpState; // General "describe situtation verbosely in log" command. - (void) dumpState; // General "describe situtation verbosely in log" command.
- (void) dumpSelfState; // Subclasses should override this, not -dumpState, and call throught to super first. - (void) dumpSelfState; // Subclasses should override this, not -dumpState, and call throught to super first.

View File

@ -987,7 +987,7 @@ static NSString * const kOOLogEntityVerificationError = @"entity.linkedList.ver
} }
- (void) takeEnergyDamage:(double) amount from:(Entity *) ent becauseOf:(Entity *) other - (void) takeEnergyDamage:(double) amount from:(Entity *) ent becauseOf:(Entity *) other weaponIdentifier:(NSString *)weaponIdentifier
{ {
} }

View File

@ -96,9 +96,12 @@ MA 02110-1301, USA.
Entity *e = (Entity *)[collidingEntities objectAtIndex:i]; Entity *e = (Entity *)[collidingEntities objectAtIndex:i];
if ([e rootShipEntity] != [self owner]) if ([e rootShipEntity] != [self owner])
{ {
// we're going to force the weapon id to be a phantom equipment key so there is something for
// the PlayerEntitySound to reference. it allow allows for the sound effects to be overridden by OXP.
[e takeEnergyDamage:[self energy] * attenuation [e takeEnergyDamage:[self energy] * attenuation
from:self from:self
becauseOf:[self owner]]; becauseOf:[self owner]
weaponIdentifier:@"EQ_WEAPON_PLASMA_SHOT"];
[UNIVERSE removeEntity:self]; [UNIVERSE removeEntity:self];
// Spawn a plasma burst. // Spawn a plasma burst.

View File

@ -99,13 +99,15 @@ MA 02110-1301, USA.
_color[0] = 0.25f * tf * randf(); _color[0] = 0.25f * tf * randf();
_color[1] = 0.0f; _color[1] = 0.0f;
} }
// manage collisions // manage collisions
Entity *owner = [self owner]; Entity *owner = [self owner];
Entity *e = nil; Entity *e = nil;
foreach (e, collidingEntities) foreach (e, collidingEntities)
{ {
[e takeEnergyDamage:energy from:self becauseOf:owner]; // we're going to force the weapon id to be the qbomb key here, because at this point the cascade entity isn't a ship any more
// and there's no link back to the original.
[e takeEnergyDamage:energy from:self becauseOf:owner weaponIdentifier:@"EQ_QC_MINE"];
} }
// expire after ttl // expire after ttl

View File

@ -2211,6 +2211,7 @@ NSComparisonResult marketSorterByMassUnit(id a, id b, void *market);
[UNIVERSE setGalaxyTo:galaxy_number]; [UNIVERSE setGalaxyTo:galaxy_number];
[UNIVERSE setSystemTo:system_id]; [UNIVERSE setSystemTo:system_id];
[self setUpWeaponSounds];
[self setGalacticHyperspaceBehaviourTo:[[UNIVERSE globalSettings] oo_stringForKey:@"galactic_hyperspace_behaviour" defaultValue:@"BEHAVIOUR_STANDARD"]]; [self setGalacticHyperspaceBehaviourTo:[[UNIVERSE globalSettings] oo_stringForKey:@"galactic_hyperspace_behaviour" defaultValue:@"BEHAVIOUR_STANDARD"]];
[self setGalacticHyperspaceFixedCoordsTo:[[UNIVERSE globalSettings] oo_stringForKey:@"galactic_hyperspace_fixed_coords" defaultValue:@"96 96"]]; [self setGalacticHyperspaceFixedCoordsTo:[[UNIVERSE globalSettings] oo_stringForKey:@"galactic_hyperspace_fixed_coords" defaultValue:@"96 96"]];
@ -5858,7 +5859,7 @@ NSComparisonResult marketSorterByMassUnit(id a, id b, void *market);
{ {
firedMissile = [self launchMine:missile]; firedMissile = [self launchMine:missile];
if (!replacingMissile) [self removeFromPylon:activeMissile]; if (!replacingMissile) [self removeFromPylon:activeMissile];
if (firedMissile != nil) [self playMineLaunched:[self missileLaunchPosition]]; if (firedMissile != nil) [self playMineLaunched:[self missileLaunchPosition] weaponIdentifier:identifier];
} }
else else
{ {
@ -5869,7 +5870,7 @@ NSComparisonResult marketSorterByMassUnit(id a, id b, void *market);
if (firedMissile != nil) if (firedMissile != nil)
{ {
if (!replacingMissile) [self removeFromPylon:activeMissile]; if (!replacingMissile) [self removeFromPylon:activeMissile];
[self playMissileLaunched:[self missileLaunchPosition]]; [self playMissileLaunched:[self missileLaunchPosition] weaponIdentifier:identifier];
} }
} }
@ -6135,7 +6136,7 @@ NSComparisonResult marketSorterByMassUnit(id a, id b, void *market);
{ {
if (![weapon_to_be_fired isTurretLaser]) if (![weapon_to_be_fired isTurretLaser])
{ {
[self fireLaserShotInDirection:currentWeaponFacing]; [self fireLaserShotInDirection:currentWeaponFacing weaponIdentifier:[[self currentWeapon] identifier]];
weaponFired = YES; weaponFired = YES;
} }
else else
@ -6233,7 +6234,7 @@ NSComparisonResult marketSorterByMassUnit(id a, id b, void *market);
- (void) takeEnergyDamage:(double)amount from:(Entity *)ent becauseOf:(Entity *)other - (void) takeEnergyDamage:(double)amount from:(Entity *)ent becauseOf:(Entity *)other weaponIdentifier:(NSString *)weaponIdentifier
{ {
HPVector rel_pos; HPVector rel_pos;
OOScalar d_forward, d_right, d_up; OOScalar d_forward, d_right, d_up;
@ -6269,7 +6270,7 @@ NSComparisonResult marketSorterByMassUnit(id a, id b, void *market);
d_up = dot_product(HPVectorToVector(rel_pos), v_up); d_up = dot_product(HPVectorToVector(rel_pos), v_up);
Vector relative = make_vector(d_right,d_up,d_forward); Vector relative = make_vector(d_right,d_up,d_forward);
[self playShieldHit:relative]; [self playShieldHit:relative weaponIdentifier:weaponIdentifier];
// firing on an innocent ship is an offence // firing on an innocent ship is an offence
if ([other isShip]) if ([other isShip])
@ -6309,7 +6310,7 @@ NSComparisonResult marketSorterByMassUnit(id a, id b, void *market);
if (amount > 0.0) if (amount > 0.0)
{ {
energy -= amount; energy -= amount;
[self playDirectHit:relative]; [self playDirectHit:relative weaponIdentifier:weaponIdentifier];
if (ship_temperature < SHIP_MAX_CABIN_TEMP) if (ship_temperature < SHIP_MAX_CABIN_TEMP)
{ {
/* Heat increase from energy impacts will never directly cause /* Heat increase from energy impacts will never directly cause

View File

@ -992,7 +992,7 @@ static NSTimeInterval time_last_frame;
{ {
if ([self fireMainWeapon]) if ([self fireMainWeapon])
{ {
[self playLaserHit:([self shipHitByLaser] != nil) offset:[[self currentLaserOffset] oo_vectorAtIndex:0]]; [self playLaserHit:([self shipHitByLaser] != nil) offset:[[self currentLaserOffset] oo_vectorAtIndex:0] weaponIdentifier:[[self currentWeapon] identifier]];
} }
} }

View File

@ -2248,7 +2248,7 @@ static int shipsFound;
if (mainStation != nil) if (mainStation != nil)
{ {
[UNIVERSE unMagicMainStation]; [UNIVERSE unMagicMainStation];
[mainStation takeEnergyDamage:500000000.0 from:nil becauseOf:nil]; // 500 million should do it! [mainStation takeEnergyDamage:500000000.0 from:nil becauseOf:nil weaponIdentifier:@""]; // 500 million should do it!
} }
} }

View File

@ -27,6 +27,7 @@ MA 02110-1301, USA.
@interface PlayerEntity (Sound) @interface PlayerEntity (Sound)
- (void) setUpSound; - (void) setUpSound;
- (void) setUpWeaponSounds;
- (void) destroySound; - (void) destroySound;
// Interface sounds; only one at a time // Interface sounds; only one at a time
@ -117,15 +118,15 @@ MA 02110-1301, USA.
- (void) playFuelLeak; - (void) playFuelLeak;
// Damage sounds // Damage sounds
- (void) playShieldHit:(Vector)attackVector; - (void) playShieldHit:(Vector)attackVector weaponIdentifier:(NSString *)weaponIdentifier;
- (void) playDirectHit:(Vector)attackVector; - (void) playDirectHit:(Vector)attackVector weaponIdentifier:(NSString *)weaponIdentifier;
- (void) playScrapeDamage:(Vector)attackVector; - (void) playScrapeDamage:(Vector)attackVector;
// Weapon sounds // Weapon sounds
- (void) playLaserHit:(BOOL)hit offset:(Vector)weaponOffset; - (void) playLaserHit:(BOOL)hit offset:(Vector)weaponOffset weaponIdentifier:(NSString *)weaponIdentifier;
- (void) playWeaponOverheated:(Vector)weaponOffset; - (void) playWeaponOverheated:(Vector)weaponOffset;
- (void) playMissileLaunched:(Vector)weaponOffset; - (void) playMissileLaunched:(Vector)weaponOffset weaponIdentifier:(NSString *)weaponIdentifier;
- (void) playMineLaunched:(Vector)weaponOffset; - (void) playMineLaunched:(Vector)weaponOffset weaponIdentifier:(NSString *)weaponIdentifier;
// Miscellaneous sounds // Miscellaneous sounds
- (void) playEscapePodScooped; - (void) playEscapePodScooped;

View File

@ -28,6 +28,7 @@ MA 02110-1301, USA.
#import "Universe.h" #import "Universe.h"
#import "OOSoundSourcePool.h" #import "OOSoundSourcePool.h"
#import "OOMaths.h" #import "OOMaths.h"
#import "OOEquipmentType.h"
// Sizes of sound source pools // Sizes of sound source pools
@ -52,6 +53,12 @@ static OOSoundSource *sBreakPatternSource;
static OOSoundSourcePool *sBuySellSourcePool; static OOSoundSourcePool *sBuySellSourcePool;
static OOSoundSource *sAfterburnerSources[2]; static OOSoundSource *sAfterburnerSources[2];
static NSDictionary *weaponShotMiss;
static NSDictionary *weaponShotHit;
static NSDictionary *weaponShieldHit;
static NSDictionary *weaponUnshieldedHit;
static NSDictionary *weaponLaunched;
static const Vector kInterfaceBeepPosition = { 0.0f, -0.2f, 0.5f }; static const Vector kInterfaceBeepPosition = { 0.0f, -0.2f, 0.5f };
static const Vector kInterfaceWarningPosition = { 0.0f, -0.2f, 0.4f }; static const Vector kInterfaceWarningPosition = { 0.0f, -0.2f, 0.4f };
static const Vector kBreakPatternPosition = { 0.0f, 0.0f, 1.0f }; static const Vector kBreakPatternPosition = { 0.0f, 0.0f, 1.0f };
@ -94,6 +101,54 @@ static const Vector kAfterburner2Position = { 0.1f, 0.0f, -1.0f };
} }
// sets up the sound key dictionaries for all the available weapons/missiles/mines defined.
- (void) setUpWeaponSounds
{
NSArray *eqTypes = [OOEquipmentType allEquipmentTypes];
NSMutableDictionary *shotMissSounds = [NSMutableDictionary dictionary];
NSMutableDictionary *shotHitSounds = [NSMutableDictionary dictionary];
NSMutableDictionary *shieldHitSounds = [NSMutableDictionary dictionary];
NSMutableDictionary *unshieldedHitSounds = [NSMutableDictionary dictionary];
NSMutableDictionary *weaponLaunchedSounds = [NSMutableDictionary dictionary];
NSEnumerator *eqTypeEnum = nil;
OOEquipmentType *eqType = nil;
// special case: turrets aren't defined with a "EQ_WEAPON" prefix, and plasma shots don't have a matching equipment item,
// so add a unique entry here. this could be overridden if an OXP creates an equipment item with this key.
// plasma shots don't make a sound when fired, so we only need to provide for the hit player sound keys.
[shieldHitSounds setObject:@"[player-hit-by-weapon]" forKey:@"EQ_WEAPON_PLASMA_SHOT"];
[unshieldedHitSounds setObject:@"[player-direct-hit]" forKey:@"EQ_WEAPON_PLASMA_SHOT"];
// grab a local copy of the sound identifiers for weapons to make the process of looking up a sound ref as fast as possible
for (eqTypeEnum = [eqTypes objectEnumerator]; (eqType = [eqTypeEnum nextObject]); )
{
if ([[eqType identifier] hasPrefix:@"EQ_WEAPON"])
{
[shotMissSounds setObject:[eqType fxShotMissName] forKey:[eqType identifier]];
[shotHitSounds setObject:[eqType fxShotHitName] forKey:[eqType identifier]];
[shieldHitSounds setObject:[eqType fxShieldHitName] forKey:[eqType identifier]];
[unshieldedHitSounds setObject:[eqType fxUnshieldedHitName] forKey:[eqType identifier]];
}
if ([eqType isMissileOrMine])
{
[weaponLaunchedSounds setObject:[eqType fxWeaponLaunchedName] forKey:[eqType identifier]];
[shieldHitSounds setObject:[eqType fxShieldHitName] forKey:[eqType identifier]];
[unshieldedHitSounds setObject:[eqType fxUnshieldedHitName] forKey:[eqType identifier]];
}
}
DESTROY(weaponShotMiss);
DESTROY(weaponShotHit);
DESTROY(weaponShieldHit);
DESTROY(weaponUnshieldedHit);
DESTROY(weaponLaunched);
weaponShotMiss = [[NSDictionary alloc] initWithDictionary:shotMissSounds];
weaponShotHit = [[NSDictionary alloc] initWithDictionary:shotHitSounds];
weaponShieldHit = [[NSDictionary alloc] initWithDictionary:shieldHitSounds];
weaponUnshieldedHit = [[NSDictionary alloc] initWithDictionary:unshieldedHitSounds];
weaponLaunched = [[NSDictionary alloc] initWithDictionary:weaponLaunchedSounds];
}
- (void) destroySound - (void) destroySound
{ {
DESTROY(sInterfaceBeepSource); DESTROY(sInterfaceBeepSource);
@ -109,6 +164,12 @@ static const Vector kAfterburner2Position = { 0.1f, 0.0f, -1.0f };
DESTROY(sWeaponSoundPool); DESTROY(sWeaponSoundPool);
DESTROY(sDamageSoundPool); DESTROY(sDamageSoundPool);
DESTROY(sMiscSoundPool); DESTROY(sMiscSoundPool);
DESTROY(weaponShotMiss);
DESTROY(weaponShotHit);
DESTROY(weaponShieldHit);
DESTROY(weaponUnshieldedHit);
DESTROY(weaponLaunched);
} }
@ -575,15 +636,15 @@ static const Vector kAfterburner2Position = { 0.1f, 0.0f, -1.0f };
} }
- (void) playShieldHit:(Vector)attackVector - (void) playShieldHit:(Vector)attackVector weaponIdentifier:(NSString *)weaponIdentifier
{ {
[sDamageSoundPool playSoundWithKey:@"[player-hit-by-weapon]" position:attackVector]; [sDamageSoundPool playSoundWithKey:[weaponShieldHit objectForKey:weaponIdentifier] position:attackVector];
} }
- (void) playDirectHit:(Vector)attackVector - (void) playDirectHit:(Vector)attackVector weaponIdentifier:(NSString *) weaponIdentifier
{ {
[sDamageSoundPool playSoundWithKey:@"[player-direct-hit]" position:attackVector]; [sDamageSoundPool playSoundWithKey:[weaponUnshieldedHit objectForKey:weaponIdentifier] position:attackVector];
} }
@ -593,15 +654,16 @@ static const Vector kAfterburner2Position = { 0.1f, 0.0f, -1.0f };
} }
- (void) playLaserHit:(BOOL)hit offset:(Vector)weaponOffset - (void) playLaserHit:(BOOL)hit offset:(Vector)weaponOffset weaponIdentifier:(NSString *)weaponIdentifier
{ {
if (hit) if (hit)
{ {
[sWeaponSoundPool playSoundWithKey:@"[player-laser-hit]" priority:1.0 expiryTime:0.05 overlap:YES position:weaponOffset]; [sWeaponSoundPool playSoundWithKey:[weaponShotHit objectForKey:weaponIdentifier] priority:1.0 expiryTime:0.05 overlap:YES position:weaponOffset];
} }
else else
{ {
[sWeaponSoundPool playSoundWithKey:@"[player-laser-miss]" priority:1.0 expiryTime:0.05 overlap:YES position:weaponOffset]; [sWeaponSoundPool playSoundWithKey:[weaponShotMiss objectForKey:weaponIdentifier] priority:1.0 expiryTime:0.05 overlap:YES position:weaponOffset];
} }
} }
@ -612,15 +674,15 @@ static const Vector kAfterburner2Position = { 0.1f, 0.0f, -1.0f };
} }
- (void) playMissileLaunched:(Vector)weaponOffset - (void) playMissileLaunched:(Vector)weaponOffset weaponIdentifier:(NSString *)weaponIdentifier
{ {
[sWeaponSoundPool playSoundWithKey:@"[missile-launched]" position:weaponOffset]; [sWeaponSoundPool playSoundWithKey:[weaponLaunched objectForKey:weaponIdentifier] position:weaponOffset];
} }
- (void) playMineLaunched:(Vector)weaponOffset - (void) playMineLaunched:(Vector)weaponOffset weaponIdentifier:(NSString *)weaponIdentifier
{ {
[sWeaponSoundPool playSoundWithKey:@"[mine-launched]" position:weaponOffset]; [sWeaponSoundPool playSoundWithKey:[weaponLaunched objectForKey:weaponIdentifier] position:weaponOffset];
} }

View File

@ -1115,7 +1115,7 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q
- (BOOL) fireDirectLaserDefensiveShot; - (BOOL) fireDirectLaserDefensiveShot;
- (BOOL) fireDirectLaserShotAt:(Entity *)my_target; - (BOOL) fireDirectLaserShotAt:(Entity *)my_target;
- (NSArray *) laserPortOffset:(OOWeaponFacing)direction; - (NSArray *) laserPortOffset:(OOWeaponFacing)direction;
- (BOOL) fireLaserShotInDirection:(OOWeaponFacing)direction; - (BOOL) fireLaserShotInDirection:(OOWeaponFacing)direction weaponIdentifier:(NSString *)weaponIdentifier;
- (void) adjustMissedShots:(int)delta; - (void) adjustMissedShots:(int)delta;
- (int) missedShots; - (int) missedShots;
- (void) considerFiringMissile:(double)delta_t; - (void) considerFiringMissile:(double)delta_t;

View File

@ -845,7 +845,7 @@ static ShipEntity *doOctreesCollide(ShipEntity *prime, ShipEntity *other);
{ {
[se setSuppressExplosion:NO]; [se setSuppressExplosion:NO];
[se setEnergy:1]; [se setEnergy:1];
[se takeEnergyDamage:500000000.0 from:nil becauseOf:nil]; [se takeEnergyDamage:500000000.0 from:nil becauseOf:nil weaponIdentifier:@""];
} }
} }
} }
@ -8881,11 +8881,11 @@ NSComparisonResult ComparePlanetsBySurfaceDistance(id i1, id i2, void* context)
{ {
if ([self owner]) if ([self owner])
{ {
[e2 takeEnergyDamage:damage from:self becauseOf:[self owner]]; [e2 takeEnergyDamage:damage from:self becauseOf:[self owner] weaponIdentifier:[self primaryRole]];
} }
else else
{ {
[e2 takeEnergyDamage:damage from:self becauseOf:self]; [e2 takeEnergyDamage:damage from:self becauseOf:self weaponIdentifier:[self primaryRole]];
} }
} }
} }
@ -8923,7 +8923,7 @@ NSComparisonResult ComparePlanetsBySurfaceDistance(id i1, id i2, void* context)
double ecr = [e2 collisionRadius]; double ecr = [e2 collisionRadius];
double d = (magnitude(p2) - ecr) * 2.6; // 2.6 is a correction constant to stay in limits of the old code. double d = (magnitude(p2) - ecr) * 2.6; // 2.6 is a correction constant to stay in limits of the old code.
double damage = (d > 0) ? weapon_damage * desired_range / (d * d) : weapon_damage; double damage = (d > 0) ? weapon_damage * desired_range / (d * d) : weapon_damage;
[e2 takeEnergyDamage:damage from:self becauseOf:[self owner]]; [e2 takeEnergyDamage:damage from:self becauseOf:[self owner] weaponIdentifier:[self primaryRole]];
} }
} }
} }
@ -11496,7 +11496,7 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q
} }
else else
{ {
[self fireLaserShotInDirection:direction]; [self fireLaserShotInDirection:direction weaponIdentifier:[weapon_type identifier]];
fired = YES; fired = YES;
} }
} }
@ -11764,13 +11764,13 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q
if (subent != nil && [victim isFrangible]) if (subent != nil && [victim isFrangible])
{ {
// do 1% bleed-through damage... // do 1% bleed-through damage...
[victim takeEnergyDamage:0.01 * weapon_damage from:self becauseOf:parent]; [victim takeEnergyDamage:0.01 * weapon_damage from:self becauseOf:parent weaponIdentifier:[[self weaponTypeForFacing:WEAPON_FACING_FORWARD strict:YES] identifier]];
victim = subent; victim = subent;
} }
if (hitAtRange < weaponRange) if (hitAtRange < weaponRange)
{ {
[victim takeEnergyDamage:weapon_damage from:self becauseOf:parent]; // a very palpable hit [victim takeEnergyDamage:weapon_damage from:self becauseOf:parent weaponIdentifier:[[self weaponTypeForFacing:WEAPON_FACING_FORWARD strict:YES] identifier]]; // a very palpable hit
[shot setRange:hitAtRange]; [shot setRange:hitAtRange];
Vector vd = vector_forward_from_quaternion([shot orientation]); Vector vd = vector_forward_from_quaternion([shot orientation]);
@ -11889,13 +11889,13 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q
if (subent != nil && [victim isFrangible]) if (subent != nil && [victim isFrangible])
{ {
// do 1% bleed-through damage... // do 1% bleed-through damage...
[victim takeEnergyDamage: 0.01 * weapon_damage from:self becauseOf:self]; [victim takeEnergyDamage: 0.01 * weapon_damage from:self becauseOf:self weaponIdentifier:[[self weaponTypeForFacing:WEAPON_FACING_FORWARD strict:YES] identifier]];
victim = subent; victim = subent;
} }
if (hit_at_range * hit_at_range < range_limit2) if (hit_at_range * hit_at_range < range_limit2)
{ {
[victim takeEnergyDamage:weapon_damage from:self becauseOf:self]; // a very palpable hit [victim takeEnergyDamage:weapon_damage from:self becauseOf:self weaponIdentifier:[[self weaponTypeForFacing:WEAPON_FACING_FORWARD strict:YES] identifier]]; // a very palpable hit
[shot setRange:hit_at_range]; [shot setRange:hit_at_range];
Vector vd = vector_forward_from_quaternion([shot orientation]); Vector vd = vector_forward_from_quaternion([shot orientation]);
@ -11938,7 +11938,7 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q
} }
- (BOOL) fireLaserShotInDirection:(OOWeaponFacing)direction - (BOOL) fireLaserShotInDirection:(OOWeaponFacing)direction weaponIdentifier:(NSString *)weaponIdentifier
{ {
double range_limit2 = weaponRange * weaponRange; double range_limit2 = weaponRange * weaponRange;
GLfloat hit_at_range; GLfloat hit_at_range;
@ -11997,13 +11997,13 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q
if (subent != nil && [victim isFrangible]) if (subent != nil && [victim isFrangible])
{ {
// do 1% bleed-through damage... // do 1% bleed-through damage...
[victim takeEnergyDamage: 0.01 * effective_damage from:self becauseOf:self]; [victim takeEnergyDamage: 0.01 * effective_damage from:self becauseOf:self weaponIdentifier:weaponIdentifier];
victim = subent; victim = subent;
} }
if (hit_at_range * hit_at_range < range_limit2) if (hit_at_range * hit_at_range < range_limit2)
{ {
[victim takeEnergyDamage:effective_damage from:self becauseOf:self]; // a very palpable hit [victim takeEnergyDamage:effective_damage from:self becauseOf:self weaponIdentifier:weaponIdentifier]; // a very palpable hit
[shot setRange:hit_at_range]; [shot setRange:hit_at_range];
Vector vd = vector_forward_from_quaternion([shot orientation]); Vector vd = vector_forward_from_quaternion([shot orientation]);
@ -13120,7 +13120,7 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q
} }
- (void) takeEnergyDamage:(double)amount from:(Entity *)ent becauseOf:(Entity *)other - (void) takeEnergyDamage:(double)amount from:(Entity *)ent becauseOf:(Entity *)other weaponIdentifier:(NSString *)weaponIdentifier
{ {
if ([self status] == STATUS_DEAD) return; if ([self status] == STATUS_DEAD) return;
if (amount <= 0.0) return; if (amount <= 0.0) return;

View File

@ -1296,7 +1296,7 @@ NSDictionary *OOMakeDockingInstructions(StationEntity *station, HPVector coords,
return [super hasHostileTarget] || ([self primaryTarget] != nil && ((alertLevel == STATION_ALERT_LEVEL_YELLOW) || (alertLevel == STATION_ALERT_LEVEL_RED))); return [super hasHostileTarget] || ([self primaryTarget] != nil && ((alertLevel == STATION_ALERT_LEVEL_YELLOW) || (alertLevel == STATION_ALERT_LEVEL_RED)));
} }
- (void) takeEnergyDamage:(double)amount from:(Entity *)ent becauseOf:(Entity *)other - (void) takeEnergyDamage:(double)amount from:(Entity *)ent becauseOf:(Entity *)other weaponIdentifier:(NSString *)weaponIdentifier
{ {
// stations must ignore friendly fire, otherwise the defenders' AI gets stuck. // stations must ignore friendly fire, otherwise the defenders' AI gets stuck.
BOOL isFriend = NO; BOOL isFriend = NO;
@ -1339,7 +1339,7 @@ NSDictionary *OOMakeDockingInstructions(StationEntity *station, HPVector coords,
if (!isFriend && (self != [UNIVERSE station] || amount < energy) ) if (!isFriend && (self != [UNIVERSE station] || amount < energy) )
{ {
// Handle damage like a ship. // Handle damage like a ship.
[super takeEnergyDamage:amount from:ent becauseOf:other]; [super takeEnergyDamage:amount from:ent becauseOf:other weaponIdentifier:weaponIdentifier];
} }
} }

View File

@ -149,6 +149,11 @@ SOFTWARE.
- (GLfloat) weaponShotTemperature; - (GLfloat) weaponShotTemperature;
- (GLfloat) weaponThreatAssessment; - (GLfloat) weaponThreatAssessment;
- (OOColor *) weaponColor; - (OOColor *) weaponColor;
- (NSString *) fxShotMissName;
- (NSString *) fxShotHitName;
- (NSString *) fxShieldHitName;
- (NSString *) fxUnshieldedHitName;
- (NSString *) fxWeaponLaunchedName;
@end @end

View File

@ -617,7 +617,6 @@ static NSDictionary *sMissilesRegistry = nil;
} }
// weapon properties follow // weapon properties follow
- (BOOL) isTurretLaser - (BOOL) isTurretLaser
{ {
@ -673,6 +672,36 @@ static NSDictionary *sMissilesRegistry = nil;
} }
- (NSString *) fxShotMissName
{
return [_weaponInfo oo_stringForKey:@"fx_shot_miss_name" defaultValue:@"[player-laser-miss]"];
}
- (NSString *) fxShotHitName
{
return [_weaponInfo oo_stringForKey:@"fx_shot_hit_name" defaultValue:@"[player-laser-hit]"];
}
- (NSString *) fxShieldHitName
{
return [_weaponInfo oo_stringForKey:@"fx_hitplayer_shielded_name" defaultValue:@"[player-hit-by-weapon]"];
}
- (NSString *) fxUnshieldedHitName
{
return [_weaponInfo oo_stringForKey:@"fx_hitplayer_unshielded_name" defaultValue:@"[player-direct-hit]"];
}
- (NSString *) fxWeaponLaunchedName
{
return [_weaponInfo oo_stringForKey:@"fx_weapon_launch_name" defaultValue:([[self identifier] hasSuffix:@"_MINE"] ? @"[mine-launched]" : @"[missile-launched]")];
}
/* This method exists purely to suppress Clang static analyzer warnings that /* This method exists purely to suppress Clang static analyzer warnings that
this ivar is unused (but may be used by categories, which it is). this ivar is unused (but may be used by categories, which it is).
FIXME: there must be a feature macro we can use to avoid actually building FIXME: there must be a feature macro we can use to avoid actually building

View File

@ -3370,7 +3370,7 @@ static BOOL RemoveOrExplodeShip(JSContext *context, uintN argc, jsval *vp, BOOL
{ {
[thisEnt setSuppressExplosion:!explode]; [thisEnt setSuppressExplosion:!explode];
[thisEnt setEnergy:1]; [thisEnt setEnergy:1];
[thisEnt takeEnergyDamage:500000000.0 from:nil becauseOf:nil]; [thisEnt takeEnergyDamage:500000000.0 from:nil becauseOf:nil weaponIdentifier:@""];
} }
OOJS_RETURN_VOID; OOJS_RETURN_VOID;