adapt System.ocg headers to style guidelines and small clean ups

install-platforms
Maikel de Vries 2017-06-02 17:14:52 +02:00
parent f3cadedff1
commit 2b88e77254
37 changed files with 340 additions and 299 deletions

View File

@ -1,6 +1,9 @@
/** /**
Decay.c
Animals can use Decay() in their Death() function so they will slowly decay and spawn a few temporary flies. Animals can use Decay() in their Death() function so they will slowly decay and spawn a few temporary flies.
The delay parameter specifies the amount of frames before decaying one Con. The delay parameter specifies the amount of frames before decaying one Con.
@author
*/ */
global func Decay(int delay) global func Decay(int delay)

View File

@ -1,5 +1,8 @@
/** /**
Contains functions that require definitions from the "disasters" folder. Disasters.c
Contains functions that require definitions from the Disasters.ocd folder.
@author
*/ */
/** /**

View File

@ -1,5 +1,8 @@
/* /*
Effect.c
Contains functions for (visual) effects that require particles or definitions from Objects.ocd to be loaded. Contains functions for (visual) effects that require particles or definitions from Objects.ocd to be loaded.
@author
*/ */
/* /*
@ -11,11 +14,11 @@ global func ExplosionEffect(int level, int x, int y, int smoothness, bool silent
// Zero-size explosion doesn't affect anything // Zero-size explosion doesn't affect anything
if (level <= 0) return; if (level <= 0) return;
if(!silent) //Does object use it's own explosion sound effect? if (!silent) //Does object use it's own explosion sound effect?
{ {
// Select sound according to level: from 1 to 3, add the * to allow alternatives. // Select sound according to level: from 1 to 3, add the * to allow alternatives.
var grade = BoundBy(level / 10 - 1, 1, 3); var grade = BoundBy(level / 10 - 1, 1, 3);
if(GBackLiquid(x, y)) if (GBackLiquid(x, y))
SoundAt(Format("Fire::BlastLiquid%d*",grade), x, y); SoundAt(Format("Fire::BlastLiquid%d*",grade), x, y);
else else
SoundAt(Format("Fire::Blast%d*", grade), x, y); SoundAt(Format("Fire::Blast%d*", grade), x, y);

View File

@ -1,4 +1,5 @@
/* /**
FindLocation.c
This script contains the function FindLocation which uses a parameter-system similar to FindObject. This script contains the function FindLocation which uses a parameter-system similar to FindObject.
This function should mainly be used for placement of objects at the start of a scenario. This function should mainly be used for placement of objects at the start of a scenario.
FindLocation is not guaranteed to always return a spot if a fitting spot exists, it's just best effort. FindLocation is not guaranteed to always return a spot if a fitting spot exists, it's just best effort.
@ -8,6 +9,8 @@
FindLocation([Loc_Tunnel()]); FindLocation([Loc_Tunnel()]);
finds a floor spot but not in front of tunnel: finds a floor spot but not in front of tunnel:
FindLocation([Loc_Not(Find_Tunnel()), Loc_Wall(CNAT_Bottom)]); FindLocation([Loc_Not(Find_Tunnel()), Loc_Wall(CNAT_Bottom)]);
@author Zapper
*/ */
static const LOC_INVALID = 0; static const LOC_INVALID = 0;

View File

@ -1,5 +1,8 @@
/** /**
GUI.c
Contains UI related functions that require definitions from Objects.ocd to be loaded. Contains UI related functions that require definitions from Objects.ocd to be loaded.
@author Zapper
*/ */
// The default menu decoration used in most places. // The default menu decoration used in most places.

View File

@ -1,5 +1,8 @@
/** /**
InflameLandscape.c
Engine callback handling for landscape inflammation Engine callback handling for landscape inflammation
@author
*/ */
// Callback from engine when landsape is incinerated at an incindiary material. // Callback from engine when landsape is incinerated at an incindiary material.

View File

@ -1,7 +1,13 @@
/* Configurable pathfinder for graphs */ /**
AStar.c
Configurable pathfinder for graphs.
@author Luchs
*/
// Generic A* implementation. // Generic A* implementation.
static const AStar = new Global { static const AStar = new Global
{
/* Overwrite these functions */ /* Overwrite these functions */
/* ========================= */ /* ========================= */
@ -93,7 +99,8 @@ static const AStar = new Global {
// //
// Graph nodes are a regular grid over the landscape with a configurable size // Graph nodes are a regular grid over the landscape with a configurable size
// (step). Nodes are represented as {x, y} proplists. // (step). Nodes are represented as {x, y} proplists.
static const AStarMap = new AStar { static const AStarMap = new AStar
{
// This function is used both as heuristic (node to the goal) and as cost // This function is used both as heuristic (node to the goal) and as cost
// function (two neighboring nodes). // function (two neighboring nodes).
distance = func(proplist a, proplist b) distance = func(proplist a, proplist b)
@ -132,8 +139,8 @@ static const AStarMap = new AStar {
}; };
/* Binary Min-Heap */ /* Binary Min-Heap */
static const MinHeap = new Global { static const MinHeap = new Global
{
// A heap is an array of [key, value] array-tuples. // A heap is an array of [key, value] array-tuples.
Heapify = func(array heap, int i) Heapify = func(array heap, int i)
{ {

View File

@ -1,9 +1,9 @@
/*-- /**
Action.c Action.c
Authors: Günther Stuff for the proplist changes.
Stuff for the proplist changes. @author Günther
--*/ */
static const DFA_NONE = nil; static const DFA_NONE = nil;
static const DFA_WALK = "WALK"; static const DFA_WALK = "WALK";
@ -21,7 +21,8 @@ static const DFA_FLOAT = "FLOAT";
static const DFA_ATTACH = "ATTACH"; static const DFA_ATTACH = "ATTACH";
static const DFA_CONNECT = "CONNECT"; static const DFA_CONNECT = "CONNECT";
static const DFA_PULL = "PULL"; static const DFA_PULL = "PULL";
static const Action = { static const Action =
{
GetName = Global.GetName, GetName = Global.GetName,
Length = 1, Length = 1,
Directions = 1, Directions = 1,
@ -29,9 +30,12 @@ static const Action = {
Procedure = DFA_NONE, Procedure = DFA_NONE,
}; };
global func GameCall(string fn, ...) { global func GameCall(string fn, ...)
if (!fn) return; {
if (!fn)
return;
var f = Scenario[fn]; var f = Scenario[fn];
if (!f) return; if (!f)
return;
return Scenario->Call(f, ...); return Scenario->Call(f, ...);
} }

View File

@ -1,9 +1,9 @@
/*-- /**
Array.c Array.c
Authors: Zapper, Sven2 Global array helper functions.
Global array helper functions. @author Zapper, Sven2
--*/ */
// Concatenates two arrays and returns a new array. // Concatenates two arrays and returns a new array.

View File

@ -1,7 +1,8 @@
/* /**
This file contains functions that can be commonly used to make functions safe. Assert.c
Functions that can be commonly used to make functions safe.
Author: Marky @author Marky
*/ */

View File

@ -1,10 +1,9 @@
/**
/*-- CollectStatistics.c
CollectStatistics.c Global entry point for statistics collection for the masterserver.
Authors: Luchs
@author Luchs
Global entry point for statistics collection for the masterserver. */
--*/
// This function is called after the round ends. The return value is passed to // This function is called after the round ends. The return value is passed to

View File

@ -1,9 +1,9 @@
/*-- /**
Colors.c Colors.c
Authors: Tyron All sorts of operations on colors.
All sorts of operations on colors. @author Tyron
--*/ */
static const RGBA_ALPHA = 0; static const RGBA_ALPHA = 0;
static const RGBA_RED = 1; static const RGBA_RED = 1;
@ -27,7 +27,8 @@ global func SetRGBaValue(int val, int newval, int sel)
return val | newval << ((3 - sel) * 8); return val | newval << ((3 - sel) * 8);
} }
global func SplitRGBaValue(int rgb) { global func SplitRGBaValue(int rgb)
{
return [GetRGBaValue(rgb, 1), GetRGBaValue(rgb, 2), GetRGBaValue(rgb, 3), GetRGBaValue(rgb, 0)]; return [GetRGBaValue(rgb, 1), GetRGBaValue(rgb, 2), GetRGBaValue(rgb, 3), GetRGBaValue(rgb, 0)];
} }
@ -110,5 +111,5 @@ global func RGB2HSL(int rgb)
hue -= 255; hue -= 255;
} }
return RGB(hue,sat,lightness); return RGB(hue, sat, lightness);
} }

View File

@ -1,38 +1,27 @@
/*-- /**
Controls.c Controls.c
Authors: boni Helper functions to find out if a Control fits into a certain category. (Throwing, using, interacting,...).
Helper functions to find out if a Control fits into a certain category. (Throwing, using, interacting,...) @author boni
--*/ */
/** Control tells the clonk to move */ // Control tells the clonk to move.
global func IsMovementControl(int ctrl) global func IsMovementControl(int ctrl)
{ {
// up, up, down, down, left, right, left, right, B, A return ctrl == CON_Up || ctrl == CON_Down || ctrl == CON_Left || ctrl == CON_Right;
if(ctrl == CON_Up
|| ctrl == CON_Down
|| ctrl == CON_Left
|| ctrl == CON_Right)
return true;
return false;
} }
/** Control throws selected item */ // Control throws selected item.
global func IsThrowControl(int ctrl) global func IsThrowControl(int ctrl)
{ {
// right mouse button return ctrl == CON_Throw;
if(ctrl == CON_Throw)
return true;
return false;
} }
/** Control drops items from inventory (hotkey or selected items) */ // Control drops items from inventory (hotkey or selected items).
global func IsDropControl(int ctrl) global func IsDropControl(int ctrl)
{ {
// selected items // selected items
if(ctrl == CON_Drop if (ctrl == CON_Drop
// hotkeys // hotkeys
|| ctrl == CON_DropHotkey0 || ctrl == CON_DropHotkey0
|| ctrl == CON_DropHotkey1 || ctrl == CON_DropHotkey1
@ -49,11 +38,11 @@ global func IsDropControl(int ctrl)
return false; return false;
} }
/** Control has the goal of interacting with some other object (Interaction, Grabbing, Entering,...) */ // Control has the goal of interacting with some other object (Interaction, Grabbing, Entering,...).
global func IsInteractionControl(int ctrl) global func IsInteractionControl(int ctrl)
{ {
// Interaction itself // Interaction itself
if(ctrl == CON_Interact if (ctrl == CON_Interact
// hotkeys // hotkeys
|| ctrl == CON_InteractionHotkey0 || ctrl == CON_InteractionHotkey0
|| ctrl == CON_InteractionHotkey1 || ctrl == CON_InteractionHotkey1
@ -70,11 +59,11 @@ global func IsInteractionControl(int ctrl)
return false; return false;
} }
/** Control has the goal of switching the currently selected crewmember */ // Control has the goal of switching the currently selected crewmember.
global func IsCrewControl(int ctrl) global func IsCrewControl(int ctrl)
{ {
// next/previous // next/previous
if(ctrl == CON_NextCrew if (ctrl == CON_NextCrew
|| ctrl == CON_PreviousCrew || ctrl == CON_PreviousCrew
// hotkeys // hotkeys
|| ctrl == CON_PlayerHotkey0 || ctrl == CON_PlayerHotkey0
@ -93,9 +82,8 @@ global func IsCrewControl(int ctrl)
return false; return false;
} }
/** Control uses selected item */ // Control uses selected item.
global func IsUseControl(int ctrl) global func IsUseControl(int ctrl)
{ {
if (ctrl == CON_Use || ctrl == CON_UseAlt) return true; return ctrl == CON_Use || ctrl == CON_UseAlt;
return false;
} }

View File

@ -1,9 +1,9 @@
/*-- /**
Creation.c Creation.c
Authors: Ringwaul, Tyron Creation of objects, particles or PSX.
Creation of objects, particles or PSX. @author Ringwaul, Tyron
--*/ */
// Creates amount objects of type id inside the indicated rectangle(optional) in the indicated material. // Creates amount objects of type id inside the indicated rectangle(optional) in the indicated material.
// Returns the number of iterations needed, or -1 when the placement failed. // Returns the number of iterations needed, or -1 when the placement failed.

View File

@ -1,9 +1,9 @@
/*-- /**
Definition.c Definition.c
Authors: Maikel Functions generally applicable to definitions.
Functions generally applicable to definitions. @author Maikel
--*/ */
static GetDefinition_Loaded_Definition_List; static GetDefinition_Loaded_Definition_List;

View File

@ -1,9 +1,9 @@
/*-- /**
Effect.c Effect.c
Authors: Günther Prototype for effect prototypes and useful effects.
Prototype for effect prototypes. @author Günther
--*/ */
static const Effect = new Global static const Effect = new Global
{ {

View File

@ -1,15 +1,12 @@
/*-- /**
Explode.c Explode.c
Authors: Newton Everything about the explosion.
Everything about the explosion. @author Newton
TODO: documentation. */
--*/
/*-- // Particle definitions used by the explosion effect.
Particle definitions used by the explosion effect. // They will be initialized lazily whenever the first blast goes off.
They will be initialized lazily whenever the first blast goes off.
--*/
static ExplosionParticles_Smoke; static ExplosionParticles_Smoke;
static ExplosionParticles_Blast; static ExplosionParticles_Blast;
static ExplosionParticles_BlastSmooth; static ExplosionParticles_BlastSmooth;

View File

@ -2,6 +2,7 @@
Fade.c Fade.c
Function to fade in and out objects. Function to fade in and out objects.
@author
*/ */
global func FadeOut(int time, bool del) global func FadeOut(int time, bool del)

View File

@ -1,9 +1,9 @@
/*-- /**
FindObject.c FindObject.c
Authors: Wrappers for convenient calls to the FindObject family.
Wrappers for convenient calls to the FindObject family. @author
--*/ */
/*-- Find functions --*/ /*-- Find functions --*/
@ -142,7 +142,8 @@ Similar to Find_Hostile, but defaults to treating all players as hostile when pl
*/ */
global func Find_AnimalHostile(int plr) global func Find_AnimalHostile(int plr)
{ {
if (plr == NO_OWNER) return Find_Not(Find_Owner(NO_OWNER)); if (plr == NO_OWNER)
return Find_Not(Find_Owner(NO_OWNER));
return Find_Or(Find_Owner(NO_OWNER), Find_Hostile(plr)); return Find_Or(Find_Owner(NO_OWNER), Find_Hostile(plr));
} }

View File

@ -1,11 +1,9 @@
/*-- /**
Fire.c Fire.c
Authors: Zapper, Maikel The fire effect ported from the engine. Functions to be used as documented in the docs.
The fire effect ported from the engine. @author Zapper, Maikel
*/
Functions to be used as documented in the docs.
--*/
static const FIRE_LIGHT_COLOR = 0xc86400; static const FIRE_LIGHT_COLOR = 0xc86400;

View File

@ -1,5 +1,8 @@
/* /**
GUI.c
This file contains functions that are used for layouting custom menus. This file contains functions that are used for layouting custom menus.
@author Zapper
*/ */
/* -- constants used for layout -- */ /* -- constants used for layout -- */

View File

@ -1,15 +1,14 @@
/*-- /**
GetXVal.c GetXVal.c
Authors: Some functions which request information from the GetXVal family.
Attention: These functions directly access internal values of the engine.
Some functions which request information from the GetXVal family. The usage might, under certain circumstances, lead to desynchronisation in
Attention: These functions directly access internal values of the engine. either network games or save games. The most dangerous functions are marked
The usage might, under certain circumstances, lead to desynchronisation in with //(!).
either network games or save games. The most dangerous functions are marked These functions are also very slow. Values should be cached if possible.
with //(!).
@author
These functions are also very slow. Values should be cached if possible. */
--*/
global func GetActMapVal(string entry, string action, id def, int num) global func GetActMapVal(string entry, string action, id def, int num)
{ {

View File

@ -2,7 +2,7 @@
Heal.c Heal.c
Function to heal livings over time. Function to heal livings over time.
Author: Armin @author Armin
*/ */
/** /**

View File

@ -1,13 +1,13 @@
/*-- /**
HitCheck.c HitCheck.c
Authors: Newton, Boni Effect for hit checking.
Facilitates any hit check of a projectile. The Projectile hits anything
Effect for hit checking. which is either alive or returns for IsProjectileTarget(object projectile,
Facilitates any hit check of a projectile. The Projectile hits anything object shooter) true. If the projectile hits something, it calls
which is either alive or returns for IsProjectileTarget(object projectile, HitObject(object target) in the projectile.
object shooter) true. If the projectile hits something, it calls
HitObject(object target) in the projectile. @author Newton, Boni
--*/ */
global func FxHitCheckStart(object target, proplist effect, int temp, object by_obj, bool never_shooter) global func FxHitCheckStart(object target, proplist effect, int temp, object by_obj, bool never_shooter)
{ {

View File

@ -1,5 +1,8 @@
/* /**
global functions that belong to Libraries.ocd/Inventory.ocd Library_Inventory.c
Global functions that belong to Libraries.ocd/Inventory.ocd.
@author
*/ */
// overload function for objects with Inventory.ocd // overload function for objects with Inventory.ocd

View File

@ -1,9 +1,9 @@
/*-- /**
Material.c Material.c
Authors: Ringwaul Functions relating to materials; any kind of operations.
Functions in relation to material; any kind of operations. @author Ringwaul
--*/ */
global func MaterialDepthCheck(int x, int y, string mat, int depth) global func MaterialDepthCheck(int x, int y, string mat, int depth)
{ {
@ -59,8 +59,8 @@ global func FindPosInMat(string sMat, int iXStart, int iYStart, int iWidth, int
global func ExtractLiquid(int x, int y, bool distant_first) global func ExtractLiquid(int x, int y, bool distant_first)
{ {
var result = ExtractLiquidAmount(x, y, 1, distant_first); var result = ExtractLiquidAmount(x, y, 1, distant_first);
if(!result) return -1; if (!result)
return -1;
return result[0]; return result[0];
} }

View File

@ -1,9 +1,9 @@
/*-- /**
Math.c Math.c
Authors: Maikel, flgr, Newton, Tyron, Zapper Any kind of help with calculations.
Any kind of help with calculation. @author Maikel, flgr, Newton, Tyron, Zapper
--*/ */
// Returns the offset to x. // Returns the offset to x.
global func AbsX(int x) global func AbsX(int x)
@ -122,7 +122,7 @@ global func GetCalcDir()
return GetDir() * 2 - 1; return GetDir() * 2 - 1;
} }
//Moves param 'a' towards param 'b' by 'max' amount per frame // Moves param 'a' towards param 'b' by 'max' amount per frame.
global func MoveTowards(int a, int b, int max) global func MoveTowards(int a, int b, int max)
{ {
if(b == nil) return false; if(b == nil) return false;

View File

@ -1,10 +1,9 @@
/*-- /**
MeshAnimation.c MeshAnimation.c
Authors: ck Wrappers for convenient calls to PlayAnimation.
Wrappers for convenient calls to PlayAnimation. @author ck
--*/ */
global func Anim_Const(int value) global func Anim_Const(int value)
{ {

View File

@ -1,21 +1,20 @@
/*-- /**
NamedParams.c NamedParams.c
Adapts some functions with lots of optional parameters to take a proplist instead.
Adapts some functions with lots of optional parameters to take a proplist instead. @author Marky
--*/ */
global func Sound(string name, opts, ...) global func Sound(string name, opts, ...)
{ {
if (GetType(opts) == C4V_PropList) if (GetType(opts) == C4V_PropList)
return inherited(name, opts.global, opts.volume, opts.player, opts.loop_count, opts.custom_falloff_distance, opts.pitch, opts.modifier); return inherited(name, opts.global, opts.volume, opts.player, opts.loop_count, opts.custom_falloff_distance, opts.pitch, opts.modifier);
else return inherited(name, opts, ...);
return inherited(name, opts, ...);
} }
global func SoundAt(string name, int x, int y, opts, ...) global func SoundAt(string name, int x, int y, opts, ...)
{ {
if (GetType(opts) == C4V_PropList) if (GetType(opts) == C4V_PropList)
return inherited(name, x, y, opts.volume, opts.player, opts.custom_falloff_distance, opts.pitch, opts.modifier); return inherited(name, x, y, opts.volume, opts.player, opts.custom_falloff_distance, opts.pitch, opts.modifier);
else return inherited(name, x, y, opts, ...);
return inherited(name, x, y, opts, ...);
} }

View File

@ -1,9 +1,9 @@
/*-- /**
Objects.c Objects.c
Authors: Maikel, boni, Ringwaul, Sven2, flgr, Clonkonaut, Günther, Randrian Functions generally applicable to objects; not enough to be worth distinct scripts though.
Functions generally applicable to objects; not enough to be worth distinct scripts though. @author Maikel, boni, Ringwaul, Sven2, flgr, Clonkonaut, Günther, Randrian
--*/ */
// Does not set the speed of an object. But you can set two components of the velocity vector with this function. // Does not set the speed of an object. But you can set two components of the velocity vector with this function.
global func SetSpeed(int x_dir, int y_dir, int prec) global func SetSpeed(int x_dir, int y_dir, int prec)
@ -321,15 +321,17 @@ global func StonyObjectHit(int x, int y)
// Failsafe // Failsafe
if (!this) return false; if (!this) return false;
var xdir = GetXDir(), ydir = GetYDir(); var xdir = GetXDir(), ydir = GetYDir();
if(x) x = x / Abs(x); if (x) x = x / Abs(x);
if(y) y = y / Abs(y); if (y) y = y / Abs(y);
// Check for solid in hit direction // Check for solid in hit direction
var i = 0; var i = 0;
var average_obj_size = Distance(0,0, GetObjWidth(), GetObjHeight()) / 2 + 2; var average_obj_size = Distance(0,0, GetObjWidth(), GetObjHeight()) / 2 + 2;
while(!GBackSolid(x*i, y*i) && i < average_obj_size) i++; while (!GBackSolid(x * i, y * i) && i < average_obj_size)
i++;
// To catch some high speed cases: if no solid found, check directly beneath // To catch some high speed cases: if no solid found, check directly beneath
if (!GBackSolid(x*i, y*i)) if (!GBackSolid(x * i, y * i))
while(!GBackSolid(x*i, y*i) && i < average_obj_size) i++; while (!GBackSolid(x * i, y * i) && i < average_obj_size)
i++;
// Check if digfree // Check if digfree
if (!GetMaterialVal("DigFree", "Material", GetMaterial(x*i, y*i)) && GBackSolid(x*i, y*i)) if (!GetMaterialVal("DigFree", "Material", GetMaterial(x*i, y*i)) && GBackSolid(x*i, y*i))
return Sound("Hits::Materials::Rock::RockHit?"); return Sound("Hits::Materials::Rock::RockHit?");
@ -356,76 +358,87 @@ global func RemoveAll(p, ...)
return cnt; return cnt;
} }
// Pulls an object above ground if it was buried (e.g. by PlaceVegetation). // Pulls an object above ground if it was buried (e.g. by PlaceVegetation), mainly used by plants.
// The object must have 'Bottom' and 'Center' CNAT to use this. // 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) // (bottom is the point which should be buried, center the lowest point that must not be buried)
// Mainly used by plants.
global func RootSurface() global func RootSurface()
{ {
if (HasCNAT(CNAT_Center)) if (HasCNAT(CNAT_Center))
{ {
var i = 0; var i = 0;
while(GetContact(-1) & CNAT_Center && i < GetObjHeight()/2) { SetPosition(GetX(),GetY()-1); i++; } //Move up if too far underground // Move up if too far underground.
while (GetContact(-1) & CNAT_Center && i < GetObjHeight()/2)
{
SetPosition(GetX(), GetY() - 1);
i++;
}
} }
if (HasCNAT(CNAT_Bottom)) if (HasCNAT(CNAT_Bottom))
{ {
i = 0; i = 0;
while(!(GetContact(-1) & CNAT_Bottom) && i < GetObjHeight()/2) { SetPosition(GetX(),GetY()+1); i++; } //Move down if in midair // Move down if in midair.
while (!(GetContact(-1) & CNAT_Bottom) && i < GetObjHeight()/2)
if (!Stuck()) SetPosition(GetX(),GetY()+1); // try make the plant stuck {
SetPosition(GetX(), GetY() + 1);
i++;
}
// Try to make the plant stuck.
if (!Stuck())
SetPosition(GetX(), GetY() + 1);
} }
} }
// Buys an object. Returns the object if it could be bought. // Buys an object. Returns the object if it could be bought.
global func Buy (id idBuyObj, int iForPlr, int iPayPlr, object pFromVendor, bool fShowErrors) global func Buy(id buy_def, int for_plr, int pay_plr, object from_vendor, bool show_errors)
{ {
// if no vendor is given try this // if no vendor is given try this
if (!pFromVendor) pFromVendor = this; if (!from_vendor)
from_vendor = this;
// not a vendor? // not a vendor?
if (!pFromVendor->~IsVendor()) if (!from_vendor->~IsVendor())
return nil; return nil;
return pFromVendor->DoBuy(idBuyObj, iForPlr, iPayPlr, nil, 0, fShowErrors); return from_vendor->DoBuy(buy_def, for_plr, pay_plr, nil, 0, show_errors);
} }
// Sells an object. Returns true if it could be sold. // Sells an object. Returns true if it could be sold.
global func Sell (int iPlr, object pObj, object pToVendor) global func Sell(int plr, object obj, object to_vendor)
{ {
// if no vendor is given try this // if no vendor is given try this
if(!pToVendor) pToVendor = this; if (!to_vendor)
to_vendor = this;
// not a vendor? // not a vendor?
if (!pToVendor->~IsVendor()) if (!to_vendor->~IsVendor())
return false; return false;
return pToVendor->DoSell(pObj, iPlr); return to_vendor->DoSell(obj, plr);
} }
/* GetXEdge returns the position of the objects top/bottom/left/right edge */ // GetXEdge returns the position of the objects top/bottom/left/right edge.
global func GetLeftEdge() global func GetLeftEdge()
{ {
return GetX()-GetObjWidth()/2; return GetX() - GetObjWidth() / 2;
} }
global func GetRightEdge() global func GetRightEdge()
{ {
return GetX()+GetObjWidth()/2; return GetX() + GetObjWidth() / 2;
} }
global func GetTopEdge() global func GetTopEdge()
{ {
return GetY()-GetObjHeight()/2; return GetY() - GetObjHeight() / 2;
} }
global func GetBottomEdge() global func GetBottomEdge()
{ {
return GetY()+GetObjHeight()/2; return GetY() + GetObjHeight() / 2;
} }
// Returns if the object is standing in front of the back-object // Returns if the object is standing in front of the back-object
global func InFrontOf(object back) global func InFrontOf(object back)
{ {
var front = this; var front = this;
if(!front) if (!front)
return; return;
return front->FindObject(front->Find_AtPoint(), Find_Not(Find_Exclude(back))) != nil; return front->FindObject(front->Find_AtPoint(), Find_Not(Find_Exclude(back))) != nil;
} }

View File

@ -1,8 +1,12 @@
/** /**
Particles.c
This file contains some default particle behavior definitions as well as helper functions. This file contains some default particle behavior definitions as well as helper functions.
@author Zapper
*/ */
/* particle helper/effect functions */
/*-- Helper/Effect Functions --*/
global func CreateMuzzleFlash(int x, int y, int angle, int size) global func CreateMuzzleFlash(int x, int y, int angle, int size)
{ {
@ -30,7 +34,8 @@ global func Smoke(int x, int y, int level, int color, bool heavy)
} }
/* particle definitions */ /*-- Particle Definitions --*/
global func Particles_Dust() global func Particles_Dust()
{ {
return return
@ -55,7 +60,6 @@ global func Particles_Cloud()
}; };
} }
global func Particles_Smoke(bool heavy) global func Particles_Smoke(bool heavy)
{ {
return return
@ -294,7 +298,6 @@ global func Particles_Air()
}; };
} }
global func Particles_Thrust(int size) global func Particles_Thrust(int size)
{ {
size = size ?? 10; size = size ?? 10;
@ -367,7 +370,8 @@ global func Particles_ElectroSpark2()
}; };
} }
/* weather particles */
/*-- Weather Particles --*/
global func Particles_Rain(int color) global func Particles_Rain(int color)
{ {

View File

@ -1,10 +1,9 @@
/*-- /**
Player.c Player.c
Authors: timi, Maikel, Joern, Zapper, Randrian Player and team related functions.
Player and team related functions. @author timi, Maikel, Joern, Zapper, Randrian
--*/ */
// Returns the player number of plr_name, or none if there is no such player. (written by timi for CR/CE/CP) // Returns the player number of plr_name, or none if there is no such player. (written by timi for CR/CE/CP)
global func GetPlayerByName(string plr_name) global func GetPlayerByName(string plr_name)
@ -124,8 +123,10 @@ global func DoWealth(int plr, int value)
// checks whether two players are allied - that means they are not hostile and neither of them is NO_OWNER // checks whether two players are allied - that means they are not hostile and neither of them is NO_OWNER
global func IsAllied(int plr1, int plr2, bool check_one_way_only /* whether to check the hostility only in one direction */) global func IsAllied(int plr1, int plr2, bool check_one_way_only /* whether to check the hostility only in one direction */)
{ {
if(plr1 == NO_OWNER) return false; if (plr1 == NO_OWNER)
if(plr2 == NO_OWNER) return false; return false;
if (plr2 == NO_OWNER)
return false;
return !Hostile(plr1, plr2, check_one_way_only); return !Hostile(plr1, plr2, check_one_way_only);
} }

View File

@ -1,10 +1,9 @@
/*-- /**
PlayerControl.c PlayerControl.c
Authors: Newton Functions to handle player controls (i.e. input keys).
Functions to handle player controls (i.e. input keys) @author Newton
--*/ */
static const CON_Gamepad_Deadzone = 60; static const CON_Gamepad_Deadzone = 60;
static CON_VC_Players; static CON_VC_Players;
@ -75,7 +74,7 @@ global func PlayerControl(int plr, int ctrl, id spec_id, int x, int y, int stren
// local coordinates // local coordinates
var cursorX = x, cursorY = y; var cursorX = x, cursorY = y;
if(x != nil || y != nil) if (x != nil || y != nil)
{ {
cursorX -= cursor->GetX(); cursorX -= cursor->GetX();
cursorY -= cursor->GetY(); cursorY -= cursor->GetY();
@ -110,7 +109,7 @@ global func InitializePlayerControl(int plr, string controlset_name, bool keyboa
CON_VC_Players[plr] = !mouse; CON_VC_Players[plr] = !mouse;
// for all clonks... // for all clonks...
for(var clonk in FindObjects(Find_OCF(OCF_CrewMember))) for (var clonk in FindObjects(Find_OCF(OCF_CrewMember)))
{ {
clonk->~ReinitializeControls(); clonk->~ReinitializeControls();
} }
@ -118,7 +117,7 @@ global func InitializePlayerControl(int plr, string controlset_name, bool keyboa
global func PlayerHasVirtualCursor(int plr) global func PlayerHasVirtualCursor(int plr)
{ {
if(!CON_VC_Players) if (!CON_VC_Players)
return false; return false;
return CON_VC_Players[plr]; return CON_VC_Players[plr];
@ -189,7 +188,7 @@ global func GetPlayerCursorPos(int plr)
global func StopSelected(int plr) global func StopSelected(int plr)
{ {
var cursor = GetCursor(plr); var cursor = GetCursor(plr);
if(cursor) if (cursor)
{ {
cursor->SetCommand("None"); cursor->SetCommand("None");
cursor->SetComDir(COMD_Stop); cursor->SetComDir(COMD_Stop);
@ -207,14 +206,14 @@ global func Control2Effect(int plr, int ctrl, int x, int y, int strength, bool r
if (!this) return false; if (!this) return false;
// Count down from EffectCount, in case effects get deleted // Count down from EffectCount, in case effects get deleted
var i = GetEffectCount("*Control*", this), iEffect; var i = GetEffectCount("*Control*", this), fx;
while (i--) while (i--)
{ {
iEffect = GetEffect("*Control*", this, i); fx = GetEffect("*Control*", this, i);
if (iEffect) if (fx)
if (EffectCall(this, iEffect, "Control", ctrl, x,y,strength, repeat, status)) if (EffectCall(this, fx, "Control", ctrl, x,y,strength, repeat, status))
return true; return true;
} }
// No effect handled the control // No effect handled the control
return false; return false;
} }
@ -283,8 +282,8 @@ global func ObjectControlMovement(int plr, int ctrl, int strength, int status, b
if (Contained()) return false; if (Contained()) return false;
// this is for controlling movement with Analogpad // this is for controlling movement with Analogpad
if(status == CONS_Down) if (status == CONS_Down)
if(strength != nil && strength < CON_Gamepad_Deadzone) if (strength != nil && strength < CON_Gamepad_Deadzone)
return true; return true;
var proc = GetProcedure(); var proc = GetProcedure();
@ -294,9 +293,9 @@ global func ObjectControlMovement(int plr, int ctrl, int strength, int status, b
// Jump control // Jump control
if (ctrl == CON_Jump) if (ctrl == CON_Jump)
{ {
if(proc == "WALK" && GetComDir() == COMD_Up) if (proc == "WALK" && GetComDir() == COMD_Up)
SetComDir(COMD_Stop); SetComDir(COMD_Stop);
if(proc == "WALK") if (proc == "WALK")
{ {
this->ObjectCommand("Jump"); this->ObjectCommand("Jump");
return true; return true;
@ -501,10 +500,10 @@ global func ObjectComLetGo(int vx, int vy)
global func MouseHover(int player, object leaving, object entering, object dragged) global func MouseHover(int player, object leaving, object entering, object dragged)
{ {
// Leaving the hovering zone should be processed first. // Leaving the hovering zone should be processed first.
if(leaving) if (leaving)
leaving->~OnMouseOut(player, dragged); leaving->~OnMouseOut(player, dragged);
// Then process entering a new hovering zone. // Then process entering a new hovering zone.
if(entering) if (entering)
entering->~OnMouseOver(player, dragged); entering->~OnMouseOver(player, dragged);
return true; return true;
} }

View File

@ -1,4 +1,10 @@
/* Scenario saving functionality */ /**
SaveScenario.c
Scenario saving functionality
@author Sven2
*/
// Defines script function SaveScenarioObjects, which is called by the // Defines script function SaveScenarioObjects, which is called by the
// engine to generate the Objects.c file for scenario saving // engine to generate the Objects.c file for scenario saving
// Also called for object duplication in the editor // Also called for object duplication in the editor

View File

@ -1,9 +1,9 @@
/*-- /**
Schedule.c Schedule.c
Authors: Schedule can be used to execute scripts or functions repetitively with delay.
Schedule can be used to execute scripts or functions repetitively with delay. @author
--*/ */
// Executes a script repetitively with delay. // Executes a script repetitively with delay.
global func Schedule(object obj, string script, int interval, int repeats) global func Schedule(object obj, string script, int interval, int repeats)
@ -12,21 +12,21 @@ global func Schedule(object obj, string script, int interval, int repeats)
if (!repeats) if (!repeats)
repeats = 1; repeats = 1;
// Create effect. // Create effect.
var effect = AddEffect("IntSchedule", obj, 1, interval, obj); var fx = AddEffect("IntSchedule", obj, 1, interval, obj);
if (!effect) if (!fx)
return false; return false;
// Set variables. // Set variables.
effect.Script = script; fx.Script = script;
effect.Repeats = repeats; fx.Repeats = repeats;
return true; return true;
} }
global func FxIntScheduleTimer(object obj, proplist effect) global func FxIntScheduleTimer(object obj, effect fx)
{ {
// Just a specific number of repeats. // Just a specific number of repeats.
var done = --effect.Repeats <= 0; var done = --fx.Repeats <= 0;
// Execute. // Execute.
eval(effect.Script); eval(fx.Script);
// Remove schedule if done. // Remove schedule if done.
if (done) if (done)
return FX_Execute_Kill; return FX_Execute_Kill;
@ -42,10 +42,10 @@ global func AddTimer(call_function, int interval)
if (interval == nil) if (interval == nil)
interval = 36; interval = 36;
// Create effect and add function and repeat infinitely. // Create effect and add function and repeat infinitely.
var effect = AddEffect("IntScheduleCall", this, 1, interval, this); var fx = AddEffect("IntScheduleCall", this, 1, interval, this);
effect.Function = call_function; fx.Function = call_function;
effect.NoStop = true; fx.NoStop = true;
effect.Pars = []; fx.Pars = [];
return true; return true;
} }
@ -55,12 +55,12 @@ global func RemoveTimer(call_function /* name or pointer to the timer to remove
if(!this) if(!this)
return false; return false;
var effect, index = 0; var fx, index = 0;
while(effect = GetEffect("IntScheduleCall", this, index++)) while(fx = GetEffect("IntScheduleCall", this, index++))
{ {
if(effect.Function != call_function) continue; if(fx.Function != call_function) continue;
if(effect.NoStop != true) continue; if(fx.NoStop != true) continue;
RemoveEffect(nil, this, effect); RemoveEffect(nil, this, fx);
return true; return true;
} }
@ -75,39 +75,39 @@ global func ScheduleCall(object obj, call_function, int interval, int repeats, p
if (!repeats) if (!repeats)
repeats = 1; repeats = 1;
// Create effect. // Create effect.
var effect = AddEffect("IntScheduleCall", obj, 1, interval, obj); var fx = AddEffect("IntScheduleCall", obj, 1, interval, obj);
if (!effect) if (!fx)
return false; return false;
// Set variables. // Set variables.
effect.Function = call_function; fx.Function = call_function;
effect.Repeats = repeats; fx.Repeats = repeats;
effect.Pars = [par0, par1, par2, par3, par4]; fx.Pars = [par0, par1, par2, par3, par4];
return true; return true;
} }
global func FxIntScheduleCallTimer(object obj, proplist effect) global func FxIntScheduleCallTimer(object obj, effect fx)
{ {
// Just a specific number of repeats. // Just a specific number of repeats.
var done = --effect.Repeats <= 0; var done = --fx.Repeats <= 0;
// Execute. // Execute.
Call(effect.Function, effect.Pars[0], effect.Pars[1], effect.Pars[2], effect.Pars[3], effect.Pars[4]); Call(fx.Function, fx.Pars[0], fx.Pars[1], fx.Pars[2], fx.Pars[3], fx.Pars[4]);
// Remove schedule call if done, take into account infinite schedules. // Remove schedule call if done, take into account infinite schedules.
if (done && !effect.NoStop) if (done && !fx.NoStop)
return FX_Execute_Kill; return FX_Execute_Kill;
return FX_OK; return FX_OK;
} }
global func ClearScheduleCall(object obj, call_function) global func ClearScheduleCall(object obj, call_function)
{ {
var i, effect; var i, fx;
// Count downwards from effectnumber, to remove effects. // Count downwards from effectnumber, to remove effects.
i = GetEffectCount("IntScheduleCall", obj); i = GetEffectCount("IntScheduleCall", obj);
while (i--) while (i--)
// Check All ScheduleCall-Effects. // Check All ScheduleCall-Effects.
if (effect = GetEffect("IntScheduleCall", obj, i)) if (fx = GetEffect("IntScheduleCall", obj, i))
// Found right function. // Found right function.
if (effect.Function == call_function) if (fx.Function == call_function)
// Remove effect. // Remove effect.
RemoveEffect(nil, obj, effect); RemoveEffect(nil, obj, fx);
return; return;
} }

View File

@ -2,7 +2,7 @@
String.c String.c
Functions for string manipulation. Functions for string manipulation.
@authors Maikel @author Maikel
*/ */
// Returns the reduced string with only the characters in the interval [begin, end) are taken. The value begin starts // Returns the reduced string with only the characters in the interval [begin, end) are taken. The value begin starts

View File

@ -1,9 +1,9 @@
/*-- /**
Vertices.c Vertices.c
Authors: Clonkonaut, flgr Vertex related functions.
Vertex related functions. @author Clonkonaut, flgr
--*/ */
// Sets both the X and Y-coordinate of one vertex. // Sets both the X and Y-coordinate of one vertex.
global func SetVertexXY(int index, int x, int y) global func SetVertexXY(int index, int x, int y)
@ -88,46 +88,46 @@ global func HalfVehicleFadeJumpStop()
{ {
if (!this) if (!this)
return FatalError("this function requires object context"); return FatalError("this function requires object context");
var effect; var fx;
if(effect = GetEffect("IntHalfVehicleFadeJump", this)) { if (fx = GetEffect("IntHalfVehicleFadeJump", this))
effect.Interval = 1; fx.Interval = 1;
}
} }
global func FxIntHalfVehicleFadeJumpStart(object target, proplist effect, int temp) global func FxIntHalfVehicleFadeJumpStart(object target, effect fx, int temp)
{ {
if (temp) if (temp)
return FX_OK; return FX_OK;
if (!target) { if (!target) {
return FX_Start_Deny; return FX_Start_Deny;
} }
effect.collideverts = CreateArray(); fx.collideverts = CreateArray();
for (var i = target->GetVertexNum(); i-->0;) for (var i = target->GetVertexNum(); i-->0;)
if(!(target->GetVertex(i, VTX_CNAT) & CNAT_PhaseHalfVehicle)) { if(!(target->GetVertex(i, VTX_CNAT) & CNAT_PhaseHalfVehicle)) {
PushBack(effect.collideverts, i); PushBack(fx.collideverts, i);
target->SetVertexCNAT(i, CNAT_PhaseHalfVehicle, true); target->SetVertexCNAT(i, CNAT_PhaseHalfVehicle, true);
} }
effect.origpos = target->GetPosition(); fx.origpos = target->GetPosition();
return FX_OK; return FX_OK;
} }
global func FxIntHalfVehicleFadeJumpTimer(object target, proplist effect, int time) global func FxIntHalfVehicleFadeJumpTimer(object target, effect fx, int time)
{ {
if (DeepEqual(target->GetPosition(), effect.origpos)) if (DeepEqual(target->GetPosition(), fx.origpos))
return FX_OK; return FX_OK;
for (var i = GetLength(effect.collideverts); i-->0;) { for (var i = GetLength(fx.collideverts); i-- > 0;)
if (target->GetMaterial(target->GetVertex(effect.collideverts[i], VTX_X), {
target->GetVertex(effect.collideverts[i], VTX_Y)) == Material("HalfVehicle")) if (target->GetMaterial(target->GetVertex(fx.collideverts[i], VTX_X),
target->GetVertex(fx.collideverts[i], VTX_Y)) == Material("HalfVehicle"))
return FX_OK; return FX_OK;
} }
return FX_Execute_Kill; return FX_Execute_Kill;
// The way this is implemented, it may ignore smaller cracks beteween half-solid masks at high speeds. Fix if necessary. // The way this is implemented, it may ignore smaller cracks beteween half-solid masks at high speeds. Fix if necessary.
} }
global func FxIntHalfVehicleFadeJumpStop(object target, proplist effect, int reason, bool temp) global func FxIntHalfVehicleFadeJumpStop(object target, effect fx, int reason, bool temp)
{ {
if (reason == FX_Call_RemoveClear) if (reason == FX_Call_RemoveClear)
return; return;
for (var i = GetLength(effect.collideverts); i-->0;) for (var i = GetLength(fx.collideverts); i-- > 0;)
target->SetVertexCNAT(effect.collideverts[i], CNAT_PhaseHalfVehicle, false); target->SetVertexCNAT(fx.collideverts[i], CNAT_PhaseHalfVehicle, false);
} }