File: weapon_stick.cpp

package info (click to toggle)
rafkill 1.2.2-3.3
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 13,268 kB
  • sloc: cpp: 13,508; makefile: 64; sh: 14
file content (114 lines) | stat: -rw-r--r-- 2,713 bytes parent folder | download | duplicates (12)
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
#include "weaponobj.h"
#include "weapon_stick.h"
#include "hull.h"
#include "hulls/hull_weapon_explode.h"
#include "ebox.h"
#include "trigtable.h"
#include <vector>
using namespace std;

Sticky::Sticky( int qx, int qy, double kx, double ky, HullObject * hnew, int al, ECollide ** _collide_list, int _max_collide, int _strength ):
WeaponNode(qx,qy,kx,ky,hnew,al),
max_collide( _max_collide ),
tick( -1 ),
bomb_rad( 0 ),
strength( _strength ) {

	collide_list = _collide_list;
	station = NULL;

}


bool Sticky::Damage( double much ) {
	return false;
}


void Sticky::Collided( SpaceObject * who, ExplosionClass ** explr, int M_EX ) {
	if ( tick == -1 ) {
		tick = 30;
		station = who;
		ang = getAngle( station->getX(), station->getY(), getX(), getY() );
		ds = (int) dist( station->getX(), station->getY(), getX(), getY() );
	}

	if ( tick == 0 ) {

		ECollide * ec = hull->getCollide();
		EQuad * e = ec->getLast();
		int x = e->getPosX();
		int y = e->getPosY();
		addExplode( explr, M_EX, new ExplosionClass(x,y,0,0,Util::rnd(6) + 3 ) );
	}
	
	setDX( 0 );
	setDY( 0 );

	/*
	station = check;
	ang = gang( station->actualx, station->actualy, actualx, actualy );
	ds = dist( station->actualx, station->actualy, actualx, actualy );
	*/

}


bool Sticky::Collide(SpaceObject * check) {
	// if ( !CanbeHit( check ) ) return false;
	
	if ( tick > 0 ) return false;
	/*
	bool cy = hull->Collide( actualx, actualy, check );
	if ( cy ){
		station = check;
		ang = gang( station->actualx, station->actualy, actualx, actualy );
		ds = dist( station->actualx, station->actualy, actualx, actualy );
	}
	*/
	return hull->Collide( getX(), getY(), check );
}


void Sticky::MoveMe( vector< SpaceObject * > * Ammo, const vector< SpaceObject * > * fight, Section * onscreen ){

	if ( tick > 0 ) {
		tick--;
		if ( tick == 0 ) {

			this->giveHull( new Explode_WHull( strength, collide_list, max_collide ) );
			collide_list = NULL;

		}
	}

	if ( tick == 0 ) {
		/*
		bomb_rad = (bomb_rad+1) % 3;
		if ( bomb_rad == 0 ) hull->Moved( 0, 0, 0, 0 );
		*/
		hull->Moved( 0, 0, 0, 0 );
	}
	MoveReal();
	if ( station != NULL && tick != 0 ) {

		vector< SpaceObject * >::const_iterator it;
		for ( it = fight->begin(); station != *it && it != fight->end(); it++ );
		if ( it == fight->end() )tick = 1;
		else this->SetCoordXY( (int)(station->getX()+Tcos(ang)*ds), (int)(station->getY()+Tsine(ang)*ds) );

	}

	// if ( hull ) hull->addSection( this, onscreen, getX(), getY() );
	// return ( getX() < -20 || getX() > screen_x + 20 || getY() < -10 || getY() > screen_y + 20 );

}


Sticky::~Sticky() {
	if ( collide_list != NULL ) {
		//for ( int q = 0; q < max_collide; q++ )
		//	delete collide_list[q];
		//delete[] collide_list;
	}
}