Expose the simulation-time object IDs

They are useful
This commit is contained in:
Norbi Peti 2020-06-05 00:57:22 +02:00
parent cae626197f
commit 448cf3af48
2 changed files with 19 additions and 4 deletions

View file

@ -144,14 +144,14 @@ namespace GamecraftModdingAPI.Blocks
return ret.ToArray(); return ret.ToArray();
} }
public ObjectIdentifier[] GetObjectIDsFromID(byte id) public ObjectIdentifier[] GetObjectIDsFromID(byte id, bool sim)
{ {
var ret = new FasterList<ObjectIdentifier>(4); var ret = new FasterList<ObjectIdentifier>(4);
if (!entitiesDB.HasAny<ObjectIdEntityStruct>(CommonExclusiveGroups.OWNED_BLOCKS_GROUP)) if (!entitiesDB.HasAny<ObjectIdEntityStruct>(CommonExclusiveGroups.OWNED_BLOCKS_GROUP))
return new ObjectIdentifier[0]; return new ObjectIdentifier[0];
var oids = entitiesDB.QueryEntities<ObjectIdEntityStruct>(CommonExclusiveGroups.OWNED_BLOCKS_GROUP); var oids = entitiesDB.QueryEntities<ObjectIdEntityStruct>(CommonExclusiveGroups.OWNED_BLOCKS_GROUP);
foreach (ref ObjectIdEntityStruct oid in oids) foreach (ref ObjectIdEntityStruct oid in oids)
if (oid.objectId == id) if (sim ? oid.simObjectId == id : oid.objectId == id)
ret.Add(new ObjectIdentifier(oid.ID)); ret.Add(new ObjectIdentifier(oid.ID));
return ret.ToArray(); return ret.ToArray();
} }

View file

@ -32,10 +32,25 @@ namespace GamecraftModdingAPI.Blocks
} }
/// <summary> /// <summary>
/// Finds the identfier blocks with the given ID. /// Simulation-time ID. Assigned by the game starting from 0.
/// </summary>
public byte SimID
{
get => BlockEngine.GetBlockInfo<ObjectIdEntityStruct>(Id).simObjectId;
}
/// <summary>
/// Finds the identifier blocks with the given ID.
/// </summary> /// </summary>
/// <param name="id">The ID to look for</param> /// <param name="id">The ID to look for</param>
/// <returns>An array that may be empty</returns> /// <returns>An array that may be empty</returns>
public static ObjectIdentifier[] GetByID(char id) => BlockEngine.GetObjectIDsFromID((byte) (id - 'A')); public static ObjectIdentifier[] GetByID(char id) => BlockEngine.GetObjectIDsFromID((byte) (id - 'A'), false);
/// <summary>
/// Finds the identifier blocks with the given simulation-time ID. This ID is assigned by the game starting from 0.
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public static ObjectIdentifier[] GetBySimID(byte id) => BlockEngine.GetObjectIDsFromID(id, true);
} }
} }