Last active
October 20, 2016 22:54
-
-
Save dedmen/9c06a8d57e1e9e4c0bf97de234f42b33 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GameValue GetAllMissionObjects(const GameState *state, GameValuePar oper1) | |
{ | |
GameValue value = state->CreateGameValue(GameArray); | |
RString typeName = oper1; | |
if (GWorld) | |
{ | |
GameArrayType &array = value; | |
// repair all objects, remove any non-primaries | |
for( int x=0; x< GLandscape->GetLandRange(); x++ ) for( int z=0; z< GLandscape->GetLandRange(); z++ ) | |
{ | |
const ObjectList &list=GLandscape->GetObjects(x,z); | |
for (int i = 0; i < list.Size(); i++) | |
{ | |
Object *obj=list[i]; | |
if( obj->GetType() != Primary && obj->GetType() != Network) | |
{ | |
if (typeName.GetLength() > 0) | |
{ | |
const EntityType *type = obj->GetEntityType(); | |
if (!type->IsKindOf(typeName)) continue; | |
} | |
array.Add(GameValueExt(obj)); | |
} | |
} | |
} | |
array.Compact(); | |
return value; | |
} | |
return value; | |
} | |
GameValue GetEntities(const GameState *state, GameValuePar oper1) | |
{ | |
GameValue value = state->CreateGameValue(GameArray); | |
if (!GWorld) return value; | |
GameArrayType &array = value; | |
BuildVehicleListByType build(array, oper1); | |
GWorld->ForEachVehicle(build); | |
array.Compact(); | |
return value; | |
} | |
GameValue GetNearestObjects(const GameState *state, GameValuePar oper1) | |
{ | |
Vector3 pos; | |
GameValue value = state->CreateGameValue(GameArray); | |
GameArrayType &objs = value; | |
const GameArrayType &array = oper1; | |
if (array.Size() != 3) | |
{ | |
state->SetError(EvalDim,array.Size(),3); | |
return value; | |
} | |
// get position | |
if (!GetPos(state,pos,array[0])) return value; | |
if (array[1].GetType() != GameArray) | |
{ | |
state->TypeError(GameArray, array[1].GetType()); | |
return value; | |
} | |
GameArrayType t = array[1]; | |
RefArray<const EntityType> types; | |
for (int i=0; i<t.Size(); i++) | |
{ | |
if (t[i].GetType() != GameString) | |
{ | |
state->TypeError(GameString, t[i].GetType()); | |
return value; | |
} | |
RString tName = t[i]; | |
types.Add(VehicleTypes.New(tName)); | |
} | |
int nTypes = types.Size(); | |
// return an array of objects within a certain distance | |
if (array[2].GetType() != GameScalar) | |
{ | |
state->TypeError(GameScalar, array[2].GetType()); | |
return value; | |
} | |
float limit = array[2]; | |
int xMin, xMax, zMin, zMax; | |
ObjRadiusRectangle(xMin, xMax, zMin, zMax, pos, pos, limit); | |
float minDist2 = Square(limit); | |
for (int x=xMin; x<=xMax; x++) for (int z=zMin; z<=zMax; z++) | |
{ | |
const ObjectListUsed &list = GLandscape->UseObjects(x,z); | |
int n = list.Size(); | |
for (int i=0; i<n; i++) | |
{ | |
Object *obj = list[i]; | |
if (obj->FutureVisualState().Position().Distance2(pos) > minDist2) continue; | |
if (nTypes > 0) | |
{ | |
// test to see if vehicle inherits from the requested type | |
//VBS2, changed, since it was missing objects like streetlamps | |
#if !_VBS3 | |
EntityAI *ai=dyn_cast<EntityAI>(obj); | |
if (!ai) continue; | |
#endif | |
bool typeFound = false; | |
for (int j=0; j<nTypes; j++) | |
#if !_VBS3 | |
if( ai->GetType()->IsKindOf(types[j]) ) {typeFound = true; break;} | |
#else | |
if( obj->GetEntityType()->IsKindOf(types[j]) ) {typeFound = true; break;} | |
#endif | |
if (!typeFound) continue; | |
} | |
objs.Add(GameValueExt(obj,GameValExtObject)); | |
} | |
} | |
QSort(objs.Data(), objs.Size(), pos, CmpNearObjs); | |
objs.Compact(); | |
return value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment