Mat
General
Posts: 1,814
|
Post by Mat on May 4, 2015 22:33:02 GMT 1
after i finished my work on the mod i will join this section fulltime!
|
|
|
Post by Quintaxel on May 5, 2015 11:26:59 GMT 1
Let me do some research and testing... If you can collect the location data for each starting point, it seems to me you can use the ROTATE command to make them face it. But you suggest that you cannot do this. That just doesn't seem logical to me. I have seen this in use before in BH-Rommel (I think). I'll go back and look at it. The problem you outline now should be easier than what I incorrectly described earlier. You can collect the location data of a unit using the function GetObjCoord (iScriptID) but this returns the units x,y coordinates and, to my knowledge, does not give information about the direction the unit’s front is facing. If it is possible to collect the angle in which a unit is positioned then it would be logical that a unit could also be rotated to a certain angle but that seems not to be the case. Therefore I see no real use for the function GetObjCoord(iScriptID) so there must be something I overlook.
|
|
|
Post by Quintaxel on May 7, 2015 8:53:58 GMT 1
Is it possible to create an engineering unit that can only place AT mines or to put it differently, ‘disable’ an existing engineering unit so it can no longer lay AP mines ? The reason I'm asking is that the BK Lua function for placing landmines Cmd (11, iScriptID, x,y); will place AP mines by default. I do not know why but there seems no way in BK Lua to control the type of mines that the engineering unit lays. Now if the engineering unit could only lay AT mines then I guess/expect/hope that the calling the function Cmd (11, iScriptID, x,y); would force this unit to place AT.
|
|
|
Post by Major Pain on May 7, 2015 15:06:31 GMT 1
We can program an Engineer to lay specific mines. We cannot program the Engineer to remove specific mines, they remove all with the same binary command.
You earlier pointed out the use of
angle = GetFrontDir(iScriptID)/65536 * 360
This will give to the direction a unit is facing.
If we just need to rotate a unit toward the other location, just use the x, y coordinate for each unit pointing to the other coordinate.
Use:
GetObjCoord(iScriptID)
for each unit to get the coordinates of each unit.
Then follow that up with the
Cmd(8, iScriptID, x, y)
on each unit to make it face the other location.
Using this method does not require the angle of facing...
|
|
|
Post by Quintaxel on May 7, 2015 15:51:31 GMT 1
We can program an Engineer to lay specific mines. And how would we do this ? The syntax Cmd (11, iScriptID, x,y); does not specify a mine type or do I miss a parameter here? If I give the engineering unit the command for placing a mine it through script it always places a AP mine. I want to place AT mines. You are right that the angle of the unit is not required if units A and Unit B are facing each other in their starting position as in the example. However Unit A and Unit B could be facing any direction on the map. BK lua does not include the math library and the Lua function Require to load an run libraries does not seem to work so the options are limited here. I have a rough idea on how to solve this problem but I will need time to work it out. Like a 100 years or so
|
|
|
Post by Major Pain on May 7, 2015 16:09:12 GMT 1
No... collect the coordinates at the very beginning. These coordinates would not change as to rotating toward them.
Example: X1, Y1 and X2, Y2. These are constants. It has nothing to do with turning toward the other model, only the coordinate. It does not matter what angle the other unit is turned to, or where the other unit is. The final position of the vehicles path is all you are worried about.
When each unit arrives at its new location, run the Cmd(8, iScriptID, x, y) and it will rotate to the opposite coordinate. The x, y Coordinates would be the same throughout the game.
Now, if you use several places where these units may start from, say at random, then you can still collect the x. y in the beginning and just continue to use them throughout the map.
|
|
|
Post by Quintaxel on May 7, 2015 16:33:49 GMT 1
I do collect the x1,y1 and x2,y2 coordinates at the beginning. If I run the Cmd (8,iScriptID, x,y); after each unit reaches its new location then both units will indeed look at each other, regardless the position they had on the map. That I understand. See images below to clarify what I mean The units are not looking in each others directions so I need to capture not only their position x,y but also their angle on the map. When the units have switched positions I need the information about the angle to make them rotate to exact the same position the vehicle they replaced.
|
|
|
Post by Major Pain on May 7, 2015 16:53:04 GMT 1
Try this Quin Cmd(33, iScriptID, x, y)This is an undocumented command. However, if you begin to look at the binaries. they work the same way for the cmd as they do in the 1.xml Example: Cmd(11, iScriptID, x, y) = place mine (AP) If you look at the 1.xml Binary Commands... Binary Command 12 = Place AP Mine So let's work from the reverse this time: Binary Command 34 = Place AT Mine So we subtract 1 (the Binary offset) which gives us 33... So Cmd(33, iScriptID, x, y) should have the Engineer Place the AT Mine. Note: I have never tried this... so if it works, then you just added a new command that was not documented... we'll call it the Quin's Command. If it does not work, well it didn't cost you anything and you get no Command named after you. Refer to Calvin's for as minute and you will find strangely that cmd 33 is not listed... Ever wonder why? Look at the above example... Another hint:The only difference between the Binary Commands in the 1.xml and the Cmd Commands in the script is the value 1 offset. The Binary does not begin with Command ZERO... it starts with "1"... But the cmd commands start with ZERO, which just happen to be one less for the corresponding command in the Binary Command. Note: In the Lua Script, Cmd Commands are called Actions. Look at the Move Command In the Binary Commands, it is 1 In the Cmd Commands it is Zero (0) Look at the Attack Command In the Binary Commands, it is 2 In the Cmd Commands, it is 1 Attack ObjectAbout Cmd(2, iScriptID, iScriptID_Cible) which corresponds to Binary Command 3. This cmd does not work, but in the Binary Command it give a unit the ability to attack. I should make the distinction, these are attack objects, not other units. The reason this command will not work is the game table stores everything as an object... If you give any object a ScriptID, Cmd 1 should cover it. I am looking at the CMD tables to see if this Command can be utilized. I believe it does work in Stalingrad. Will someone verify that please. My memory does not always work. SWARM toBinary Command 4 Cmd = 3
These destinations and commands/actions hold up throughout the Binaries. Both command sets are in fact the same binary codes. Binary Command 23 should have never been added to the 1.xml commands... paradrop. This only works if you wish to call the paradrop with Cmd(22, Avion_iScriptID, iParty, x, y) in the script. A unit cannot call a paradrop from the 1.xml commands. Curious Questions:Given the relationship... there is no examples of Cmd(47) which should be Binary Command 48 or Repair Object. Although we know that Cmd(24) does not seem to work in the example listed. I'm thinking the Cmd(24) and Cmd(47) should be assigned by a player or ScriptID and Coordinate Cmd(24, ScriptID, x, y) But this is untested, as is Cmd(47) What about STAND GROUND? Binary Command 51 Cmd(52, Player, x, y) would make Players units stand ground at x, y location... but perhaps it is a much larger circle or area with x, y being the center. We are only limited by our imagination... the LUA Script is dynamic and powerful and not fully documented for BK.
|
|
|
Post by Major Pain on May 7, 2015 16:55:33 GMT 1
I do collect the x1,y1 and x2,y2 coordinates at the beginning. If I run the Cmd (8,iScriptID, x,y); after each unit reaches its new location then both units will indeed look at each other, regardless the position they had on the map. That I understand. See images below to clarify what I mean The units are not looking in each others directions so I need to capture not only their position x,y but also their angle on the map. When the units have switched positions I need the information about the angle to make them rotate to exact the same position the vehicle they replaced. Let me clarify something for a second... Are you saying that each unit does not start in the beginning looking toward the other one? If that is correct, then we might be able to use a little geometry to calculate the angles... then based on that angle, rotate to the coordinates.
|
|
|
Post by Quintaxel on May 8, 2015 11:47:39 GMT 1
Thanks for the info MP. It looks like there will be no Quin function, at least not in near future. Cmd(33, iScriptID, x, y) does not seem to work but this command does not cause an error. Ill try the other command you suggested to see what happens. About the rotation of units. It's correct, each unit does not start in the beginning looking toward the other one. So I'll need to use geometry to make the unit rotate to the position of the unit it is replacing but,....BK Lua has no math functions so this limits the possibilities. I'll have to brood over this.
|
|
|
Post by Major Pain on May 8, 2015 16:41:10 GMT 1
Yes we can.
It would be a rather long formula, but I think we can use 4 or 5 lines to build the data into a function, then transfer that data to the rotation function. I'm going to do some testing on this now, and will send you some things to check. I don't have the game on this system at work, so you will have to verify the data I work this out.
The first thing is translating the direction they are facing in relation to the other coordinate then calculating the angle. Can you provide the coordinates for each location so i have something to start with?
|
|
|
Post by Quintaxel on May 8, 2015 18:08:43 GMT 1
The x1,y1 and x2,Y2 coördinates could be of any position on the map. I would capture the x,y position of both vehicles on the map. These coordinates are needed to change their position (unitA with x1 y1 coodinates will move to position x2,y2) I would also capture the angle of each unit. This angle could then be used to determine the direction of the unit. The angle could be roughly translated to a vector for the direction. I will be out for the next hour or so but I will to explain what I mean in further detail. Maybe there is a better approach of what I have in my head now but for now this is the best I can come up with
|
|
|
Post by Major Pain on May 9, 2015 2:49:02 GMT 1
We can collect the x, y Coordinates... then calculate the angle.... then project a set of new coordinates that we want to face that is offset at the correct angle. We'll need to use 0, 0 (Upper left Corner) and the lower right corner coordinates to calculate against, to set maximum offset angle on the map. On a Square map, this will be 45 degrees... We already know that 0, 0 to the Upper right and 0, 0 to the Lower left is 90 Degrees. So once we get the x, y of the vehicle x1, y1 = GetObjCoord(1000)then we collect the angle Angle1 = GetFrontDir(1000)With these two values, we can project the new coordinates that are at the proper angle. We'll have to have a check-range built in so we do not project coordinates less than x= 0 or y = 0, and higher than the maximum Script Coordinates (Lower Right Corner). With the angle, we can calculate the points along a Vector from the original coordinates. All we have to do is determine a length for the Vector... 2 should be enough. The formula does not require the original coordinates. We only have to insert two values into our formula, length and angle. Once we have defined the new Coordinate ( x2, y2) we can Rotate the unit toward that Coordinate. Cmd(8, 1000, x2, y2)The Function: Function RotateUnit()
x1, y1 = GetObjCoord(1000); Angle1 = GetFrontDir(1000); Length = 2 -- This can be any value but should be high enough to obtain an accurate coordinate. x2 = Length * cos(Angle1); y2 = Length * sin(Angle1);
Cmd(8, 1000, x2, y2);
suicide; end;
|
|
|
Post by Quintaxel on May 9, 2015 11:56:56 GMT 1
Major, this is indeed the most logical and probably the best solution for solving the problem but sin and cos functions are part of the math library in Lua and as far as I know not available in the BK Lua version ? In the past I already made some futile attempts to add Lua libraries for math function and string manipulation to BK Lua version using the Lua "Require" function. It seems to me that Nival left out the standard Lua libraries. If we had access to the Lua libraries then this would boost the possibilities for creating new funtions in BK and then yes indeed the possibilities would be limitless. Now it often feels like you have to reinvent the wheel when trying to write a simple function. To solve the problem of the rotation I was thinking of using 2 tables that contain sin and cos vlaues for each angle between 0 and 360 degrees because BK Lua cannot handle the sin and cos functions. Anyway I'll try the sin and cos funtions once more to be sure.
|
|
|
Post by keepitsimple on May 9, 2015 12:29:48 GMT 1
I have the same experiences with sin and cos function. For my close air support of Bombers I used the following:
local afstand = 1200; {distance to enemy} local bomafstand = 1400;{distance of bomber is send to observer} local leeft1 = GetNUnitsInScriptGroup(250, 0); {check to see observer is a life} local X1,Y1 = GetObjCoord(250); {place of observer} local hoek = GetFrontDir(250)/65536*360; {angle of degrees the observer is looking}
{Circles in degree around the observer}
local hoek0 = GetNUnitsInCircle(1, X1,Y1+afstand, 500); {between - 15 and + 15 degrees} local hoek30 = GetNUnitsInCircle(1, X1-(0.6*afstand),Y1+(0.8*afstand), 500); {between 15 and 45 degrees} local hoek60 = GetNUnitsInCircle(1, X1-(0.8*afstand),Y1+(0.6*afstand), 500); local hoek90 = GetNUnitsInCircle(1, X1+afstand,Y1, 500); local hoek120 = GetNUnitsInCircle(1, X1-(0.8*afstand),Y1-(0.6*afstand),500); local hoek150 = GetNUnitsInCircle(1, X1-(0.6*afstand),Y1-(0.8*afstand),500); local hoek180 = GetNUnitsInCircle(1, X1,Y1-afstand,500); local hoek210 = GetNUnitsInCircle(1, X1+(0.6*afstand),Y1-(0.8*afstand),500); local hoek240 = GetNUnitsInCircle(1, X1+(0.8*afstand),Y1-(0.6*afstand),500); local hoek270 = GetNUnitsInCircle(1, X2+afstand,Y2,500); local hoek300 = GetNUnitsInCircle(1, X2+(0.8*afstand),Y2+(0.6*afstand),500); local hoek330 = GetNUnitsInCircle(1, X2+(0.6*afstand),Y2+(0.8*afstand),500);
-- Truck is turn to 0 degree, if enemy are in range then the bommers are send --
{The direction of truck is looking is determined if looking. If this is between - 15 and + 15 and in circle before the truck there are enemies bombers are send}
if (leeft1 ==1) and ((hoek <=15) or (hoek>345)) and (hoek0>=1) then DisplayTrace("Port Moresby: We send in the bombers"); Cmd(19,3,2,X2,Y2+bomafstand); RunScript( "CloseAirSupport12", 120000,1); Suicide();
-- 30 degree --
elseif (leeft2 ==1) and (hoek >15) and (hoek<=45) and (hoek30>=1) then DisplayTrace("Port Moresby: We send in the bombers"); Cmd(19,3,2,X2-(0.6*bomafstand),Y2+(0.8*bomafstand)); RunScript( "CloseAirSupport12", 120000,1); Suicide();
etc.
Of course this is of not exact but it works.
|
|