//ai_mine - Mining routine for NPC Units //By Deva Bryson Winblood. 04/30/2005 ////////////////////////////////////////////////////////////////////// #include "antistuck_h" #include "prc_inc_racial" void fnMine(object oMineable) { // PURPOSE: Handle the mining of the object object oMe=OBJECT_SELF; string sID=GetLocalString(oMe,"sTeamID"); int nP=d100(); object oItem; int nAmt=GetLocalInt(oMineable,"nResAmt"); string sRes=GetResRef(oMineable); AssignCommand(oMe,ClearAllActions()); AssignCommand(oMe,ActionAttack(oMineable,TRUE)); AssignCommand(oMineable,PlaySound("as_cv_minepick1")); if (MyPRCGetRacialType(oMe)==RACIAL_TYPE_DWARF) nP=nP-10; else if (MyPRCGetRacialType(oMe)==RACIAL_TYPE_GNOME) nP=nP-5; if (sRes=="resgold") { // gold if (nP<25) { // gold mined CreateItemOnObject("gold_nugget",oMe,1); nAmt=nAmt-1; SetLocalInt(oMineable,"nResAmt",nAmt); if (nAmt<1) DestroyObject(oMineable); } // gold mined } // gold else if (sRes=="resadm") { // adamantine if (nP<6) { // adamantine mined CreateItemOnObject("bar_admant",oMe,1); nAmt=nAmt-1; SetLocalInt(oMineable,"nResAmt",nAmt); if (nAmt<1) DestroyObject(oMineable); } // adamantine mined } // adamantine else if (sRes=="resiron") { // iron if (nP<10) { // iron mined CreateItemOnObject("bar_iron",oMe,1); nAmt=nAmt-1; SetLocalInt(oMineable,"nResAmt",nAmt); if (nAmt<1) DestroyObject(oMineable); } // iron mined } // iron else if (sRes=="mithral") { // mithral if (nP<3) { // mithral mined CreateItemOnObject("bar_mith",oMe,1); nAmt=nAmt-1; SetLocalInt(oMineable,"nResAmt",nAmt); if (nAmt<1) DestroyObject(oMineable); } // mithral mined } // mithral } // fnMine() int fnCountMined(object oMe,string sTag,int nMax) { // PURPOSE: Return how much of the item has been mined int nCount=0; object oItem=GetItemPossessedBy(oMe,sTag); if (GetIsObjectValid(oItem)) SetLocalInt(oMe,"bDeposit",TRUE); if (GetIsObjectValid(oItem)&&nMax>1) { // count oItem=GetFirstItemInInventory(oMe); while(GetIsObjectValid(oItem)&&nCount=nMax) { // take back to lair sTag=""; sItem=""; nMax=0; } // take back to lair oMineable=GetNearestObjectByTag(sTag,oMe); if (GetIsObjectValid(oMineable)&&GetObjectType(oMineable)==OBJECT_TYPE_PLACEABLE) { // object found if (GetDistanceBetween(oMe,oMineable)>2.0) { // move to object ASActionMoveToObject(oMineable,TRUE,1.5); } // move to object else { // mine AssignCommand(oMe,fnMine(oMineable)); } // mine } // object found else { // nothing to mine return to lair SetLocalInt(oMe,"nMState",2); SetLocalInt(oMe,"nSState",0); AssignCommand(oMe,ClearAllActions(TRUE)); AssignCommand(oMe,SpeakString("I need to take minerals back to the throne.")); DeleteLocalObject(oMe,"oDestWP"); SetLocalInt(oMe,"nParm",5); object oGArea=GetObjectByTag(GetLocalString(oMe,"sTeamID")+"_START"); SetLocalObject(oMe,"oGArea",oGArea); } // nothing to mine return to lair } // okay to mine }