/// <summary> /// Calculates all the differences in comparison to our grid position that we need to search for targets. /// </summary> /// <returns></returns> private List <int[]> CalculateAllDifferences(INTERACTION_DIR DIRECTIONS, int DISTANCE) { // The return list of grid position differences to search for. List <int[]> differences = new List <int[]>(); // The rotation to adjust for. ROTATION_VAL[] ROT_ADJUST_ENUM = GetComponent <GridController>().GRID_ROT; // The rotation values to use when adjusting Vector3 ROT_ADJUST = GetComponent <GridController>().CalculateRotVector(ROT_ADJUST_ENUM); // List of directions to use when calculating. List <Vector3> directions = new List <Vector3>(); // Add all the directional vectors from our transform depending on our flags. if (ID_UTIL.HasTag(DIRECTIONS, INTERACTION_DIR.Front)) { directions.Add(transform.forward); } if (ID_UTIL.HasTag(DIRECTIONS, INTERACTION_DIR.Back)) { directions.Add(-transform.forward); } if (ID_UTIL.HasTag(DIRECTIONS, INTERACTION_DIR.Left)) { directions.Add(-transform.right); } if (ID_UTIL.HasTag(DIRECTIONS, INTERACTION_DIR.Right)) { directions.Add(transform.right); } if (ID_UTIL.HasTag(DIRECTIONS, INTERACTION_DIR.Top)) { directions.Add(transform.up); } if (ID_UTIL.HasTag(DIRECTIONS, INTERACTION_DIR.Bottom)) { directions.Add(-transform.up); } // Calculate the difference that we want to search for each direction we need to look at. foreach (Vector3 DIR in directions) { // The difference we are going to add. int[] difference = GetComponent <GridController>().CalculateGridPos( GetComponent <GridController>().TARGET_POS + DIR * CONSTANTS.grid_length * DISTANCE); // Add the calculate difference. differences.Add(difference); } // Return all calculated differences. // IF there are none this will be count 0. return(differences); }
/// <summary> /// Scans for an inventory to extract from. /// </summary> /// <returns></returns> public EntityController ScanForTarget(INTERACTION_DIR DIRECTIONS, int DISTANCE) { //First get all the search coordinates we need. List <int[]> SEARCH_COORDS = CalculateAllDifferences(DIRECTIONS, DISTANCE); //List for all possible entities List <GameObject> POSSIBLE_TARGETS = new List <GameObject>(); //Search through all the search coordinates. foreach (int[] coord in SEARCH_COORDS) { //The target object at the given difference. GameObject TARGET = GameManager.Instance.FindEntityWithDifference(GetComponent <GridController>(), coord); //If we received a target object, and it has an inventory component if (TARGET != null) { //If the entity has the tag to treat it as an inventory... if (ENT_UTIL.HasTag(TARGET.GetComponent <EntityController>().INFO.FLAGS, ENTITY_TYPE.InventoryEntity)) { //If we pass the inventory permission check if (GameManager.Instance.CheckInventoryPermissions(GetComponent <EntityController>().INFO.FLAGS, TARGET.GetComponent <Inventory>().INV_FLAGS)) { POSSIBLE_TARGETS.Add(TARGET); } }//If the entity has the tag to treat it as a belt... else if (ENT_UTIL.HasTag(TARGET.GetComponent <EntityController>().INFO.FLAGS, ENTITY_TYPE.TransportEntity)) { //All belts are accessible so add as possible targets. POSSIBLE_TARGETS.Add(TARGET); } } } //Return the first target that has inventory component. //This means that it will return the direction that is higher in priority, //as in the ones with lower bit values. //Order is: Front -> Back -> Left -> Right -> Top -> Bottom. foreach (GameObject OBJ in POSSIBLE_TARGETS) { return(OBJ.GetComponent <EntityController>()); } //If we find nothing, return null. return(null); }
/// <summary> /// Checks if a given set of flags contains a flag /// Cannot check for flag none. /// </summary> /// <param name="FLAGS"></param> /// <param name="NEW_FLAG"></param> /// <returns></returns> public bool HasTag(INTERACTION_DIR FLAGS, INTERACTION_DIR NEW_FLAG) { return((FLAGS & NEW_FLAG) != 0); }
/// <summary> /// Toggles a given flag within the set of flags. /// If it was false, makes it true, if it was true, makes it false. /// </summary> /// <param name="FLAGS"></param> /// <param name="NEW_FLAG"></param> /// <returns></returns> public INTERACTION_DIR ToggleTag(INTERACTION_DIR FLAGS, INTERACTION_DIR NEW_FLAG) { return(FLAGS ^= NEW_FLAG); }
/// <summary> /// Removes a given flag for an item /// </summary> /// <param name="FLAGS"></param> /// <param name="NEW_FLAG"></param> /// <returns></returns> public INTERACTION_DIR RemoveTag(INTERACTION_DIR FLAGS, INTERACTION_DIR NEW_FLAG) { return(FLAGS &= ~NEW_FLAG); }
/// <summary> /// Adds new tags to items /// </summary> /// <param name="FLAGS"></param> /// <param name="NEW_FLAG"></param> /// <returns></returns> public INTERACTION_DIR AddTag(INTERACTION_DIR FLAGS, INTERACTION_DIR NEW_FLAG) { return(FLAGS |= NEW_FLAG); }