/// <summary> /// Adds an item given an extractor/inserter. Calculates and places in the right slot. /// </summary> /// <param name="item"></param> /// <param name="inserter"></param> /// <returns></returns> public GenericItem AddItem(GenericItem item, Extractor inserter) { //Side the inserter is using InsertSide insert_side = inserter.OUTPUT_SIDE; InsertDir insert_dir = GetInsertDir(inserter.GetComponent <GridController>()); BeltSide side = GetBeltSide(insert_dir, insert_side); BeltPos pos = GetBeltPos(insert_dir, insert_side); //If it isn't valid, return immediately. if (!isValidInsert(insert_dir, insert_side)) { return(null); } else { //Get the relevant list. List <ItemController> LIST = GetSideList(side); //Get the relevant index. int index = GetIndex(side, pos); //Update the right index. LIST[(int)pos] = item.SpawnObject(ITEM_POSITIONS[index].position, ITEM_POSITIONS[index].rotation, ITEM_POSITIONS[index]); return(LIST[(int)pos].INFO); } }
/// <summary> /// Attempts to insert an item given an extractor/inserter. /// Returns the item if successful, else null. /// </summary> /// <param name="item"></param> /// <param name="inserter"></param> /// <returns></returns> public bool AttemptExtractItem(GenericItem item, Extractor inserter) { //Side the inserter is using InsertSide insert_side = inserter.OUTPUT_SIDE; InsertDir insert_dir = GetInsertDir(inserter.GetComponent <GridController>()); BeltSide side = GetBeltSide(insert_dir, insert_side); BeltPos pos = GetBeltPos(insert_dir, insert_side); return(isItemAccessible(side, pos, item)); }
/// <summary> /// Returns the index in the item positions list for the given slot. /// </summary> /// <param name="side"></param> /// <param name="pos"></param> /// <returns></returns> public int GetIndex(BeltSide side, BeltPos pos) { if (side == BeltSide.Left) { return((int)pos); } else { return((int)pos + 3); } }
/// <summary> /// Returns the list that pertains to the inputted side of the belt. /// </summary> /// <param name="side"></param> /// <returns></returns> public List <ItemController> GetSideList(BeltSide side) { switch (side) { case BeltSide.Left: return(LEFT_BELT); case BeltSide.Right: return(RIGHT_BELT); default: throw new System.Exception("Error, invalid side."); } }
/// <summary> /// Returns true or false depending on if the slot that is meant to be used on insert based on direction is empty. /// Inserters output either to their left or right half of the square. As such: /// Left insert direction inserters outputting to the left output to the front of the belt. /// Left insert direction inserters outputting to the right output to the back of the belt. /// </summary> /// <param name="insertDir"></param> /// <returns></returns> public bool isValidInsert(InsertDir insertDir, InsertSide insertSide) { BeltSide side = GetBeltSide(insertDir, insertSide); BeltPos pos = GetBeltPos(insertDir, insertSide); ItemController EC = GetItem(side, pos); if (EC == null) { return(true); } else { return(false); } }
/// <summary> /// Checks if the given item is in the given side and position. /// </summary> /// <param name="side"></param> /// <param name="pos"></param> /// <param name="item"></param> /// <returns></returns> public bool isItemAccessible(BeltSide side, BeltPos pos, GenericItem item) { ItemController SLOT_ITEM = GetItem(side, pos); if (SLOT_ITEM == null) { return(false); } else if (SLOT_ITEM.INFO == item) { return(true); } else { return(false); } }
/// <summary> /// Returns the entitycontroller in the given position on the given side. /// </summary> /// <param name="side"></param> /// <param name="pos"></param> /// <returns></returns> public ItemController GetItem(BeltSide side, BeltPos pos) { //Get the right side of the belt. List <ItemController> SIDE_LIST = GetSideList(side); //Return the entity in a given position from the side list. switch (pos) { case BeltPos.Back: return(SIDE_LIST[(int)BeltPos.Back]); case BeltPos.Middle: return(SIDE_LIST[(int)BeltPos.Middle]); case BeltPos.Front: return(SIDE_LIST[(int)BeltPos.Front]); default: throw new System.Exception("Error, invalid belt position."); } }
/// <summary> /// Extracts item with given inserter. /// Only decrements this inventory, does not add to the inserter's inventory. /// Returns the item if successful, else null; /// </summary> /// <param name="item"></param> /// <param name="inserter"></param> /// <returns></returns> public GenericItem ExtractItem(GenericItem item, Extractor inserter) { //Side the inserter is using InsertSide insert_side = inserter.OUTPUT_SIDE; InsertDir insert_dir = GetInsertDir(inserter.GetComponent <GridController>()); BeltSide side = GetBeltSide(insert_dir, insert_side); BeltPos pos = GetBeltPos(insert_dir, insert_side); //Get the relevant list. List <ItemController> LIST = GetSideList(side); //Get the relevant index. int index = GetIndex(side, pos); //Save the item to be returned GenericItem item_ret = LIST[(int)pos].INFO; //Update side list. LIST[(int)pos].DespawnObject(); LIST[(int)pos] = null; return(item_ret); }
// ******************************************************************************************************** // PARAMS CREATION **************************************************************************************** // ******************************************************************************************************** // CREATION OF BELT PARAMS private BeltParams CreateBeltParams(BeltType beltType, BeltSide beltSide, int parentPoleID) { BeltParams beltParams = null; switch (beltType) { case BeltType.gun: beltParams = new BeltParams() { beltMaxSpin = 1.5f, beltMinSpin = 0.1F, beltSpinPrecision = 1f, unitMaxSpin = 1.5f, unitSpinPrecision = 1f, unitMinAngle = -30, unitMaxAngle = 30, }; break; case BeltType.machinegun: beltParams = new BeltParams() { beltMaxSpin = 2f, beltMinSpin = 0.1F, beltSpinPrecision = 0.1f, unitMaxSpin = 2f, unitSpinPrecision = 0.1f, unitMinAngle = -45, unitMaxAngle = 45, }; break; case BeltType.rocket: beltParams = new BeltParams() { beltMaxSpin = 1f, beltMinSpin = 0.1F, beltSpinPrecision = 3f, unitMaxSpin = 1f, unitSpinPrecision = 3f, unitMinAngle = -20, unitMaxAngle = 20, }; break; case BeltType.plasma: break; case BeltType.grenadelauncher: break; case BeltType.railgun: break; case BeltType.missile: break; case BeltType.autotracking_lasers: break; case BeltType.shield: break; case BeltType.radar: break; default: break; } beltParams.type = beltType; beltParams.side = beltSide; return(beltParams); }