//------------------------------------------------------------------------------------------------- // private methods //------------------------------------------------------------------------------------------------- private bool checkAndExchangeItems(EntityAction giver, EntityAction getter, GameTypes.ItemType type, float cycle_amount) //checks everything and moves some of one item from the giver to the getter { //check the progress mCycleProgress += cycle_amount; int amount = 0; if (mCycleProgress >= 100) { amount = 1; mCycleProgress = 0f; } else { return(false); } //does the acter have the item? Item act_item = giver.getItemOfType(type); if (!act_item) { //acter doesnt have the item, so cant do exchange setRemoveItem(type); //Debug.Log("acter doesnt have the item"); return(false); } //does the acter have enough of the item if (act_item.getAmount() < amount) { amount = act_item.getAmount(); //Debug.Log("acter doesnt have enough of the item, adjusting amount"); } //does the target have the item to receive? Item tar_item = getter.getItemOfType(type); if (!tar_item) { //target doesnt have the item, make one tar_item = ObjectManager.initItem(type, getter.getInventory().transform); getter.addItem(tar_item); //Debug.Log("target doesnt have the item"); } //does the target have enough space for this item int cap = getter.getInventory().mCapacity; int invsize = getter.getInventorySize(); if (invsize + amount > cap) { //target doesnt have space, reduce the amount amount = cap - invsize; if (amount <= 0) { setRemoveItem(type); return(false); } //control flow moves on if cycle amount is big enough } //target has space, add and remove the amount tar_item.setAmount(tar_item.getAmount() + amount); act_item.setAmount(act_item.getAmount() - amount); if (mExchangeList[type] >= 0) { mExchangeList[type] = mExchangeList[type] - amount; } else if (mExchangeList[type] < 0) { mExchangeList[type] = mExchangeList[type] + amount; } return(false); }
//------------------------------------------------------------------------------------------------- // public methods //------------------------------------------------------------------------------------------------- public void populate(Entity ent) { //clear menu clear(); //populate the info for the Entity string text = string.Format("Name: {0}\n", ent.mName); Vector3 epos = ent.transform.position; text += string.Format("Pos: ({0:0},{1:0})\n", epos.x, epos.z); EntityHP ent_hp = ent as EntityHP; if (ent) { //TEMP, see if the entity is in the visible list foreach (Entity e in ObjectManager.getVisibleEntities()) { if (ent == e) { text += string.Format("Is Visible: True\n"); break; } } } if (ent_hp) { text += string.Format("HP: {0:0} \n", ent_hp.mHP); } EntityAction ent_act = ent as EntityAction; Unit unit = ent as Unit; if (ent_act) { if (!unit) { text += string.Format("InvCap.: {0:0} \n", ent_act.getInventory().mCapacity); } if (ent_act.mTown) { text += string.Format("Town: {0}\n", ent_act.mTown.mName); //text += string.Format("StockPile: {0}\n", ent_act.mTown.mStockpile.mName); } } Resource res = ent as Resource; if (res) { text += string.Format("Amount: {0:0} \n", res.mAmount); } //unit if (unit) { //hunger text += string.Format("Hunger: {0:0}\n", unit.getHunger()); //garrison status if (unit.isGarrisoned()) { text += string.Format("Garrison: {0}\n", unit.getGarrison().mName); setupUnitUngarrisonButton(unit, mButton1); } //gender text += string.Format("Gender: {0}\n", unit.getGender().ToString()); //pregnancy if (unit.getGender() == GameTypes.GenderType.Female) { text += string.Format("Pregnant: {0}\n", unit.isPregnant().ToString()); if (unit.isPregnant()) { text += string.Format("Preg.Prog.: {0:0}\n", unit.getPregnancyProgress()); } } text += unit.printStats(); } Building build = ent as Building; if (build) { text += string.Format("GarrisonCap.: {0}\n", build.getUnitInventory().mCapacity); text += string.Format("Garrisoned: {0}\n", build.getUnitInventorySize()); if (build.getUnitInventorySize() > 0) { //make the ungarrisonall button setupBuildingUngarrisonButton(build, mButton1); } } Construction constro = ent as Construction; if (constro) { text += constro.printMaterialsMap(); text += string.Format("Progress: {0:0}", constro.getProgress()); } WorkedBuilding wb = ent as WorkedBuilding; if (wb) { text += string.Format("Progress: {0:0}\n", wb.displayProgress()); text += string.Format("NumWorkers: {0}/{1}\n", wb.getNWorkers(), wb.getMaxWorkers()); WorkedProdBuilding wpb = wb as WorkedProdBuilding; if (wpb) { text += wpb.printNeededItems(); } } mText.text = text; }