3
*************************************************************************
5
ArmageTron -- Just another Tron Lightcycle Game in 3D.
6
Copyright (C) 2000 Manuel Moos (manuel@moosnet.de)
8
**************************************************************************
10
This program is free software; you can redistribute it and/or
11
modify it under the terms of the GNU General Public License
12
as published by the Free Software Foundation; either version 2
13
of the License, or (at your option) any later version.
15
This program is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
GNU General Public License for more details.
20
You should have received a copy of the GNU General Public License
21
along with this program; if not, write to the Free Software
22
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
***************************************************************************
30
#include "eDebugLine.h"
37
eSensor::eSensor(eGameObject *o,const eCoord &start,const eCoord &d)
38
:eGameObject(o->grid, start,d,o->currentFace,0),owned(o)
39
,hit(1000),ehit(NULL),lr(0)
43
currentFace=owned->currentFace;
45
// find a better current face if our start postion is not really at the
46
// current position of the owner
47
if ( grid && !currentFace || !currentFace->IsInside( pos ) && currentFace->IsInside( owned->pos ) )
49
currentFace = o->grid->FindSurroundingFace( pos, currentFace );
56
void eSensor::PassEdge(const eWall *w,REAL time,REAL a,int){
62
if (owned && !owned->EdgeIsDangerous(w, owned->LastTime(), a))
67
const eHalfEdge *e = w->Edge();
69
eCoord eEdge_dir=w->Vec();
70
eCoord collPos = w->Point( a );
72
// con << dir << eEdge_dir << '\n';
73
REAL dec=- eEdge_dir*dir;
84
before_hit=collPos-dir*.000001;
89
//void eSensor::PassEdge(eEdge *e,REAL time,REAL a,int recursion){
90
// PassEdge((const eEdge *)e,time,a,recursion);
93
void eSensor::detect(REAL range){
94
// eCoord start = pos;
96
before_hit=pos+dir*(range-.001);
103
ePoint b(pos+dir*range);
107
for(int i=eGameObject::gameObjects.Len()-1;i>=0;i--){
108
eGameObject *target=gameobject::gameObjects(i);
110
if (target->type()==ArmageTron_CYCLE){
111
gCycle *c=(gCycle *)target;
112
if (c->Alive() && c!=owned){
113
const eEdge *oe=c->Edge();
115
ePoint *meet=e.IntersectWith(oe);
117
if (meet){ // whoops. Hit!
118
REAL ratio=oe->Ratio(*meet);
119
// gPlayerWall *w=(gPlayerWall *)oe->w;
120
REAL time=e.Ratio(*meet)*range;
121
PassEdge(oe,time,ratio,1);
131
Move(pos+dir*range,0,range);
136
eDebugLine::SetColor (0, 1, 1);
137
eDebugLine::Draw(start, .1, before_hit, .1);
139
eDebugLine::SetColor (0, .5, 1);
140
eDebugLine::Draw(before_hit, .1, before_hit, 2.0);
144
eDebugLine::SetColor (1, 0, 0);
145
eDebugLine::Draw(start, .5, pos, .5);