bb
General
Blitzkrieg junkie (tried to quit several times).
Posts: 1,363
|
Post by bb on May 18, 2017 13:01:53 GMT 1
bb , could you be a bit more specific or could you give an example of what you would like to now more about ? My idea was to start from scratch, so no prior knowledge of scripting or programming required but if you have specific questions then I'm happy to answer (if I can) Well, I think would be nice start from the begining, explaining the basic mechanics of the script, the diference between the variables, arrays and simple commands in the script and also simple questions like how to repeat a script several times or how to combine different commands in one single line and so on.
|
|
|
Post by Quintaxel on May 18, 2017 13:34:03 GMT 1
Okay, I will see what I can come with. Now if I start from the basics then people can judge if there's something interesting for them or not.
|
|
|
Post by Quintaxel on May 23, 2017 21:23:20 GMT 1
I was just thinking of a script to calculate how much terrain of a map is occupied by Player units or AI units and how much terrain is neutral. The idea is to check the size of the map and then let divide the map into zones. (see image below) Next the script can check the number of units in that zone for each party. In this way a zone can be counted as belonging to the AI, the player or be neutral. The terrain that is occupied could be used as a win loose condition. In the example below 2 zones would be occupied by the AI (red) and 3 by the Player. 11 zones are neutral. The purpose of the images is just to explain the principle. The actual function should a be a bit more refined. Looks like fun to script this.
|
|
|
Post by Stanenberg on May 23, 2017 22:08:17 GMT 1
Would this work in a multiplayer map?
|
|
|
Post by Quintaxel on May 23, 2017 22:49:54 GMT 1
I have no experience with multi-player maps but I guess it would. I'll do scripting to see if the concept works for single maps. If this works then I could look at multi-player maps.
|
|
Grot
General
J-23 znowu nadaje
Posts: 4,049
|
Post by Grot on May 23, 2017 23:13:37 GMT 1
looking at the diagram it became clear to me who is behind engineering the Black Goo.. your avatar is the proof !
|
|
BigJoe
General-major
Posts: 538
|
Post by BigJoe on May 23, 2017 23:14:58 GMT 1
Yes, it will work.
The only thing we have to take into account for multiplayer games is that players of a game, all have the same files: Lua, maps.bzm or xml.
Also keep in mind, that the units or models used by all players of the same game, that all xml files are identical, a comma or a point, will cause the game to break. And the game will fail.
|
|
|
Post by Quintaxel on May 24, 2017 6:43:51 GMT 1
Yes, it will work. The only thing we have to take into account for multiplayer games is that players of a game, all have the same files: Lua, maps.bzm or xml. Also keep in mind, that the units or models used by all players of the same game, that all xml files are identical, a comma or a point, will cause the game to break. And the game will fail. If there's a Lua file linked to the map then it should not matter. The idea is quite simple and does not require xml files. Imagine that you print a map. Then you draw circles on it like in the image i posted. The area covered by the circle we call a zone. (The circles should overlap to cover as much of the map as possible.) Next you start counting the number of units of each party within each circle. If there are ; a) no units in a circle (zone) then that zone is neutral. b) only units of one party in a zone (eg. party 0) then that zone belongs to that party. c) units belonging to different parties in a zone then that zone is 'disputed' If you then count the number of zones belonging to each party you can calculate how much zones (terrain) each party occupies. It's as simple as that. I practically written the script I'm thinking of creating a function for this so mappers would not have to worry about the script itself. something like;
GetPartyMapOccupation (IParty, resolution, accuracy) (finding a good name for a function is not always easy)where; Iparty = player party ( 0,1,2,3,...) Resolution = how many zones (circles) accuracy = how much overlapping of the circles
|
|
|
Post by Quintaxel on May 24, 2017 14:59:06 GMT 1
I was also thinking about using squares however dropped the idea because it would complicate things a lot. There's no BK function to calculate the number of units within a square, but finding out the number of units within a circle is easy. So even if I could find a way to count the number of units within a square then it would require more calculation power. Doing calculations in Lua is not the best option as Lua is a slower than the BK function written in C+.
If all units would be have a ScriptID than I could not only use square zones but also return the type of unit within that square. I tried this is the past but it requires a lot of work to give each unit a unique SciptID.
|
|
kaoz
General
inter faesces et urinam nascimur
Posts: 1,112
|
Post by kaoz on May 24, 2017 19:24:54 GMT 1
You would need a new game engine to understand your new lua function, no?
I'm not sure if i understand you correctly but >> GetNUnitsInArea where area = square zone.
Counting will be tricky, because a squad is sometimes counted as 1 for the whole squad and sometimes as seperate soldiers.
|
|
|
Post by Quintaxel on May 24, 2017 20:43:26 GMT 1
kaoz This script should work with the current BK engine, with it's limitations of course. The use of GetNUnitsInArea would require to put the script areas on the map itself. I want to avoid this by using a script. Counting is indeed tricky but the idea is not to count exactly how many units there are in a zone (circle) but to what party they belong. So if a zone only contains units belonging to party O then this zone is counted as belonging to party 0, regardless of the number of units or their strength. The problem with the circles is the accuracy. The circles as shown in the images above cover only +/- 80% of the maps' terrain because the area that fall out of the circles is not checked. By arranging the circles in a different way, staggered, the accuracy could be improved. (I would need to calculate how much coverage this would give) The script would be something like this 1)Calculate the size of the map x-axis, y-axis 2)Calculate the centre point of the circles (argument 'resolution') 3)Use double for... loop to Check the number of units for each circle => GetNUnitsInCircle (party, xi,yj, radius) where radius is the argument 'accuracy' of the function. I see if I can put something together to demonstrate what I mean.
|
|
bb
General
Blitzkrieg junkie (tried to quit several times).
Posts: 1,363
|
Post by bb on May 25, 2017 4:21:04 GMT 1
Can I change the subject for a while? Which are the best script to tell a unit to never leave from a script area (like a circle for example)?
|
|
|
Post by feldgrau on May 25, 2017 6:37:10 GMT 1
Hi bb
Look ---> here, is BK1 without everything mbkg Feldgrau
|
|
|
Post by Quintaxel on May 29, 2017 13:41:55 GMT 1
Finally found some time to work on this function to check how much of a map is occupied by each player. I tested the function on a 20x20 map. With the current settings this means that the script checks 20x20 circles or zones, so 400 in total each time it runs. The calculations do not seem to affect the game on a low spec laptop.
I opted to make the circles overlap, so the whole map is covered. In the images I posted earlier each circle fits into a square but as a result this method only covers about 78 % of the surface of the map. I decided to increase the radius of the circle so that each square of 1024X1024 script points now fit within a circle with a radius of 725 script points. (725 = diagonal of the square/2) I still have to figure out if the ideal size of the circles (zones). If you want to tray the function then just copy the script below and link it to a map. You should see how much of the map is controlled by the Player, the AI, how many zones are neutral and how many zones are disputed (so contain player and AI units). You also get the total zones on the map.
The function itself is quite straightforward and just uses a nested for..do loop.
DisplayTrace ("Test function GetMapControl");
DisplayTrace ("Checking how much of a map is controlled by each player party");
DisplayTrace ("Revision 29-05-2017");
function TestGetMapControl()
local prty0,prty1,prty2, disp, totzones = GetMapControl();
DisplayTrace ("TestGetMapControl is running");
DisplayTrace ("Player 0 occupies %g zones of %g zones",prty0,totzones);
DisplayTrace ("Player 1 occupies %g zones of %g zones",prty1,totzones);
DisplayTrace ("%g zones of %gzones are neutral",prty2, totzones);
DisplayTrace ("%g of %g are disputed",disp,totzones);
DisplayTrace ("There are %g zones on the map.",totzones);
Suicide ();
end;
function GetMapControl()
--Quintaxel 29-05-2017
--GetMapControl returns zones controled by party0,party1,party2,disputed,totalzones;
local step = 1024; --distance between centre points of circles
local party0, party1, party2, disputed = 0,0,0,0;
local totalzones,xaxis,yaxis,xoffset, yoffset; --total # zones on map
yoffset = step;
local radius = 725; -- 725 is radius of circles
--Calculating the number of zones on the map
xaxis, yaxis = GetMapSize();
xaxis = xaxis/step;
yaxis = yaxis/step;
totalzones = xaxis * yaxis;
for j = 1,yaxis do
xoffset = step;
for i = 1,xaxis do
party0unitsincircle = GetNUnitsInCircle (0,xoffset,yoffset,radius);
party1unitsincircle = GetNUnitsInCircle (1,xoffset,yoffset,radius);
party2unitsincircle = GetNUnitsInCircle (2,xoffset,yoffset,radius);
if party0unitsincircle > 0 and party1unitsincircle > 0 then
disputed = disputed + 1;
elseif party0unitsincircle > 0 and party1unitsincircle == 0 then
party0 = party0 + 1;
elseif
party1unitsincircle > 0 and party0unitsincircle == 0 then
party1 = party1 + 1;
elseif
party1unitsincircle == 0 and party0unitsincircle == 0 then
party2 = party2 + 1;
else
disputed = disputed + 1;
end;
xoffset = xoffset + step;
end;
yoffset = yoffset + step;
end;
--Trace () functions below can be omitted but may come in handy to when debugging.
Trace ("Player 0 occupies %g zones of %g zones",party0,totalzones);
Trace ("Player 1 occupies %g zones of %g zones",party1,totalzones);
Trace ("%g zones of %gzones are neutral",party2, totalzones);
Trace ("%g of %g are disputed",disputed,totalzones);
Trace ("There are %g zones on the map", totzones);
return party0,party1,party2,disputed,totalzones;
end;
function Init()
RunScript ("TestGetMapControl",5000);
end;
|
|
|
Post by Quintaxel on Jun 2, 2017 18:12:00 GMT 1
Can I change the subject for a while? Which are the best script to tell a unit to never leave from a script area (like a circle for example)? I have been thinking about how this could be made into a function. the function could look something like this; PinUnitToCircle (ScriptId, radius)
When the function is called the script would have to do the following;
- Store the unit's Scriptid, x,y coordinates on the map and the radius of the circle into a multi dimensional array. - Check for each unit in the array if it is still within the circle - If the unit is close or outside the circle then make the unit return to the stored x,y coordinates. You could then also have a function that 'unpins' a unit, so make it possible for the unit to leave the circle. UnpinUnitToCircle (ScriptId)This function unit should remove the unit from the array so the script doe no longer check if the unit is within the circle. More variation should be possible like pinning a unit to a script area or to a fixed position on the map. The most challenging thing is managing the array so that units can be stored and removed but it should not be too difficult. Any ideas, thoughts or other possible approaches are welcome.
|
|