Add comment next to all documented functions in System.ocg

Many functions in System.ocg have proper documentation, but not next to
the code. When changing these functions, it is easy to forget updating
the docs. Nobody likes outdated documentation!
install-platforms
Lukas Werling 2017-10-21 00:10:42 +02:00
parent 6605d390a9
commit afa348ab21
22 changed files with 107 additions and 3 deletions

View File

@ -30,6 +30,7 @@ static const Action =
Procedure = DFA_NONE,
};
// documented in /docs/sdk/script/fn
global func GameCall(string fn, ...)
{
if (!fn)

View File

@ -10,15 +10,19 @@ static const RGBA_RED = 1;
static const RGBA_GREEN = 2;
static const RGBA_BLUE = 3;
// documented in /docs/sdk/script/fn
global func HSL(int h, int s, int l) { return HSL2RGB(RGB(h, s, l)); }
global func HSLa(int h, int s, int l, int a) { return HSL2RGB(RGB(h, s, l)) ^ ~(a & 255) << 24; }
// documented in /docs/sdk/script/fn
global func RGB(int r, int g, int b) { return (255 << 24) | (r & 255) << 16 | (g & 255) << 8 | (b & 255); }
global func RGBa (int r, int g, int b, int a) { return (a & 255) << 24 | (r & 255) << 16 | (g & 255) << 8 | (b & 255); }
// documented in /docs/sdk/script/fn
global func GetRGBaValue(int val, int sel) { return val >> ((3 - sel) * 8) & 255; }
global func DoRGBaValue(int val, int chng, int sel) { return val + (chng << ((3 - sel) * 8)); }
// documented in /docs/sdk/script/fn
global func SetRGBaValue(int val, int newval, int sel)
{
// 'delete' old color
@ -27,6 +31,7 @@ global func SetRGBaValue(int val, int newval, int sel)
return val | newval << ((3 - sel) * 8);
}
// documented in /docs/sdk/script/fn
global func SplitRGBaValue(int rgb)
{
return {
@ -37,6 +42,7 @@ global func SplitRGBaValue(int rgb)
};
}
// documented in /docs/sdk/script/fn
global func HSL2RGB(int hsl)
{
var hue = GetRGBaValue(hsl, 1), sat = GetRGBaValue(hsl, 2), lightness = GetRGBaValue(hsl, 3);
@ -79,6 +85,7 @@ global func Hue_2_RGB(int var1, int var2, int hue)
return var1;
}
// documented in /docs/sdk/script/fn
global func RGB2HSL(int rgb)
{
var red = GetRGBaValue(rgb, RGBA_RED), green = GetRGBaValue(rgb, RGBA_GREEN), blue = GetRGBaValue(rgb, RGBA_BLUE);

View File

@ -13,6 +13,7 @@
// Sets the component of an object or definition.
// documented in /docs/sdk/script/fn
global func SetComponent(id component, int count)
{
// Safety: can only be called from object.
@ -40,6 +41,7 @@ global func SetComponent(id component, int count)
// Returns the amount if the component parameter is specified. If the component parameter is nil
// it returns the definition of the component for the given index.
// documented in /docs/sdk/script/fn
global func GetComponent(id component, int index)
{
// Safety: can only be called from object or definition context.
@ -97,6 +99,7 @@ global func OnCompletionChange(int old_con, int new_con)
}
// Splits the calling object into its components.
// documented in /docs/sdk/script/fn
global func Split2Components()
{
// Safety: can only be called from object context.

View File

@ -7,6 +7,7 @@
// 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.
// documented in /docs/sdk/script/fn
global func PlaceObjects(id id, int amount, string mat_str, int x, int y, int wdt, int hgt, bool onsf, bool nostuck)
{
var i, j;
@ -86,6 +87,7 @@ global func PlaceObjects(id id, int amount, string mat_str, int x, int y, int wd
return j;
}
// documented in /docs/sdk/script/fn
global func CastObjects(id def, int am, int lev, int x, int y, int angs, int angw)
{
var objects = [];
@ -111,6 +113,7 @@ global func CastObjects(id def, int am, int lev, int x, int y, int angs, int ang
return objects;
}
// documented in /docs/sdk/script/fn
global func CastPXS(string mat, int am, int lev, int x, int y, int angs, int angw)
{
if (!angw)
@ -123,6 +126,7 @@ global func CastPXS(string mat, int am, int lev, int x, int y, int angs, int ang
return;
}
// documented in /docs/sdk/script/fn
global func DrawParticleLine(string particle, int x0, int y0, int x1, int y1, int prtdist, xdir, ydir, lifetime, proplist properties)
{
// Right parameters?

View File

@ -9,6 +9,7 @@ static GetDefinition_Loaded_Definition_List;
// Returns the definition or nil if par is a string and the definition exists.
// See the documentation for the case when par is an integer.
// documented in /docs/sdk/script/fn
global func GetDefinition(par)
{
// Overload behavior when par is a string.
@ -26,4 +27,4 @@ global func GetDefinition(par)
return GetDefinition_Loaded_Definition_List[par];
}
return _inherited(par, ...);
}
}

View File

@ -111,6 +111,7 @@ global func ExplosionParticles_Init()
/*-- Explosion --*/
// documented in /docs/sdk/script/fn
global func Explode(int level, bool silent, int damage_level)
{
if(!this) FatalError("Function Explode must be called from object context");
@ -194,6 +195,7 @@ global func ExplosionEffect(...)
/*-- Blast objects & shockwaves --*/
// Damage and hurl objects away.
// documented in /docs/sdk/script/fn
global func BlastObjects(int x, int y, int level, object container, int cause_plr, int damage_level, object layer, object prev_container)
{
var obj;
@ -269,6 +271,7 @@ global func BlastObject(int level, int caused_by)
return;
}
// documented in /docs/sdk/script/fn
global func DoShockwave(int x, int y, int level, int cause_plr, object layer, int off_x, int off_y)
{
// Zero-size shockwave
@ -370,6 +373,7 @@ strength falls off linearly by distance from 100% to 0% when the player is 700 p
@param y_off y offset in relative coordinates from the calling object
@param range range of clonk to explosion at which shaking falls off to 0%
*/
// documented in /docs/sdk/script/fn
global func ShakeViewport(int level, int x_off, int y_off, range)
{
if (level <= 0)

View File

@ -8,11 +8,13 @@
/*-- Find functions --*/
// documented in /docs/sdk/script/fn
global func Find_Not(cond)
{
return [C4FO_Not, cond];
}
// documented in /docs/sdk/script/fn
global func Find_And(...)
{
var result = [C4FO_And];
@ -21,6 +23,7 @@ global func Find_And(...)
return result;
}
// documented in /docs/sdk/script/fn
global func Find_Or(...)
{
var result = [C4FO_Or];
@ -29,6 +32,7 @@ global func Find_Or(...)
return result;
}
// documented in /docs/sdk/script/fn
global func Find_Exclude(object obj)
{
if (!obj)
@ -38,16 +42,19 @@ global func Find_Exclude(object obj)
return [C4FO_Exclude, obj];
}
// documented in /docs/sdk/script/fn
global func Find_ID(id def)
{
return [C4FO_ID, def];
}
// documented in /docs/sdk/script/fn
global func Find_InRect(int x, int y, int wdt, int hgt)
{
return [C4FO_InRect, x, y, wdt, hgt];
}
// documented in /docs/sdk/script/fn
global func Find_AtPoint(int x, int y)
{
return [C4FO_AtPoint, x, y];
@ -58,16 +65,19 @@ global func Find_AtRect(int x, int y, int wdt, int hgt)
return [C4FO_AtRect, x, y, wdt, hgt];
}
// documented in /docs/sdk/script/fn
global func Find_OnLine(int x, int y, int x2, int y2)
{
return [C4FO_OnLine, x, y, x2, y2];
}
// documented in /docs/sdk/script/fn
global func Find_Distance(int r, int x, int y)
{
return [C4FO_Distance, x, y, r];
}
// documented in /docs/sdk/script/fn
global func Find_Cone(int r, int cone_angle, int cone_width, int x, int y, int prec_angle)
{
if (!prec_angle)
@ -75,31 +85,37 @@ global func Find_Cone(int r, int cone_angle, int cone_width, int x, int y, int p
return [C4FO_Cone, x, y, r, cone_angle, cone_width, prec_angle];
}
// documented in /docs/sdk/script/fn
global func Find_OCF(int ocf)
{
return [C4FO_OCF, ocf];
}
// documented in /docs/sdk/script/fn
global func Find_Category(int category)
{
return [C4FO_Category, category];
}
// documented in /docs/sdk/script/fn
global func Find_Action(string action)
{
return [C4FO_Action, action];
}
// documented in /docs/sdk/script/fn
global func Find_ActionTarget(object target)
{
return [C4FO_ActionTarget, target, 0];
}
// documented in /docs/sdk/script/fn
global func Find_ActionTarget2(object target)
{
return [C4FO_ActionTarget, target, 1];
}
// documented in /docs/sdk/script/fn
global func Find_ActionTargets(object target)
{
return [C4FO_Or, Find_ActionTarget(target), Find_ActionTarget2(target)];
@ -110,21 +126,25 @@ global func Find_Procedure(string procedure)
return [C4FO_Procedure, procedure];
}
// documented in /docs/sdk/script/fn
global func Find_Container(object container)
{
return [C4FO_Container, container];
}
// documented in /docs/sdk/script/fn
global func Find_NoContainer()
{
return [C4FO_Container, nil];
}
// documented in /docs/sdk/script/fn
global func Find_AnyContainer()
{
return [C4FO_AnyContainer];
}
// documented in /docs/sdk/script/fn
global func Find_Owner(int owner)
{
return [C4FO_Owner, owner];
@ -135,6 +155,7 @@ global func Find_Controller(int controller)
return [C4FO_Controller, controller];
}
// documented in /docs/sdk/script/fn
global func Find_Hostile(int plr)
{
var p = [C4FO_Or];
@ -154,6 +175,7 @@ global func Find_AnimalHostile(int plr)
return Find_Or(Find_Owner(NO_OWNER), Find_Hostile(plr));
}
// documented in /docs/sdk/script/fn
global func Find_Allied(int plr)
{
var p = [C4FO_Or];
@ -163,6 +185,7 @@ global func Find_Allied(int plr)
return p;
}
// documented in /docs/sdk/script/fn
global func Find_Team(int team)
{
var p = [C4FO_Or];
@ -172,26 +195,31 @@ global func Find_Team(int team)
return p;
}
// documented in /docs/sdk/script/fn
global func Find_Func(string f, p1, p2, p3, p4, p5, p6, p7, p8, p9)
{
return [C4FO_Func, f, p1, p2, p3, p4, p5, p6, p7, p8, p9];
}
// documented in /docs/sdk/script/fn
global func Find_Layer(object layer)
{
return [C4FO_Layer, layer];
}
// documented in /docs/sdk/script/fn
global func Find_InArray(array a)
{
return [C4FO_InArray, a];
}
// documented in /docs/sdk/script/fn
global func Find_Property(string s)
{
return [C4FO_Property, s];
}
// documented in /docs/sdk/script/fn
global func Find_AnyLayer()
{
return [C4FO_AnyLayer];
@ -211,11 +239,13 @@ global func Find_PathFreeCheck(object to_obj)
/*-- Sort functions --*/
// documented in /docs/sdk/script/fn
global func Sort_Reverse(array sort)
{
return [C4SO_Reverse, sort];
}
// documented in /docs/sdk/script/fn
global func Sort_Multiple(...)
{
var result = [C4SO_Multiple];
@ -224,31 +254,37 @@ global func Sort_Multiple(...)
return result;
}
// documented in /docs/sdk/script/fn
global func Sort_Distance(int x, int y)
{
return [C4SO_Distance, x, y];
}
// documented in /docs/sdk/script/fn
global func Sort_Random()
{
return [C4SO_Random];
}
// documented in /docs/sdk/script/fn
global func Sort_Speed()
{
return [C4SO_Speed];
}
// documented in /docs/sdk/script/fn
global func Sort_Mass()
{
return [C4SO_Mass];
}
// documented in /docs/sdk/script/fn
global func Sort_Value()
{
return [C4SO_Value];
}
// documented in /docs/sdk/script/fn
global func Sort_Func(string f, p1, p2, p3, p4, p5, p6, p7, p8, p9)
{
return [C4SO_Func, f, p1, p2, p3, p4, p5, p6, p7, p8, p9];

View File

@ -16,6 +16,7 @@ static const C4Fx_FireMode_Last = 3; // largest valid fire mode
// Returns whether the object is burning.
// documented in /docs/sdk/script/fn
global func OnFire()
{
if (!this)
@ -27,6 +28,7 @@ global func OnFire()
}
// Extinguishes the calling object with specified strength.
// documented in /docs/sdk/script/fn
global func Extinguish(strength /* strength between 0 and 100 */)
{
if (!this)
@ -46,6 +48,7 @@ global func Extinguish(strength /* strength between 0 and 100 */)
}
// Incinerates the calling object with specified strength.
// documented in /docs/sdk/script/fn
global func Incinerate(
strength /* strength between 0 and 100 */
, int caused_by /* the player that caused the incineration */

View File

@ -60,11 +60,13 @@ static const GUI_GridCellLayout = new Global {
/* -- menu functions -- */
// documented in /docs/sdk/script/fn
global func GuiAction_Call(proplist target, string function, value)
{
return [GUI_Call, target, function, value];
}
// documented in /docs/sdk/script/fn
global func GuiAction_SetTag(string tag, int subwindow, object target)
{
return [GUI_SetTag, tag, subwindow, target];

View File

@ -10,6 +10,7 @@
@author
*/
// documented in /docs/sdk/script/fn
global func GetActMapVal(string entry, string action, id def, int num)
{
if (!def)

View File

@ -6,6 +6,7 @@
*/
// overload function for objects with Inventory.ocd
// documented in /docs/sdk/script/fn
global func ShiftContents(bool shift_back, id target_id)
{
if (this && (this.HandObjects > 0))
@ -46,4 +47,4 @@ global func ShiftContents(bool shift_back, id target_id)
return false;
}
return _inherited(shift_back, target_id, ...);
}
}

View File

@ -56,6 +56,7 @@ global func FindPosInMat(string sMat, int iXStart, int iYStart, int iWidth, int
@param y Y coordinate
@param distant_first If true, extraction position takes largest horizontal distance from given offset at same height to a maximum value of MaxSlide. Useful to ensure that no floor of 1px of liquid remains.
@return The material index of the removed pixel, or -1 if no liquid was found. */
// documented in /docs/sdk/script/fn
global func ExtractLiquid(int x, int y, bool distant_first)
{
var result = ExtractLiquidAmount(x, y, 1, distant_first);
@ -123,4 +124,4 @@ global func DrawMaterialTriangle(string mat_tex, int cx, int cy, int dir, int ed
sub
);
return;
}
}

View File

@ -6,18 +6,21 @@
*/
// Returns the offset to x.
// documented in /docs/sdk/script/fn
global func AbsX(int x)
{
return x - GetX();
}
// Returns the offset to y.
// documented in /docs/sdk/script/fn
global func AbsY(int y)
{
return y - GetY();
}
// Supports negative values, and can deliver random values between two bounds.
// documented in /docs/sdk/script/fn
global func RandomX(int start, int end)
{
var swap;
@ -39,6 +42,7 @@ global func Sign(int x)
}
// Tangens.
// documented in /docs/sdk/script/fn
global func Tan(int angle, int radius, int prec)
{
return radius * Sin(angle, radius * 100, prec) / Cos(angle, radius * 100, prec);
@ -98,6 +102,7 @@ global func GetTurnDirection(
return dir;
}
// documented in /docs/sdk/script/fn
global func SetBit(int old_val, int bit_nr, bool bit)
{
if (GetBit(old_val, bit_nr) != (bit != 0))
@ -105,11 +110,13 @@ global func SetBit(int old_val, int bit_nr, bool bit)
return old_val;
}
// documented in /docs/sdk/script/fn
global func GetBit(int value, int bit_nr)
{
return (value & (1 << bit_nr)) != 0;
}
// documented in /docs/sdk/script/fn
global func ToggleBit(int old_val, int bit_nr)
{
return old_val ^ (1 << bit_nr);

View File

@ -5,46 +5,55 @@
@author ck
*/
// documented in /docs/sdk/script/fn
global func Anim_Const(int value)
{
return [C4AVP_Const, value];
}
// documented in /docs/sdk/script/fn
global func Anim_Linear(int position, int begin, int end, int length, int ending)
{
return [C4AVP_Linear, position, begin, end, length, ending];
}
// documented in /docs/sdk/script/fn
global func Anim_X(int position, int begin, int end, int length)
{
return [C4AVP_X, position, begin, end, length];
}
// documented in /docs/sdk/script/fn
global func Anim_Y(int position, int begin, int end, int length)
{
return [C4AVP_Y, position, begin, end, length];
}
// documented in /docs/sdk/script/fn
global func Anim_R(int begin, int end)
{
return [C4AVP_R, begin, end, this];
}
// documented in /docs/sdk/script/fn
global func Anim_AbsX(int position, int begin, int end, int length)
{
return [C4AVP_AbsX, position, begin, end, length];
}
// documented in /docs/sdk/script/fn
global func Anim_AbsY(int position, int begin, int end, int length)
{
return [C4AVP_AbsY, position, begin, end, length];
}
// documented in /docs/sdk/script/fn
global func Anim_Dist(int position, int begin, int end, int length)
{
return [C4AVP_Dist, position, begin, end, length];
}
// documented in /docs/sdk/script/fn
global func Anim_XDir(int begin, int end, int max_xdir, int prec)
{
if (prec == nil)
@ -52,6 +61,7 @@ global func Anim_XDir(int begin, int end, int max_xdir, int prec)
return [C4AVP_XDir, begin, end, max_xdir, prec];
}
// documented in /docs/sdk/script/fn
global func Anim_YDir(int begin, int end, int max_ydir, int prec)
{
if (prec == nil)
@ -101,6 +111,7 @@ global func Anim_SinV(int begin, int end, int offset, int prec)
return [C4AVP_SinV, begin, end, offset, prec];
}
// documented in /docs/sdk/script/fn
global func Anim_Action()
{
return [C4AVP_Action];

View File

@ -5,6 +5,7 @@
@author Marky
*/
// documented in /docs/sdk/script/fn
global func Sound(string name, opts, ...)
{
if (GetType(opts) == C4V_PropList)
@ -12,6 +13,7 @@ global func Sound(string name, opts, ...)
return inherited(name, opts, ...);
}
// documented in /docs/sdk/script/fn
global func SoundAt(string name, int x, int y, opts, ...)
{
if (GetType(opts) == C4V_PropList)

View File

@ -6,6 +6,7 @@
*/
// Does not set the speed of an object. But you can set two components of the velocity vector with this function.
// documented in /docs/sdk/script/fn
global func SetSpeed(int x_dir, int y_dir, int prec)
{
SetXDir(x_dir, prec);
@ -65,6 +66,7 @@ global func AddVelocity(int angle, int speed, int precision_angle, int precision
// Sets the completion of this to new_con.
// documented in /docs/sdk/script/fn
global func SetCon(int new_con, int precision, bool grow_from_center)
{
return DoCon(new_con - GetCon(), precision, grow_from_center);
@ -351,6 +353,7 @@ global func StonyObjectHit(int x, int y)
}
// Removes all objects of the given type.
// documented in /docs/sdk/script/fn
global func RemoveAll(p, ...)
{
var cnt;
@ -399,6 +402,7 @@ global func RootSurface(int max_movement)
}
// Buys an object. Returns the object if it could be bought.
// documented in /docs/sdk/script/fn
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
@ -411,6 +415,7 @@ global func Buy(id buy_def, int for_plr, int pay_plr, object from_vendor, bool s
}
// Sells an object. Returns true if it could be sold.
// documented in /docs/sdk/script/fn
global func Sell(int plr, object obj, object to_vendor)
{
// if no vendor is given try this

View File

@ -18,6 +18,7 @@ global func CreateMuzzleFlash(int x, int y, int angle, int size)
CreateParticle("StarFlash", x, y, PV_Random(xdir - size, xdir + size), PV_Random(ydir - size, ydir + size), PV_Random(20, 60), Particles_Glimmer(), size);
}
// documented in /docs/sdk/script/fn
global func Smoke(int x, int y, int level, int color, bool heavy)
{
level = level ?? 10;
@ -151,6 +152,7 @@ global func Particles_Spark()
};
}
// documented in /docs/sdk/script/fn
global func Particles_Colored(prototype, color, color2)
{
// Colors the given particle. If color2 is given, colors in a random fade between color and color2

View File

@ -6,6 +6,7 @@
*/
// Returns the player number of plr_name, or none if there is no such player. (written by timi for CR/CE/CP)
// documented in /docs/sdk/script/fn
global func GetPlayerByName(string plr_name)
{
// Loop through all players.
@ -34,6 +35,7 @@ global func GetTeamByName(string team_name)
}
// Returns the name of a player, including color markup using the player color.
// documented in /docs/sdk/script/fn
global func GetTaggedPlayerName(int plr)
{
var plr_name = GetPlayerName(plr);
@ -115,6 +117,7 @@ global func GetPlayerByID(int plr_id)
}
// Adds value to the account of iPlayer.
// documented in /docs/sdk/script/fn
global func DoWealth(int plr, int value)
{
return SetWealth(plr, value + GetWealth(plr));
@ -152,6 +155,7 @@ global func GetDefaultMenuDecoration()
}
// Find a base of the given player. Use index to search through all bases.
// documented in /docs/sdk/script/fn
global func FindBase(int plr, int index)
{
return FindObjects(Find_Owner(plr), Find_Func("IsBase"))[index];

View File

@ -13,6 +13,7 @@ static g_player_cursor_pos; // array of [x,y] pos arrays; indexed by player. las
// Called by engine whenever a control is issued
// Forwards control to special handler or cursor
// Return whether handled
// documented in /docs/sdk/script/fn
global func PlayerControl(int plr, int ctrl, id spec_id, int x, int y, int strength, bool repeat, int status)
{
var release = status == CONS_Up;

View File

@ -330,6 +330,7 @@ global func AddScenarioSaveDependency()
if (save_scenario_obj_dependencies && GetIndexOf(save_scenario_obj_dependencies, this)<0) save_scenario_obj_dependencies[GetLength(save_scenario_obj_dependencies)] = this;
}
// documented in /docs/sdk/script/fn
global func MakeScenarioSaveName()
{
// Get name to be used to store this object in a scenario
@ -492,6 +493,7 @@ global func SaveScenarioObject(props)
return true;
}
// documented in /docs/sdk/script/fn
global func SaveScenarioObjectAction(props)
{
// Helper function to store action properties

View File

@ -6,6 +6,7 @@
*/
// Executes a script repetitively with delay.
// documented in /docs/sdk/script/fn
global func Schedule(object obj, string script, int interval, int repeats)
{
// Defaults.
@ -69,6 +70,7 @@ global func RemoveTimer(call_function /* name or pointer to the timer to remove
}
// Executes a function repetitively with delay.
// documented in /docs/sdk/script/fn
global func ScheduleCall(object obj, call_function, int interval, int repeats, par0, par1, par2, par3, par4)
{
// Defaults.
@ -97,6 +99,7 @@ global func FxIntScheduleCallTimer(object obj, effect fx)
return FX_OK;
}
// documented in /docs/sdk/script/fn
global func ClearScheduleCall(object obj, call_function)
{
var i, fx;

View File

@ -6,6 +6,7 @@
*/
// Sets both the X and Y-coordinate of one vertex.
// documented in /docs/sdk/script/fn
global func SetVertexXY(int index, int x, int y)
{
// Set vertices.
@ -15,6 +16,7 @@ global func SetVertexXY(int index, int x, int y)
}
// Returns the number of stuck vertices. (of this)
// documented in /docs/sdk/script/fn
global func VerticesStuck()
{
var vertices = 0;
@ -28,6 +30,7 @@ global func VerticesStuck()
}
// Automatically move an object up to <range> pixels in each direction if it is stuck
// documented in /docs/sdk/script/fn
global func Unstick(int range)
{
if (Stuck())