Jump to content
Sign in to follow this  
Rydygier

How to obtain via script map's true center position (or map's size values)?

Recommended Posts

Tried this:

getArray (configFile >> "CfgWorlds" >> worldName >> "centerPosition"

But for uknown to me reason on some maps this point isn't true center point. On Chernaruss map it is, but on Takistan or Duala - isn't...

I found only this here:

http://forums.bistudio.com/showthread.php?138863-Grab-list-of-all-buildings-on-the-map&p=2210361&highlight=Map+center+position#post2210361

But surface type check seems to be not universal method - each map has other, and some probably haven't this special "dynamic outside terrain" (?). Tried also to find any helpful entry in map's config - no luck.

Share this post


Link to post
Share on other sites

Not exact, but best workaround, that I found till now, based on objects presence:

_xPr = 0;
_yPr = 0;

_ObjCount = 1;

while {(_ObjCount < 2)} do
{
_xPr = _xPr + 500;
_yPr = _yPr + 500;
_ObjCount = count (nearestObjects [[_xPr,_yPr], [], 500]);
};

while {(_ObjCount > 1)} do
{
_xPr = _xPr + 500;
_yPr = _yPr + 500;
_ObjCount = count (nearestObjects [[_xPr,_yPr], [], 500]);
};

_cntr = [_xPr/2,_yPr/2,0];

This takes some seconds (on Chernaruss about 3 with weak CPU), but neaerstObjects can't be replaced with eg nearObjects, as seems, that only first command can see objects without class. Sea is the problem, as it is object-less too. So first loop brings us at first spotted shore. After that, check without objects found means end of the map. Exactly - end of the land. This is sufficient to me, as only land concern my work. Theoretically this can fail though - if after first land on the diagonal is present another wide enough sea area before next land, code will consider this as end of map. Anyway, if there will be not any better solution - I'll use this code.

Edited by Rydygier

Share this post


Link to post
Share on other sites

CenterPosition is not the map's center. It's the default position of the cursor/view in the editor when you load up the map.

Share this post


Link to post
Share on other sites

Wrote an FSM awhle back that would determine the dimensions of a map for determing GPS zoom levels for a GPS script. Found this out on accident due to a typo lol.

Break the maps down into its min and max world positions (all of which are positive).

Bottom Left corner is [0,0,0];

Heres where I lucked out:

_map_cntrl ctrlMapAnimAdd [0, 1000, [9999999999, 9999999999]];

waitUntil {ctrlMapAnimDone _map_cntrl};

_zoom_max = ctrlMapScale _map_cntrl;

_limit = _map_cntrl ctrlMapScreenToWorld [0.5, 0.5];

_x_max = _limit select 0;

_y_max = _limit select 1;

Doing this Forces the map to center over the farthest upper right extreme of the map (the upper Right Corner). and using the above the code you can get the extreme upper right coordinates of the map. The rest is easy.

//These valuse will give you maps mins and maxes for determing map size.

_top_right = [_x_max,_y_max,0];

_top_left = [0,_y_max,1];

_btm_left = [0,0,0];

_btm_right = [_x_max,0,0];

_map_center = [0.5*(_limit select 0),0.5*(_limit select 1)];

Presto! you have your center!

Note: I added this as a fallback for user made maps. I recomend adding a copy function and preloading the centers of known maps, then adding more as go. The above code will require forcing the player map open, which should only be used as a fallback. The following are centers I have already defined. Have at em.

_MapConfigured = true;

switch (WorldName) do {

case "Takistan": {

JTK_HALO_Min_GPS_Zoom = 0.065;

JTK_MapCenter = [6400,6400];

};

case "Chernarus": {

JTK_HALO_Min_GPS_Zoom = 0.05;

JTK_MapCenter = [7680,7680];

};

case "utes": {

JTK_HALO_Min_GPS_Zoom = 0.05;

JTK_MapCenter = [2560,2560];

};

case "ProvingGrounds_PMC": {

JTK_HALO_Min_GPS_Zoom = 0.25;

JTK_MapCenter = [1024,1024];

};

case "Shapur_BAF": {

JTK_HALO_Min_GPS_Zoom = 0.25;

JTK_MapCenter = [1024,1024];

};

case "Zargabad": {

JTK_HALO_Min_GPS_Zoom = 0.085;

JTK_MapCenter = [4096,4096];

};

case "Desert_E": {

JTK_HALO_Min_GPS_Zoom = 0.25;

JTK_MapCenter = [1024,1024];

};

default {

JTK_HALO_Min_GPS_Zoom = nil;

JTK_MapCenter = nil;

_MapConfigured = false;

};

};

Edited by Kempco

Share this post


Link to post
Share on other sites

nice one Kempco :bounce3:

So far I put a gamelogic in the bottom left and top right area that still covers land (not map - can be done too, if you want all water areas included too).

Share this post


Link to post
Share on other sites

Thanks a lot. Very interesting, I'll study this, however opening the map is hard to accept in this case... For my purposes (BB from HAC) thought about that logic method, where user, as part of his mission set up will place a center logic at a position, which should be considered by HAC as map center.

Share this post


Link to post
Share on other sites

Rydygier his approach may even work on the server. At least with scripting you can automate every step of it.

Share this post


Link to post
Share on other sites

So, I think, as usual, when in doubt, will make it optional, so this will become user's doubt :). Manually placed center in BB may be useful for people, that want to set up only part of map for BB's calculations. Automated will be default, but I must still to learn more about all this controls stuff, as barely started with that a few days ago. For example do not know yet, how to get value for _map_cntrl variable.

Share this post


Link to post
Share on other sites

Converted the code I used to sqf. Copy and Paste and save as "WHATEVER.sqf". The execute via [player,true] execVM "WHATEVER.sqf"; Set the True to false to disable markers.

_unit = _this select 0;

_debug = _this select 1;

private ["_grid_size"];

disableserialization;

openMap [true, false];

WaitUntil {visibleMap};

_Map_display = findDisplay 12;

_map_cntrl = _Map_display displayCtrl 51;

// Temporarily zoom out as much as possible and measure the screen.

_map_cntrl ctrlMapAnimAdd [0, 1000, [9999999999, 9999999999]];

ctrlMapAnimCommit _map_cntrl;

waitUntil {ctrlMapAnimDone _map_cntrl};

_zoom_max = ctrlMapScale _map_cntrl;

_limit = _map_cntrl ctrlMapScreenToWorld [0.5, 0.5];

_x_max = _limit select 0;

_y_max = _limit select 1;

_top_right = [_x_max,_y_max,0];

_top_left = [0,_y_max,1];

_btm_left = [0,0,0];

_btm_right = [_x_max,0,0];

_map_center = [0.5*(_limit select 0),0.5*(_limit select 1)];

_cfg=configFile>>"CfgWorlds">>worldName>>"Grid";

_grid_size_y =getNumber(_cfg>>"Zoom1">>"stepX");

_grid_size_x =getNumber(_cfg>>"Zoom1">>"stepY");

_grid_size = abs(_grid_size_y);

if (_grid_size_y < 100) then {

_grid_size = abs(_grid_size_y*_grid_size_x);

}else{_grid_size = abs(_grid_size_y)};

_w = _top_right distance _top_left;

_h = _top_right distance _btm_right;

_map_width = _limit select 0;

_map_height = _limit select 1;

_Map_Area_Grids = (_map_width/_grid_size)*(_map_height/_grid_size);

_Map_Area_km = (_map_width/1000)*(_map_height/1000);

if (_debug) then {

_m = createmarker ["MapSize",_map_center];

_m setmarkerShape "RECTANGLE";

_m setmarkerSize [_map_width /2,_map_height/2];

_m setmarkerAlpha 0.15;

_m setmarkercolor "ColorRed";

_m = createmarker ["MapWNote",[-150,(_map_center select 0)]];

_m setmarkerText format["Delta X: %1 km",(_x_max/1000)];

_m setmarkersize [0,0];

_m setmarkerType "Dot";

_m setmarkercolor "Colorblack";

_m = createmarker ["MapLNote",[(_map_center select 1),-150]];

_m setmarkerText format ["Delta Y: %1 km",(_y_max/1000)];

_m setmarkersize [0,0];

_m setmarkerType "Dot";

_m setmarkercolor "Colorblack";

_m = createmarker ["MapSizeNote",_map_center];

_m setmarkerText format ["(Map Size: %1 sq km)",_Map_Area_km];

_m setmarkersize [0,0];

_m setmarkerType "Dot";

_m setmarkercolor "Colorblack";

};

_mapsize = _Map_Area_km;

WaitUntil {!isNil "_mapsize"};

_Size_stndrd = 235.93;

_zoom_stndrd = 0.05;

private ["_zoom","_mltplr"];

_add = true;

_percnt = (_mapsize/_Size_stndrd);

if (_percnt > 1) then {_percnt = _percnt mod 1;_add = false};

_percntof = 1 - (_percnt);

_zoom_dif = _percntof*_zoom_stndrd;

if !(_add) then {

_zoom = _zoom_stndrd - _zoom_dif;

}else{

_zoom = _zoom_dif + _zoom_stndrd;

};

if (_zoom > 0.095) then {

_zoom = 0.25

}else{

if (_zoom == 0) then {

_zoom = _zoom + _zoom_stndrd

}else{

if (_zoom < 0) then {_zoom = 0};

};

};

JTK_HALO_Min_GPS_Zoom = _zoom;

JTK_MapCenter = _map_center;

openMap [false, false];

Edited by Kempco

Share this post


Link to post
Share on other sites

Thanks a lot!

_Map_display = findDisplay 12;

_map_cntrl = _Map_display displayCtrl 51;

Ah, yes, that was a big uknown. Great.

Share this post


Link to post
Share on other sites

Yea, sorry about that. Keep in mind that if you if decide to go that route it requires the unit has a map. Think I ran a check and added one if the unit didnt have one, saved the condtion to the unit then removed it if one was added once the values I needed were defined.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×