File: weapon_follow.cpp

package info (click to toggle)
rafkill 1.2.2-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 12,196 kB
  • sloc: cpp: 13,298; ansic: 238; makefile: 21; sh: 4
file content (125 lines) | stat: -rw-r--r-- 2,570 bytes parent folder | download | duplicates (3)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "trigtable.h"
#include "weaponobj.h"
#include "weapon_follow.h"
#include "hulls/hull_weapon_follow.h"
#include "spaceobj.h"
#include <cstdlib>
#include <vector>

using namespace std;

#define FOLLOW_SPEED 2.1

Follow::Follow(int qx, int qy, int sang, const vector< SpaceObject * > * f, int al, int _life ):
WeaponNode( qx, qy, 0, 0, new Follow_WHull( _life ), al ),
ang( sang ) {
	fight = f;
	murder = NULL;
}


void Follow::Collided( SpaceObject * who, ExplosionClass ** explr, int M_EX ) {
	addExplode( explr, M_EX, new ExplosionClass(getX(),getY(),0,0,Util::rnd(6) + 3 ) );
}


SpaceObject * Follow::getFight() {

	if ( fight->empty() ) {
		murder = NULL;
		return murder;
	}

	SpaceObject * gay = new SpaceObject(0,0,0,0,NULL,NULL,PLANE_AIR|PLANE_GROUND, alignment );
	bool cy = false;

	for ( vector< SpaceObject * >::const_iterator it = fight->begin(); it != fight->end(); it++ )
		if ( (*it)->CanbeHit( gay ) ) cy = true;
	if ( !cy ) {
		delete gay;
		murder = NULL;
		return murder;
	}

	cy = true;
	if ( murder != NULL ) {
		for ( vector< SpaceObject * >::const_iterator it = fight->begin(); it != fight->end(); ) {
			if ( murder == (*it) ) {
				cy = false;
				it = fight->end();
			} else it++;
		}
	}

	if ( cy ) {
		murder = (*fight)[ Util::rnd( fight->size() ) ];
		while ( !murder->CanbeHit( gay ) ) murder = (*fight)[ Util::rnd( fight->size() ) ];
	}

	delete gay;
	return murder;

}


bool Follow::Damage( double much ) {
	return SpaceObject::Damage( much );
}


/*
void Follow::Explode( ExplosionClass ** explr, int ME ) {
	int q = 0;
	while ( q < ME && explr[q] != NULL )
		q++;
	if ( q >= ME )
		return;
	double a = (double)( Util::rnd( 45 ) + 15 ) / -10.0;
	explr[q] = new ExplosionClass( actualx, actualy, 0, a, Util::rnd( 9 ) + 6 );
}
*/

void Follow::MoveReal() {

	getFight();

	if ( murder != NULL && Util::rnd( 3 ) ) {
		int bang = gang( getX(), getY(), murder->getX(), murder->getY() );
		for ( int q = 0; q < 2; q++ ) {
			if ( abs( bang - ang ) <= 180 ) {
				if ( ang < bang ) ang++;
				else ang--;
			}
			else if ( abs( bang - ang ) >= 270 ) {
				if ( bang > ang )
					ang--;
				else    ang++;
			}
			else {
				if( bang > ang ) ang--;
				else ang++;
			}
			ang += 360;
			ang %= 360;
		}
	}

	/*
	dx = tcos[ ang ] * FOLLOW_SPEED;
	dy = tsine[ ang ] * FOLLOW_SPEED;
	*/
	setDX( Tcos( ang ) * FOLLOW_SPEED );
	setDY( Tsine( ang ) * FOLLOW_SPEED );

	setX( getVX() + getDX() );
	setY( getVY() + getDY() );
	/*
	virtualx += getDX();
	virtualy += getDY();
	*/
	/*
	actualx = (int)virtualx;
	actualy = (int)virtualy;
	*/

}