Make ship.weaponPosition* return an array of vectors

This commit is contained in:
cim 2015-08-22 15:34:22 +01:00
parent cb97021d18
commit 5a84795861
8 changed files with 63 additions and 3 deletions

View File

@ -1971,7 +1971,7 @@ static ShipEntity *doOctreesCollide(ShipEntity *prime, ShipEntity *other);
}
#define MAKE_VECTOR_ARRAY(v) [NSArray arrayWithObjects:[NSNumber numberWithFloat:v.x], [NSNumber numberWithFloat:v.y], [NSNumber numberWithFloat:v.z], nil]
#define MAKE_VECTOR_ARRAY(v) [[[OONativeVector alloc] initWithVector:v] autorelease]
- (NSArray *) getWeaponOffsetFrom:(NSDictionary *)dict withKey:(NSString *)key inMode:(NSString *)mode
{
@ -11467,7 +11467,10 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q
ShipEntity *se = nil;
for (subEnum = [self shipSubEntityEnumerator]; (se = [subEnum nextObject]); )
{
if ([se fireSubentityLaserShot:range]) fired = YES;
if ([se fireSubentityLaserShot:range])
{
fired = YES;
}
}
}

View File

@ -1409,7 +1409,11 @@ Vector OOVectorFromObject(id object, Vector defaultValue)
Vector result = defaultValue;
NSDictionary *dict = nil;
if ([object isKindOfClass:[NSString class]])
if ([object isKindOfClass:[OONativeVector class]])
{
result = [object getVector];
}
else if ([object isKindOfClass:[NSString class]])
{
// This will only write result if a valid vector is found, and will write an error message otherwise.
ScanVectorFromString(object, &result);

View File

@ -131,6 +131,18 @@ OOINLINE Vector normal_to_surface(Vector v1, Vector v2, Vector v3) CONST_FUNC;
#if __OBJC__
NSString *VectorDescription(Vector vector); // @"(x, y, z)"
/* For storing vectors in NSArrays */
@interface OONativeVector: NSObject
{
@private
Vector v;
}
- (id) initWithVector:(Vector)vect;
- (Vector) getVector;
@end
#endif
#if OOMATHS_OPENGL_INTEGRATION

View File

@ -44,9 +44,31 @@ NSString *VectorDescription(Vector vector)
{
return [NSString stringWithFormat:@"(%g, %g, %g)", vector.x, vector.y, vector.z];
}
@implementation OONativeVector
- (id) initWithVector:(Vector)vect
{
self = [super init];
if (EXPECT_NOT(self == nil)) return nil;
v = vect;
return self;
}
- (Vector) getVector
{
return v;
}
@end
#endif
#if !OOMATHS_STANDALONE
/* This generates random vectors distrubuted evenly over the surface of the
unit sphere. It does this the simple way, by generating vectors in the

View File

@ -4122,6 +4122,9 @@ static JSBool ShipThreatAssessment(JSContext *context, uintN argc, jsval *vp)
// check lasers
OOWeaponType wt = [thisEnt weaponTypeIDForFacing:WEAPON_FACING_FORWARD strict:NO];
/* Not affected by multiple mounts here: they're either just a
* split of the power, or only more dangerous until they
* overheat */
assessment += ShipThreatAssessmentWeapon(wt);
if (isWeaponNone(wt))
{

View File

@ -73,3 +73,6 @@ BOOL VectorFromArgumentList(JSContext *context, NSString *scriptClass, NSString
Like VectorFromArgumentList(), but does not report an error on failure.
*/
BOOL VectorFromArgumentListNoError(JSContext *context, uintN argc, jsval *argv, HPVector *outVector, uintN *outConsumed) GCC_ATTR((nonnull (1, 3, 4)));

View File

@ -1136,3 +1136,5 @@ static JSBool VectorStaticRandomDirectionAndLength(JSContext *context, uintN arg
OOJS_PROFILE_EXIT
}

View File

@ -1904,6 +1904,17 @@ NSString *OOJSDescribeValue(JSContext *context, jsval value, BOOL abbreviateObje
@end
@implementation OONativeVector (OOJavaScriptConversion)
- (jsval)oo_jsValueInContext:(JSContext *)context
{
jsval value = JSVAL_VOID;
VectorToJSValue(context, v, &value);
return value;
}
@end
@implementation NSDictionary (OOJavaScriptConversion)