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 256 257 258 259 260
|
/*--
Flag
Author: Maikel
Flag for CTF goal, to be captured and defended.
--*/
/*-- Team --*/
// Team to which the flag belongs.
local team;
public func SetTeam(int to_team)
{
if (!to_team)
return;
team = to_team;
//UpdateColor();
return;
}
public func GetTeam()
{
return team;
}
public func FindTeam(int find_team)
{
if (!find_team || !team)
return false;
return team == find_team;
}
protected func Initialize()
{
PlayAnimation("Wave", 1, Anim_Linear(0, 0, GetAnimationLength("Wave"), 78, ANIM_Loop));
AddEffect("FlagAutoPickup", this, 100, 2, this);
return;
}
public func DisablePickup()
{
// Disable pickup search in case flag is used outside the regular CTF goal
return RemoveEffect("FlagAutoPickup", this);
}
// Handles automatic picking up of the flag.
protected func FxFlagAutoPickupTimer(object target, effect)
{
// Do nothing if flag is being carried.
if (target->GetAction() == "AttachCarrier")
return 1;
// Find a near clonk which can grab the flag.
for(var clonk in FindObjects(Find_OCF(OCF_CrewMember), Find_Distance(20), Sort_Distance()))
{
var plr = clonk->GetOwner();
if(GetPlayerTeam(plr) != team)
{
// Fiendly team, grab flag.
SetAction("AttachCarrier", clonk);
Log("$MsgFlagStolen$", GetTaggedTeamName(GetPlayerTeam(plr)), GetTaggedTeamName(team));
AddEffect("FlagCarried", clonk, 100, 5, this);
return 1;
}
else
{
// Friendly team can only beam flag if return delay is over.
if (target->IsAtBase())
continue;
if(GetEffect("FlagReturnDelay",target))
continue;
target->BeamFlag(true);
return 1;
}
}
return 1;
}
// Return delay for friendly team after flag has been dropped.
protected func FxFlagReturnDelayTimer() { return -1; }
protected func FxFlagCarriedStart(object target, effect, int temp)
{
ReducePhysicals(target, effect);
if (temp) return;
effect.x=target->GetX();
effect.y=target->GetY();
var trans = Trans_Mul(Trans_Translate(-17000, 0, 0), Trans_Rotate(90, 1, 0, 0));
effect.mesh_id = target->AttachMesh(this, "pos_back1", "main", trans);
this.Visibility = VIS_None;
var color = GetTeamColor(this->GetTeam());
effect.tracer_particles =
{
Size = PV_KeyFrames(0, 0, 0, 200, 5, 900, 10, 1000, 0),
R = (color >> 16) & 0xff,
G = (color >> 8) & 0xff,
B = (color >> 0) & 0xff,
Alpha = 200,
Attach = ATTACH_Back
};
return 1;
}
// Checks whether the carrier has reached its base.
protected func FxFlagCarriedTimer(object target, effect)
{
var controller = target->GetController();
var ctrl_team = GetPlayerTeam(controller);
var x = effect.x;
var y = effect.y;
var newx = target->GetX();
var newy = target->GetY();
// Draw partical line following the flag.
if (Distance(x, y, newx, newy) > 5)
{
target->CreateParticle("SphereSpark", 0, 0, 0, 0, PV_Random(36 * 3, 36 * 3 + 10), effect.tracer_particles);
effect.x=newx;
effect.y=newy;
}
// Search for nearby base to drop flag and score a point.
var base = FindObject(Find_ID(Goal_FlagBase), Find_Func("FindTeam", ctrl_team), Find_Distance(20));
if (base && base->IsBaseWithFlag())
{
var goal = FindObject(Find_ID(Goal_CaptureTheFlag));
if (goal)
goal->AddTeamScore(ctrl_team);
Log("$MsgFlagCaptured$", GetTaggedTeamName(ctrl_team));
BeamFlag(false);
return -1;
}
return 1;
}
protected func FxFlagCarriedStop(object target, effect, int reason, bool temp)
{
if (target)
ResetPhysicals(target, effect);
if (temp)
return 1;
this.Visibility = VIS_All;
if (reason == 4)
{
SetAction("Idle");
Log("$MsgFlagDropped$", GetTaggedTeamName(GetPlayerTeam(target->GetOwner())), GetTaggedTeamName(team));
}
if (target)
{
target->DetachMesh(effect.mesh_id);
}
// Prevent beaming flag for 3 seconds.
AddEffect("FlagReturnDelay", this, 100, 36 * 3, this);
return 1;
}
// Reduces physicals by 80%.
private func ReducePhysicals(object clonk, effect)
{
effect.clonk_jumpspeed = clonk.JumpSpeed;
clonk.JumpSpeed = clonk.JumpSpeed * 8 / 10;
var phys = ["Walk"/*, "Scale"*/, "Hangle", "Swim"];
for (var i = 0; i < GetLength(phys); i++)
clonk->PushActionSpeed(phys[i], 8 * clonk.ActMap[phys[i]].Speed / 10);
return;
}
// Resets physicals.
private func ResetPhysicals(object clonk, effect)
{
clonk.JumpSpeed = effect.clonk_jumpspeed;
var phys = ["Walk"/*, "Scale"*/, "Hangle", "Swim"];
for (var i = 0; i < GetLength(phys); i++)
clonk->PopActionSpeed(phys[i]);
return;
}
// Create a new flag on destruction.
protected func Destruction()
{
var base = FindObject(Find_ID(Goal_FlagBase), Find_Func("FindTeam", GetTeam()));
if (base)
{
var flag = CreateObject(Goal_Flag, 0, 0, GetOwner());
flag->SetTeam(GetTeam());
SetAction("AttachBase", base);
Log("$MsgFlagRestored$", GetTaggedTeamName(team));
}
return;
}
// Returns whether the flag is at its base.
public func IsAtBase()
{
if (GetAction() == "AttachBase")
return true;
return false;
}
private func BeamFlag(bool msg)
{
if (IsAtBase())
return;
if (msg)
Log("$MsgFlagBeamed$", GetTaggedTeamName(team));
var base = FindObject(Find_ID(Goal_FlagBase), Find_Func("FindTeam", team));
if (base)
SetAction("AttachBase", base);
else
RemoveObject();
return;
}
func StartAttachCarrier()
{
// attach fourth vertex of the flag to third vertex of Clonk
// this results in the best overlapping of the shapes
SetActionData((4 << 8) + 3);
}
func StartAttachBase()
{
// reset possible action data
SetActionData(0);
}
local Name = "$Name$";
local Plane = 310;
local ActMap = {
AttachCarrier = {
Prototype = Action,
Name = "AttachCarrier",
Procedure = DFA_ATTACH,
Length = 1,
Delay = 0,
NextAction = "AttachCarrier",
Animation = "Wave",
StartCall = "StartAttachCarrier"
},
AttachBase = {
Prototype = Action,
Name = "AttachBase",
Procedure = DFA_ATTACH,
Length = 1,
Delay = 0,
NextAction = "AttachBase",
Animation = "Wave",
StartCall = "StartAttachBase"
},
};
protected func Definition(def)
{
SetProperty("MeshTransformation", Trans_Mul(Trans_Translate(-9000, 1000, 0), Trans_Rotate(60, 0, 1, 0)), def);
SetProperty("PictureTransformation", Trans_Mul(Trans_Rotate(60, 0, 1, 0), Trans_Scale(1200), Trans_Translate(-4000, 6500, -3000)), def);
}
|