Added collidable areas which can trigger a script, started work on AI, fixed position secured, updated engine

This commit is contained in:
Light2
2013-12-02 23:58:22 +01:00
parent 6857bd562b
commit 30e1e1c8ec
19 changed files with 574 additions and 26 deletions
@@ -0,0 +1,83 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* This File is part of NGECore2.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Using NGEngine to work with NGECore2 is making a combined work based on NGEngine.
* Therefore all terms and conditions of the GNU Lesser General Public License cover the combination.
******************************************************************************/
package resources.common.collidables;
import java.util.Vector;
import main.NGECore;
import org.python.core.Py;
import org.python.core.PyObject;
import engine.resources.objects.SWGObject;
import engine.resources.scene.Planet;
public abstract class AbstractCollidable {
private PyObject callback;
public Vector<SWGObject> collidedObjects = new Vector<SWGObject>();
private Planet planet;
public abstract boolean doesCollide(SWGObject obj);
public PyObject getCallback() {
return callback;
}
public void setCallback(PyObject callback) {
this.callback = callback;
}
public void addCollidedObject(SWGObject obj) {
collidedObjects.add(obj);
}
public void removeCollidedObject(SWGObject obj) {
collidedObjects.remove(obj);
}
public boolean isInCollisionList(SWGObject obj) {
return collidedObjects.contains(obj);
}
public void doCollisionCheck(SWGObject obj) {
// check if already collided
if(isInCollisionList(obj) && doesCollide(obj)) {
return;
} else if(isInCollisionList(obj) && !doesCollide(obj)) {
removeCollidedObject(obj);
} else if(doesCollide(obj) && !isInCollisionList(obj)) {
addCollidedObject(obj);
if(getCallback() != null)
getCallback().__call__(Py.java2py(NGECore.getInstance()), Py.java2py(obj), Py.java2py(this));
}
}
public Planet getPlanet() {
return planet;
}
public void setPlanet(Planet planet) {
this.planet = planet;
}
}
@@ -0,0 +1,28 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* This File is part of NGECore2.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Using NGEngine to work with NGECore2 is making a combined work based on NGEngine.
* Therefore all terms and conditions of the GNU Lesser General Public License cover the combination.
******************************************************************************/
package resources.common.collidables;
public class CollidableBox {
}
@@ -0,0 +1,74 @@
/*******************************************************************************
* Copyright (c) 2013 <Project SWG>
*
* This File is part of NGECore2.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Using NGEngine to work with NGECore2 is making a combined work based on NGEngine.
* Therefore all terms and conditions of the GNU Lesser General Public License cover the combination.
******************************************************************************/
package resources.common.collidables;
import engine.resources.objects.SWGObject;
import engine.resources.scene.Planet;
import engine.resources.scene.Point3D;
public class CollidableCircle extends AbstractCollidable {
private Point3D center;
private float radius;
// for bh traps
private boolean useYAxis = false;
public CollidableCircle(Point3D center, float radius, Planet planet) {
this.setCenter(center);
this.setRadius(radius);
this.setPlanet(planet);
}
public Point3D getCenter() {
return center;
}
public void setCenter(Point3D center) {
this.center = center;
}
public float getRadius() {
return radius;
}
public void setRadius(float radius) {
this.radius = radius;
}
public boolean isUseYAxis() {
return useYAxis;
}
public void setUseYAxis(boolean useYAxis) {
this.useYAxis = useYAxis;
}
@Override
public boolean doesCollide(SWGObject obj) {
Point3D objectPos = obj.getWorldPosition();
if(useYAxis) {
return center.getDistance(objectPos) <= radius && objectPos.y == center.y;
} else {
return center.getDistance(objectPos) <= radius;
}
}
}
@@ -541,7 +541,7 @@ public class CreatureMessageBuilder extends ObjectMessageBuilder {
}
public IoBuffer buildSpeedModDelta(float speed) {
public IoBuffer buildSpeedModBaseDelta(float speed) {
IoBuffer buffer = bufferPool.allocate(4, false).order(ByteOrder.LITTLE_ENDIAN);
buffer.putFloat(speed);
@@ -552,6 +552,19 @@ public class CreatureMessageBuilder extends ObjectMessageBuilder {
return buffer;
}
public IoBuffer buildSpeedModDelta(float speedModifier) {
IoBuffer buffer = bufferPool.allocate(4, false).order(ByteOrder.LITTLE_ENDIAN);
buffer.putFloat(speedModifier);
int size = buffer.position();
buffer.flip();
buffer = createDelta("CREO", (byte) 4, (short) 1, (short) 5, buffer, size + 4);
return buffer;
}
public IoBuffer buildTurnRadiusDelta(float turnRadius) {
@@ -492,7 +492,7 @@ public class CreatureObject extends TangibleObject implements IPersistent {
synchronized(objectMutex) {
this.speedMultiplierBase = speedMultiplierBase;
}
IoBuffer speedDelta = messageBuilder.buildSpeedModDelta(speedMultiplierBase);
IoBuffer speedDelta = messageBuilder.buildSpeedModBaseDelta(speedMultiplierBase);
notifyObservers(speedDelta, true);
@@ -508,6 +508,9 @@ public class CreatureObject extends TangibleObject implements IPersistent {
synchronized(objectMutex) {
this.speedMultiplierMod = speedMultiplierMod;
}
IoBuffer speedDelta = messageBuilder.buildSpeedModDelta(speedMultiplierMod);
notifyObservers(speedDelta, true);
}
public long getListenToId() {