1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
#include "StdAfx.h"
#include "mmgr.h"
#include "InterceptHandler.h"
#include "GlobalSynced.h"
#include "Sim/Weapons/Weapon.h"
#include "Sim/Projectiles/WeaponProjectiles/WeaponProjectile.h"
#include "Sim/Units/Unit.h"
#include "Sim/Weapons/WeaponDefHandler.h"
#include "Sim/Weapons/PlasmaRepulser.h"
#include "Sim/Misc/TeamHandler.h"
#include "LogOutput.h"
#include "myMath.h"
#include "creg/STL_List.h"
CR_BIND(CInterceptHandler, )
CR_REG_METADATA(CInterceptHandler, (
CR_MEMBER(interceptors),
CR_MEMBER(plasmaRepulsors),
CR_RESERVED(8)
));
CInterceptHandler interceptHandler;
CInterceptHandler::CInterceptHandler(void)
{
}
CInterceptHandler::~CInterceptHandler(void)
{
}
void CInterceptHandler::AddInterceptorWeapon(CWeapon* weapon)
{
interceptors.push_back(weapon);
}
void CInterceptHandler::RemoveInterceptorWeapon(CWeapon* weapon)
{
interceptors.remove(weapon);
}
void CInterceptHandler::AddInterceptTarget(CWeaponProjectile* target,float3 destination)
{
int targTeam=-1;
if(target->owner())
targTeam=target->owner()->allyteam;
for(std::list<CWeapon*>::iterator wi=interceptors.begin();wi!=interceptors.end();++wi){
CWeapon* w=*wi;
if ((targTeam==-1 || !teamHandler->Ally(w->owner->allyteam,targTeam)) && (target->weaponDef->targetable & w->weaponDef->interceptor) && w->weaponPos.SqDistance2D(destination) < Square(w->weaponDef->coverageRange)){
w->incoming.push_back(target);
w->AddDeathDependence(target);
}
}
}
void CInterceptHandler::AddShieldInterceptableProjectile(CWeaponProjectile* p)
{
for(std::list<CPlasmaRepulser*>::iterator wi=plasmaRepulsors.begin();wi!=plasmaRepulsors.end();++wi){
CPlasmaRepulser* shield=*wi;
if(shield->weaponDef->shieldInterceptType & p->weaponDef->interceptedByShieldType){
shield->NewProjectile(p);
}
}
}
float CInterceptHandler::AddShieldInterceptableBeam(CWeapon* emitter, float3 start, float3 dir, float length, float3& newDir, CPlasmaRepulser*& repulsedBy)
{
float minRange=99999999;
float3 tempDir;
for(std::list<CPlasmaRepulser*>::iterator wi=plasmaRepulsors.begin();wi!=plasmaRepulsors.end();++wi){
CPlasmaRepulser* shield=*wi;
if(shield->weaponDef->shieldInterceptType & emitter->weaponDef->interceptedByShieldType){
float dist=shield->NewBeam(emitter,start,dir,length,tempDir);
if(dist>0 && dist<minRange){
minRange=dist;
newDir=tempDir;
repulsedBy=shield;
}
}
}
return minRange;
}
void CInterceptHandler::AddPlasmaRepulser(CPlasmaRepulser* r)
{
plasmaRepulsors.push_back(r);
}
void CInterceptHandler::RemovePlasmaRepulser(CPlasmaRepulser* r)
{
plasmaRepulsors.remove(r);
}
|