- Joined
- Jun 6, 2012
- Messages
- 382
- Reaction score
- 254
- Points
- 78
- Location
- Sydney, Australia, Earth, Sol
- Website
- www.orbithangar.com
hey im trying to code a simple vessel, (i want to make a Cassini ad-on) and i have everything working pretty well, but i am having serious trouble with the payload attachment-point coding. i have the attachments working perfectly, and when i define a vessel to be attached to my ship in a scenario, it works, the vessel is attached, but when i press "j" the attached payload is not jettisoned. i have tried so many things to fix this but i just cant get it working 
i have the code here, if anyone could help me out i would really appreciate it...
i have the code here, if anyone could help me out i would really appreciate it...
Code:
//############################################################################//
#define ORBITER_MODULE
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_NONSTDC_NO_DEPRECATE
#include <math.h>
#include <stdio.h>
#include "orbitersdk.h"
//############################################################################//
#include "Cassini.h"
//############################################################################//
int main()
{
return 0;
}
//Class creation
Cassini::Cassini(OBJHANDLE hObj,int fmodel):VESSEL2(hObj,fmodel){}
Cassini::~Cassini(){}
//############################################################################//
//Fill attachment point definition
void Cassini::make_attachment(int n,char *name,char *id,bool loose,bool ischild,double range,VECTOR3 pos,VECTOR3 dir,VECTOR3 rot)
{
strcpy(att[n].id,id);
strcpy(att[n].name,name);
att[n].ischild=ischild;
att[n].loose=loose;
att[n].range=range;
att[n].pos=pos;
att[n].dir=dir;
att[n].rot=rot;
}
//############################################################################//
//All the parameters
void Cassini::clbkSetClassCaps(FILEHANDLE cfg)
{
int i;
THRUSTER_HANDLE **grps;
int *grpc;
//Base stuff
SetSize(10);
SetEmptyMass(2199);
SetPMI(_V(18.91,12.16,14.4));
SetCrossSections(_V(15.67,13.3,16.8));
SetRotDrag(_V(0.5,0.5,0.5));
SetTouchdownPoints(_V(0,-1,3),_V(-3,-1,-3),_V(3,-1,-3));
SetSurfaceFrictionCoeff(0.07,0.3);
SetCW(0.5,0.5,0.5,0.5);
EnableTransponder(true);
InitNavRadios(4);
SetCameraOffset(_V(0,0,0));
SetVisibilityLimit(0,0.002);
SetAlbedoRGB(_V((float)255/255,(float)255/255,(float)255/255));
SetGravityGradientDamping(0);
SetWingAspect(0);
SetWingEffectiveness(0);
SetMaxWheelbrakeForce(200000);
SetBankMomentScale(0);
SetPitchMomentScale(0);
//Attachments
att_on=0;
att_sel=0;
att_blank=0;
make_attachment(0,"","XS",true,true,0,_V(0,1.5,0),_V(0,-1,0),_V(0,0,1));
make_attachment(1,"","GS",false,true,0,_V(0,1.95,0.65),_V(0,1,0),_V(-1,0,0));
make_attachment(2,"","GS",false,true,0,_V(0,1.95,-1.35),_V(0,1,0),_V(-1,0,0));
for(i=0;i<ATTACH_COUNT;i++)att_h[i]=CreateAttachment(att[i].ischild,att[i].pos,att[i].dir,att[i].rot,att[i].id,att[i].loose);
/* set the propellant handle to NULL so I can check if I need to
/* create it in the SetMainStage() function. */
ph_first=NULL;
atchmass = 0.0;
attach = _V(0,0,3.1);
attachdir = _V(0,0,1);
// child pos dir rot handle
attachpos = CreateAttachment (false, attach, attachdir, _V(0,-1,0), "X");
//Fuel
ph_h[0]=CreatePropellantResource(3132);
//Thrusters and groups
grps=(THRUSTER_HANDLE**)malloc(15*sizeof(THRUSTER_HANDLE));
grpc=(int*)malloc(15*sizeof(int));
for(i=0;i<15;i++){grps[i]=(THRUSTER_HANDLE*)malloc(16*sizeof(THRUSTER_HANDLE));grpc[i]=0;}
th_h[0]=CreateThruster(_V(0,0,0),_V(0,0,1),445,ph_h[0],93091.9,0,101400);
grps[0][grpc[0]]=th_h[0];
grpc[0]++;
th_h[1]=CreateThruster(_V(0,0,0),_V(0,1,0),445,ph_h[0],93091.9,0,101400);
grps[2][grpc[2]]=th_h[1];
grpc[2]++;
th_h[2]=CreateThruster(_V(-6,0.7,-0.4),_V(0,-1,0),100,ph_h[0],93091.9,0,101400);
grps[7][grpc[7]]=th_h[2];
grpc[7]++;
th_h[3]=CreateThruster(_V(6,-0.7,-0.4),_V(0,1,0),100,ph_h[0],93091.9,0,101400);
grps[7][grpc[7]]=th_h[3];
grpc[7]++;
th_h[4]=CreateThruster(_V(-6,-0.7,-0.4),_V(0,1,0),100,ph_h[0],93091.9,0,101400);
grps[8][grpc[8]]=th_h[4];
grpc[8]++;
th_h[5]=CreateThruster(_V(6,0.7,-0.4),_V(0,-1,0),100,ph_h[0],93091.9,0,101400);
grps[8][grpc[8]]=th_h[5];
grpc[8]++;
th_h[6]=CreateThruster(_V(0,0,15),_V(0,1,0),100,ph_h[0],93091.9,0,101400);
grps[3][grpc[3]]=th_h[6];
grpc[3]++;
grps[11][grpc[11]]=th_h[6];
grpc[11]++;
th_h[7]=CreateThruster(_V(0,0,-15),_V(0,-1,0),100,ph_h[0],93091.9,0,101400);
grps[3][grpc[3]]=th_h[7];
grpc[3]++;
grps[12][grpc[12]]=th_h[7];
grpc[12]++;
th_h[8]=CreateThruster(_V(0,0,15),_V(0,-1,0),100,ph_h[0],93091.9,0,101400);
grps[4][grpc[4]]=th_h[8];
grpc[4]++;
grps[12][grpc[12]]=th_h[8];
grpc[12]++;
th_h[9]=CreateThruster(_V(0,0,-15),_V(0,1,0),100,ph_h[0],93091.9,0,101400);
grps[4][grpc[4]]=th_h[9];
grpc[4]++;
grps[11][grpc[11]]=th_h[9];
grpc[11]++;
th_h[10]=CreateThruster(_V(0,0,15),_V(1,0,0),100,ph_h[0],93091.9,0,101400);
grps[6][grpc[6]]=th_h[10];
grpc[6]++;
grps[9][grpc[9]]=th_h[10];
grpc[9]++;
th_h[11]=CreateThruster(_V(0,0,-15),_V(-1,0,0),100,ph_h[0],93091.9,0,101400);
grps[6][grpc[6]]=th_h[11];
grpc[6]++;
grps[10][grpc[10]]=th_h[11];
grpc[10]++;
th_h[12]=CreateThruster(_V(0,0,15),_V(-1,0,0),100,ph_h[0],93091.9,0,101400);
grps[5][grpc[5]]=th_h[12];
grpc[5]++;
grps[10][grpc[10]]=th_h[12];
grpc[10]++;
th_h[13]=CreateThruster(_V(0,0,-15),_V(1,0,0),100,ph_h[0],93091.9,0,101400);
grps[5][grpc[5]]=th_h[13];
grpc[5]++;
grps[9][grpc[9]]=th_h[13];
grpc[9]++;
th_h[14]=CreateThruster(_V(0,0,0),_V(0,0,-1),200,ph_h[0],93091.9,0,101400);
grps[14][grpc[14]]=th_h[14];
grpc[14]++;
th_h[15]=CreateThruster(_V(0,0,0),_V(0,0,1),200,ph_h[0],93091.9,0,101400);
grps[13][grpc[13]]=th_h[15];
grpc[13]++;
for(i=0;i<15;i++){
if(i<15)thg_h[i]=CreateThrusterGroup(grps[i],grpc[i],(THGROUP_TYPE)(THGROUP_MAIN+i));
else thg_h[i]=CreateThrusterGroup(grps[i],grpc[i],THGROUP_USER);
}
//Exhausts
AddExhaust(th_h[0],0.75,0.1,_V(0.1,0.25,-2),_V(0,0,-1));
//Meshes
SetMeshVisibilityMode(msh_idh[0]=AddMesh(msh_h[0]=oapiLoadMeshGlobal("cassini\\cassini")),1);
}
//############################################################################//
void Cassini::clbkLoadStateEx(FILEHANDLE scn,void *vs)
{
char *line;
while(oapiReadScenario_nextline(scn,line)){
ParseScenarioLineEx(line,vs);
}
}
//############################################################################//
void Cassini::clbkSaveState(FILEHANDLE scn)
{
SaveDefaultState(scn);
}
//############################################################################//
void Cassini::toggle_attach(int point)
{
VESSEL *v;
DWORD nAttach,i,j;
double dst,min_dst;
VECTOR3 gpos,grms,pos,dir,rot;
OBJHANDLE hv,min_hv;
ATTACHMENTHANDLE tgt_att,min_att;
//const char *id;
min_dst=1e50;
min_att=NULL;
min_hv=NULL;
hv=GetAttachmentStatus(att_h[point]);
if(hv){
//release
DetachChild(att_h[point]);
}else{
//grapple
Local2Global(att[point].pos,grms); //global position of RMS tip
for(i=0;i<oapiGetVesselCount();i++){
hv=oapiGetVesselByIndex(i);
if(hv==GetHandle())continue;
oapiGetGlobalPos(hv,&gpos);
dst=dist(gpos,grms);
if(dst<oapiGetSize(hv)+oapiGetSize(GetHandle())){
v=oapiGetVesselInterface(hv);
nAttach=v->AttachmentCount(true);
for(j=0;j<nAttach;j++){
tgt_att=v->GetAttachmentHandle(true,j);
if(v->GetAttachmentStatus(tgt_att))continue;
//id=v->GetAttachmentId(tgt_att);
//if(strncmp(id,"GS",2))continue;
v->GetAttachmentParams(tgt_att,pos,dir,rot);
v->Local2Global(pos,gpos);
dst=dist(gpos,grms);
if((dst<att[point].range)&&(dst<min_dst)){
min_dst=dst;
min_att=tgt_att;
min_hv=hv;
}
}
}
}
//Attach closest
if(min_att)AttachChild(min_hv,att_h[point],min_att);
}
}
//#######################################################################################//
//Creation
DLLCLBK void InitModule(HINSTANCE hModule){}
DLLCLBK void ExitModule(HINSTANCE hModule){}
DLLCLBK VESSEL *ovcInit(OBJHANDLE hvessel,int flightmodel){return new Cassini(hvessel,flightmodel);}
DLLCLBK void ovcExit(VESSEL *vessel){if(vessel)delete(Cassini*)vessel;}
//#######################################################################################//