Request Gateway transport system

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,877
Reaction score
2,131
Points
203
Location
between the planets
So something like if hvessel = Gate then oapiGetGlobalPos(hvessel, &gatepos);

No, since you're only executing the code if the vessel is NOT the gate:

Code:
if (hvessel != GetHandle())

Just use GetHandle() again:
Code:
oapiGetGlobalPos(hvessel, &vesselpos);
oapiGetGlobalPos(GetHandle(), &gatepos);
VECTOR3 relpos = vesselpos - gatepos;
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
Thanks. I guess it would get the position of the 2 gates?
Code:
void WORMHOLE::clbkPostStep(double simt, double simdt, double mjd)
{
	for (UINT i = 0; i<oapiGetVesselCount(); i++)
	{
		OBJHANDLE hvessel = oapiGetVesselByIndex(i);

		
		if (hvessel != GetHandle())
		{
			
			oapiGetGlobalPos(hvessel, &vesselpos);
			oapiGetGlobalPos(GetHandle(), &gatepos);
			relpos = vesselpos - gatepos;

		

			double distance = length(relpos);

		}



			sprintf(oapiDebugString(), "DISTANCE %0.9f", distance);


So when I run the debugger:
- gatepos {data=0x16228d64 {1.4739400953469026e-249, -3.5175216902623281e-069, 2.8869270252392989e-251} x=1.4739400953469026e-249 ...} VECTOR3
and
- vesselpos {data=0x16228d7c {1.4739400953469026e-249, -3.5175216902623281e-069, -4.8366966656860381e-026} x=1.4739400953469026e-249 ...} VECTOR3
and distance:
distance -2.5301707587854818e-098 double



I have the jump stuff commented out. As I move the DG around I expected the distance value to change.
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,877
Reaction score
2,131
Points
203
Location
between the planets
Thanks. I guess it would get the position of the 2 gates?

No, the determination of the position of the second gate happens further down.
The code until here looks at every vessel currently in the simulation, and if it's not the gate in which the code runs, calculates the distance to it.

Here's where the code determines the other gate (it's a pretty awkward identity check, but it will have the intended result, at least if the gates are named correctly):

Code:
OBJHANDLE h_other_gate;
char myname[16];
char GateA[16];
sprintf(myname, GetName());
sprintf(GateA, "Gate_A");
if (strcmp(myname, GateA) == 0)
{
    h_other_gate = oapiGetVesselByName("Gate_B");
}
else{
    h_other_gate = oapiGetVesselByName("Gate_A");
}


As I move the DG around I expected the distance value to change.

I'm pretty sure it does. The problem is, are you looking at the right vessel? As mentioned above, the code calculates the distance between the gate and every vessel in the simulation, one by one.
Since you're writing the distance to the debug string, that string will always show the distance to the last vessel being looked at, which is by no means guaranteed to be the one you're moving around.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
So I made a scenario with 1 dg and 1 gate:
BEGIN_SHIPS
Gate_A:WORMHOLE
STATUS Orbiting Earth
RPOS 1754494.29 -0.02 6784938.48
RVEL -7301.517 -0.000 1888.077
AROT 0.00 -0.00 0.00
AFCMODE 7
NAVFREQ 0 0
XPDR 0
END
dg:Deltaglider
STATUS Orbiting Earth
RPOS 1754494.12 -0.02 6784562.71
RVEL -7301.525 -0.000 1880.458
AROT 0.00 -0.00 0.00
RCSMODE 2
AFCMODE 7
PRPLEVEL 0:0.985416 1:0.992303
NAVFREQ 0 0 0 0
XPDR 0
AAP 0:0 0:0 0:0
END
END_SHIPS





- gatepos {data=0x00aefdd0 {0.94151034603643613, 1.2780000000000000, 2.4042173117536429} x=0.94151034603643613 ...} VECTOR3

- vesselpos {data=0x00aefdb0 {0.87565040588378906, 0.80224166120070428, 1.1983085207591453} x=0.87565040588378906 ...} VECTOR3

distance -2.5301697413473045e-098 double
+ relpos {data=0x162594ec {-4.8366978272229995e-026, -4.8366978272229995e-026, -4.8366978272229995e-026} x=-4.8366978272229995e-026 ...} VECTOR3



then ran it a couple of continues
- vesselpos {data=0x00aefdb0 {-0.076702019738933619, 0.91709767174754342, 9.4666892485023829e-288} x=-0.076702019738933619 ...} VECTOR3

- gatepos {data=0x00aefdd0 {2.5118790309371882e-297, 9729801645506.0898, 3.1497445605217158e-307} x=2.5118790309371882e-297 ...} VECTOR3

+ relpos {data=0x162594ec {1.589611773301e-314#DEN, 5.5329046628180653e-222, -4.8366978829529967e-026} x=1.589611773301e-314#DEN ...} VECTOR3

distance -2.5301697413473045e-098 double


Not sure why on the 2nds time the relpos x value is x=1.589611773301e-314#DEN

This is what I have right now:
Code:
void WORMHOLE::clbkPostStep(double simt, double simdt, double mjd)
{
	for (UINT i = 0; i<oapiGetVesselCount(); i++)
	{
		OBJHANDLE hvessel = oapiGetVesselByIndex(i);

		
		if (hvessel != GetHandle())
		{
			VECTOR3 vesselpos = _V(0, 0, 0);
			VECTOR3 gatepos = _V(0, 0, 0);
			oapiGetGlobalPos(hvessel, &vesselpos);
			oapiGetGlobalPos(GetHandle(), &gatepos);
			relpos = vesselpos - gatepos;

		

			double distance = length(relpos);

		}

		

		sprintf(oapiDebugString(), "DISTANCE %0.9f" , distance);

So focused on the DG. we need to get the dg pos, gateA pos and Gate B pos. Calculate the differences

Then if one gate is close enough to something, right?
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,877
Reaction score
2,131
Points
203
Location
between the planets
So I made a scenario with 1 dg and 1 gate:

very good!

Not sure why on the 2nds time the relpos x value is x=1.589611773301e-314#DEN

A denormal number (or subnormal number) is used if the value is too close to zero to be represented as non-zero by double floating point precision. As mentioned, you probably still have a strange compiler setting active, as by default the visual studio compiler does not produce these (they slow things down quite a bit), but it shouldn't currently matter for the result.

I'm a bit worried about the distance being exactly the same both times, that shouldn't really be the case. Now that you have only the DG and one Gate, I would suggest running it in orbiter and watching the debug string for a more comprehensive result.

So focused on the DG. we need to get the dg pos, gateA pos and Gate B pos. Calculate the differences

What you have to understand is that this code runs in the gate, not the DG. And it will run once per frame for every gate in the scenario. So this is not the place to check which gate the DG is closest to, just whether it's close enough to this gate to trigger an action.

Only then you need to determine the position of the other gate and teleport the DG.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
Thanks. So I ran it in orbiter and no change is distance. I placed the DG on Earth and no change.

One odd thing. Sometimes when I run the debugger it says another orbiter is running. When there isn't one running?

I rebooted and now debugger runs>
- gatepos {data=0x00aefdd0 {1.4971965735776354e-304, 7130758279867.4902, 3.1497445605217158e-307} x=1.4971965735776354e-304 ...} VECTOR3
- vesselpos {data=0x00aefdb0 {0.99312895549935754, -0.11702511587305009, 4.7333446242511915e-288} x=0.99312895549935754 ...} VECTOR3
- relpos {data=0x1571a2f4 {4.2392581063321460e-085, -4.6266496851570525e+279, -4.8366978908870802e-026} x=4.2392581063321460e-085 ...} VECTOR3
distance -2.5301697413473045e-098 double

BEGIN_FOCUS
Ship Gate_A
END_FOCUS

BEGIN_CAMERA
TARGET Gate_A
MODE Extern
POS 55.85 85.12 -26.93
TRACKMODE TargetRelative
FOV 60.00
END_CAMERA

BEGIN_HUD
TYPE Surface
END_HUD

BEGIN_SHIPS
Gate_A:WORMHOLE
STATUS Orbiting Earth
RPOS 944376.56 -0.02 6944191.45
RVEL -7472.895 -0.000 1016.280
AROT 0.00 -0.00 0.00
AFCMODE 7
NAVFREQ 0 0
XPDR 0
END
dg:Deltaglider
STATUS Landed Earth
POS -80.6758960 28.5227640
HEADING 85.92
RCSMODE 2
AFCMODE 7
PRPLEVEL 0:0.968101 1:0.992303
NAVFREQ 0 0 0 0
XPDR 0
AAP 0:0 0:0 0:0
END
END_SHIPS
 
Last edited:

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,877
Reaction score
2,131
Points
203
Location
between the planets
Please post the entire code that is currently being executed in clbkPostStep. There's several things here that don't add up.
 
Last edited:

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
Thanks. here you go:
Code:
WORMHOLE::WORMHOLE (OBJHANDLE hObj, int fmodel)
: VESSEL2 (hObj, fmodel)

{
	distance = 0;
	rpos = _V(0, 0, 0);
	rvel = _V(0, 0, 0);
	gpos1 = _V(0, 0, 0);
	
}

void WORMHOLE::clbkSetClassCaps (FILEHANDLE cfg)
{
	// physical specs
	SetSize (500);
	SetEmptyMass (1000.0);
	SetCW (0.3, 0.3, 0.6, 0.9);
	SetWingAspect (1.7);
	SetWingEffectiveness (14.1);
	SetCrossSections (_V(5.4, 5.4,25.77 ));
	SetRotDrag (_V(3.5,3.5,3.5));
	if (GetFlightModel() >= 1) {
		SetPitchMomentScale (1e-4);
		SetBankMomentScale (1e-4);
	}
	SetPMI (_V(2.58,2.57, 12.00));
	SetTrimScale (0.08);
	SetCameraOffset (_V(0,2.5,0));
SetTouchdownPoints  (_V(0,.01,5.7), _V(-3.448,.01,-5.0), _V(3.448,.01,-5.0));; 



EnableTransponder (true);

	// propellant resources

//SetMeshVisibilityMode(AddMesh(oapiLoadMeshGlobal("INTERSTELLAR\\VESSEL\\WHole")), MESHVIS_ALWAYS); //Main ship mesh

SetMeshVisibilityMode(AddMesh(oapiLoadMeshGlobal("gateway")), MESHVIS_ALWAYS); //Main ship mesh




}

void WORMHOLE::clbkPostStep(double simt, double simdt, double mjd)
{
	for (UINT i = 0; i<oapiGetVesselCount(); i++)
	{
		OBJHANDLE hvessel = oapiGetVesselByIndex(i);

		
		if (hvessel != GetHandle())
		{
			VECTOR3 vesselpos = _V(0, 0, 0);
			VECTOR3 gatepos = _V(0, 0, 0);
			oapiGetGlobalPos(hvessel, &vesselpos);
			oapiGetGlobalPos(GetHandle(), &gatepos);
			relpos = vesselpos - gatepos;

		

			double distance = length(relpos);

		}

		

		sprintf(oapiDebugString(), "DISTANCE %0.9f" , distance);

			/*
		//	if ((distance<2) && (rpos.z>0) && (rvel.z<0))
			//if (distance<2)
			{

				VESSELSTATUS2 vs_vessel, vs_other_gate;
				memset(&vs_vessel, 0, sizeof(vs_vessel));
				memset(&vs_other_gate, 0, sizeof(vs_other_gate));
				vs_vessel.version = 2;
				vs_other_gate.version = 2;

				VESSEL *v;
				v = oapiGetVesselInterface(hvessel);
				v->GetStatusEx(&vs_vessel);
				OBJHANDLE h_other_gate;
				char myname[16];
				char GateA[16];
				sprintf(myname, GetName());
				sprintf(GateA, "Gate_A");
				if (strcmp(myname, GateA) == 0)
				{
					h_other_gate = oapiGetVesselByName("Gate_B");
				}
				else{
					h_other_gate = oapiGetVesselByName("Gate_A");
				}
				VESSEL *v_other_gate;
				v_other_gate = oapiGetVesselInterface(h_other_gate);
				v_other_gate->GetStatusEx(&vs_other_gate);
				vs_vessel.rbody = vs_other_gate.rbody;
				vs_vessel.rpos = vs_other_gate.rpos;
				vs_vessel.vrot = vs_other_gate.vrot;
				vs_vessel.arot = vs_other_gate.arot;

				VECTOR3 outvel = _V(rvel.x, rvel.y, rvel.z);
				VECTOR3 rofs;
				GlobalRot(outvel, rofs);
				vs_vessel.rvel.x = vs_other_gate.rvel.x + rofs.x;
				vs_vessel.rvel.y = vs_other_gate.rvel.y + rofs.y;
				vs_vessel.rvel.z = vs_other_gate.rvel.z + rofs.z;






				v->DefSetStateEx(&vs_vessel);
			
			
	}
	*/
		}
	
	

}
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,877
Reaction score
2,131
Points
203
Location
between the planets
I don't understand... That code shouldn't even compile!

Code:
relpos = vesselpos - gatepos;

relpos isn't declared anywhere. Why does this even run?

---------- Post added at 09:03 PM ---------- Previous post was at 08:52 PM ----------

Also, I've just spotted the reason why your distance doesn't change. Going back a few pages and looking at your header file, I see that distance is an instance variable for some reason (it has no reason to be!).

And then you're doing this:

Code:
if (hvessel != GetHandle())
{
    ...
    [COLOR="red"]double [/COLOR]distance = length(relpos);

[B][COLOR="Red"]}[/COLOR][/B]

sprintf(oapiDebugString(), "DISTANCE %0.9f" , distance);

You're redeclaring distance, hiding the instance variable of the same name, then fill the local variable with the calculated distance.
Then you close the scope, which means that this variable no longer exists!
You then go on to print the instance variable of the same name to the debug string, but this variable never received the value you calculated. In fact, as far as I can see from the code, it is never used anywhere.
Now, if you wouldn't have declared it as an instance variable in the header, you would immediately have noticed that something is wrong, because the compiler would have thrown a fit.

If you're making an instance variable, there must be a reason for it. Think before declaring them!
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
Thanks. I had this in the h:
Code:
//VECTOR3 relpos;

But Now I have this:
Code:
void WORMHOLE::clbkPostStep(double simt, double simdt, double mjd)
{
	for (UINT i = 0; i<oapiGetVesselCount(); i++)
	{
		OBJHANDLE hvessel = oapiGetVesselByIndex(i);

		
		if (hvessel != GetHandle())
		{
			VECTOR3 vesselpos = _V(0, 0, 0);
			VECTOR3 gatepos = _V(0, 0, 0);
			VECTOR3 relpos = _V(0, 0, 0);
			oapiGetGlobalPos(hvessel, &vesselpos);
			oapiGetGlobalPos(GetHandle(), &gatepos);
			relpos = vesselpos - gatepos;

		

			 distance = length(relpos);

		}

		

		sprintf(oapiDebugString(), "DISTANCE %0.9f" , distance);

And now the distance changes.

So I guess the next step is to check to see which gate is closer?

And then if a GAte is within the distance asked?
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,877
Reaction score
2,131
Points
203
Location
between the planets
But Now I have this:

Here's a better idea: Throw all of those instance variables out and declare them locally. All except for jump, which is the only variable that has to carry state over multiple calls as far as I can see.

If a variable isn't used by multiple methods, and doesn't have to carry state over multiple method calls, it has no business bein in the class scope.

So I guess the next step is to check to see which gate is closer?

No need for that. You don't need to know which gate is closer. This check is run for each gate, so unless your triggering distance is larger than half the distance between the gates, you know that the vessel is closer to the gate of which it is in triggering distance.

So the next task is to check if the distance is smaller than the triggering distance.
If it is, find the other gate and teleport the vessel that is below triggering distance.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
So are saying that need to be declared in the H and not in the

void WORMHOLE::clbkPostStep(double simt, double simdt, double mjd)

So like this;
Code:
void WORMHOLE::clbkPostStep(double simt, double simdt, double mjd)
{
	for (UINT i = 0; i<oapiGetVesselCount(); i++)
	{
		OBJHANDLE hvessel = oapiGetVesselByIndex(i);

		
		if (hvessel != GetHandle())
oapiGetGlobalPos(hvessel, &vesselpos);
			oapiGetGlobalPos(GetHandle(), &gatepos);
			relpos = vesselpos - gatepos;

		

			 distance = length(relpos);

		}
		{


I am not sure how this is code so if distance is less than trigger distance then do something.
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,877
Reaction score
2,131
Points
203
Location
between the planets
So are saying that need to be declared in the H and not in the

void WORMHOLE::clbkPostStep(double simt, double simdt, double mjd)

Uhm, no. I was meaning the exact other way around. An instance variable is valid in the entire class scope. A local variable is only valid until the end of its current scope (a scope is, simplified, anything inside {} brackets).
The scope of variables should always be as limited as possible, as open as necessary. Since you don't need these variables anywhere else in your class, declaring them in the function where they are used makes the most sense.

I am not sure how this is code so if distance is less than trigger distance then do something.

Basically,
Code:
if (distance < 2 && jump == true) { ... //code that finds the other gate and teleports vessel to it}
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
So like this:
Code:
void WORMHOLE::clbkPostStep(double simt, double simdt, double mjd)
{
	for (UINT i = 0; i<oapiGetVesselCount(); i++)
	{
		OBJHANDLE hvessel = oapiGetVesselByIndex(i);

		
		if (hvessel != GetHandle())
		{
			VECTOR3 vesselpos = _V(0, 0, 0);
			VECTOR3 gatepos = _V(0, 0, 0);
			VECTOR3 relpos = _V(0, 0, 0);
			oapiGetGlobalPos(hvessel, &vesselpos);
			oapiGetGlobalPos(GetHandle(), &gatepos);
			relpos = vesselpos - gatepos;

		

			 double distance = length(relpos);
			 if (distance < triggerdistance) jump = 1;
		}

		

	//	sprintf(oapiDebugString(), "DISTANCE %0.9f" , distance);

			
		//	if ((distance<2) && (rpos.z>0) && (rvel.z<0))
			if (jump==1)
			{

				VESSELSTATUS2 vs_vessel, vs_other_gate;
				memset(&vs_vessel, 0, sizeof(vs_vessel));
				memset(&vs_other_gate, 0, sizeof(vs_other_gate));
				vs_vessel.version = 2;
				vs_other_gate.version = 2;

				VESSEL *v;
				v = oapiGetVesselInterface(hvessel);
				v->GetStatusEx(&vs_vessel);
				OBJHANDLE h_other_gate;
				char myname[16];
				char GateA[16];
				sprintf(myname, GetName());
				sprintf(GateA, "Gate_A");
				if (strcmp(myname, GateA) == 0)
				{
					h_other_gate = oapiGetVesselByName("Gate_B");
				}
				else{
					h_other_gate = oapiGetVesselByName("Gate_A");
				}
				VESSEL *v_other_gate;
				v_other_gate = oapiGetVesselInterface(h_other_gate);
				v_other_gate->GetStatusEx(&vs_other_gate);
				vs_vessel.rbody = vs_other_gate.rbody;
				vs_vessel.rpos = vs_other_gate.rpos;
				vs_vessel.vrot = vs_other_gate.vrot;
				vs_vessel.arot = vs_other_gate.arot;

				VECTOR3 outvel = _V(rvel.x, rvel.y, rvel.z);
				VECTOR3 rofs;
				GlobalRot(outvel, rofs);
				vs_vessel.rvel.x = vs_other_gate.rvel.x + rofs.x;
				vs_vessel.rvel.y = vs_other_gate.rvel.y + rofs.y;
				vs_vessel.rvel.z = vs_other_gate.rvel.z + rofs.z;






				v->DefSetStateEx(&vs_vessel);
			
			
	}
	
		}
	
	

}
h:
Code:
	VECTOR3 rpos, rvel;
	//VECTOR3 relpos;
private: 
UINT iMeshMAIN;
//double distance;
double triggerdistance;
int jump;
};

So if distance is less than trigger distance then jump =1;

So on the jump code.
Code:
VESSEL *v;
				v = oapiGetVesselInterface(hvessel);
				v->GetStatusEx(&vs_vessel);
hvessel is NOT the gate but DG in my example?
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,877
Reaction score
2,131
Points
203
Location
between the planets
So like this:

Much better! :)

hvessel is NOT the gate but DG in my example?

Very explicitly so, as you're comparing it to the handle of the gate and not executing the code if it is the same:

Code:
OBJHANDLE hvessel = oapiGetVesselByIndex(i);

		
		if (hvessel != GetHandle())

So if distance is less than trigger distance then jump =1;

No, jump would have to be set by something else (like for example that keypress). In fact the whole code should only be executed if jump is true in the first place (if it can have only two states, use a boolean, not an integer!). I can't even see why this whole piece of code is in clbkPostStep, it should be in a method that gets called from clbkConsumeBufferedKey directly, but let's not change that right now. You've got enough to worry about, we'll do the optimisations later.

The reason why we need an additional condition to just the distance is that if we don't, the vessel will just teleport between the two gates without ever stopping.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
Ok. So a key to open the gate. then when jumped the gate closed. So if distance < triggerdistance and gate open then jump=true?

The reason i asked about the Hvessel is now Gate a is being set to the same location as Gate B?
 
Last edited:

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,877
Reaction score
2,131
Points
203
Location
between the planets
Ok. So a key to open the gate. then when jumped the gate closed. So if distance < triggerdistance and gate open then jump=true?

In the code so far, jump has been used as the trigger, i.e. would signify that the gate is "open". Just set it to true when the key is pressed, execute the teleportation code if jump == true && distance < 2, and set jump to false again at the end of clbkPostStep.

The reason i asked about the Hvessel is now Gate a is being set to the same location as Gate B?

From what I've seen in the code, this shouldn't be the case. What makes you think so?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
In the code so far, jump has been used as the trigger, i.e. would signify that the gate is "open". Just set it to true when the key is pressed, execute the teleportation code if jump == true && distance < 2, and set jump to false again at the end of clbkPostStep.


So the user would need to open the gate( jump=true) and if distance <2 then do the jump Jump=false (gate is closed)


From what I've seen in the code, this shouldn't be the case. What makes you think so?

Because in the start of the scenario Gate A is orbiting the Earth while Gate B is orbiting the Moon. But then now Gate A and Gate B are at the same place orbiting the moon.

But let me put the trigger in and see if that works.



What if I put a timer. So the gate is open and you approach the gate. If within 2 meters it moves you to the next gate. Timer starts. This will give you time to move away from the gate? Then when the timer stops the gate reopens?
 
Last edited:

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,877
Reaction score
2,131
Points
203
Location
between the planets
Because in the start of the scenario Gate A is orbiting the Earth while Gate B is orbiting the Moon. But then now Gate A and Gate B are at the same place orbiting the moon.

Ah. If your code is the same as above, that would be the case, since the whole thing is not inside the if-block. I just assumed you'd have moved that in there after uncommenting it, as it seems kind of obvious. After all, the whole purpose of that if statement is to exclude the current gate from processing itself.

What if I put a timer. So the gate is open and you approach the gate. If within 2 meters it moves you to the next gate. Timer starts. This will give you time to move away from the gate? Then when the timer stops the gate reopens?

That would work too, yes. Might just be a bit awkward if you can't get out of the way fast enough and suddenly find yourself back where you started.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
So if I understand it
This part needs to be in the if
if (hvessel != GetHandle())
Code:
{

				VESSELSTATUS2 vs_vessel, vs_other_gate;
				memset(&vs_vessel, 0, sizeof(vs_vessel));
				memset(&vs_other_gate, 0, sizeof(vs_other_gate));
				vs_vessel.version = 2;
				vs_other_gate.version = 2;

				VESSEL *v;
				v = oapiGetVesselInterface(hvessel);
				v->GetStatusEx(&vs_vessel);
				OBJHANDLE h_other_gate;
				char myname[16];
				char GateA[16];
				sprintf(myname, GetName());
				sprintf(GateA, "Gate_A");
				if (strcmp(myname, GateA) == 0)
				{
					h_other_gate = oapiGetVesselByName("Gate_B");
				}
				else{
					h_other_gate = oapiGetVesselByName("Gate_A");
				}
				VESSEL *v_other_gate;
				v_other_gate = oapiGetVesselInterface(h_other_gate);
				v_other_gate->GetStatusEx(&vs_other_gate);
				vs_vessel.rbody = vs_other_gate.rbody;
				vs_vessel.rpos = vs_other_gate.rpos;
				vs_vessel.vrot = vs_other_gate.vrot;
				vs_vessel.arot = vs_other_gate.arot;

				VECTOR3 outvel = _V(rvel.x, rvel.y, rvel.z);
				VECTOR3 rofs;
				GlobalRot(outvel, rofs);
				vs_vessel.rvel.x = vs_other_gate.rvel.x + rofs.x;
				vs_vessel.rvel.y = vs_other_gate.rvel.y + rofs.y;
				vs_vessel.rvel.z = vs_other_gate.rvel.z + rofs.z;






				v->DefSetStateEx(&vs_vessel);
			
			
	}
	
		}
 
Top