//------------------------------------------------------------------------------------------------- // private methods //------------------------------------------------------------------------------------------------- private void setupType() { //sets up the type info in case it isnt initalised correct and so I can remember what it should be switch (mType) { case GameTypes.BuildingType.Farm: getInventory().mCapacity = 50; //default 50 mUnitInventory.mCapacity = 2; mMaxProgress = 100; //default 100 mCreateItemType = GameTypes.ItemType.Food; mWorkers.mCapacity = 2; break; default: WorkedProdBuilding wpb = (WorkedProdBuilding)this; if (!wpb) { Debug.LogError("Building type not recognised"); } break; } }
//------------------------------------------------------------------------------------------------- // 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; }
//------------------------------------------------------------------------------------------------- // private methods //------------------------------------------------------------------------------------------------- private void doWork() { /*if (mActer.isInventoryFull()) * { * //make sure there is nothing else filling up the inventory * if ( mActer.makeInventorySpaceFor(mTarget.getCreateItemType()) ) * return; * mActer.returnToStockpile(mTarget.getCreateItemType()); * } * * //is the worked buildings inventory more than half full? * if ( mTarget.getInventorySize() >= mTarget.getInventory().mCapacity/2f ) * { * //worked buildings inventory is more than half full, fill inventory * //if the inventory is already full, return to stockpile * * //if (mActer.isInventoryFull()) * //{ * // //this will dump the inventory if it full of some other item * // * //} * //else * //{ * //clear the unit inventory of everything but the required item * * int invspace = mActer.getInventoryFreeSpace(); * //dump the inventory after ... * //mActer.dumpInventory(); * //after making an exchange with the building * mActer.exchangeWith(mTarget, mTarget.getCreateItemType(), -1*invspace); * * //} * return; * }*/ //does the unit have the create item amount in their inventory already? Item it = mActer.getItemOfType(mTarget.getCreateItemType()); if (it) { if (it.getAmount() >= mTarget.getCreateItemAmount()) { //return to stockpile mActer.returnToStockpile(mTarget.getCreateItemType()); return; } } //is the inventory of the target half full, then take items from the target if (mTarget.getInventorySize() >= mTarget.getInventory().mCapacity / 2f) { //does the unit not have space for the created items? if (mActer.getInventoryFreeSpace() < mTarget.getCreateItemAmount()) { //yes it doesn't have space mActer.dumpInventory(); Debug.Log("Dumping inventory becasue there isn enough space for the created items."); return; } int invspace = mActer.getInventoryFreeSpace(); mActer.exchangeWith(mTarget, mTarget.getCreateItemType(), -1 * invspace); return; } //is it a WorkedProdBuilding and does it need materials? WorkedProdBuilding wpb = mTarget as WorkedProdBuilding; if (wpb) { //it is a wpb, does it need materials? Debug.Log("Its a WorkedProdBuilding"); KeyValuePair <GameTypes.ItemType, int> needed = wpb.neededItem(); if (!needed.Equals(new KeyValuePair <GameTypes.ItemType, int>())) { //need to get items Debug.Log("It needed resources"); getItemsForProduction(needed); return; } else { Debug.Log("It doesnt need resources"); wpb.doCycle(mActer.getWorkSpeed() / 10f); return; } } else { mTarget.doCycle(mActer.getWorkSpeed() / 10f); return; } }