diff --git a/planet/Objects.c4d/Items.c4d/Weapons.c4d/Bow.c4d/Arrow.c4d/Script.c b/planet/Objects.c4d/Items.c4d/Weapons.c4d/Bow.c4d/Arrow.c4d/Script.c index de72b69a7..5804592ec 100644 --- a/planet/Objects.c4d/Items.c4d/Weapons.c4d/Bow.c4d/Arrow.c4d/Script.c +++ b/planet/Objects.c4d/Items.c4d/Weapons.c4d/Bow.c4d/Arrow.c4d/Script.c @@ -35,15 +35,15 @@ public func Launch(int angle, int str, object shooter) private func Stick() { - SetXDir(0); - SetYDir(0); - SetRDir(0); - if(GetEffect("InFlight",this)) { RemoveEffect("HitCheck",this); RemoveEffect("InFlight",this); + SetXDir(0); + SetYDir(0); + SetRDir(0); + var x=Sin(GetR(),+12); var y=Cos(GetR(),-12); var mat = GetMaterial(x,y); @@ -69,7 +69,7 @@ public func HitObject(object obj) obj->~OnArrowHit(this); if(!this) return; // ouch! - var dmg = ArrowStrength()*speed/50; + var dmg = ArrowStrength()*speed/100; if(obj->GetAlive()) { obj->DoEnergy(-dmg); diff --git a/planet/Objects.c4d/Items.c4d/Weapons.c4d/Bow.c4d/Script.c b/planet/Objects.c4d/Items.c4d/Weapons.c4d/Bow.c4d/Script.c index 782c34369..a75f1ee6d 100644 --- a/planet/Objects.c4d/Items.c4d/Weapons.c4d/Bow.c4d/Script.c +++ b/planet/Objects.c4d/Items.c4d/Weapons.c4d/Bow.c4d/Script.c @@ -13,7 +13,7 @@ local aimtime; public func HoldingEnabled() { return true; } -protected func ControlUse(object clonk, int x, int y) +protected func ControlUseStart(object clonk, int x, int y) { // check for ammo if(!Contents(0)) @@ -27,7 +27,11 @@ protected func ControlUse(object clonk, int x, int y) } aimtime = 30; - if(!Contents(0)) return true; + if(!Contents(0)) + { + // + sound or message that he doesnt have arrows anymore + clonk->CancelUse(); + } return true; } @@ -35,7 +39,11 @@ protected func ControlUse(object clonk, int x, int y) public func ControlUseHolding(object clonk, int x, int y) { // check procedure - if(!ClonkCanAim(clonk)) return -1; + if(!ClonkCanAim(clonk)) + { + clonk->CancelUse(); + return true; + } // angle var angle = Angle(0,0,x,y); @@ -53,14 +61,16 @@ public func ControlUseHolding(object clonk, int x, int y) Message("Cannot aim there",clonk); else Message("Aiming",clonk); + + return true; } protected func ControlUseStop(object clonk, int x, int y) { Message("",clonk); + // "canceled" if(aimtime > 0) return true; - if(!ClonkCanAim(clonk)) return true; var angle = Angle(0,0,x,y); if(!ClonkAimLimit(clonk,angle)) return true; diff --git a/planet/Objects.c4d/Items.c4d/Weapons.c4d/Musket.c4d/Ammo.c4d/MusketBall.c4d/Script.c b/planet/Objects.c4d/Items.c4d/Weapons.c4d/Musket.c4d/Ammo.c4d/MusketBall.c4d/Script.c index 473158196..b2a73d470 100644 --- a/planet/Objects.c4d/Items.c4d/Weapons.c4d/Musket.c4d/Ammo.c4d/MusketBall.c4d/Script.c +++ b/planet/Objects.c4d/Items.c4d/Weapons.c4d/Musket.c4d/Ammo.c4d/MusketBall.c4d/Script.c @@ -25,7 +25,7 @@ private func HitObject(object pVictim) { Message("Ouch!", pVictim); //Remove when sound works; for debug - Punch(pVictim,RandomX(20,30)); + pVictim->DoEnergy(-RandomX(10,15)); RemoveObject(); } diff --git a/planet/Objects.c4d/Items.c4d/Weapons.c4d/Musket.c4d/Script.c b/planet/Objects.c4d/Items.c4d/Weapons.c4d/Musket.c4d/Script.c index 7cab70ef1..f1fed5dbc 100644 --- a/planet/Objects.c4d/Items.c4d/Weapons.c4d/Musket.c4d/Script.c +++ b/planet/Objects.c4d/Items.c4d/Weapons.c4d/Musket.c4d/Script.c @@ -6,13 +6,15 @@ --*/ -#strict 2 - //Uses the extra slot library #include L_ES -local ReloadTimer; -local Loaded; +func Definition(def) { + SetProperty("Name", "$Name$", def); +} + +local loaded; +local reload; local yOffset; local iBarrel; @@ -25,155 +27,113 @@ protected func Initialize() protected func HoldingEnabled() { return true; } -protected func ControlUse(object pClonk, ix, iy) +func ControlUseStart(object clonk, int x, int y) { - //Don't throw the musket away! - return 1; + // nothign in extraslot? + if(!Contents(0)) + { + // put something inside + var obj; + if(obj = FindObject(Find_Container(clonk), Find_Func("IsMusketAmmo"))) + { + obj->Enter(this); + } + } + + // something in extraslot + if(Contents(0)) + { + // reload weapon if not loaded yet + if(!loaded) reload = 50; + } + else clonk->CancelUse(); + + return true; } -public func ControlUseHolding(object pClonk, ix, iy) +func ControlUseHolding(object pClonk, ix, iy) { - //Angle Finder - var IX=Sin(180-Angle(0,0,ix,iy),iBarrel); - var IY=Cos(180-Angle(0,0,ix,iy),iBarrel); - //Create debug dot to show muzzle-point - CastParticles("DebugReticle",1,0,IX,IY,30,30,RGB(255,0,0),RGB(255,0,0)); - //DrawParticleLine("DebugReticle",0,0,IX,IY,2,20,RGB(30,30,30),RGB(100,100,100)); //Debug: Enable to see firing angle of musket + // loading... + if(!loaded) + { + // If Clonk messes up during reload, he must restart. :( + if(Contained()->GetProcedure() != "WALK") + pClonk->CancelUse(); + + // count + Message("%d",pClonk,reload); + + reload--; + if(reload <= 0) + { + loaded = true; + reload = 0; + Message("Pashunk!", Contained()); + pClonk->CancelUse(); + } + } + // loaded + else + { + //Angle Finder + var IX=Sin(180-Angle(0,0,ix,iy),iBarrel); + var IY=Cos(180-Angle(0,0,ix,iy),iBarrel); + //Create debug dot to show muzzle-point + CastParticles("DebugReticle",1,0,IX,IY,30,30,RGB(255,0,0),RGB(255,0,0)); + //DrawParticleLine("DebugReticle",0,0,IX,IY,2,20,RGB(30,30,30),RGB(100,100,100)); //Debug: Enable to see firing angle of musket + } + + return true; } protected func ControlUseStop(object pClonk, ix, iy) { - // Reload if empty - if(Contents(0)==nil && FindObject(Find_Container(pClonk), Find_Func("IsMusketAmmo"))==nil) return 1; - if(Contents(0)==nil && Loaded==1) Loaded=0; - if(!GetEffect("Reloading",this) && IsReloading()==true) ResumeReloading(); - if(CheckCanUse(pClonk)==true && IsReloading()==false && Loaded!=true) - { - if(Contents(0)==nil || Loaded==false) - { - ReloadWeapon(50); - return 1; - } - } - + if(!loaded) return true; + + if(!ClonkCanAim(pClonk)) return true; + // Fire - var IX=Sin(180-Angle(0,0,ix,iy),iBarrel); - var IY=Cos(180-Angle(0,0,ix,iy),iBarrel); - if(Contents(0)!=nil && PathFree(pClonk->GetX(),pClonk->GetY(),GetX()+IX,GetY()+IY)) //Stops musket from firing into ground or through walls. + if(Contents(0)) { - if(Contents(0)->IsMusketAmmo()==1 && Loaded==true && CheckCanUse(pClonk)==true) + if(Contents(0)->IsMusketAmmo()) { - FireWeapon(pClonk, ix, iy); - return 1; + FireWeapon(pClonk, ix, iy); } } -return 1; + return true; } private func FireWeapon(object pClonk,iX,iY) { - var shot=Contents(0)->TakeObject(); + var shot = Contents(0)->TakeObject(); shot->LaunchProjectile(Angle(0,0,iX,iY)+RandomX(-2, 2), iBarrel, 300); var iAngle=Angle(0,0,iX,iY); shot->AffectShot(pClonk,iY,iX,iAngle); - Loaded=false; + + loaded = false; Sound("Blast3"); + Message("Bang!", pClonk); //For debug. - //Muzzle Flash - /*var flash = pClonk->CreateObject(FLSH); - flash->SetAction("Flash",pClonk); - flash->SetR(Angle(0,0,iX,iY)); - */ - - //Muzzle Flash - var iAngle=Angle(0,0,iX,iY);; + // Muzzle Flash + var iAngle=Angle(0,0,iX,iY); var IX=Sin(180-Angle(0,0,iX,iY),iBarrel); var IY=Cos(180-Angle(0,0,iX,iY),iBarrel); CreateParticle("MuzzleFlash",IX,IY,+Sin(iAngle,500),-Cos(iAngle,500),300,RGB(255,255,255),pClonk); //Gun Smoke CastParticles("GunSmoke",10,3,IX,IY,20,50,RGBa(110,110,110,128),RGB(150,150,150,128)); - } -private func ReloadWeapon(int iReloadTime) +private func ClonkCanAim(object clonk) { - //Put ammo into gun's extra slot - var Ammo; - if(Ammo=FindObject(Find_Container(Contained()), Find_Func("IsMusketAmmo"))) - { - if(Contents(0)==nil) Ammo->Enter(this()); //Only put new more ammo in gun if gun is empty - } - - ReloadTimer=iReloadTime; - AddEffect("Reloading",this,300,1,this,this); -} - -protected func FxReloadingTimer(pTarget,iEffectNumber,iEffectTime) -{ - //If Clonk messes up reload, he must restart. :( - if(Contained()==nil || CheckCanUse(Contained())==false) - { - PauseReloading(); - ReloadTimer=50; - } - - if(ReloadTimer<=0) - { - Loaded=true; - return -1; - } - if(ReloadTimer>0) ReloadTimer=--ReloadTimer; - Message("%d", Contained(), ReloadTimer); -} - -protected func FxReloadingStop(pTarget,iEffectNumber,iReason,fTemp) -{ - Message("Pashunk!", Contained()); //This whole function is just for debug, unless there will be a sound for finishing a reload. -} - -public func IsReloading() -{ - if(ReloadTimer>0) return true; - return false; -} - -public func PauseReloading() -{ - if(GetEffect("Reloading",this)) - { - RemoveEffect("Reloading",this,0,1); - return true; - } - return false; -} - -public func ResumeReloading() -{ - if(ReloadTimer>0 && !GetEffect("Reloading",this)) - { - AddEffect("Reloading",this,300,1,this,this); - return true; - } - return false; -} - -private func CheckCanUse(object pClonk) -{ - if(pClonk->GetOCF() & OCF_NotContained) - { - if(pClonk->GetAction() == "Walk" || pClonk->GetAction() == "Jump") return true; - } - return false; + var p = clonk->GetProcedure(); + if(p != "WALK" && p != "ATTACH" && p != "FLIGHT") return false; + return true; } func RejectCollect(id shotid, object shot) { - //Only collect musket-balls - if(!(shot->~IsMusketBall())) return true; + // Only collect musket-ammo + if(!(shot->~IsMusketAmmo())) return true; } - -func Definition(def) { - SetProperty("Name", "$Name$", def); -} \ No newline at end of file diff --git a/planet/Objects.c4d/Libraries.c4d/ClonkControl.c4d/Script.c b/planet/Objects.c4d/Libraries.c4d/ClonkControl.c4d/Script.c index b2144f763..b9b569151 100644 --- a/planet/Objects.c4d/Libraries.c4d/ClonkControl.c4d/Script.c +++ b/planet/Objects.c4d/Libraries.c4d/ClonkControl.c4d/Script.c @@ -152,6 +152,10 @@ public func Switch2Items(int one, int two) inventory[one] = inventory[two]; inventory[two] = temp; + // callbacks + if(using == inventory[one] || using == inventory[two]) + CancelUse(); + if(one == selected) inventory[two]->~Deselection(this,false); else if(one == selected2) inventory[two]->~Deselection(this,true); if(two == selected) inventory[one]->~Deselection(this,false); @@ -253,12 +257,16 @@ protected func Collection2(object obj) protected func Ejection(object obj) { var i; - // find obj in array and delete + // find obj in array and delete (cancel using too) for(i = 0; i < MaxContentsCount(); ++i) { if (inventory[i] == obj) - { inventory[i] = nil; break; } + { + inventory[i] = nil; + break; + } } + if(using == obj) CancelUse(); this->~OnSlotEmpty(i); @@ -475,36 +483,55 @@ private func CancelUse() if (Contained() == using) control = "Contained"; - StopUseControl(control, mlastx, mlasty, using); + CancelUseControl(control, mlastx, mlasty, using); } private func StartUseControl(int ctrl, control, int x, int y, object obj) { + using = obj; + var hold_enabled = obj->Call("~HoldingEnabled"); + + if(hold_enabled) + SetPlayerControlEnabled(GetOwner(), CON_Aim, true); + if (ctrl == CON_Use) alt = false; else alt = true; var estr = ""; if (alt && !(obj->Contained())) estr = "Alt"; - var handled = obj->Call(Format("~%sUse%s",control,estr),this,x,y); - if (!handled) return false; - - using = obj; - - if(obj->Call("~HoldingEnabled")) - SetPlayerControlEnabled(GetOwner(), CON_Aim, true); + // first call UseStart. If unhandled, call Use (mousecontrol) + var handled = obj->Call(Format("~%sUseStart%s",control,estr),this,x,y); + if (!handled) + handled = obj->Call(Format("~%sUse%s",control,estr),this,x,y); + if (!handled) + { + using = nil; + if(hold_enabled) + SetPlayerControlEnabled(GetOwner(), CON_Aim, false); + return false; + } return handled; } -private func StopUseControl(control, int x, int y, object obj) +private func CancelUseControl(control, int x, int y, object obj) +{ + return StopUseControl(control, x, y, obj, true); +} + +private func StopUseControl(control, int x, int y, object obj, bool cancel) { var estr = ""; if (alt && !(obj->Contained())) estr = "Alt"; var holding_enabled = obj->Call("~HoldingEnabled"); - - var handled = obj->Call(Format("~%sUse%sStop",control,estr),this,x,y); + + var stop = "Stop"; + if(cancel) stop = "Cancel"; + + // ControlUseStop, ControlUseAltStop, ContainedUseAltStop, ContainedUseCancel, etc... + var handled = obj->Call(Format("~%sUse%s%s",control,estr,stop),this,x,y); using = nil; alt = false; @@ -518,11 +545,14 @@ private func StopUseControl(control, int x, int y, object obj) private func Control2Script(int ctrl, int x, int y, int strength, bool repeat, bool release, string control, object obj) { - // do not use secondary when using primary and the other way round + // click on secondary cancels primary and the other way round if (using) { - if (ctrl == CON_Use && alt) return true; - if (ctrl == CON_UseAlt && !alt) return true; + if (ctrl == CON_Use && alt || ctrl == CON_UseAlt && !alt) + { + CancelUseControl(control, x, y, using); + return true; + } } // for the use command @@ -539,7 +569,8 @@ private func Control2Script(int ctrl, int x, int y, int strength, bool repeat, b else if (release && using) { // leftover use release - return CancelUse(); + CancelUse(); + return true; } else if (repeat && using == obj) { @@ -548,12 +579,6 @@ private func Control2Script(int ctrl, int x, int y, int strength, bool repeat, b var handled = obj->Call(Format("~%sUse%sHolding",control,estr),this,x,y); - // if that function returns -1, the control is stopped (*UseStop) - // and no more *UseHolding-calls are made. - if (handled == -1) - { - handled = StopUseControl(control, x, y, obj); - } return handled; } }