////////////////////////////////////////////////////////////////////////// // Enemy AI Leaders // By Deva Bryson Winblood 12/15/2003 ////////////////////////////////////////////////////////////////////////// /* This AI will cause the AI opponents on teams with no PCs in them to create a few units that they will command to either Guard The Lair or to RAID a PC lair. Each AI can have 3 units which will DESPAWN if a PC takes over the team. oAIUnit1, oAIUnit2, oAIUnit3 */ #include "lib_hos1_aisupp" const int DWF_TEAM =1; const int UND_TEAM =2; const int UNC_TEAM =3; const int SPID_TEAM=4; const int CMD_GUARD_LAIR = 11; const int CMD_RAID = 17; void fnLeaderExists() { // make sure leader still exists... if not despawn object oLead=GetLocalObject(OBJECT_SELF,"oLeader"); if ((oLead==OBJECT_INVALID||GetIsDead(oLead)==TRUE)&&GetIsInCombat(OBJECT_SELF)!=TRUE) DestroyObject(OBJECT_SELF); else { DelayCommand(30.0,fnLeaderExists()); } } // fnLeaderExists() int fnEnemy(string sTeam) { // find prefered raiding target int nRet=0; object oMod=GetModule(); object oLead; if (sTeam=="UND") { // undead oLead=GetLocalObject(oMod,"oTeamLeadDWF"); if (GetIsPC(oLead)==TRUE) return DWF_TEAM; oLead=GetLocalObject(oMod,"oTeamLeadSPID"); if (GetIsPC(oLead)==TRUE) return SPID_TEAM; oLead=GetLocalObject(oMod,"oTeamLeadUNC"); if (GetIsPC(oLead)==TRUE) return UNC_TEAM; } // undead if (sTeam=="DWF") { // dwarves oLead=GetLocalObject(oMod,"oTeamLeadUND"); if (GetIsPC(oLead)==TRUE) return UND_TEAM; oLead=GetLocalObject(oMod,"oTeamLeadUNC"); if (GetIsPC(oLead)==TRUE) return UNC_TEAM; oLead=GetLocalObject(oMod,"oTeamLeadSPID"); if (GetIsPC(oLead)==TRUE) return SPID_TEAM; } // dwarves if (sTeam=="UNC") { // unclean oLead=GetLocalObject(oMod,"oTeamLeadSPID"); if (GetIsPC(oLead)==TRUE) return SPID_TEAM; oLead=GetLocalObject(oMod,"oTeamLeadDWF"); if (GetIsPC(oLead)==TRUE) return DWF_TEAM; oLead=GetLocalObject(oMod,"oTeamLeadUND"); if (GetIsPC(oLead)==TRUE) return UND_TEAM; } // unclean if (sTeam=="SPID") { // spiders oLead=GetLocalObject(oMod,"oTeamLeadUNC"); if (GetIsPC(oLead)==TRUE) return UNC_TEAM; oLead=GetLocalObject(oMod,"oTeamLeadUND"); if (GetIsPC(oLead)==TRUE) return UND_TEAM; oLead=GetLocalObject(oMod,"oTeamLeadDWF"); if (GetIsPC(oLead)==TRUE) return DWF_TEAM; } // spiders return nRet; } // fnEnemy() void main() { object oMod=GetModule(); object oMe=OBJECT_SELF; object oAIUnit1=GetLocalObject(oMe,"oAIUnit1"); object oAIUnit2=GetLocalObject(oMe,"oAIUnit2"); object oAIUnit3=GetLocalObject(oMe,"oAIUnit3"); float fCR=GetChallengeRating(oMe); string sCR=FloatToString(fCR); string sSCR; string sID=GetLocalString(oMe,"sTeamID"); int nMode; // 0 = Guard Lair, 1 = raid dwf, 2 = raid und, 3 = raid spid, 4 = raid unc string sRes=sID+"1"; int nActivate; int nOpponentSpeed=GetLocalInt(oMod,"nOpponentSpeed"); // for future support of speeding or slowing the AI object oSpawn=GetWaypointByTag(sID+"_START"); float fAIDelay=60.0; if (GetArea(oMe)!=GetArea(oSpawn)) { // leader is not in lair return; } // leader is not in lair if (nOpponentSpeed<1) nOpponentSpeed=3; if (GetLocalInt(oMod,"nAISetting")!=0) { // champions if (!GetLocalInt(oMod,"bNoChampions")) { // if champions are not in play if (!GetLocalInt(oMod,"bChampionsCreated")) { // create champions SetLocalInt(oMod,"bChampionsCreated",TRUE); ExecuteScript("champ_create",oMod); } // create champions } // if champions are not in play } // champions if (GetLocalInt(oMod,"nAISetting")==1) ExecuteScript("ai_advanced",oMe); else if (GetLocalInt(oMod,"nAISetting")==2) { // custom AI sSCR=GetLocalString(oMod,"sAICode"+sID); if (GetStringLength(sSCR)>0) { // custom AI defined ExecuteScript(sSCR,oMe); } // custom AI defined else { ExecuteScript("ai_advanced",oMe); } } // custom AI else { // easy AI fAIDelay=fAIDelay*IntToFloat(nOpponentSpeed); //if (oMe!=OBJECT_INVALID) PrintString("AI OPPONENT:"+GetName(oMe)+" in area "+GetName(GetArea(oMe))+". CR=["+sCR+"] sID="+sID+" Unit1:"+GetName(oAIUnit1)); // else { PrintString("AI OPPONENT: Called for a nonexistent leader."); } if (fCR>2.9&&GetIsInCombat(oMe)!=TRUE) { // this AI is ready to command some units PrintString(" Commanding Units sID='"+sID+"' fCR="+FloatToString(fCR)); if (oAIUnit1==OBJECT_INVALID) { // create unit 1 nMode=0; if (sID=="UND"||sID=="und") { // undead if (fCR<4.0) { sRes="UND24"; } else if (fCR<6.0) { sRes="UND7"; } else if (fCR<8.0) { sRes="UND8"; } else if (fCR<10.0) { sRes="UND18"; } else if (fCR<12.0) { sRes="UND16"; } else if (fCR<14.0) { sRes="UND19"; } else { sRes="UND13"; } } // undead else if (sID=="DWF"||sID=="dwf") { // dwarves if (fCR<4.0) { sRes="DWF3"; } else if (fCR<6.0) { sRes="DWF5"; } else if (fCR<8.0) { sRes="DWF6"; } else if (fCR<10.0) { sRes="DWF8"; } else if (fCR<12.0) { sRes="DWF9"; } else if (fCR<14.0) { sRes="DWF9"; } else { sRes="DWF11"; } } // dwarves else if (sID=="UNC"||sID=="unc") { // unclean if (fCR<4.0) { sRes="UNC5"; } else if (fCR<6.0) { sRes="UNC6"; } else if (fCR<8.0) { sRes="UNC6"; } else if (fCR<10.0) { sRes="UNC6"; } else if (fCR<12.0) { sRes="UNC11"; } else if (fCR<14.0) { sRes="UNC11"; } else { sRes="UNC9"; } } // unclean else if (sID=="SPID"||sID=="spid") { // Spiders if (fCR<4.0) { sRes="SPID29"; } else if (fCR<6.0) { sRes="SPID29"; } else if (fCR<8.0) { sRes="SPID29"; } else if (fCR<10.0) { sRes="SPID24"; } else if (fCR<12.0) { sRes="SPID19"; } else if (fCR<14.0) { sRes="SPID19"; } else { sRes="SPID27"; } } // Spiders oAIUnit1=CreateObject(OBJECT_TYPE_CREATURE,sRes,GetLocation(oMe),FALSE); if (oAIUnit1!=OBJECT_INVALID) PrintString(GetName(oMe)+" AI Created: '"+GetName(oAIUnit1)+"'"); else { PrintString(GetName(oMe)+" AI Failed to create a unit.'"+sRes+"'"); } SetLocalObject(oMe,"oAIUnit1",oAIUnit1); SetLocalString(oAIUnit1,"sTeamID",sID); SetLocalObject(oAIUnit1,"oLeader",oMe); AssignCommand(oAIUnit1,fnLeaderExists()); SetAILevel(oAIUnit1,AI_LEVEL_NORMAL); if (nMode==0) { // Guard lair SetLocalInt(oAIUnit1,"nMState",CMD_GUARD_LAIR); SetLocalInt(oAIUnit1,"nSState",0); } // Guard lair else { // raid attack if (nMode==DWF_TEAM) SetLocalString(oAIUnit1,"sTeamToRaid","DWF"); else if (nMode==UND_TEAM) SetLocalString(oAIUnit1,"sTeamToRaid","UND"); else if (nMode==UNC_TEAM) SetLocalString(oAIUnit1,"sTeamToRaid","UNC"); else if (nMode==SPID_TEAM) SetLocalString(oAIUnit1,"sTeamToRaid","SPID"); SetLocalInt(oAIUnit1,"nParm",1); SetLocalInt(oAIUnit1,"nMState",CMD_RAID); SetLocalInt(oAIUnit1,"nSState",0); } // raid attack } // create unit 1 if (oAIUnit2==OBJECT_INVALID) { // create unit 2 nMode=0; if (sID=="UND"||sID=="und") { // undead if (fCR<4.0) { sRes="UND24"; } else if (fCR<6.0) { sRes="UND5"; } else if (fCR<8.0) { sRes="UND17"; nMode=fnEnemy(sID); } else if (fCR<10.0) { sRes="UND12"; } else if (fCR<12.0) { sRes="UND12"; } else if (fCR<14.0) { sRes="UND25"; nMode=fnEnemy(sID); } else { sRes="UND20"; } } // undead else if (sID=="SPID"||sID=="spid") { // Spiders if (fCR<4.0) { sRes="SPIDM"; } else if (fCR<6.0) { sRes="SPIDM"; } else if (fCR<8.0) { sRes="SPID24"; } else if (fCR<10.0) { sRes="SPID6"; } else if (fCR<12.0) { sRes="SPID6"; } else if (fCR<14.0) { sRes="SPID19"; } else { sRes="SPID28"; } } // spiders else if (sID=="DWF"||sID=="dwf") { // dwarves if (fCR<4.0) { sRes="DWF13"; } else if (fCR<6.0) { sRes="DWF13"; } else if (fCR<8.0) { sRes="DWF14"; } else if (fCR<10.0) { sRes="DWF14"; } else if (fCR<12.0) { sRes="DWF14"; } else if (fCR<14.0) { sRes="DWF15"; } else { sRes="DWF16"; } } // dwarves else if (sID=="UNC"||sID=="unc") { // unclean if (fCR<4.0) { sRes="UNC3"; } else if (fCR<6.0) { sRes="UNC5"; } else if (fCR<8.0) { sRes="UNC24"; nMode=fnEnemy(sID); } else if (fCR<10.0) { sRes="UNC13"; } else if (fCR<12.0) { sRes="UNC13"; } else if (fCR<14.0) { sRes="UNC10"; } else { sRes="UNC10"; } } // unclean oAIUnit2=CreateObject(OBJECT_TYPE_CREATURE,sRes,GetLocation(oMe),FALSE); if (oAIUnit2!=OBJECT_INVALID) PrintString(GetName(oMe)+" AI Created: '"+GetName(oAIUnit2)+"'"); else { PrintString(GetName(oMe)+" AI Failed to create a unit.'"+sRes+"'"); } SetLocalObject(oMe,"oAIUnit2",oAIUnit2); SetLocalString(oAIUnit2,"sTeamID",sID); SetLocalObject(oAIUnit2,"oLeader",oMe); AssignCommand(oAIUnit2,fnLeaderExists()); SetAILevel(oAIUnit2,AI_LEVEL_NORMAL); if (nMode==0) { // Guard lair SetLocalInt(oAIUnit2,"nMState",CMD_GUARD_LAIR); SetLocalInt(oAIUnit2,"nSState",0); } // Guard lair else { // raid attack if (nMode==DWF_TEAM) SetLocalString(oAIUnit2,"sTeamToRaid","DWF"); else if (nMode==UND_TEAM) SetLocalString(oAIUnit2,"sTeamToRaid","UND"); else if (nMode==UNC_TEAM) SetLocalString(oAIUnit2,"sTeamToRaid","UNC"); else if (nMode==SPID_TEAM) SetLocalString(oAIUnit2,"sTeamToRaid","SPID"); SetLocalInt(oAIUnit2,"nParm",1); SetLocalInt(oAIUnit2,"nMState",CMD_RAID); SetLocalInt(oAIUnit2,"nSState",0); } // raid attack } // create unit 2 else { // see if need to activate nMode=GetLocalInt(oAIUnit2,"nMState"); nActivate=FALSE; if (sID=="UNC"&&(fCR>=6.0&&fCR<8.0)&&nMode!=CMD_RAID) nActivate=TRUE; else if (sID=="UND"&&((fCR>=6.0&&fCR<8.0)||(fCR>=12.0&&fCR<14.0))&&nMode!=CMD_RAID) nActivate=TRUE; nMode=fnEnemy(sID); if (nActivate==TRUE&&nMode!=0) { // make this unit switch to raid mode if (nMode==DWF_TEAM) SetLocalString(oAIUnit2,"sTeamToRaid","DWF"); else if (nMode==UND_TEAM) SetLocalString(oAIUnit2,"sTeamToRaid","UND"); else if (nMode==UNC_TEAM) SetLocalString(oAIUnit2,"sTeamToRaid","UNC"); else if (nMode==SPID_TEAM) SetLocalString(oAIUnit2,"sTeamToRaid","SPID"); SetLocalInt(oAIUnit2,"nParm",1); SetLocalInt(oAIUnit2,"nMState",CMD_RAID); SetLocalInt(oAIUnit2,"nSState",0); } // make this unit switch to raid mode } // see if need to activate if (oAIUnit3==OBJECT_INVALID) { // create unit 3 nMode=fnEnemy(sID); if (sID=="UND"||sID=="und") { // undead if (fCR<4.0) { sRes="UND1"; nMode=0; } else if (fCR<6.0) { sRes="UND3"; } else if (fCR<8.0) { sRes="UND5"; } else if (fCR<10.0) { sRes="UND9"; nMode=0; } else if (fCR<12.0) { sRes="UND18"; } else if (fCR<14.0) { sRes="UND14"; } else { sRes="UND20"; } } // undead else if (sID=="DWF"||sID=="dwf") { // dwarves if (fCR<4.0) { sRes="DWF3"; nMode=0; } else if (fCR<6.0) { sRes="DWF13"; nMode=0; } else if (fCR<8.0) { sRes="DWF13"; nMode=0; } else if (fCR<10.0) { sRes="DWF17"; } else if (fCR<12.0) { sRes="DWF18"; } else if (fCR<14.0) { sRes="DWF19"; } else { sRes="DWF20"; } } // dwarves else if (sID=="UNC"||sID=="unc") { // unclean if (fCR<4.0) { sRes="UNC4"; } else if (fCR<6.0) { sRes="UNC2"; } else if (fCR<8.0) { sRes="UNC24"; } else if (fCR<10.0) { sRes="UNC24"; } else if (fCR<12.0) { sRes="UNC6"; nMode=0; } else if (fCR<14.0) { sRes="UNC10"; } else { sRes="UNC11"; } } // unclean else if (sID=="SPID"||sID=="spid") { // Spiders if (fCR<4.0) { sRes="SPIDM"; nMode=0; } else if (fCR<6.0) { sRes="SPID29"; } else if (fCR<8.0) { sRes="SPID29"; } else if (fCR<10.0) { sRes="SPID6"; } else if (fCR<12.0) { sRes="SPID15"; } else if (fCR<14.0) { sRes="SPID15"; } else { sRes="SPID27"; } } // Spiders oAIUnit3=CreateObject(OBJECT_TYPE_CREATURE,sRes,GetLocation(oMe),FALSE); if (oAIUnit3!=OBJECT_INVALID) PrintString(GetName(oMe)+" AI Created: '"+GetName(oAIUnit3)+"'"); else { PrintString(GetName(oMe)+" AI Failed to create a unit.'"+sRes+"'"); } SetLocalObject(oMe,"oAIUnit3",oAIUnit3); SetLocalString(oAIUnit3,"sTeamID",sID); SetLocalObject(oAIUnit3,"oLeader",oMe); AssignCommand(oAIUnit3,fnLeaderExists()); SetAILevel(oAIUnit3,AI_LEVEL_NORMAL); if (nMode==0) { // Guard lair SetLocalInt(oAIUnit3,"nMState",CMD_GUARD_LAIR); SetLocalInt(oAIUnit3,"nSState",0); } // Guard lair else { // raid attack if (nMode==DWF_TEAM) SetLocalString(oAIUnit3,"sTeamToRaid","DWF"); else if (nMode==UND_TEAM) SetLocalString(oAIUnit3,"sTeamToRaid","UND"); else if (nMode==UNC_TEAM) SetLocalString(oAIUnit3,"sTeamToRaid","UNC"); else if (nMode==SPID_TEAM) SetLocalString(oAIUnit3,"sTeamToRaid","SPID"); SetLocalInt(oAIUnit3,"nParm",1); SetLocalInt(oAIUnit3,"nMState",CMD_RAID); SetLocalInt(oAIUnit3,"nSState",0); } // raid attack } // create unit 3 else { // see if need to activate nMode=GetLocalInt(oAIUnit3,"nMState"); nActivate=FALSE; if (sID=="UNC"&&(fCR<10.0||fCR>=12.0)&&nMode!=CMD_RAID) nActivate=TRUE; else if (sID=="UND"&&((fCR>=4.0&&fCR<8.0)||fCR>=10.0)&&nMode!=CMD_RAID) nActivate=TRUE; else if (sID=="DWF"&&fCR>=8.0&&nMode!=CMD_RAID) nActivate=TRUE; else if (sID=="SPID"&&fCR>=4.0&&nMode!=CMD_RAID) nActivate=TRUE; nMode=fnEnemy(sID); if (nActivate==TRUE&&nMode!=0) { // make this unit switch to raid mode if (nMode==DWF_TEAM) SetLocalString(oAIUnit3,"sTeamToRaid","DWF"); else if (nMode==UND_TEAM) SetLocalString(oAIUnit3,"sTeamToRaid","UND"); else if (nMode==UNC_TEAM) SetLocalString(oAIUnit3,"sTeamToRaid","UNC"); else if (nMode==SPID_TEAM) SetLocalString(oAIUnit3,"sTeamToRaid","SPID"); SetLocalInt(oAIUnit3,"nParm",1); SetLocalInt(oAIUnit3,"nMState",CMD_RAID); SetLocalInt(oAIUnit3,"nSState",0); } // make this unit switch to raid mode } // see if need to activate } // this AI is ready to command some units } // easy AI // DelayCommand(fAIDelay,ExecuteScript("ai_opponents",OBJECT_SELF)); }