From bf795164f2ae684b29eef070f0b80fb648b9bc00 Mon Sep 17 00:00:00 2001 From: Felix Wagner Date: Tue, 3 Apr 2012 02:12:44 +0100 Subject: [PATCH] Resolved all warnings due to global function in included scripts. --- .../Libraries.ocd/Base.ocd/Script.c | 36 +----------- .../Libraries.ocd/ClonkControl.ocd/Script.c | 10 ---- .../ElevatorControl.ocd/Script.c | 6 +- .../Libraries.ocd/Flag.ocd/Script.c | 33 ----------- .../Libraries.ocd/Goal.ocd/Script.c | 50 ----------------- .../Libraries.ocd/Plant.ocd/Script.c | 22 -------- .../Elevator.ocd/Case.ocd/Script.c | 2 +- planet/System.ocg/ClonkControl.c | 15 +++++ planet/System.ocg/Flag.c | 38 +++++++++++++ planet/System.ocg/Goal.c | 55 +++++++++++++++++++ planet/System.ocg/Object.c | 51 ++++++++++++++++- planet/System.ocg/Player.c | 8 ++- 12 files changed, 170 insertions(+), 156 deletions(-) create mode 100644 planet/System.ocg/ClonkControl.c create mode 100644 planet/System.ocg/Flag.c create mode 100644 planet/System.ocg/Goal.c diff --git a/planet/Objects.ocd/Libraries.ocd/Base.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/Base.ocd/Script.c index 692eb0441..c684e1792 100644 --- a/planet/Objects.ocd/Libraries.ocd/Base.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/Base.ocd/Script.c @@ -388,38 +388,4 @@ func DoSell(object pObj, int iPlr, bool bRight) return true; } -// ------------------------ global functions --------------------------- -global func Buy (id idBuyObj, int iForPlr, int iPayPlr, object pToBase, bool fShowErrors) -{ - // if no base is given try this - if(!pToBase) pToBase = this; - // not a base? - if( !pToBase->~IsBase() ) - return 0; - return pToBase->DoBuy(idBuyObj, iForPlr, iPayPlr, 0, 0, fShowErrors); -} - -global func Sell (int iPlr, object pObj, object pToBase) -{ - // if no base is given try this - if(!pToBase) pToBase = this; - // not a base? - if( !pToBase->~IsBase() ) - return 0; - return pToBase->DoSell(pObj, iPlr); -} - -global func FindBase (int iPlr, int iIndex) -{ - return FindObjects(Find_Owner(iPlr), Find_Func("IsBase"))[iIndex]; -} - -global func GetBase () -{ - if(!(this->~IsBase())) return NO_OWNER; - return GetOwner(); -} - -local Name = "$Name$"; - - +local Name = "$Name$"; \ No newline at end of file diff --git a/planet/Objects.ocd/Libraries.ocd/ClonkControl.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/ClonkControl.ocd/Script.c index 54373097c..35177e007 100644 --- a/planet/Objects.ocd/Libraries.ocd/ClonkControl.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/ClonkControl.ocd/Script.c @@ -266,16 +266,6 @@ public func Collect(object item, bool ignoreOCF, int pos, bool force) return success; } -// disable ShiftContents for objects with ClonkControl.ocd - -global func ShiftContents() -{ - if (this) - if (this->~HandObjects() != nil) - return false; - return _inherited(...); -} - /* ################################################# */ protected func Construction() diff --git a/planet/Objects.ocd/Libraries.ocd/ElevatorControl.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/ElevatorControl.ocd/Script.c index e181a4d00..c2451c8aa 100644 --- a/planet/Objects.ocd/Libraries.ocd/ElevatorControl.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/ElevatorControl.ocd/Script.c @@ -48,13 +48,13 @@ func Control2Elevator(int control, object clonk) /* Effect */ -global func FxElevatorControlStart(object vehicle, proplist effect, int temp, object case) +public func FxElevatorControlStart(object vehicle, proplist effect, int temp, object case) { if (temp) return; effect.case = case; } -global func FxElevatorControlTimer(object vehicle, proplist effect) +public func FxElevatorControlTimer(object vehicle, proplist effect) { if (ObjectDistance(effect.case, vehicle) > 12) return -1; @@ -65,7 +65,7 @@ global func FxElevatorControlTimer(object vehicle, proplist effect) } } -global func FxElevatorControlStop(object vehicle, proplist effect, int reason, bool temp) +public func FxElevatorControlStop(object vehicle, proplist effect, int reason, bool temp) { if (temp) return; if (effect.controlled) diff --git a/planet/Objects.ocd/Libraries.ocd/Flag.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/Flag.ocd/Script.c index 32d0955a5..79d2c9550 100644 --- a/planet/Objects.ocd/Libraries.ocd/Flag.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/Flag.ocd/Script.c @@ -12,33 +12,6 @@ local lflag; public func IsFlagpole(){return true;} -global func GetFlagpoleForPosition(int x, int y) -{ - if(GetType(LibraryFlag_flag_list) != C4V_Array) return nil; - - var oldest = nil, oldest_time = 0; - - for(var flag in LibraryFlag_flag_list) - { - var d = Distance(GetX() + x, GetY() + y, flag->GetX(), flag->GetY()); - if(d > flag->GetFlagRadius()) continue; - - if(oldest == nil || flag->GetFlagConstructionTime() < oldest_time) - { - oldest = flag; - oldest_time = flag->GetFlagConstructionTime(); - } - } - return oldest; -} - -global func GetOwnerOfPosition(int x, int y) -{ - var flag = GetFlagpoleForPosition(x, y); - if(!flag) return NO_OWNER; - return flag->GetOwner(); -} - func RefreshAllFlagLinks() { for(var f in LibraryFlag_flag_list) @@ -368,12 +341,6 @@ public func SetFlagRadius(int to) return true; } -global func RedrawAllFlagRadiuses() -{ - for(var f in LibraryFlag_flag_list) - f->RedrawFlagRadius(); -} - public func GetFlagRadius(){return lflag.radius;} public func GetFlagConstructionTime() {return lflag.construction_time;} public func GetFlagMarkerID(){return LibraryFlag_Marker;} diff --git a/planet/Objects.ocd/Libraries.ocd/Goal.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/Goal.ocd/Script.c index 316b58346..6146f333d 100644 --- a/planet/Objects.ocd/Libraries.ocd/Goal.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/Goal.ocd/Script.c @@ -64,56 +64,6 @@ protected func InitializePlayer(int plr) HUD->OnGoalUpdate(this); } -global func FxIntGoalCheckTimer(object trg, effect, int time) -{ - if (!time) - return true; - var curr_goal = effect.curr_goal; - // Check current goal object - if (curr_goal && (curr_goal->GetCategory() & C4D_Goal)) - { - curr_goal->NotifyHUD(); - if (!curr_goal->~IsFulfilled()) - return true; - } - // Current goal is fulfilled/destroyed - check all others - var goal_count = 0; - for (curr_goal in FindObjects(Find_Category(C4D_Goal))) - { - ++goal_count; - if (!curr_goal->~IsFulfilled()) - { - effect.curr_goal = curr_goal; - curr_goal->NotifyHUD(); - return true; - } - } - // No goal object? Kill timer - if (!goal_count) - return FX_Execute_Kill; - // Game over :( - AllGoalsFulfilled(); - return FX_Execute_Kill; -} - -global func AllGoalsFulfilled() -{ - // Goals fulfilled: Set mission password(s) - for (var goal in FindObjects(Find_Category(C4D_Goal))) - if (goal.mission_password) - GainMissionAccess(goal.mission_password); - // Custom scenario goal evaluation? - if (GameCall("OnGoalsFulfilled")) return true; - // We're done. Play some sound and schedule game over call - Sound("Fanfare", true); - AddEffect("IntGoalDone", 0, 1, 30, 0); -} - -global func FxIntGoalDoneStop() -{ - GameOver(); -} - // Set mission password to be gained when all goals are fulfilled public func SetMissionAccess(string str_password) { diff --git a/planet/Objects.ocd/Libraries.ocd/Plant.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/Plant.ocd/Script.c index 3e0a5590a..dc6272ae5 100644 --- a/planet/Objects.ocd/Libraries.ocd/Plant.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/Plant.ocd/Script.c @@ -5,28 +5,6 @@ @author Clonkonaut */ -/* Global */ - -/** Pulls the plant above ground if it was buried by PlaceVegetation. A plant must have 'Bottom' and 'Center' CNAT to use this (bottom is the point which should be buried, center the lowest point that must not be buried) -*/ -global func RootSurface() -{ - if (HasCNAT(CNAT_Center)) - { - var i = 0; - while(GetContact(-1) & CNAT_Center && i < GetObjHeight()/2) { SetPosition(GetX(),GetY()-1); i++; } //Move up if too far underground - } - if (HasCNAT(CNAT_Bottom)) - { - i = 0; - while(!(GetContact(-1) & CNAT_Bottom) && i < GetObjHeight()/2) { SetPosition(GetX(),GetY()+1); i++; } //Move down if in midair - - if (!Stuck()) SetPosition(GetX(),GetY()+1); // try make the plant stuck - } -} - -/* Local */ - // This is a plant public func IsPlant() { diff --git a/planet/Objects.ocd/Structures.ocd/Elevator.ocd/Case.ocd/Script.c b/planet/Objects.ocd/Structures.ocd/Elevator.ocd/Case.ocd/Script.c index 6e9f93c6d..95d101c36 100644 --- a/planet/Objects.ocd/Structures.ocd/Elevator.ocd/Case.ocd/Script.c +++ b/planet/Objects.ocd/Structures.ocd/Elevator.ocd/Case.ocd/Script.c @@ -74,7 +74,7 @@ func Movement() // TimerCall vehicle->SetPosition(GetX(), GetY() + 12 - vehicle->GetObjHeight()/2 ); vehicle->SetSpeed(); vehicle->SetR(); - AddEffect("ElevatorControl", vehicle, 30, 5, nil, nil, this); + AddEffect("ElevatorControl", vehicle, 30, 5, vehicle, nil, this); } // no power? diff --git a/planet/System.ocg/ClonkControl.c b/planet/System.ocg/ClonkControl.c new file mode 100644 index 000000000..18b13bec9 --- /dev/null +++ b/planet/System.ocg/ClonkControl.c @@ -0,0 +1,15 @@ +/*-- + Global functions used in correlation to Objects.ocd\Libraries.ocd\ClonkControl.ocd + + Authors: Newton +--*/ + +// disable ShiftContents for objects with ClonkControl.ocd + +global func ShiftContents() +{ + if (this) + if (this->~HandObjects() != nil) + return false; + return _inherited(...); +} \ No newline at end of file diff --git a/planet/System.ocg/Flag.c b/planet/System.ocg/Flag.c new file mode 100644 index 000000000..50bafaeba --- /dev/null +++ b/planet/System.ocg/Flag.c @@ -0,0 +1,38 @@ +/*-- + Global functions used in correlation to Objects.ocd\Libraries.ocd\Flag.ocd + + Authors: Zapper +--*/ + +global func GetFlagpoleForPosition(int x, int y) +{ + if(GetType(LibraryFlag_flag_list) != C4V_Array) return nil; + + var oldest = nil, oldest_time = 0; + + for(var flag in LibraryFlag_flag_list) + { + var d = Distance(GetX() + x, GetY() + y, flag->GetX(), flag->GetY()); + if(d > flag->GetFlagRadius()) continue; + + if(oldest == nil || flag->GetFlagConstructionTime() < oldest_time) + { + oldest = flag; + oldest_time = flag->GetFlagConstructionTime(); + } + } + return oldest; +} + +global func GetOwnerOfPosition(int x, int y) +{ + var flag = GetFlagpoleForPosition(x, y); + if(!flag) return NO_OWNER; + return flag->GetOwner(); +} + +global func RedrawAllFlagRadiuses() +{ + for(var f in LibraryFlag_flag_list) + f->RedrawFlagRadius(); +} \ No newline at end of file diff --git a/planet/System.ocg/Goal.c b/planet/System.ocg/Goal.c new file mode 100644 index 000000000..1008c94a8 --- /dev/null +++ b/planet/System.ocg/Goal.c @@ -0,0 +1,55 @@ +/*-- + Global functions used in correlation to Objects.ocd\Libraries.ocd\Goal.ocd + + Authors: Sven2 +--*/ + +global func FxIntGoalCheckTimer(object trg, effect, int time) +{ + if (!time) + return true; + var curr_goal = effect.curr_goal; + // Check current goal object + if (curr_goal && (curr_goal->GetCategory() & C4D_Goal)) + { + curr_goal->NotifyHUD(); + if (!curr_goal->~IsFulfilled()) + return true; + } + // Current goal is fulfilled/destroyed - check all others + var goal_count = 0; + for (curr_goal in FindObjects(Find_Category(C4D_Goal))) + { + ++goal_count; + if (!curr_goal->~IsFulfilled()) + { + effect.curr_goal = curr_goal; + curr_goal->NotifyHUD(); + return true; + } + } + // No goal object? Kill timer + if (!goal_count) + return FX_Execute_Kill; + // Game over :( + AllGoalsFulfilled(); + return FX_Execute_Kill; +} + +global func AllGoalsFulfilled() +{ + // Goals fulfilled: Set mission password(s) + for (var goal in FindObjects(Find_Category(C4D_Goal))) + if (goal.mission_password) + GainMissionAccess(goal.mission_password); + // Custom scenario goal evaluation? + if (GameCall("OnGoalsFulfilled")) return true; + // We're done. Play some sound and schedule game over call + Sound("Fanfare", true); + AddEffect("IntGoalDone", 0, 1, 30, 0); +} + +global func FxIntGoalDoneStop() +{ + GameOver(); +} \ No newline at end of file diff --git a/planet/System.ocg/Object.c b/planet/System.ocg/Object.c index 5326d9330..1c35845a4 100644 --- a/planet/System.ocg/Object.c +++ b/planet/System.ocg/Object.c @@ -1,6 +1,6 @@ /*-- Objects.c - Authors: Maikel, boni, Ringwaul, Sven2, flgr, Clonkonaut, Günther + Authors: Maikel, boni, Ringwaul, Sven2, flgr, Clonkonaut, Günther, Randrian Functions generally applicable to objects; not enough to be worth distinct scripts though. --*/ @@ -240,4 +240,53 @@ global func Split2Components() } RemoveObject(); return; +} + +// Pulls an object above ground if it was buried (e.g. by PlaceVegetation). +// The object must have 'Bottom' and 'Center' CNAT to use this. +// (bottom is the point which should be buried, center the lowest point that must not be buried) +// Mainly used by plants. +global func RootSurface() +{ + if (HasCNAT(CNAT_Center)) + { + var i = 0; + while(GetContact(-1) & CNAT_Center && i < GetObjHeight()/2) { SetPosition(GetX(),GetY()-1); i++; } //Move up if too far underground + } + if (HasCNAT(CNAT_Bottom)) + { + i = 0; + while(!(GetContact(-1) & CNAT_Bottom) && i < GetObjHeight()/2) { SetPosition(GetX(),GetY()+1); i++; } //Move down if in midair + + if (!Stuck()) SetPosition(GetX(),GetY()+1); // try make the plant stuck + } +} + +// Buys an object. +global func Buy (id idBuyObj, int iForPlr, int iPayPlr, object pToBase, bool fShowErrors) +{ + // if no base is given try this + if(!pToBase) pToBase = this; + // not a base? + if( !pToBase->~IsBase() ) + return 0; + return pToBase->DoBuy(idBuyObj, iForPlr, iPayPlr, 0, 0, fShowErrors); +} + +// Sells an object. +global func Sell (int iPlr, object pObj, object pToBase) +{ + // if no base is given try this + if(!pToBase) pToBase = this; + // not a base? + if( !pToBase->~IsBase() ) + return 0; + return pToBase->DoSell(pObj, iPlr); +} + +// Returns the owner if this is a base. +global func GetBase () +{ + if(!(this->~IsBase())) return NO_OWNER; + return GetOwner(); } \ No newline at end of file diff --git a/planet/System.ocg/Player.c b/planet/System.ocg/Player.c index 142a4dfcf..f1073e2bb 100644 --- a/planet/System.ocg/Player.c +++ b/planet/System.ocg/Player.c @@ -1,6 +1,6 @@ /*-- Player.c - Authors: timi, Maikel, Joern, Zapper + Authors: timi, Maikel, Joern, Zapper, Randrian Player and team related functions. --*/ @@ -107,4 +107,10 @@ global func MessageWindow(string msg, int for_plr, id icon, string caption) return false; cursor->AddMenuItem(caption, nil, nil, 0, 0, msg); return true; +} + +// Find a base of the given player. Use index to search through all bases. +global func FindBase (int iPlr, int iIndex) +{ + return FindObjects(Find_Owner(iPlr), Find_Func("IsBase"))[iIndex]; } \ No newline at end of file