Added script function GetPlayerZoomLimits (#1071).

issue1247
Sven Eberhardt 2014-05-11 11:10:13 +02:00
parent 893d5e87da
commit 488044f266
4 changed files with 94 additions and 1 deletions

View File

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE funcs
SYSTEM '../../../clonk.dtd'>
<?xml-stylesheet type="text/xsl" href="../../../clonk.xsl"?>
<funcs>
<func>
<title>GetPlayerZoomLimits</title>
<category>Player</category>
<subcat>View</subcat>
<version>5.5 OC</version>
<syntax>
<rtype>proplist</rtype>
<params>
<param>
<type>int</type>
<name>player</name>
<desc>Player whose zoom limits are queried.</desc>
</param>
</params>
</syntax>
<desc>Returns currently set zoom limits for a player. The return value is a proplist with the following properties:
<table>
<rowh>
<col>Property</col>
<col>Description</col>
</rowh>
<row>
<literal_col>MaxWidth</literal_col>
<col>Maximum width of landscpe in viewport, i.e. how far the player can view if zoomed out as far as possible. May be zero if MaxHeight is nonzero and zoom limits are determined by maximum view height only.</col>
</row>
<row>
<literal_col>MaxHeight</literal_col>
<col>Maximum height of landscpe in viewport. May be zero if MaxWidth is nonzero.</col>
</row>
<row>
<literal_col>MinWidth</literal_col>
<col>Minimum width of landscpe in viewport, i.e. how far the player can view if zoomed in as far as possible. May be zero if MinHeight is nonzero and zoom limits are determined by minimunm view height only.</col>
</row>
<row>
<literal_col>MinHeight</literal_col>
<col>Minimum height of landscpe in viewport. May be zero if MinWidth is nonzero.</col>
</row>
<row>
<literal_col>MaxValue</literal_col>
<col>Maximum zoom if set as a direct pixel-to-landscape correspondance value using <funclink>SetPlayerZoom</funclink> function. Zero if a direct zoom value is not specified.</col>
</row>
<row>
<literal_col>MinValue</literal_col>
<col>Minimum zoom if set as a direct pixel-to-landscape correspondance value using <funclink>SetPlayerZoom</funclink> function. Zero if a direct zoom value is not specified.</col>
</row>
</table>
</desc>
<remark>It is currently not possible to query the current zoom because these values are not synchronized.</remark>
<examples>
<example>
<code>func ReduceSight(int player)
{
var zoom_limits = <funclink>GetPlayerZoomLimits</funclink>(player);
SetPlayerZoomByViewRange(player, zoom_limits.MaxWidth/2, zoom_limits.MaxHeight/2, PLRZOOM_LimitMax);
return true;
}
</code>
<text>Halves the view range of a player.</text>
</example>
</examples>
<related>
<funclink>SetPlayerZoomByViewRange</funclink>
<funclink>SetPlayerZoom</funclink>
</related>
</func>
<author>Sven2</author><date>2014-05</date>
</funcs>

View File

@ -80,11 +80,12 @@
</examples>
<related>
<funclink>SetPlayerZoomByViewRange</funclink>
<funclink>GetPlayerZoomLimits</funclink>
<funclink>SetPlayerViewLock</funclink>
<funclink>SetPlrView</funclink>
<funclink>SetPlrViewRange</funclink>
<funclink>SetFoW</funclink>
</related>
</func>
<author>Sven2</author><date>2010-09</date>
<author>Sven2</author><date>2014-03</date>
</funcs>

View File

@ -79,6 +79,7 @@
</examples>
<related>
<funclink>SetPlayerZoom</funclink>
<funclink>GetPlayerZoomLimits</funclink>
<funclink>SetPlayerViewLock</funclink>
<funclink>SetPlrView</funclink>
<funclink>SetPlrViewRange</funclink>

View File

@ -716,6 +716,24 @@ static bool FnSetPlayerZoomByViewRange(C4PropList * _this, long plr_idx, long ra
return true;
}
static C4PropList *FnGetPlayerZoomLimits(C4PropList * _this, long plr_idx)
{
// get player
C4Player *plr = ::Players.Get(plr_idx);
if (!plr) return NULL;
// collect limits in a prop list
// if neither width not height is set for zoom limits, return engine defaults.
C4PropList *result = C4PropList::New();
if (!result) return NULL;
result->SetPropertyByS(::Strings.RegString("MaxWidth"), C4VInt((plr->ZoomLimitMaxWdt || plr->ZoomLimitMaxHgt) ? plr->ZoomLimitMaxWdt : C4VP_DefMaxViewRangeX));
result->SetPropertyByS(::Strings.RegString("MaxHeight"), C4VInt(plr->ZoomLimitMaxHgt));
result->SetPropertyByS(::Strings.RegString("MaxValue"), C4VInt(fixtoi(plr->ZoomLimitMaxVal, 100)));
result->SetPropertyByS(::Strings.RegString("MinWidth"), C4VInt((plr->ZoomLimitMinWdt || plr->ZoomLimitMinHgt) ? plr->ZoomLimitMinWdt : C4VP_DefMinViewRangeX));
result->SetPropertyByS(::Strings.RegString("MinHeight"), C4VInt(plr->ZoomLimitMinHgt));
result->SetPropertyByS(::Strings.RegString("MinValue"), C4VInt(fixtoi(plr->ZoomLimitMinVal, 100)));
return result;
}
static bool FnSetPlayerZoom(C4PropList * _this, long plr_idx, long zoom, long precision, long flags)
{
// parameter safety. 0/0 means "reset to default".
@ -2520,6 +2538,7 @@ void InitGameFunctionMap(C4AulScriptEngine *pEngine)
AddFunc(pEngine, "SetClimate", FnSetClimate);
AddFunc(pEngine, "GetClimate", FnGetClimate);
AddFunc(pEngine, "SetPlayerZoomByViewRange", FnSetPlayerZoomByViewRange);
AddFunc(pEngine, "GetPlayerZoomLimits", FnGetPlayerZoomLimits);
AddFunc(pEngine, "SetPlayerZoom", FnSetPlayerZoom);
AddFunc(pEngine, "SetPlayerViewLock", FnSetPlayerViewLock);
AddFunc(pEngine, "DoBaseMaterial", FnDoBaseMaterial);