@@ -9,16 +9,22 @@
#ifndef SRC_INTERACTIONMANAGER_H_
#define SRC_INTERACTIONMANAGER_H_
#include "Pushable.h"
class Projectile;
#include "Projectile.h"
#include "Hittable.h"
#include "InteractionGroup1.h"
#include "InteractionGroup2.h"
class InteractionManager
{
public:
InteractionGroup1<Pushable> push;
InteractionGroup2<Projectile,Hittable> collide;

spacevec chunk;//for debug only

void resetAll();

InteractionManager();
InteractionManager(spacevec myChunk);
~InteractionManager();
};

@@ -0,0 +1,94 @@
/*
* Projectile.cpp
*
* Created on: 04.07.2018
* Author: HL65536
* Version: 2.0
*/

#include "Projectile.h"

#include "WarnErrReporter.h"
#include <algorithm>

void Projectile::interact(Entity* self, DualPointer<Hittable> other, float time,TickServiceProvider* tsp)
{
if(type==0)
{
WarnErrReporter::notInitializedErr("Projectile has no type flag set, ignoring this collision");
return;
}
if(other.pIF->acceptedConversions==0)
{
WarnErrReporter::notInitializedErr("Hittable has no type flag set, ignoring this collision");
return;
}

hitType match=type&other.pIF->acceptedConversions;
if(match==0) return;
int before=collisions.size();
other.pIF->testHit(&collisions,DualPointer<Projectile>(self,this),tsp->getChunkManager());
int after=collisions.size();
if(after) if(!before) tsp->requestRetick((Retickable *)this);
}

//TODO remove includes along with temp code
#include "EntityProjectile.h"
#include "Zombie_Enemy.h"

void Projectile::retick(TickServiceProvider* tsp)
{
int size=collisions.size();
std::cout<<"before:"<<std::endl;
for(int i=0;i<size;i++)
{
std::cout<<collisions[i].location<<" "<<collisions[i].originChunk.x.intpart<<";"<<collisions[i].originChunk.z.intpart<<std::endl;
}
std::stable_sort(collisions.begin(), collisions.end());
std::cout<<"after:"<<std::endl;
for(int i=0;i<size;i++)
{
std::cout<<collisions[i].location<<" "<<collisions[i].originChunk.x.intpart<<";"<<collisions[i].originChunk.z.intpart<<std::endl;
}
for(int i=0;i<size;i++)
{
EntityProjectile * ep=dynamic_cast<EntityProjectile *>(this);
if(ep==0)
{
WarnErrReporter::notInitializedErr("ep is null");
break;
}
Zombie_Enemy * ze=dynamic_cast<Zombie_Enemy *>(collisions[i].hitVictim.e);
if(ze==0)
{
WarnErrReporter::notInitializedErr("ze is null");
break;
}
spacevec middleChunk=tsp->getChunkManager()->getMiddleChunk();
spacevec relPos=ze->pos-middleChunk;
vec3 relPosMeters=tsp->getChunkManager()->toMeters(relPos);
ze->checkProjectile(ep,relPosMeters,tsp->getChunkManager());
break;
//TODO remove above temp code and implement this:
//params=BulletHittable::getBulletTargetParams(...)
//continue,damageProperties=BulletProjectile::applyHit(params);
//BulletHittable::applyDamage(damageProperties);
//if(!continue) break;
}
collisions.clear();
}

void Projectile::registerHitCheck(Entity* e, float seconds,TickServiceProvider* tsp)
{
std::vector<InteractionManager *> * vec = tsp->getInterManVector();
tsp->getChunkManager()->giveInteractionManagers(e,vec,tsp);
int size=vec->size();
for(int i=0;i<size;i++)
{
(*vec)[i]->collide.registerInteractionCheck(this,e,seconds,tsp);
}
}

Projectile::~Projectile()
{}

@@ -0,0 +1,41 @@
/*
* Projectile.h
*
* Created on: 04.07.2018
* Author: HL65536
* Version: 2.0
*/

#ifndef SRC_PROJECTILE_H_
#define SRC_PROJECTILE_H_

#include <vector>
#include "Spacevec.h"
#include "Hittable.h"
#include "DualPointer.h"
#include "Retickable.h"
class Entity;
class TickServiceProvider;
class ProjectileCollision;
class Projectile: public Retickable
{
std::vector<ProjectileCollision> collisions;
public:
hitType type=0;

spacevec posOld;
void interact(Entity * self,DualPointer<Hittable> other, float time, TickServiceProvider* tsp);

void registerHitCheck(Entity * e,float seconds,TickServiceProvider * tsp);

virtual void retick(TickServiceProvider * tsp);

//TODO delete collisions at end of retick

virtual ~Projectile();
};
#include "Entity.h"
#include "TickServiceProvider.h"
#include "ProjectileCollision.h"

#endif /* SRC_PROJECTILE_H_ */
@@ -0,0 +1,29 @@
/*
* ProjectileCollision.cpp
*
* Created on: 09.07.2018
* Author: HL65536
* Version: 1.0
*/

#include "ProjectileCollision.h"


ProjectileCollision::ProjectileCollision(float Location, Entity* asEntity,Hittable* asHittable,spacevec OriginChunk):
location(Location),hitVictim(asEntity,asHittable),originChunk(OriginChunk)
{
}

ProjectileCollision::ProjectileCollision(float Location,DualPointer<Hittable> HitVictim):
location(Location),hitVictim(HitVictim)
{
}

bool ProjectileCollision::operator <(const ProjectileCollision& other) const
{
return location<other.location;
}

ProjectileCollision::~ProjectileCollision()
{}

@@ -0,0 +1,33 @@
/*
* ProjectileCollision.h
*
* Created on: 09.07.2018
* Author: HL65536
* Version: 1.0
*/

#ifndef SRC_PROJECTILECOLLISION_H_
#define SRC_PROJECTILECOLLISION_H_

class Hittable;
#include "Entity.h"
#include "DualPointer.h"
#include "Spacevec.h"

class ProjectileCollision
{
public:
float location;//starting point of projectile this tick=0, end point=1
DualPointer<Hittable> hitVictim;
spacevec originChunk;//TODO remove after debugging


bool operator<(const ProjectileCollision& other) const;

ProjectileCollision(float Location,Entity * asEntity,Hittable * asHittable,spacevec OriginChunk);
ProjectileCollision(float Location,DualPointer<Hittable> HitVictim);
~ProjectileCollision();
};
#include "Hittable.h"

#endif /* SRC_PROJECTILECOLLISION_H_ */
@@ -23,7 +23,7 @@ class Pushable
virtual ~Pushable();
};

#include "Entity.h"
#include "TickServiceProvider.h"
#include "Entity.h"

#endif /* SRC_PUSHABLE_H_ */
@@ -0,0 +1,26 @@
/*
* Retickable.cpp
*
* Created on: 12.07.2018
* Author: HL65536
* Version: 1.0
*/

#include "Retickable.h"

Retickable::Retickable()
{
// TODO Auto-generated constructor stub

}
#include "WarnErrReporter.h"
void Retickable::retick(TickServiceProvider* tsp)
{
WarnErrReporter::noOverrideErr("requested retick without overriding Retickable::retick(...)");
}

Retickable::~Retickable()
{
// TODO Auto-generated destructor stub
}

@@ -0,0 +1,22 @@
/*
* Retickable.h
*
* Created on: 12.07.2018
* Author: HL65536
* Version: 1.0
*/

#ifndef SRC_RETICKABLE_H_
#define SRC_RETICKABLE_H_
class TickServiceProvider;
class Retickable
{
public:
virtual void retick(TickServiceProvider * tsp);

Retickable();
virtual ~Retickable();
};

#include "TickServiceProvider.h"
#endif /* SRC_RETICKABLE_H_ */
@@ -22,10 +22,27 @@ TickServiceProvider::~TickServiceProvider()
void TickServiceProvider::initNextTick()
{
tickID++;
AABB::intersectionCounter=0;
AABB::checkCounter=0;
}

std::vector<InteractionManager*>* TickServiceProvider::getInterManVector()
{
interManVec.clear();
return &interManVec;
}

void TickServiceProvider::doReticks()
{
int size=retickRequests.size();
for(int i=0;i<size;i++)
{
retickRequests[i]->retick(this);
}
retickRequests.clear();
}

void TickServiceProvider::requestRetick(Retickable * r)
{
retickRequests.push_back(r);
}
@@ -16,11 +16,13 @@ class TickServiceProvider;
#include "ChunkManager.h"
class InteractionManager;
#include "InteractionManager.h"
#include "Retickable.h"

//provides services for tickable items
class TickServiceProvider
{
std::vector<InteractionManager *> interManVec;
std::vector<Retickable *> retickRequests;
public:
int tickID=0;
virtual void spawnEntity(Entity * e)=0;//spawns Entity into World
@@ -32,6 +34,8 @@ class TickServiceProvider

//initializes the next tick, call once before ticking everyone
void initNextTick();
void doReticks();
void requestRetick(Retickable * e);

TickServiceProvider();
virtual ~TickServiceProvider();
@@ -0,0 +1,33 @@
/*
* WarnErrReporter.cpp
*
* Created on: 09.07.2018
* Author: HL65536
* Version: 1.0
*/

#include "WarnErrReporter.h"


#include <iostream>


void WarnErrReporter::notInitializedErr(std::string text)
{
std::cout<<std::endl;
std::cout<<std::endl;
std::cout<<"soft error (notInitializedErr): no crash, but this should not have happened:"<<std::endl;
std::cout<<text<<std::endl;
std::cout<<std::endl;
std::cout<<std::endl;
}

void WarnErrReporter::noOverrideErr(std::string text)
{
std::cout<<std::endl;
std::cout<<std::endl;
std::cout<<"soft error (noOverrideErr): no crash, but this should not have happened:"<<std::endl;
std::cout<<text<<std::endl;
std::cout<<std::endl;
std::cout<<std::endl;
}
@@ -0,0 +1,30 @@
/*
* WarnErrReporter.h
*
* Created on: 09.07.2018
* Author: HL65536
* Version: 1.0
*/

#ifndef SRC_WARNERRREPORTER_H_
#define SRC_WARNERRREPORTER_H_

#include <string>

class WarnErrReporter
{
public:

//warnings:


//soft errors (no crash, some default behavior is used)
static void notInitializedErr(std::string text);
static void noOverrideErr(std::string text);

//hard errors (requires crash and extensive log)
//TODO

};

#endif /* SRC_WARNERRREPORTER_H_ */
@@ -6,6 +6,7 @@
Zombie_Enemy::Zombie_Enemy(Timestamp spawnTime,ITexture * texture,spacevec startPos,ChunkManager * chm):
tex(texture),ml(4),cm(chm),legDmg(0),bodyAnim(1,0),fallAnim(0.25f,0,1),transitionAnim(0.5f,0,1)
{
acceptedConversions=FLAG_HIT_TYPE_BULLET;
lastTick=spawnTime;
pos=cm->clip(startPos,true);
v=cm->fromMeters({0,0,0});
@@ -345,23 +346,15 @@ void Zombie_Enemy::tick(Timestamp t,TickServiceProvider * tsp)

bb=AABB(pos,sizeBB);
registerPushCheck((Entity *)this,seconds,tsp);
registerHitCheck((Entity *)this,seconds,tsp);
}

void Zombie_Enemy::checkHitboxes(Zombie_Physics * ph,spacevec middleChunk,ChunkManager * cm)

void Zombie_Enemy::checkProjectile(EntityProjectile * projectile,vec3 relPosMeters,ChunkManager* cm)
{
spacevec relPos=pos-middleChunk;
vec3 relPosMeters=cm->toMeters(relPos);
bool proj=false;
for (int i = 0; i < ph->pCount[0]; i++)
{
if (ph->projectiles[i])
{
if(!ph->projectiles[i]->bb.doesIntersect(bb)) continue;
proj=true;
}
}
if(!proj) return;
std::cout<<"phase 2"<<std::endl;
DualPointer<Projectile> projConv=DualPointer<Projectile>((Entity *)projectile,(Projectile *)projectile);

spacevec middleChunk=cm->getMiddleChunk();
ml.loadIdentity();
ml.translatef(relPosMeters.x, relPosMeters.y, relPosMeters.z);
ml.rotatef(facing, 0, 1, 0);
@@ -381,15 +374,15 @@ void Zombie_Enemy::checkHitboxes(Zombie_Physics * ph,spacevec middleChunk,ChunkM

ml.pushMatrix();//leg
int loc;
Zombie_Physics::hit h;
float hitTime;
loc = 1;
ml.translatef(0, 0.6f, loc * 0.1f);
ml.rotatef(sin(bodyAnim.getCurStepTau(0.25*loc))*30*animStrength, 0, 0, 1);//sin(loc*animStep * 2 *speed/size) * 30*animStrength, 0, 0, 1);
ml.translatef(0, -0.6f, 0);
ml.scalef(1, 3, 1);

h = ph->testHitbox(&ml,-0.1f, 0.1f, 0, 0.2f, -0.1f, 0.1f,middleChunk);
if (h.projectileIndex != -1) gotHit(h, 4, ph->projectiles);
hitTime = checkBox(projConv,&ml,-0.1f, 0.1f, 0, 0.2f, -0.1f, 0.1f,middleChunk);
gotHit(hitTime, 4, projectile);

ml.popMatrix();

@@ -401,8 +394,8 @@ void Zombie_Enemy::checkHitboxes(Zombie_Physics * ph,spacevec middleChunk,ChunkM
ml.translatef(0, -0.6f, 0);
ml.scalef(1, 3, 1);

h = ph->testHitbox(&ml,-0.1f, 0.1f, 0, 0.2f, -0.1f, 0.1f,middleChunk);
if (h.projectileIndex != -1) gotHit(h, 5, ph->projectiles);
hitTime = checkBox(projConv,&ml,-0.1f, 0.1f, 0, 0.2f, -0.1f, 0.1f,middleChunk);
gotHit(hitTime, 5, projectile);

ml.popMatrix();
ml.popMatrix();
@@ -422,9 +415,8 @@ void Zombie_Enemy::checkHitboxes(Zombie_Physics * ph,spacevec middleChunk,ChunkM
ml.scalef(2, 2, 2);
ml.rotatef(tilted, 1, 0, 0);

h = ph->testHitbox(&ml,-0.1f, 0.1f, 0, 0.2f, -0.1f, 0.1f,middleChunk);

if (h.projectileIndex != -1) gotHit(h, 0,ph->projectiles);
hitTime = checkBox(projConv,&ml,-0.1f, 0.1f, 0, 0.2f, -0.1f, 0.1f,middleChunk);
gotHit(hitTime, 0, projectile);


ml.popMatrix();
@@ -434,8 +426,8 @@ void Zombie_Enemy::checkHitboxes(Zombie_Physics * ph,spacevec middleChunk,ChunkM
ml.translatef(0, 0.6f, 0);
ml.scalef(1, 3, 2);

h = ph->testHitbox(&ml,-0.1f, 0.1f, 0, 0.2f, -0.1f, 0.1f,middleChunk);
if (h.projectileIndex != -1) gotHit(h, 1, ph->projectiles);
hitTime = checkBox(projConv,&ml,-0.1f, 0.1f, 0, 0.2f, -0.1f, 0.1f,middleChunk);
gotHit(hitTime, 1, projectile);

ml.popMatrix();

@@ -449,8 +441,8 @@ void Zombie_Enemy::checkHitboxes(Zombie_Physics * ph,spacevec middleChunk,ChunkM
ml.translatef(0, -0.6f, 0);
ml.scalef(1, 3, 1);

h = ph->testHitbox(&ml,-0.1f, 0.1f, 0, 0.2f, -0.1f, 0.1f,middleChunk);
if (h.projectileIndex != -1) gotHit(h, 2, ph->projectiles);
hitTime = checkBox(projConv,&ml,-0.1f, 0.1f, 0, 0.2f, -0.1f, 0.1f,middleChunk);
gotHit(hitTime, 2, projectile);

ml.popMatrix();

@@ -462,19 +454,88 @@ void Zombie_Enemy::checkHitboxes(Zombie_Physics * ph,spacevec middleChunk,ChunkM
ml.translatef(0, -0.6f, 0);
ml.scalef(1, 3, 1);

h = ph->testHitbox(&ml,-0.1f, 0.1f, 0, 0.2f, -0.1f, 0.1f,middleChunk);
if (h.projectileIndex != -1) gotHit(h, 3, ph->projectiles);
hitTime = checkBox(projConv,&ml,-0.1f, 0.1f, 0, 0.2f, -0.1f, 0.1f,middleChunk);
gotHit(hitTime, 3, projectile);

ml.popMatrix();

ml.popMatrix();
}



//TODO remove comment: old system
void Zombie_Enemy::checkHitboxes(Zombie_Physics * ph,spacevec middleChunk,ChunkManager * cm)
{
spacevec relPos=pos-middleChunk;
vec3 relPosMeters=cm->toMeters(relPos);

for (int i = 0; i < ph->pCount[0]; i++)
{
if (ph->projectiles[i])
{
if(ph->projectiles[i]->bb.doesIntersect(bb))
{
checkProjectile(ph->projectiles[i],relPosMeters,cm);
}
}
}
}

float Zombie_Enemy::checkBox(DualPointer<Projectile> projectile,MatrixLib2* ml, float xFrom, float xTo, float yFrom,float yTo, float zFrom, float zTo, spacevec relPos)
{
float ret=-1;
ml->pushMatrix();
ml->translatef(xFrom, yFrom, zFrom);
ml->scalef(xTo - xFrom, yTo - yFrom, zTo - zFrom);
mat4 matOut;
ml->invertMatrix(ml->curMatrix, matOut.mat);

vec3 p1 = matOut* (cm->toMeters(projectile.pIF->posOld-relPos));
vec3 p2 = matOut*(cm->toMeters(projectile.e->pos-relPos));
//projectile now relative to cube, where cube is at 0-1 on all 3 axis
float vx = p2.x - p1.x;//TODO check for 0
float vy = p2.y - p1.y;
float vz = p2.z - p1.z;
float x0 = -p1.x / vx;
float x1 = (1 - p1.x) / vx;
if (x1 < x0)
{
float temp = x0;
x0 = x1;
x1 = temp;
}
float y0 = -p1.y / vy;
float y1 = (1 - p1.y) / vy;
if (y1 < y0)
{
float temp = y0;
y0 = y1;
y1 = temp;
}
float z0 = -p1.z / vz;
float z1 = (1 - p1.z) / vz;
if (z1 < z0)
{
float temp = z0;
z0 = z1;
z1 = temp;
}
float minC = x0 > y0 ? x0 : y0;
minC = minC > z0 ? minC : z0;// max(x0, y0, z0);
float maxC = x1 < y1 ? x1 : y1;
maxC = maxC < z1 ? maxC : z1;// min(x1, y1, z1);
if ((minC<1)&&(maxC>0)&&(minC < maxC))
{
ret = minC;
}
ml->popMatrix();
return ret;
}

void Zombie_Enemy::gotHit(Zombie_Physics::hit hit, int part,EntityProjectile ** shots)
void Zombie_Enemy::gotHit(float time, int part, EntityProjectile * projectile)
{
if (hit.projectileIndex == -1) return;
if(time==-1) return;//no hit
float dmgMult = 0;
//float armDmgMult = 0;
float legDmgMult = 0;
@@ -503,20 +564,149 @@ void Zombie_Enemy::gotHit(Zombie_Physics::hit hit, int part,EntityProjectile **
legDmgMult = 0.55f;
break;
}
legDmg+=legDmgMult*shots[hit.projectileIndex]->fromItem->damagePerJoule;//TODO replace with better logic once guns 2.0 work
remainingHP -= shots[hit.projectileIndex]->fromItem->damagePerJoule*dmgMult;
legDmg+=legDmgMult*projectile->fromItem->damagePerJoule;//TODO replace with better logic once guns 2.0 work
remainingHP -= projectile->fromItem->damagePerJoule*dmgMult;
if(remainingHP<0)
{
remainingHP=-totalHP*dmgMult;//TODO
}
shots[hit.projectileIndex]->pos.y.intpart -= 1000;
shots[hit.projectileIndex]->posOld.y.intpart -= 1000;
projectile->pos.y.intpart -= 1000;
projectile->posOld.y.intpart -= 1000;
if(legDmg>0.25f*totalHP)
{
speed/=2.5f;
}
}

//TODO remove comment: new system
void Zombie_Enemy::testHit(std::vector<ProjectileCollision> * collisions,DualPointer<Projectile> projectile,ChunkManager * cm)
{
spacevec middleChunk=cm->getMiddleChunk();
spacevec relPos=pos-middleChunk;
vec3 relPosMeters=cm->toMeters(relPos);
ml.loadIdentity();
ml.translatef(relPosMeters.x, relPosMeters.y, relPosMeters.z);
ml.rotatef(facing, 0, 1, 0);
ml.scalef(size, size, size);


ml.pushMatrix();
float animStrength=1;
if(legDmg>0.25f*totalHP)
{
ml.translatef(-0.25f*transitionAnim.getCurStep(0)*maxTransition,0.1f*transitionAnim.getCurStep(0)*maxTransition,0);
ml.rotatef(-90*transitionAnim.getCurStep(0)*maxTransition, 0, 0, 1);
animStrength=0.15f*transitionAnim.getCurStep(0)*maxTransition;
}

ml.pushMatrix();//leg
int loc;
float hitTime;
loc = 1;
ml.translatef(0, 0.6f, loc * 0.1f);
ml.rotatef(sin(bodyAnim.getCurStepTau(0.25*loc))*30*animStrength, 0, 0, 1);//sin(loc*animStep * 2 *speed/size) * 30*animStrength, 0, 0, 1);
ml.translatef(0, -0.6f, 0);
ml.scalef(1, 3, 1);

hitTime = checkBox(projectile,&ml,-0.1f, 0.1f, 0, 0.2f, -0.1f, 0.1f,middleChunk);
if((hitTime>=0)&&(hitTime<=1))
{
collisions->push_back(ProjectileCollision(hitTime,(Entity *)this,(Hittable *) this,cm->activeChunk));
}

ml.popMatrix();


ml.pushMatrix(); //leg
loc = -1;
ml.translatef(0, 0.6f, loc * 0.1f);
ml.rotatef(sin(bodyAnim.getCurStepTau(0.25*loc))*30*animStrength, 0, 0, 1);
ml.translatef(0, -0.6f, 0);
ml.scalef(1, 3, 1);

hitTime = checkBox(projectile,&ml,-0.1f, 0.1f, 0, 0.2f, -0.1f, 0.1f,middleChunk);
if((hitTime>=0)&&(hitTime<=1))
{
collisions->push_back(ProjectileCollision(hitTime,(Entity *)this,(Hittable *) this,cm->activeChunk));
}

ml.popMatrix();
ml.popMatrix();


ml.pushMatrix();

if(legDmg>0.25f*totalHP)
{
ml.translatef(0,-0.4f*transitionAnim.getCurStep(0)*maxTransition,0);
ml.rotatef(-35*transitionAnim.getCurStep(0)*maxTransition, 0, 0, 1);
}

ml.pushMatrix(); //head

ml.translatef(0, 1.2f, 0);
ml.scalef(2, 2, 2);
ml.rotatef(tilted, 1, 0, 0);

hitTime = checkBox(projectile,&ml,-0.1f, 0.1f, 0, 0.2f, -0.1f, 0.1f,middleChunk);
if((hitTime>=0)&&(hitTime<=1))
{
collisions->push_back(ProjectileCollision(hitTime,(Entity *)this,(Hittable *) this,cm->activeChunk));
}


ml.popMatrix();


ml.pushMatrix(); //body
ml.translatef(0, 0.6f, 0);
ml.scalef(1, 3, 2);

hitTime = checkBox(projectile,&ml,-0.1f, 0.1f, 0, 0.2f, -0.1f, 0.1f,middleChunk);
if((hitTime>=0)&&(hitTime<=1))
{
collisions->push_back(ProjectileCollision(hitTime,(Entity *)this,(Hittable *) this,cm->activeChunk));
}

ml.popMatrix();



ml.pushMatrix(); //arm
loc = 1;

ml.translatef(0, 1.1f, loc * 0.3f);
ml.rotatef(sin(bodyAnim.getCurStepTau(0.25+0.25*loc))*16+90, 0, 0, 1);//sin(loc*animStep * 2 *speed/size) * 16 + 90
ml.translatef(0, -0.6f, 0);
ml.scalef(1, 3, 1);

hitTime = checkBox(projectile,&ml,-0.1f, 0.1f, 0, 0.2f, -0.1f, 0.1f,middleChunk);
if((hitTime>=0)&&(hitTime<=1))
{
collisions->push_back(ProjectileCollision(hitTime,(Entity *)this,(Hittable *) this,cm->activeChunk));
}

ml.popMatrix();

ml.pushMatrix(); //arm
loc = -1;

ml.translatef(0, 1.1f, loc * 0.3f);
ml.rotatef(sin(bodyAnim.getCurStepTau(0.25+0.25*loc))*16+90, 0, 0, 1);
ml.translatef(0, -0.6f, 0);
ml.scalef(1, 3, 1);

hitTime = checkBox(projectile,&ml,-0.1f, 0.1f, 0, 0.2f, -0.1f, 0.1f,middleChunk);
if((hitTime>=0)&&(hitTime<=1))
{
collisions->push_back(ProjectileCollision(hitTime,(Entity *)this,(Hittable *) this,cm->activeChunk));
}

ml.popMatrix();

ml.popMatrix();
}

void Zombie_Enemy::push(spacevec amount)
{
pos+=amount;//TODO?
@@ -9,8 +9,9 @@
#include "Entity.h"
#include "Pushable.h"
#include "AnimationCycle.h"
#include "Hittable.h"

class Zombie_Enemy: public Entity,public Pushable
class Zombie_Enemy: public Entity,public Pushable,public Hittable
{

struct texCooSet{
@@ -35,7 +36,7 @@ class Zombie_Enemy: public Entity,public Pushable
void drawLeg(int loc,float strength);
void drawTexturedCube(texCooSet textureCoordinates);

void gotHit(Zombie_Physics::hit hit, int part, EntityProjectile ** shots);
void gotHit(float time, int part, EntityProjectile * projectile);

public:
ChunkManager * cm;
@@ -62,8 +63,11 @@ class Zombie_Enemy: public Entity,public Pushable
virtual void draw(Timestamp t,Frustum * viewFrustum,ChunkManager * cm,DrawServiceProvider * dsp);
virtual void tick(Timestamp t,TickServiceProvider * tsp);

void checkProjectile(EntityProjectile * projectile,vec3 relPosMeters,ChunkManager * cm);
float checkBox(DualPointer<Projectile> projectile,MatrixLib2 * ml,float xFrom, float xTo, float yFrom, float yTo, float zFrom, float zTo,spacevec relPos);//valid hit from 0 to 1, otherwise -1
void checkHitboxes(Zombie_Physics * ph,spacevec middleChunk,ChunkManager * cm);

virtual void testHit(std::vector<ProjectileCollision> * collisions,DualPointer<Projectile> projectile,ChunkManager * cm);

virtual void push(spacevec amount);
// virtual spacevec getPos();
@@ -49,8 +49,8 @@ EntityProjectile * Zombie_Gun::tryShoot(Timestamp replaceThisTimestamp,ICamera3D
ml.rotatef(-cam->alpha, 1, 0, 0);
ml.rotatef(-cam->gamma, 0, 0, 1);

float maxSpreadX=1/60.0f;//TODO remove, test only
float maxSpreadY=1/60.0f;//TODO remove, test only
float maxSpreadX=0.5f/60.0f;//9.5f;//1/60.0f;//TODO properly implement
float maxSpreadY=0.5f/60.0f;//9.5f;//1/60.0f;//TODO remove, test only
float greater=maxSpreadX>maxSpreadY?maxSpreadX:maxSpreadY;
if(greater!=0)
ml.scalef(maxSpreadX/greater,maxSpreadY/greater,1);//allow horizontal spread to be different to vertical
@@ -258,9 +258,8 @@ void Zombie_World::loadStandardTex()

void Zombie_World::doPhysics(float sec,Timestamp t)
{
AABB::intersectionCounter=0;
AABB::checkCounter=0;
spacevec mid=cm->getMiddleChunk();
initNextTick();
// spacevec mid=cm->getMiddleChunk();
player->tick(t,this);
hitmark -= sec * 10;
if (hitmark < 0) hitmark = 0;
@@ -286,24 +285,24 @@ void Zombie_World::doPhysics(float sec,Timestamp t)
// std::cout<<"check counter: "<<AABB::checkCounter<<std::endl;
// cm->registerCollisionCheck(DualPointer<Pushable>(player,player),sec,this);
pm->registerTime(timestep++);
#pragma omp parallel for schedule(dynamic, 1)
for (int i = 0; i < zCount; i++)
{
if (zombies[i])
{
if (zombies[i]->remainingHP>0)
{
float hp = zombies[i]->remainingHP;
zombies[i]->checkHitboxes(physics,mid,cm);
if (hp - (zombies[i]->remainingHP))
{
hitmark = 1;
}
int scoreplus= hp-(zombies[i]->remainingHP);
score +=scoreplus;
}
}
}
//#pragma omp parallel for schedule(dynamic, 1)
// for (int i = 0; i < zCount; i++)
// {
// if (zombies[i])
// {
// if (zombies[i]->remainingHP>0)
// {
// float hp = zombies[i]->remainingHP;
// zombies[i]->checkHitboxes(physics,mid,cm);
// if (hp - (zombies[i]->remainingHP))
// {
// hitmark = 1;
// }
// int scoreplus= hp-(zombies[i]->remainingHP);
// score +=scoreplus;
// }
// }
// }
pm->registerTime(timestep++);


@@ -319,7 +318,7 @@ void Zombie_World::doPhysics(float sec,Timestamp t)
shots[i]->tick(t,this);
}
}

doReticks();

}

@@ -518,6 +517,31 @@ void Zombie_World::requestDestroy(Entity* e)
}
else
{
std::cout<<"requestDestroy got called with invalid entityIndex"<<std::endl;
bool found=false;
for (int i = 0; i < pCount; i++)
{
if ((Entity *)shots[i] == e)
{
delete shots[i];
shots[i] = 0;
found=true;
break;
}
}
if(!found)
for (int i = 0; i < zCount; i++)
{
if ((Entity *)zombies[i] == e)
{
delete zombies[i];
zombies[i] = 0;
found=true;
break;
}
}
if(found)
std::cout<<"requestDestroy got called with other entity pointer, was found later"<<std::endl;
else
std::cout<<"requestDestroy got called with invalid entity pointer:"<<std::endl;
}
}
@@ -0,0 +1,18 @@
/*
* hitType.h
*
* Created on: 06.07.2018
* Author: HL65536
* Version: 2.0
*/

#ifndef SRC_HITTYPE_H_
#define SRC_HITTYPE_H_

#define FLAG_HIT_TYPE_BULLET 0x1
#define FLAG_HIT_TYPE_INVENTORY 0x2

typedef unsigned int hitType;//bitvector


#endif /* SRC_HITTYPE_H_ */