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
|
/**
Bow
The standard bow. This object is a standard projectile weapon with an extra slot.
@author: Newton
*/
#include Library_HasExtraSlot
#include Library_RangedWeapon
#include Library_Flammable
local fAiming;
local iArrowMesh;
local animation_set;
/*-- Engine Callbacks --*/
// Default timing values for animation set
// (Adjusted for speeed multiplier and stored in animation set by Library_RangedWeapon)
local DefaultLoadTime = 30;
local DefaultLoadTime2 = 5*30/20;
local DefaultShootTime = 20;
local DefaultShootTime2 = nil;
func Initialize(...)
{
animation_set = {
AimMode = AIM_Position, // The aiming animation is done by adjusting the animation position to fit the angle
AnimationAim = "BowAimArms",
AnimationLoad = "BowLoadArms",
AnimationShoot = nil,
TurnType = 1,
WalkSpeed = 84,
WalkBack = 56,
AnimationReplacements = [
["Walk", "BowWalk"],
["Walk_Position", 20],
["Stand", "BowStand"],
["Jump", "BowJump"],
["KneelDown", "BowKneel"]
],
};
return _inherited(...);
}
func Hit()
{
Sound("Hits::Materials::Wood::WoodHit?");
}
func RejectCollect(id arrowid, object arrows)
{
// arrows are not arrows? decline!
if(!(arrows->~IsArrow())) return true;
}
/*-- Callbacks --*/
public func GetAnimationSet() { return animation_set; }
// Attach the arrow during the animation
public func DuringLoad(object clonk) { return AddArrow(clonk); }
// Callback from the clonk when loading is finished
public func FinishedLoading(object clonk)
{
clonk->~StartAim(this);
return true;
}
// Callback from the clonk, when he actually has stopped aiming
// Calls "OnLaunchArrow"
public func FinishedAiming(object clonk, int angle)
{
clonk->DetachMesh(iArrowMesh);
iArrowMesh = nil;
// shoot
if(Contents(0))
{
if(Contents(0)->~IsArrow())
{
var arrow = Contents(0)->TakeObject();
arrow->Launch(angle, shooting_strength, clonk, this);
Sound("Objects::Weapons::Bow::Shoot?");
}
}
// Open the hand to let the string go and play the fire animation
PlayAnimation("Fire", 6, Anim_Linear(0, 0, GetAnimationLength("Fire"), animation_set["ShootTime"], ANIM_Hold));
clonk->PlayAnimation("Close1Hand", 11, Anim_Const(0), Anim_Const(1000));
clonk->StartShoot(this);
return true;
}
/*
func Selection()
{
Sound("Objects::Weapons::Bow::Draw");
}
func Deselection()
{
Sound("Objects::Weapons::Bow::PutAwayBow");
}
*/
/*-- Usage --*/
public func HoldingEnabled() { return true; }
public func RejectUse(object clonk)
{
// if the clonk doesn't have an action where he can use it's hands do nothing
return !clonk->HasHandAction(false, false, true);
}
public func ControlUseStart(object clonk, int x, int y)
{
// check for ammo
if(!Contents(0))
{
// reload
var obj;
if(obj = FindObject(Find_Container(clonk), Find_Func("IsArrow")))
{
obj->Enter(this);
}
}
if(!Contents(0))
{
// + sound or message that he doesnt have arrows anymore
clonk->CancelUse();
return true;
}
// Start aiming
fAiming = 1;
PlayAnimation("Draw", 6, Anim_Linear(0, 0, GetAnimationLength("Draw"), animation_set["LoadTime"], ANIM_Hold));
clonk->StartLoad(this);
ControlUseHolding(clonk, x, y);
return true;
}
// Update the angle on mouse movement
public func ControlUseHolding(object clonk, int x, int y)
{
// Save new angle
var angle = Angle(0,0,x,y);
angle = Normalize(angle,-180);
if(angle > 160) angle = 160;
if(angle < -160) angle = -160;
clonk->SetAimPosition(angle);
return true;
}
// Stopping says the clonk to stop with aiming (he will go on untill he has finished loading and aiming at the given angle)
public func ControlUseStop(object clonk, int x, int y)
{
clonk->StopAim();
return true;
}
public func ControlUseCancel(object clonk, int x, int y)
{
clonk->CancelAiming(this);
return true;
}
// Called during loading then the arrow is added to the animation
public func AddArrow(object clonk)
{
Sound("Objects::Weapons::Bow::Load?");
iArrowMesh = clonk->AttachMesh(HelpArrow, "pos_hand1", "main", nil);
}
public func Reset(clonk)
{
fAiming = 0;
clonk->DetachMesh(iArrowMesh);
iArrowMesh = nil;
clonk->StopAnimation(clonk->GetRootAnimation(11));
StopAnimation(GetRootAnimation(6));
}
func ClonkAimLimit(object clonk, int angle)
{
angle = Normalize(angle,-180);
if(Abs(angle) > 160) return false;
if(clonk->GetDir() == 1 && angle < 0) return false;
if(clonk->GetDir() == 0 && angle > 0) return false;
return true;
}
func FxIntWalkSlowStart(pTarget, effect, fTmp, iValue)
{
if(iValue == nil || iValue == 0) iValue = 84;
pTarget->PushActionSpeed("Walk", iValue);
}
func FxIntWalkSlowStop(pTarget, effect)
{
pTarget->PopActionSpeed("Walk");
}
/*-- Production --*/
public func IsWeapon() { return true; }
public func IsArmoryProduct() { return true; }
/*-- Display --*/
public func GetCarryMode(object clonk, bool idle)
{
if (idle)
return CARRY_Back;
return CARRY_HandBack;
}
public func GetCarrySpecial(clonk)
{
if(fAiming) return "pos_hand2";
}
public func OnRelaunchCreation()
{
CreateContents(Arrow);
}
func Definition(def)
{
def.PictureTransformation = Trans_Mul(Trans_Translate(-4000,-2000,4000),Trans_Rotate(180,0,1,0),Trans_Rotate(-45,0,0,1));
return _inherited(def, ...);
}
/*-- Properties --*/
local Name = "$Name$";
local Description = "$Description$";
local Collectible = true;
local ForceFreeHands = true;
local Components = {Wood = 3};
local BlastIncinerate = 30;
local MaterialIncinerate = true;
// Initial velocity of the arrow
local shooting_strength = 100;
local ExtraSlotFilter = "IsArrow"; // For editor-provided ammo list
|