diff --git a/Doc/CHANGELOG.TXT b/Doc/CHANGELOG.TXT index 8f61a6be..7702b1fb 100644 --- a/Doc/CHANGELOG.TXT +++ b/Doc/CHANGELOG.TXT @@ -316,6 +316,7 @@ Bug fixes: * Bug making tutorial extremely difficult to complete if player obtained a bounty fixed. * Fix error with cargo dumping when reloading save after death +* Fix NPC turret aim ------------------------------------------------------------------------------- diff --git a/src/Core/Entities/ShipEntity.m b/src/Core/Entities/ShipEntity.m index 89130536..6ccae27d 100644 --- a/src/Core/Entities/ShipEntity.m +++ b/src/Core/Entities/ShipEntity.m @@ -10205,13 +10205,23 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q vector_to_target = HPVectorToVector(HPvector_subtract([target position], my_position)); // this is in absolute coordinates, so now rotate it + OOLog(@"turret.debug",@"abs:[%f %f %f], vector:[%f %f %f]",my_position.x,my_position.y,my_position.z,vector_to_target.x,vector_to_target.y,vector_to_target.z); + Entity *last = nil; Entity *father = [self parentEntity]; Quaternion q = kIdentityQuaternion; while ((father)&&(father != last) && (father != NO_TARGET)) { - q = quaternion_multiply(q,quaternion_conjugate([father orientation])); + /* Fix orientation */ + Quaternion fo = [father normalOrientation]; + fo.w = -fo.w; + /* The below code works for player turrets where the + * orientation is different, but not for NPC turrets. Taking + * the normal orientation with -w works: there is probably a + * neater way which someone who understands quaternions can + * find, but this works well enough for 1.82 - CIM */ + q = quaternion_multiply(q,quaternion_conjugate(fo)); last = father; if (![last isSubEntity]) break; father = [father owner]; @@ -10220,6 +10230,9 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q // q now contains the rotation to the turret's reference system vector_to_target = quaternion_rotate_vector(q,vector_to_target); + + OOLog(@"turret.debug",@"adjvector:[%f %f %f]",vector_to_target.x,vector_to_target.y,vector_to_target.z); + leading = quaternion_rotate_vector(q,leading); // rotate the vector to target and its velocity diff --git a/src/Core/OOShipRegistry.m b/src/Core/OOShipRegistry.m index 96fe4699..02705632 100644 --- a/src/Core/OOShipRegistry.m +++ b/src/Core/OOShipRegistry.m @@ -1660,6 +1660,13 @@ static NSString * const kVisualEffectDataCacheKey = @"visual effect data"; if ([[ScanTokensFromString(action) objectAtIndex:0] isEqualToString:@"initialiseTurret"]) return YES; } + if ([shipKey isEqualToString:@"ballturret"]) + { + // compatibility for OXPs using old subentity declarations and the + // core turret entity + return YES; + } + return NO; }