1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
|
/*
Zap
Author: Clonkonaut
Protects its hive!
*/
#include Library_InsectSwarm
local lib_swarm_standard = 5;
local swarm_enraged = 20;
local lib_swarm_density = 5;
local lib_insect_max_dist = 100;
local home;
local enraged;
local enrage_target;
local sting_damage = 2;
// Called by the zaphive
public func SetHome(object my_castle)
{
home = my_castle;
this->CreateSwarm(lib_swarm_standard);
}
// Called by the zaphive
public func SetEnraged()
{
this->CreateSwarm(swarm_enraged);
SwarmCall("SetEnragedSwarm");
}
// Called by swarm helper
public func SetEnragedSwarm()
{
enraged = true;
SetAction("Attack");
}
private func Initialize()
{
SetAction("Fly");
SetPhase(Random(3));
_inherited(...);
}
private func Death()
{
_inherited(...);
RemoveObject();
}
private func MissionComplete()
{
if (enraged)
MoveToTarget();
else
_inherited(...);
}
private func Sleep()
{
if (enraged) return MoveToTarget();
if (lib_insect_sleeping) return;
if (lib_insect_going2sleep)
{
SetAction("Sleep");
lib_insect_sleeping = true;
return;
}
// One last trip, then become invisible
MoveToTarget();
// Insect might have been removed.
if (this)
lib_insect_going2sleep = true;
}
private func SleepComplete()
{
SetAction("Sleep");
_inherited(...);
}
private func WakeUp()
{
SetAction("Fly");
_inherited(...);
}
private func GetAttraction(proplist coordinates)
{
if (enraged) return Enrage(coordinates);
if (!home)
{
HomeIsLost();
return false;
}
// GetAttraction will only be called for the swarm master, perfect to have just one being make sound
if(!Random(20))
Sound("Animals::Zap::Zap?", nil,nil,nil,nil, 200, Random(100));
coordinates.x = home->GetX() + Random(20)-10;
coordinates.y = home->GetY() + Random(20)-10;
return true;
}
private func HomeIsLost()
{
if (!Random(2)) Kill();
}
private func Enrage(proplist coordinates)
{
if (!enrage_target)
CheckTarget();
if (!this)
return false;
if (!enrage_target)
return false;
if (ObjectDistance(enrage_target) < 10)
return Sting();
if (!(enrage_target->GetAlive())) return Kill();
if (enrage_target->Contained())
{
if (!Random(25)) return Kill();
return false;
}
if (!Random(50)) return Kill();
if (!GBackSky() && !Random(25)) return Kill();
coordinates.x = enrage_target->GetX();
coordinates.y = enrage_target->GetY();
return true;
}
private func Sting()
{
if (!enrage_target) return false;
Punch(enrage_target, sting_damage);
Kill();
return true;
}
// Look for a target to attack
private func CheckTarget()
{
var clonk = FindObject(Find_Distance(200), Find_OCF(OCF_CrewMember), Find_OCF(OCF_Alive), Find_NoContainer(), Find_PathFree(), Sort_Distance());
if (clonk)
{
SwarmCall("DoAttack", clonk);
return;
}
if (!Random(10)) Kill();
}
public func DoAttack(object to_kill)
{
enrage_target = to_kill;
}
private func CheckTurn()
{
if (GetXDir() < 0)
SetDir(DIR_Left);
if (GetXDir() > 0)
SetDir(DIR_Right);
}
private func AngryBuzz()
{
Sound("Animals::Zap::Zap?", {pitch = -Random(100)});
}
/*-- Saving --*/
public func SaveScenarioObject(proplist props)
{
if (!inherited(props, ...)) return false;
// Ignore some fast-changing stuff
props->Remove("XDir");
props->Remove("YDir");
props->Remove("Command");
return true;
}
/* Definition */
local ActMap = {
Fly = {
Prototype = Action,
Name = "Fly",
Procedure = DFA_FLOAT,
Speed = 100,
Accel = 5,
Decel = 5,
Directions = 2,
FlipDir = 1,
Length = 3,
Delay = 2,
X = 0,
Y = 0,
Wdt = 2,
Hgt = 2,
NextAction = "Fly",
EndCall = "CheckTurn",
},
Attack = {
Prototype = Action,
Name = "Attack",
Procedure = DFA_FLOAT,
Speed = 200,
Accel = 30,
Decel = 30,
Directions = 2,
FlipDir = 1,
Length = 3,
Delay = 2,
X = 0,
Y = 0,
Wdt = 2,
Hgt = 2,
NextAction = "Attack",
StartCall = "AngryBuzz",
EndCall = "CheckTurn",
},
Sleep = {
Prototype = Action,
Name = "Sleep",
Procedure = DFA_FLOAT,
Speed = 0,
Directions = 2,
FlipDir = 1,
Length = 1,
Delay = 1,
X = 6,
Y = 0,
Wdt = 2,
Hgt = 2,
NextAction = "Hold",
},
};
local Name = "$Name$";
local MaxEnergy = 30000;
local MaxBreath = 250;
local Placement = 2;
local NoBurnDecay = true;
local BorderBound = C4D_Border_Sides | C4D_Border_Top | C4D_Border_Bottom;
local ContactCalls = true;
|