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 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
|
/**
Club
Simple striking weapon.
*/
#include Library_MeleeWeapon
#include Library_Flammable
local animation_set;
local fAiming;
/*-- Engine Callbacks --*/
func Initialize()
{
ClubChangeHandAnims("R");
}
func Hit()
{
Sound("Hits::Materials::Wood::WoodHit?");
}
func ClubChangeHandAnims(string hand)
{
if(hand == "R")
{
//Changes which (R/L) animation is used
animation_set = {
AimMode = AIM_Weight,
AnimationAim = Format("BatAimArms.R",hand),
AnimationAim2 = Format("BatAim2Arms.R",hand),
AimTime = 35*3,
AnimationShoot = Format("BatStrikeArms.R",hand),
AnimationShoot2 = Format("BatStrike2Arms.R",hand),
ShootTime = 35/2,
ShootTime2 = (35/2)*6/19, // At 6/19 of the shooting animation
};
}
else
{
//Changes which (R/L) animation is used
animation_set = {
AimMode = AIM_Weight,
AnimationAim = "BatAimArms.L",
AnimationAim2 = "BatAim2Arms.L",
AimTime = 35*3,
AnimationShoot = "BatStrikeArms.L",
AnimationShoot2 = "BatStrike2Arms.L",
ShootTime = 35/2,
ShootTime2 = (35/2)*6/19, // At 6/19 of the shooting animation
};
}
}
/*-- Callbacks --*/
public func GetAnimationSet() { return animation_set; }
// Callback from the clonk, when he actually has stopped aiming
public func FinishedAiming(object clonk, int angle)
{
clonk->StartShoot(this);
// since the Clonk internal callback is only once, we cannot use it
// ..
AddEffect("DuringClubShootControl", clonk, 1, 1, this, nil, angle);
// aaaand, a cooldown
AddEffect("ClubWeaponCooldown", clonk, 1, 5, this);
Sound("Objects::Weapons::WeaponSwing?", {pitch = -50});
return true;
}
// Called in the half of the shoot animation (when ShootTime2 is over)
public func DuringShoot(object clonk, int angle)
{
// called only once. We don't want it only once..
// DoStrike(clonk, angle);
}
/*-- Usage --*/
public func HoldingEnabled() { return true; }
public func RejectUse(object clonk)
{
return !CanStrikeWithWeapon(clonk) || !clonk->HasHandAction(false, false, true);
}
public func ControlUseStart(object clonk, int x, int y)
{
if(clonk->GetHandPosByItemPos(clonk->GetItemPos(this)) == 0)
ClubChangeHandAnims("R");
else
ClubChangeHandAnims("L");
fAiming = true;
clonk->StartAim(this);
return 1;
}
public func ControlUseHolding(object clonk, ix, iy)
{
var angle = Angle(0,0,ix,iy);
angle = Normalize(angle,-180);
clonk->SetAimPosition(angle);
return true;
}
public func ControlUseStop(object clonk, ix, iy)
{
clonk->StopAim();
return true;
}
public func ControlUseCancel(object clonk, int x, int y)
{
clonk->CancelAiming(this);
return true;
}
public func Reset(clonk)
{
fAiming = 0;
}
func FxDuringClubShootControlStart(target, effect, temp, p1)
{
if(temp) return;
effect.angle=p1;
}
func FxDuringClubShootControlStop(target, effect, reason, temp)
{
if(temp) return;
AddEffect("AfterClubShootControl", target, 1, 15, this);
}
func FxDuringClubShootControlTimer(target, effect, effect_time)
{
if(effect_time > 16) return -1;
if(!this) return -1;
this->DoStrike(target, effect.angle);
}
// you are not going to be hit by objects you fling away
func FxDuringClubShootControlQueryCatchBlow(object target, effect, object obj)
{
this->DoStrike(target, effect.angle);
var en=Format("CannotBeHitTwiceBy%d", this->ObjectNumber());
if(GetEffect(en, obj)) return true;
return false;
}
func FxAfterClubShootControlTimer()
{
return -1;
}
func FxAfterClubShootControlQueryCatchBlow(object target, effect, object obj)
{
var en=Format("CannotBeHitTwiceBy%d", this->ObjectNumber());
if(GetEffect(en, obj)) return true;
return false;
}
func DoStrike(clonk, angle)
{
// hit all objects in the direction of the Clonk - the angle is only important for the direction of the flinging
var x = Sin(angle, 7);
var y = -Cos(angle, 7);
var found = false;
for (var obj in FindObjects(Find_Distance(15, 0, 0), Find_Or(Find_OCF(OCF_Alive), Find_Category(C4D_Object), Find_Category(C4D_Vehicle)), Find_Exclude(clonk), Find_NoContainer(), Find_Layer(GetObjectLayer()), Sort_Distance()))
{
if (obj->Stuck()) continue;
// don't hit objects behind the Clonk
if (x < 0)
{
if (obj->GetX() > GetX()) continue;
}
else if (obj->GetX() < GetX()) continue;
// vehicles are only hit if they are pseudo vehicles. Bad system - has to be changed in the future
if (obj->GetCategory() & C4D_Vehicle)
if (!GetEffect("HitCheck", obj)) continue;
var en = Format("CannotBeHitTwiceBy%d", this->ObjectNumber());
if (GetEffect(en, obj)) continue;
if (obj->GetOCF() & OCF_Alive)
{
var damage = ClubDamage();
ApplyWeaponBash(obj, 400, angle, clonk);
obj->DoEnergy(-damage, true, FX_Call_EngGetPunched, clonk->GetOwner());
}
else
{
var div = ClubVelocityPrecision();
if(obj->GetContact(-1)) div*=10;
// the better you hit, the more power you have
var precision = BoundBy(Distance(obj->GetX(), obj->GetY(), GetX() + x, GetY() + y), 1, 15);
// mass/size factor
var fac1 = 10000 / Max(5, obj->GetMass());
var fac2 = BoundBy(10-Abs(obj->GetDefCoreVal("Width", "DefCore")-obj->GetDefCoreVal("Height", "DefCore")), 1, 10);
var speed = (3000 * fac1 * fac2) / 2 / 1000 / precision;
speed = BoundBy(speed, 500, 1500);
obj->SetXDir((obj->GetXDir(100) + Sin(angle, speed)) / 2, div);
obj->SetYDir((obj->GetYDir(100) - Cos(angle, speed)) / 2, div);
obj->SetController(clonk->GetController());
}
AddEffect(en, obj, 1, 15, nil);
found=true;
break;
}
if (found)
{
RemoveEffect("DuringClubShoot", clonk);
Sound("Hits::Materials::Wood::WoodHit?", {pitch = -10});
}
}
func ClubDamage()
{
return 5*1000;
}
func ClubVelocityPrecision()
{
return 100;
}
/*-- Production --*/
public func IsWeapon() { return true; }
public func IsArmoryProduct() { return true; }
/*-- Display --*/
public func GetCarryMode(object clonk, bool idle, bool nohand)
{
if (idle || nohand)
return CARRY_Back;
return CARRY_Blunderbuss;
}
public func GetCarrySpecial(clonk)
{
if(fAiming)
{
if(clonk->GetHandPosByItemPos(clonk->GetItemPos(this)) == 1)
return "pos_hand1";
else
return "pos_hand2";
}
}
public func GetCarryTransform(object clonk, bool idle, bool nohand)
{
if (idle || nohand || fAiming)
return;
return Trans_Mul(Trans_Rotate(10, 0, 1), Trans_Translate(-800));
}
func Definition(def)
{
def.PictureTransformation = Trans_Mul(Trans_Translate(-4500, -2000, 2000), Trans_Rotate(45,0,0,1));
}
/*-- Properties --*/
local Name = "$Name$";
local Description = "$Description$";
local Collectible = true;
local ForceFreeHands = true;
local Components = {Wood = 1, Metal = 1};
local BlastIncinerate = 30;
local MaterialIncinerate = true;
|