Updated Scripts and added projectile collisions

Added a new projectile collision detection feature.  It requires
projectiles to be added to CollideGroup.  Also added a new
ClientCommandGroup that clients should be added to after they have
finished ghosting.  Currently setMPS effects everything in MoveGroup.
setMPS now uses X, Y, and Z as arguments instead of X only.
This commit is contained in:
Calvin Balke 2015-01-30 13:36:27 -08:00
parent 4830623b7a
commit d0936c3c07
8 changed files with 206 additions and 12 deletions

View file

@ -177,5 +177,7 @@ namespace DX
m_quatF_set_matF_C(ang->x,ang->y,ang->z,ang->w);
}
};
inline float pointdistance(DX::Point3F p1, DX::Point3F p2) {
return (sqrt(pow(p1.x-p2.x,2)+pow(p1.y-p2.y,2)+pow(p1.z-p2.z,2)));
}
} // End NameSpace DX

View file

@ -5,6 +5,9 @@
namespace DX
{
class SceneObject : public NetObject
{
public:
@ -12,6 +15,7 @@ namespace DX
Point3F position;
Point3F scale;
void * container;
float * worldtoobj;
float * objtoworld;
Point3F objboxmin;

View file

@ -4,6 +4,7 @@ namespace DX
{
SceneObject::SceneObject(unsigned int obj) : position(*(float*)(obj + 168), *(float*)(obj + 184), *(float*)(obj + 200)),
scale(*(float*)(obj + 284), *(float*)(obj + 288), *(float*)(obj + 292)),
container((void*)(unsigned int)(obj+0xD8)),
worldtoobj((float*)(obj + 0xDC)),
objtoworld((float*)(obj+0x9C)),
objboxmin(*(float*)(obj + 296), *(float*)(obj + 300), *(float*)(obj + 304)),

View file

@ -5,6 +5,8 @@
#include <LinkerAPI.h>
#include <DXAPI/DXAPI.h>
#include <DXAPI/MatMath.h>
#include <set>
static float counter=0;
static float mpsx=0.0;
static float mpsy=0.0;
@ -13,9 +15,10 @@ static bool moveplayerstoo=1;
static bool clientupdate=false;
static float timecounter=0;
#define CMALLOC (char*)malloc
void sendCommandAll(int argc,char *cmd[])
{
unsigned int mainsim=(unsigned int) Sim::findObjectc("ClientGroup");
unsigned int mainsim=(unsigned int) Sim::findObjectc("ClientCommandGroup");
if (mainsim) {
DX::SimGroup ccg=DX::SimGroup(mainsim);
for (unsigned int x=0; x<ccg.getCount(); x++){
@ -35,7 +38,7 @@ void sendCommandAll(int argc,char *cmd[])
}
void sendGhostCommandAll(int argc,unsigned int obj, DX::Point3F pos)
{
unsigned int mainsim=(unsigned int) Sim::findObjectc("ClientGroup");
unsigned int mainsim=(unsigned int) Sim::findObjectc("ClientCommandGroup");
if (mainsim) {
DX::SimGroup ccg=DX::SimGroup(mainsim);
for (unsigned int x=0; x<ccg.getCount(); x++){
@ -63,6 +66,57 @@ void setClientPosition(unsigned int object,DX::Point3F pos){
sendGhostCommandAll(5,object,pos);
}
static unsigned int objcounter=0;
static unsigned int scenearray[40000000];
static unsigned int objcount1=0;
void collide(unsigned int simgroup){
unsigned int mainsim=(unsigned int)simgroup;
DX::Point3F tmppoint;
objcounter=0;
objcount1=0;
if (mainsim) {
DX::SimObject sim1=DX::SimObject(mainsim);
if ((strcmp((sim1.getClassName()),"SimGroup")==0) || (strcmp((sim1.getClassName()),"SimSet")==0)) {
DX::SimGroup sim2 = DX::SimGroup(mainsim);
for (unsigned int x=0; x<sim2.getCount(); x++) {
DX::SimObject obj2=DX::SimObject(sim2.getObject(x));
if ((strcmp((obj2.getClassName()),"SimGroup")!=0)&&(strcmp((obj2.getClassName()),"SimSet")!=0)) {
scenearray[objcounter]=sim2.getObject(x);
objcounter++;
} else {
//collideRecursive(sim2.getObject(x));
}
}
objcount1=objcounter;
objcounter=0;
for (unsigned int idx=0; idx<objcount1; idx++) {
DX::SceneObject sobj2=DX::SceneObject(scenearray[idx]);
DX::MatrixF mat1=DX::MatrixF(sobj2.objtoworld);
DX::Point3F test;
mat1.getColumn(3,&test);
tmppoint=test;
for (unsigned int iidx=0; iidx<objcount1; iidx++) {
DX::SceneObject sobj3=DX::SceneObject(scenearray[iidx]);
DX::MatrixF mat2=DX::MatrixF(sobj3.objtoworld);
DX::Point3F test2;
mat2.getColumn(3,&test2);
if (DX::pointdistance(test,test2)>3) {
char evalstring[1024]="";
sprintf (evalstring,"ProjCollisionCallback(%d,%d);",sobj2.identifier,sobj3.identifier);
Con::eval(evalstring, false, NULL);
}
}
}
}
}
}
void moveRecursive(unsigned int simgroup,float xoff, float yoff, float zoff){
unsigned int mainsim=(unsigned int)simgroup;
@ -134,19 +188,25 @@ void serverProcessReplacement(unsigned int timeDelta) {
float basex=348.08;
float basey=-178.761;
float basez=113.037;
timecounter+=((float)((timeDelta)*0.001));
if (timecounter>=0.002) {
//timecounter+=((float)((timeDelta)*0.001));
//if (timecounter>=0.002) {
clientupdate=true;
}
//}
if (Sim::findObjectc("MoveGroup")) {
basex+=counter;
DX::SceneObject sobj = DX::SceneObject((unsigned int)Sim::findObjectc("MoveGroup"));
moveRecursive((unsigned int)Sim::findObjectc("MoveGroup"),(mpsx*((float)((timeDelta)*0.001))),(mpsy*((float)((timeDelta)*0.001))),(mpsz*((float)((timeDelta)*0.001))));
Con::eval("MoveRoutineDone();",false,NULL);
}
if (Sim::findObjectc("CollideGroup")) {
basex+=counter;
DX::SceneObject sobj = DX::SceneObject((unsigned int)Sim::findObjectc("CollideGroup"));
collide((unsigned int)Sim::findObjectc("CollideGroup"));
// Con::eval("MoveRoutineDone();",false,NULL);
}
if (clientupdate==true) {
timecounter=0;
clientupdate=false;
//clientupdate=false;
}
__asm

View file

@ -3,7 +3,7 @@ memPatch("A3A100","5052BA00000000B8200000005150526800000000E8C7D6B4FF5A585981C20
memPatch("A3A200","5052BA00000000B8200000005150526800000000E8C7D5B4FF5A585981C20100000039C27CE65A58E9FC8AB8FF");
memPatch("5C2D22","E9D97447009090");
memPatch("5C2D85","E9767347009090");
memPatch("43D72E","7E");
//memPatch("43D72E","7E");
memPatch("0058665C","9090909090909090");
memPatch("00586682","90909090909090909090");
memPatch("005866AB","90909090909090909090");

View file

@ -3,7 +3,7 @@ memPatch("A3A100","5052BA00000000B8200000005150526800000000E8C7D6B4FF5A585981C20
memPatch("A3A200","5052BA00000000B8200000005150526800000000E8C7D5B4FF5A585981C20100000039C27CE65A58E9FC8AB8FF");
memPatch("5C2D22","E9D97447009090");
memPatch("5C2D85","E9767347009090");
memPatch("43D72E","7E");
//memPatch("43D72E","7E");
memPatch("0058665C","9090909090909090");
memPatch("00586682","90909090909090909090");
memPatch("005866AB","90909090909090909090");

View file

@ -4,7 +4,7 @@
loadMod("TSExtension");
$movesim = new SimSet(MoveEffectSet);
function onMoveRoutine(%obj, %offset, %center, %radius){
@ -21,11 +21,138 @@ function onMoveRoutine(%obj, %offset, %center, %radius){
$moveoffset=%offset;
}
$collidegroup = new SimSet(CollideGroup);
function DiscImage::onFire(%data, %obj, %slot)
{
if(%obj.fireTimeoutDisc) //-nite-
return;
// %data.lightStart = getSimTime();
// if( %obj.station $= "" && %obj.isCloaked() )
// {
// if( %obj.respawnCloakThread !$= "" )
// {
// Cancel(%obj.respawnCloakThread);
// %obj.setCloaked( false );
// %obj.respawnCloakThread = "";
// }
// else
// {
// if( %obj.getEnergyLevel() > 20 )
// {
// %obj.setCloaked( false );
// %obj.reCloak = %obj.schedule( 500, "setCloaked", true );
// }
// }
// }
%vehicle = 0;
%weapon = %obj.getMountedImage(0).item;
if(%obj.client.mode[%weapon] == 0)
{
%projectile = "DiscProjectile";
%mode = "LinearProjectile";
%obj.fireTimeoutDisc = 1000; //should be the same as 1.25 -Nite-
%enUse = 0;
%ammoUse = 1;
} //1250
else if(%obj.client.mode[%weapon] == 1)
{
%projectile = "TurboDisc";
%mode = "LinearProjectile";
%obj.fireTimeoutDisc = 1250; //should be the same as .25 -Nite-
%enUse = 7;
%ammoUse = 1;
} //230
else if(%obj.client.mode[%weapon] == 2)
{
%projectile = "PowerDiscProjectile";
%mode = "LinearProjectile";
%enUse = 15;
%ammoUse = 2;
%obj.fireTimeoutDisc = 1500; //should be same as 2.25 -Nite-
} //2250
if(%obj.powerRecirculator)
%enUse *= 0.75;
if(%ammoUse > %obj.getInventory(%data.ammo) || %enUse > %obj.getEnergyLevel())
{
schedule(%obj.fireTimeoutDisc, 0, "DiscFireTimeoutClear", %obj);
return;
}
%p = new(%mode)()
{
dataBlock = %projectile;
initialDirection = %obj.getMuzzleVector(%slot);
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
vehicleObject = %vehicle;
};
CollideGroup.add(%p);
%useEnergyObj = %obj.getObjectMount();
if(!%useEnergyObj)
%useEnergyObj = %obj;
%vehicle = %useEnergyObj.getType() & $TypeMasks::VehicleObjectType ? %useEnergyObj : 0;
// Vehicle Damage Modifier
if(%vehicle)
%p.vehicleMod = %vehicle.damageMod;
if(%obj.damageMod)
%p.damageMod = %obj.damageMod;
if (isObject(%obj.lastProjectile) && %obj.deleteLastProjectile)
%obj.lastProjectile.delete();
%obj.lastProjectile = %p;
%obj.deleteLastProjectile = %data.deleteLastProjectile;
MissionCleanup.add(%p);
// all this for emulating state stuff -Nite-
%obj.play3D(DiscFireSound);// play fire sounds -Nite-
if( %obj.getState() !$= "Dead" ) // +soph
%obj.setActionThread("light_recoil"); //Play anim recoil -Nite-
schedule(500, %obj.play3D(DiscReloadSound),%obj);//play reload sound 500ms after we fire -Nite-
schedule(%obj.fireTimeoutDisc, 0, "DiscFireTimeoutClear", %obj); //Use fire time out for each mode -Nite-
// serverCmdPlayAnim(%obj.client,"light_recoil"); //this worked too lol -Nite-
// AI hook
if(%obj.client)
%obj.client.projectile = %p;
%obj.decInventory(%data.ammo, %ammoUse);
%obj.useEnergy(%enUse);
if(%obj.client.mode[%weapon] == 1)
%obj.applyKick(-500);
if(%obj.client.mode[%weapon] == 2)
%obj.applyKick(-1000);
}
function ProjCollisionCallback(%proj1, %proj2) {
echo(%proj1 SPC "collided with" SPC %proj2);
%proj1.delete();
%proj2.delete();
}
function moveRoutineDone() {
for (%x=0;%x<(MoveEffectSet.getCount()); %x++) {
%obj=MoveEffectSet.getObject(%x);
%obj.setPosition(VectorAdd(%obj.position,$moveoffset));
if(%obj.getType() | $TypeMasks::PlayerObjectType) {
if (%obj.isjetting() || %obj.isjumping() ) {
echo ("Artificial Gravity Disengaged for" SPC %obj);
} else {
%obj.setPosition(VectorAdd(%obj.position,$moveoffset));
}
}
}
MoveEffectSet.clear();
@ -34,4 +161,4 @@ function moveRoutineDone() {
memPatch("5BBBDC",getServPAddr()); //Hooks the serverProcess function
$mg = new SimSet(MoveGroup);
MoveGroup.add(Team1); //Adds the Team1 base to the movement group
setMPS(-10,0.0,0.0); // Moves the base 0.5 meters per second on the X axis.
setMPS(0.0,0.0,0.0); // Moves the base 0.5 meters per second on the X axis.