Jump to content

[0.14] Instant Orbit / Debris Generator with bonus Asteroid


JellyCubes

Recommended Posts

A very simple program that can put ships into orbit and change the orbits of any existing ships in orbit. You can put a ship into low Kerbin orbit, geosynchronous orbit, low Mun orbit, Kerbol orbit, anything.

Put the file into the same folder as the persistent save files. Enter the name of the ship and change the orbital parameters. Program will change the orbital parameters of all ships with the same name. Program can be used while in the Space Center so you don\'t have to close KSP.

Backup your save just in case of any errors.


#include <fstream>
#include <string>
#include <stdio.h>

using namespace std;

int main()
{
ifstream saveFile('persistent.sfs');
ofstream writeFile('intermediate.sfs', ios::out | ios::binary);

string lineWhole;
int shipNumber = 0;

string shipName;
int shipOrbit;
string shipSemiMajorAxis;
string shipEccentricity;
string shipInclination;

cout << 'Enter name of ship:\n';
getline(cin,shipName);

cout << '\nEnter orbiting body:\n 0 - Kerbol\n 1 - Kerbin\n 2 - Mun\n';
cin >> shipOrbit;

cout << '\nEnter semi-major axis (in metres):\n';
cin >> shipSemiMajorAxis;

cout << '\nEnter eccentricity:\n';
cin >> shipEccentricity;

cout << '\nEnter inclination (in degrees):\n';
cin >> shipInclination;

while(getline(saveFile,lineWhole)){;

if(lineWhole.find(shipName)==8){
shipNumber = 1;
writeFile << lineWhole << '\n';
}
else if(shipNumber==1 && lineWhole.substr(1,5)=='sit ='){
writeFile << '\tsit = ORBITING' << '\n';
}
else if(shipNumber==1 && lineWhole.substr(1,8)=='landed ='){
writeFile << '\tlanded = False' << '\n';
}
else if(shipNumber==1 && lineWhole.substr(1,10)=='landedAt ='){
writeFile << '\tlandedAt = ' << '\n';
}
else if(shipNumber==1 && lineWhole.substr(2,5)=='SMA ='){
writeFile << '\t\tSMA = ' << shipSemiMajorAxis << '\n';
}
else if(shipNumber==1 && lineWhole.substr(2,5)=='ECC ='){
writeFile << '\t\tECC = ' << shipEccentricity << '\n';
}
else if(shipNumber==1 && lineWhole.substr(2,5)=='INC ='){
writeFile << '\t\tINC = ' << shipInclination << '\n';
}
else if(shipNumber==1 && lineWhole.substr(2,5)=='REF ='){
writeFile << '\t\tREF = ' << shipOrbit << '\n';
shipNumber = 0;
}
else{
writeFile << lineWhole << '\n';
}
}

saveFile.close();
writeFile.close();

int deleteResult = remove('persistent.sfs');
int renameResult = rename('intermediate.sfs','persistent.sfs');

if(renameResult!=0){
perror('Rename error');
}

if(deleteResult!=0){
perror('Delete error');
}

return 0;
}
#include <iostream>

Code if you want to compile it yourself. Code is probably crappy since it\'s the first program I\'ve made with C++.

Instant Orbit / Orbit Modifier V0.1


A debris field generator that puts debris into orbit. It is limited to debris with only one part. Need to enter every orbital parameter, which may be a good or bad thing depending on your point of view.

Space is so vast that unless you have tens of thousands of parts in the same orbit, you\'re unlikely to hit anything when travelling through a debris field. As a reference, our own asteroid belt only is only around 4% of the mass of the moon.

U5Osz.jpg

Debris Field Generator

500 meter Asteroid


#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <stdio.h>
#include <iomanip>

using namespace std;

double randomNumberFunction();

int main()
{
srand(time(0));

ifstream openFile('persistent.sfs');

if(openFile.is_open()){
openFile.close();
}
else{
openFile.close();
ofstream writeFile('persistent.sfs', ios::out | ios::binary | ios::app);
writeFile << '// KSP Flight State\n\nversion = 0.14.0\nUT = 0\nactiveVessel = 0\n';
writeFile.close();
}

int shipuid = time(0);

string shipName;
cout << 'Enter name of debris:\n(Name of the debris displayed in the game.)' << endl;
getline(cin,shipName);

string shipID;
cout << '\nEnter debris ID name:\n(Name of the part. The name in the config file.)' << endl;
getline(cin,shipID);

double shipMass;
cout << '\nEnter debris mass:' << endl;
cin >> shipMass;

int shipAmount;
cout << '\nAmount of debris to add:' << endl;
cin >> shipAmount;

double shipSMA;
cout << '\nEnter semi-major axis:' << endl;
cin >> shipSMA;

double shipSMAVar;
cout << '\nEnter semi-major axis variance:\n(Will add or subtract a random value up to this number to the semi-major axis.)' << endl;
cin >> shipSMAVar;

double shipECC;
cout << '\nEnter eccentricity:' << endl;
cin >> shipECC;

double shipECCVar;
cout << '\nEnter eccentricity variance:\n(Will add or subtract a random value up to this number to the eccentricity.)' << endl;
cin >> shipECCVar;

double shipINC;
cout << '\nEnter inclination:' << endl;
cin >> shipINC;

double shipINCVar;
cout << '\nEnter inclination variance:\n(Will add or subtract a random value up to this number to the inclination.)' << endl;
cin >> shipINCVar;

double shipLPE;
cout << '\nEnter longitude of periapsis (in degrees):' << endl;
cin >> shipLPE;

double shipLPEVar;
cout << '\nEnter longitude of periapasis variance:\n(Will add or subtract a random value up to this number to the longitude of periapsis.)' << endl;
cin >> shipLPEVar;

double shipLAN;
cout << '\nEnter longitude of ascending node (in degrees):' << endl;
cin >> shipLAN;

double shipLANVar;
cout << '\nEnter longitude of ascending node variance:\n(Will add or subtract a random value up to this number to the longitude of ascending node.)' << endl;
cin >> shipLANVar;

double shipMNAStart;
cout << '\nEnter start of mean anomaly where debris will spawn:\n(Mean anomaly refers to where the debris will spawn along the orbit. Enter a number between 0 and 6.2832.)\n(0 will spawn debris at periapsis, 3.1415 will spawn debris at apoapsis and 6.2832 will spawn debris back at periapsis.)' << endl;
cin >> shipMNAStart;

double shipMNAEnd;
cout << '\nEnter end of mean anomaly:' << endl;
cin >> shipMNAEnd;

double shipMNAVar;
cout << '\nEnter mean anomaly variance:\n(Will add or subtract a random value up to this number to the mean anomaly.)' << endl;
cin >> shipMNAVar;

string shipRef;
cout << '\nEnter orbiting body:\n 0 - Kerbol\n 1 - Kerbin\n 2 - Mun\n';
cin >> shipRef;

double shipMNAInc = (shipMNAEnd - shipMNAStart)/shipAmount;

ofstream writeFile('persistent.sfs', ios::out | ios::binary | ios::app);

for(int ii=0; ii<shipAmount; ii++){
writeFile << setiosflags(ios::fixed) << setprecision(8) << 'VESSEL {' << endl;
writeFile << '\tname = ' << shipName << endl << '\tsit = ORBITING\n\tlanded = False\n\tlandedAt = \n\tsplashed = False' << endl;
writeFile << '\tmet = 0\n\tlct = 0\n\troot = 0\n\tpos = 0,0,0\n\tlat = 0\n\tlon = 0\n\talt = 0' << endl;
writeFile << '\trot = ' << 2*randomNumberFunction()-1 << ',' << 2*randomNumberFunction()-1 << ',' << 2*randomNumberFunction()-1 << ',' << 2*randomNumberFunction()-1 << endl;
writeFile << '\tCoM = 0,0,0\n\tstg = 0\n\tORBIT {' << endl;
writeFile << '\t\tSMA = ' << shipSMA + 2*randomNumberFunction()*shipSMAVar - shipSMAVar << endl;
writeFile << '\t\tECC = ' << shipECC + 2*randomNumberFunction()*shipECCVar - shipECCVar << endl;
writeFile << '\t\tINC = ' << shipINC + 2*randomNumberFunction()*shipINCVar - shipINCVar << endl;
writeFile << '\t\tLPE = ' << shipLPE + 2*randomNumberFunction()*shipLPEVar - shipLPEVar << endl;
writeFile << '\t\tLAN = ' << shipLAN + 2*randomNumberFunction()*shipLANVar - shipLANVar << endl;
writeFile << '\t\tMNA = ' << shipMNAStart + ii * shipMNAInc + 2*randomNumberFunction()*shipMNAVar - shipMNAVar << endl;
writeFile << '\t\tEPH = 0' << endl;
writeFile << '\t\tREF = ' << shipRef << endl << '\t\tOBJ = 1\n\t}' << endl;

writeFile << '\tPART {\n\t\tname = ' << shipID << endl;
writeFile << '\t\tuid = ' << shipuid + ii << endl;
writeFile << '\t\tparent = 0\n\t\tposition = 0,0,0\n\t\trotation = 0,0,0,1\n\t\tistg = 0\n\t\tdstg = 0\n\t\tsqor = 0\n\t\tsidx = 0\n\t\tattm = 0\n\t\tcData = \n\t\tsrfN = None, -1\n\t\tattN = None, -1' << endl;
writeFile << '\t\tmass = ' << shipMass << endl;
writeFile << '\t\ttemp = 0\n\t\texpt = 0.5\n\t\tstate = 2\n\t\tconnected = False\n\t\tattached = True' << endl;
writeFile << '\t}\n}' << endl;
}

return 0;
}

double randomNumberFunction()
{
double randomNumber = ((double)rand())/(double)RAND_MAX;
return randomNumber;
}
#include <iostream>

Link to comment
Share on other sites

So instead of just orbiting we can modify those orbits?

The semi-major axis, eccentricity and inclination can currently be changed for any ship. Longitude of ascending node, and craft position along the orbit can\'t be changed.

Only test this with 0.14 x2 but I presume it would work for the other experimental builds.

Link to comment
Share on other sites

The semi-major axis is the sum of the apoapse radius and periapse radius (NOT altitude) divided by two. For a circular orbit, the semi-major axis is equal to the orbital radius.

Kerbin radius = 600 000 m

Mun radius = 200 000 m

Kerbol radius = 65 400 000 m

Geostationary Kerbin orbit semi-major axis = 3 468 400 m

Link to comment
Share on other sites

I still find this to be cheating. But it is still cool that this can exist.

I still find that thinking cheating exists in a sandbox singleplayer game is ridiculous :P. Think of it as simulating orbital construction before we get orbital construction.

Link to comment
Share on other sites

I still find that thinking cheating exists in a sandbox singleplayer game is ridiculous :P. Think of it as simulating orbital construction before we get orbital construction.

Well if it were to be something that you can easily get into escape velocity then don\'t expect any praise from the community. This will be mainly for stations and stuff.

Link to comment
Share on other sites

Well if it were to be something that you can easily get into escape velocity then don\'t expect any praise from the community. This will be mainly for stations and stuff.

Still not cheating. If you find more enjoyment from this so called 'cheating' or you are testing for bugs with it, there\'s no problem with it. And in a sandbox single player game those are the only 2 reasons you\'d really do that. In relation to roleplaying, it can be considered cheating, but there are already rules for this.

Link to comment
Share on other sites

I\'m afraid I\'m still rather in-the-dark as to how to use this particular program...

..may I ask for a more in-depth tutorial? Is it possible to put a vehicle currently in the VAB into an 'instant orbit'?

Link to comment
Share on other sites

I\'m afraid I\'m still rather in-the-dark as to how to use this particular program...

..may I ask for a more in-depth tutorial? Is it possible to put a vehicle currently in the VAB into an 'instant orbit'?

As far as I understand the saving system your ship has to be on the launchpad. From there you press Esc and get back to the Space Center so your craft remains on the launchpad but is written in the persistance.sfs. Turn on the Orbit Changer (has to lie in the same folder as the persistance.sfs) and type in the name under which you saved your craft in the VAB (so save it before you launch). The name has to be unique because the program can\'t differ between multiple ships with the same name. In the next steps the program asks for the orbital parameters and there you go.

Link to comment
Share on other sites

[list type=decimal]

[li]Put the Instant Orbit program in the /saves/default folder in Kerbal Space Program.[/li]

[li]Launch a ship in KSP and immediately return to the Space Center (don\'t end the flight). The ship should still be on the launchpad. Check the Flight Tracking building to confirm.[/li]

[li]If KSP is still open, return to the main Space Center scene and then open the Instant Orbit program.[/li]

[li]Enter the name of the ship that was just launched and then follow the prompts.[/li]

Step 2 is only required if you want to put something directly into orbit. Ships that are already in orbit and have their orbits changed.

All ships with the same name will have their orbits changed.

Link to comment
Share on other sites

[ quote author=Gojira link=topic=7844.msg115619#msg115619 date=1330701392]

Mac version please?

ignore that

but really, will there be a mac version?

Sorry, but I neither own a Mac or know how to cross-compile.

Link to comment
Share on other sites

I compiled a Mac version based on the source in JellyCube\'s first post.

I can\'t test it properly because being in low-bandwidth land this week means I haven\'t been able to download KSP yet... but a few simple tests show that it\'s working.

To run it, stick it in the folder with the save file, right click (or hold ctrl and click) the program, and select 'Open With->Terminal'.

Please let me know if this works for you!

*Usual disclaimers: Back up your save file first or risk breaking it, be careful about programs from an unknown source (i.e.: me, teehee), I give no warrantee nor guarantees that this will work or not harm your computer*

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...