Added the JS global randomInhabitantsDescription() method. Takes a boolean parameter or no parameters. If parameter is true, a random inhabtitants description in plural is generated. If parameter is false or no parameter exists, the generated description is in singular form.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@1640 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Nikos Barkas 2008-05-17 11:17:44 +00:00
parent fd377b0208
commit b30914187c

View File

@ -54,6 +54,7 @@ static JSBool GlobalLog(JSContext *context, JSObject *this, uintN argc, jsval *a
static JSBool GlobalExpandDescription(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
static JSBool GlobalDisplayNameForCommodity(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
static JSBool GlobalRandomName(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
static JSBool GlobalRandomInhabitantsDescription(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
static JSClass sGlobalClass =
@ -96,6 +97,7 @@ static JSFunctionSpec sGlobalMethods[] =
{ "expandDescription", GlobalExpandDescription, 1 },
{ "displayNameForCommodity", GlobalDisplayNameForCommodity, 1 },
{ "randomName", GlobalRandomName, 0 },
{ "randomInhabitantsDescription", GlobalRandomInhabitantsDescription, 1 },
{ 0 }
};
@ -205,3 +207,23 @@ static JSBool GlobalRandomName(JSContext *context, JSObject *this, uintN argc, j
return YES;
}
// randomInhabitantsDescription() : String
static JSBool GlobalRandomInhabitantsDescription(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult)
{
NSString *string = nil;
Random_Seed aSeed;
JSBool isPlural;
if (!JS_ValueToBoolean(context, argv[0], &isPlural))
{
isPlural = NO;
}
make_pseudo_random_seed( &aSeed);
string = [UNIVERSE generateSystemInhabitants:aSeed plural:isPlural];
*outResult = [string javaScriptValueInContext:context];
return YES;
}