- Joined
- Oct 17, 2013
- Messages
- 44
- Reaction score
- 1
I'm a novice programmer in C++,
Here's me taking a stab at making a entity interaction protocol (at least the part of the salvage beam interaction).
Feel free to criticise and suggest improvements. I'll add stuff once I get more done. This is generic and only here to illustrate how I would go about making such a protocol (Stuff behind // gets ignored by the compiler in C++).
Enjoy:
//author: 4plains
//Function: none
//Intention when writing this: Making a example for a easy interaction protocol
//All the ID declaration is probalby unnecessary when implemented into the Source Code of StarMade. I've put it there so the rest of the code makes sense.
#include <iostream>
using namespace std;
void EntityInteractionProtocol(int InteractorID, int InteractorTarget, double InteractionPow, int InteractorSupport=-1, int InteractorEffect=-1)
{
//Declaring all the module interaction IDs for later identification.
//Values are set as constants so that the code cannot modify them.
//These should be provided by a differet part of the source code of StarMade
//module IDs to check for
const short moduleSalvageBeam = 0;
const short moduleCannonProjectile = 1;
const short moduleDmgBeam = 2;
const short moduleDmgPulse = 3;
const short moduleMissile = 4;
const short moduleMiscBeam = 5;
//entity ID's to check for; no further needed as the entity ID's cover all the possible types of ingame entity to check for
const short planetcore = -255;
const short FactionedPlanetPlate = -254;
const short FactionedStation = -253;
const short FactionedShip = -252;
const short HomeBase = -251;
const short IntactShip = -245;
const short Ship = -250;
const short Station = -249;
const short Asteriod = -248;
const short PlanetPlate = -247;
const short Creature = -246; //Includes Players and NPCs
//now the interaction protocol
if (InteractorID == moduleSalvageBeam) //InteractionID is the interactor ID (salvage beam, ...)
{
if (InteractorTarget == planetcore) //InteractorTarget is the interaction target (a type of entity)
return 0; //terminates interaction protocol
if (InteractorTarget == FactionedPlanetPlate)
return 0;
if (InteractorTarget == FactionedStation)
return 0;
if (InteractorTarget == IntactShip) //Factioned ships are automatically also intact and therefore are not salvageable, so no need to check seperately in the salvage beam branch of this interaction protocol.
return 0;
else
{
float virtHP=200;
float virtHP=200.-InteractionPow //substract salvage power from Virtual HP
if (virtHP>=0) //if virtHP falls hits 0 or below block gets removed
//block removal code
return 0;
}
}
// I'll not bother with writing the code for how weapons and misc beams iteract with entities today, this just serves as an example. This is written in C++ language,
// so translation to Java is probably necessary. But it should illustrate how a interaction protocol should work. and how I'd fix the code for salvaging interactions.
Here's me taking a stab at making a entity interaction protocol (at least the part of the salvage beam interaction).
Feel free to criticise and suggest improvements. I'll add stuff once I get more done. This is generic and only here to illustrate how I would go about making such a protocol (Stuff behind // gets ignored by the compiler in C++).
Enjoy:
//author: 4plains
//Function: none
//Intention when writing this: Making a example for a easy interaction protocol
//All the ID declaration is probalby unnecessary when implemented into the Source Code of StarMade. I've put it there so the rest of the code makes sense.
#include <iostream>
using namespace std;
void EntityInteractionProtocol(int InteractorID, int InteractorTarget, double InteractionPow, int InteractorSupport=-1, int InteractorEffect=-1)
{
//Declaring all the module interaction IDs for later identification.
//Values are set as constants so that the code cannot modify them.
//These should be provided by a differet part of the source code of StarMade
//module IDs to check for
const short moduleSalvageBeam = 0;
const short moduleCannonProjectile = 1;
const short moduleDmgBeam = 2;
const short moduleDmgPulse = 3;
const short moduleMissile = 4;
const short moduleMiscBeam = 5;
//entity ID's to check for; no further needed as the entity ID's cover all the possible types of ingame entity to check for
const short planetcore = -255;
const short FactionedPlanetPlate = -254;
const short FactionedStation = -253;
const short FactionedShip = -252;
const short HomeBase = -251;
const short IntactShip = -245;
const short Ship = -250;
const short Station = -249;
const short Asteriod = -248;
const short PlanetPlate = -247;
const short Creature = -246; //Includes Players and NPCs
//now the interaction protocol
if (InteractorID == moduleSalvageBeam) //InteractionID is the interactor ID (salvage beam, ...)
{
if (InteractorTarget == planetcore) //InteractorTarget is the interaction target (a type of entity)
return 0; //terminates interaction protocol
if (InteractorTarget == FactionedPlanetPlate)
return 0;
if (InteractorTarget == FactionedStation)
return 0;
if (InteractorTarget == IntactShip) //Factioned ships are automatically also intact and therefore are not salvageable, so no need to check seperately in the salvage beam branch of this interaction protocol.
return 0;
else
{
float virtHP=200;
float virtHP=200.-InteractionPow //substract salvage power from Virtual HP
if (virtHP>=0) //if virtHP falls hits 0 or below block gets removed
//block removal code
return 0;
}
}
// I'll not bother with writing the code for how weapons and misc beams iteract with entities today, this just serves as an example. This is written in C++ language,
// so translation to Java is probably necessary. But it should illustrate how a interaction protocol should work. and how I'd fix the code for salvaging interactions.
Last edited: