#include "nw_i0_generic"

void main()
{

object oPC = GetEnteringObject();

if (!GetIsPC(oPC)) return;

int nInt;
object oTarget;
object oSpawn;
location lTarget;

int nEntry = GetLocalInt(oPC, "BugbearEntry");

if (nEntry == 0)
 {
 //Bugbear 1
 oTarget = GetObjectByTag("PLC_Bugbear1");
 lTarget = GetLocation(oTarget);
 SetPlotFlag(oTarget, FALSE);
 DestroyObject(oTarget, 0.0);
 oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "sarcbugbear", lTarget);
 oTarget = oSpawn;
 SetIsTemporaryEnemy(oPC, oTarget);
 AssignCommand(oTarget, ActionAttack(oPC));
 AssignCommand(oTarget, DetermineCombatRound(oPC));
 nInt = GetObjectType(oTarget);
 if (nInt != OBJECT_TYPE_WAYPOINT) DelayCommand(0.5, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), oTarget));
 else DelayCommand(0.5, ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), GetLocation(oTarget)));
 //Bugbear 2
 oTarget = GetObjectByTag("PLC_Bugbear2");
 lTarget = GetLocation(oTarget);
 SetPlotFlag(oTarget, FALSE);
 DestroyObject(oTarget, 0.0);
 oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "sarcbugbear", lTarget);
 oTarget = oSpawn;
 SetIsTemporaryEnemy(oPC, oTarget);
 AssignCommand(oTarget, ActionAttack(oPC));
 AssignCommand(oTarget, DetermineCombatRound(oPC));
 nInt = GetObjectType(oTarget);
 if (nInt != OBJECT_TYPE_WAYPOINT) DelayCommand(0.5, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), oTarget));
 else DelayCommand(0.5, ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), GetLocation(oTarget)));
 //Bugbear 3
 oTarget = GetObjectByTag("PLC_Bugbear3");
 lTarget = GetLocation(oTarget);
 SetPlotFlag(oTarget, FALSE);
 DestroyObject(oTarget, 0.0);
 oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "sarcbugbear", lTarget);
 oTarget = oSpawn;
 SetIsTemporaryEnemy(oPC, oTarget);
 AssignCommand(oTarget, ActionAttack(oPC));
 AssignCommand(oTarget, DetermineCombatRound(oPC));
 nInt = GetObjectType(oTarget);
 if (nInt != OBJECT_TYPE_WAYPOINT) DelayCommand(0.5, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), oTarget));
 else DelayCommand(0.5, ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), GetLocation(oTarget)));
 //Bugbear 4
 oTarget = GetObjectByTag("PLC_Bugbear4");
 lTarget = GetLocation(oTarget);
 SetPlotFlag(oTarget, FALSE);
 DestroyObject(oTarget, 0.0);
 oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "sarcbugbear", lTarget);
 oTarget = oSpawn;
 SetIsTemporaryEnemy(oPC, oTarget);
 AssignCommand(oTarget, ActionAttack(oPC));
 AssignCommand(oTarget, DetermineCombatRound(oPC));
 nInt = GetObjectType(oTarget);
 if (nInt != OBJECT_TYPE_WAYPOINT) DelayCommand(0.5, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), oTarget));
 else DelayCommand(0.5, ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), GetLocation(oTarget)));
 SetLocalInt(oPC, "BugbearEntry", 1);
 }

else if (nEntry == 1)
 {
 //Bugbear 5
 oTarget = GetObjectByTag("PLC_Bugbear5");
 lTarget = GetLocation(oTarget);
 SetPlotFlag(oTarget, FALSE);
 DestroyObject(oTarget, 0.0);
 oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "sarcbugbearchief", lTarget);
 oTarget = oSpawn;
 SetIsTemporaryEnemy(oPC, oTarget);
 AssignCommand(oTarget, ActionAttack(oPC));
 AssignCommand(oTarget, DetermineCombatRound(oPC));
 nInt = GetObjectType(oTarget);
 if (nInt != OBJECT_TYPE_WAYPOINT) DelayCommand(0.5, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), oTarget));
 else DelayCommand(0.5, ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), GetLocation(oTarget)));
 //Bugbear 6
 oTarget = GetObjectByTag("PLC_Bugbear6");
 lTarget = GetLocation(oTarget);
 SetPlotFlag(oTarget, FALSE);
 DestroyObject(oTarget, 0.0);
 oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "sarcbugbear", lTarget);
 oTarget = oSpawn;
 SetIsTemporaryEnemy(oPC, oTarget);
 AssignCommand(oTarget, ActionAttack(oPC));
 AssignCommand(oTarget, DetermineCombatRound(oPC));
 nInt = GetObjectType(oTarget);
 if (nInt != OBJECT_TYPE_WAYPOINT) DelayCommand(0.5, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), oTarget));
 else DelayCommand(0.5, ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), GetLocation(oTarget)));
 //Bugbear 7
 oTarget = GetObjectByTag("PLC_Bugbear7");
 lTarget = GetLocation(oTarget);
 SetPlotFlag(oTarget, FALSE);
 DestroyObject(oTarget, 0.0);
 oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "sarcbugbear", lTarget);
 oTarget = oSpawn;
 SetIsTemporaryEnemy(oPC, oTarget);
 AssignCommand(oTarget, ActionAttack(oPC));
 AssignCommand(oTarget, DetermineCombatRound(oPC));
 nInt = GetObjectType(oTarget);
 if (nInt != OBJECT_TYPE_WAYPOINT) DelayCommand(0.5, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), oTarget));
 else DelayCommand(0.5, ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), GetLocation(oTarget)));
 //Bugbear 8
 oTarget = GetObjectByTag("PLC_Bugbear8");
 lTarget = GetLocation(oTarget);
 SetPlotFlag(oTarget, FALSE);
 DestroyObject(oTarget, 0.0);
 oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "sarcbugbear", lTarget);
 oTarget = oSpawn;
 SetIsTemporaryEnemy(oPC, oTarget);
 AssignCommand(oTarget, ActionAttack(oPC));
 AssignCommand(oTarget, DetermineCombatRound(oPC));
 nInt = GetObjectType(oTarget);
 if (nInt != OBJECT_TYPE_WAYPOINT) DelayCommand(0.5, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), oTarget));
 else DelayCommand(0.5, ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), GetLocation(oTarget)));
 SetLocalInt(oPC, "BugbearEntry", 2);
 }

else if (nEntry == 2)
 {
 //Bugbear 9
 oTarget = GetObjectByTag("PLC_Bugbear9");
 lTarget = GetLocation(oTarget);
 SetPlotFlag(oTarget, FALSE);
 DestroyObject(oTarget, 0.0);
 oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "sarcbugbear", lTarget);
 oTarget = oSpawn;
 SetIsTemporaryEnemy(oPC, oTarget);
 AssignCommand(oTarget, ActionAttack(oPC));
 AssignCommand(oTarget, DetermineCombatRound(oPC));
 nInt = GetObjectType(oTarget);
 if (nInt != OBJECT_TYPE_WAYPOINT) DelayCommand(0.5, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), oTarget));
 else DelayCommand(0.5, ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), GetLocation(oTarget)));
 //Bugbear 10
 oTarget = GetObjectByTag("PLC_Bugbear10");
 lTarget = GetLocation(oTarget);
 SetPlotFlag(oTarget, FALSE);
 DestroyObject(oTarget, 0.0);
 oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "sarcbugbear", lTarget);
 oTarget = oSpawn;
 SetIsTemporaryEnemy(oPC, oTarget);
 AssignCommand(oTarget, ActionAttack(oPC));
 AssignCommand(oTarget, DetermineCombatRound(oPC));
 nInt = GetObjectType(oTarget);
 if (nInt != OBJECT_TYPE_WAYPOINT) DelayCommand(0.5, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), oTarget));
 else DelayCommand(0.5, ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), GetLocation(oTarget)));
 //Bugbear 11
 oTarget = GetObjectByTag("PLC_Bugbear11");
 lTarget = GetLocation(oTarget);
 SetPlotFlag(oTarget, FALSE);
 DestroyObject(oTarget, 0.0);
 oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "sarcbugbear", lTarget);
 oTarget = oSpawn;
 SetIsTemporaryEnemy(oPC, oTarget);
 AssignCommand(oTarget, ActionAttack(oPC));
 AssignCommand(oTarget, DetermineCombatRound(oPC));
 nInt = GetObjectType(oTarget);
 if (nInt != OBJECT_TYPE_WAYPOINT) DelayCommand(0.5, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), oTarget));
 else DelayCommand(0.5, ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), GetLocation(oTarget)));
 //Bugbear 12
 oTarget = GetObjectByTag("PLC_Bugbear12");
 lTarget = GetLocation(oTarget);
 SetPlotFlag(oTarget, FALSE);
 DestroyObject(oTarget, 0.0);
 oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "sarcbugbear", lTarget);
 oTarget = oSpawn;
 SetIsTemporaryEnemy(oPC, oTarget);
 AssignCommand(oTarget, ActionAttack(oPC));
 AssignCommand(oTarget, DetermineCombatRound(oPC));
 nInt = GetObjectType(oTarget);
 if (nInt != OBJECT_TYPE_WAYPOINT) DelayCommand(0.5, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), oTarget));
 else DelayCommand(0.5, ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), GetLocation(oTarget)));
 SetLocalInt(oPC, "BugbearEntry", 3);
 }

else if (nEntry == 3)
 {
 //Bugbear 13
 oTarget = GetObjectByTag("PLC_Bugbear13");
 lTarget = GetLocation(oTarget);
 SetPlotFlag(oTarget, FALSE);
 DestroyObject(oTarget, 0.0);
 oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "sarcbugbear", lTarget);
 oTarget = oSpawn;
 SetIsTemporaryEnemy(oPC, oTarget);
 AssignCommand(oTarget, ActionAttack(oPC));
 AssignCommand(oTarget, DetermineCombatRound(oPC));
 nInt = GetObjectType(oTarget);
 if (nInt != OBJECT_TYPE_WAYPOINT) DelayCommand(0.5, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), oTarget));
 else DelayCommand(0.5, ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), GetLocation(oTarget)));
 //Bugbear 14
 oTarget = GetObjectByTag("PLC_Bugbear14");
 lTarget = GetLocation(oTarget);
 SetPlotFlag(oTarget, FALSE);
 DestroyObject(oTarget, 0.0);
 oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "sarcbugbear", lTarget);
 oTarget = oSpawn;
 SetIsTemporaryEnemy(oPC, oTarget);
 AssignCommand(oTarget, ActionAttack(oPC));
 AssignCommand(oTarget, DetermineCombatRound(oPC));
 nInt = GetObjectType(oTarget);
 if (nInt != OBJECT_TYPE_WAYPOINT) DelayCommand(0.5, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), oTarget));
 else DelayCommand(0.5, ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), GetLocation(oTarget)));
 //Bugbear 15
 oTarget = GetObjectByTag("PLC_Bugbear15");
 lTarget = GetLocation(oTarget);
 SetPlotFlag(oTarget, FALSE);
 DestroyObject(oTarget, 0.0);
 oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "sarcbugbear", lTarget);
 oTarget = oSpawn;
 SetIsTemporaryEnemy(oPC, oTarget);
 AssignCommand(oTarget, ActionAttack(oPC));
 AssignCommand(oTarget, DetermineCombatRound(oPC));
 nInt = GetObjectType(oTarget);
 if (nInt != OBJECT_TYPE_WAYPOINT) DelayCommand(0.5, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), oTarget));
 else DelayCommand(0.5, ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), GetLocation(oTarget)));
 //Bugbear 16
 oTarget = GetObjectByTag("PLC_Bugbear16");
 lTarget = GetLocation(oTarget);
 SetPlotFlag(oTarget, FALSE);
 DestroyObject(oTarget, 0.0);
 oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "sarcbugbear", lTarget);
 oTarget = oSpawn;
 SetIsTemporaryEnemy(oPC, oTarget);
 AssignCommand(oTarget, ActionAttack(oPC));
 AssignCommand(oTarget, DetermineCombatRound(oPC));
 nInt = GetObjectType(oTarget);
 if (nInt != OBJECT_TYPE_WAYPOINT) DelayCommand(0.5, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), oTarget));
 else DelayCommand(0.5, ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_BREACH), GetLocation(oTarget)));
 SetLocalInt(oPC, "BugbearEntry", 4);
 }
else return;
}

