File: gun_laser.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 (134 lines) | stat: -rw-r--r-- 3,526 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "gunobj.h"
#include "gun_laser.h"
#include "weapons/weapon_laser.h"
#include "hulls/hull_weapon_laser.h"
#include "trigtable.h"
#include "defs.h"
#include <vector>
#include <iostream>

using namespace std;

WeaponLaser::WeaponLaser( int z, int d, int al ):
WeaponObject( d, "Laser", 36000, al, z, 4 ) {
}

WeaponObject * WeaponLaser::copy() {
	return new WeaponLaser( strength, dir, alignment );
}

void WeaponLaser::produceLaser( vector< SpaceObject * > * Ammo, const vector< SpaceObject * > * fight, int x, int y, HullObject * hwho, int al ) {
	
	// if ( fight == NULL || fight->empty() ) return;
	vector< SpaceObject * > fight_hold;
	SpaceObject * use = NULL;

	// SpaceObject * gay = new SpaceObject(0,0,0,0,NULL,NULL,PLANE_AIR|PLANE_GROUND, alignment );
	SpaceObject gay(0,0,0,0,NULL, NULL, PLANE_AIR|PLANE_GROUND, alignment );
	// bool quit = fight->empty();
	int ang = 0;

	for ( vector< SpaceObject * >::const_iterator it = fight->begin(); it != fight->end(); it++ ){
		if ( (*it)->CanbeHit( &gay ) ){
	
			SpaceObject * look = *it;
			ang = getAngle( x, y, look->getX(), look->getY() );
			if ( ang > 75 && ang < 105 ) {
				fight_hold.push_back( look );
			}

		}
	}

	if ( !fight_hold.empty() ){
		use = fight_hold[ Util::rnd( fight_hold.size() ) ];
	}

	/*
	while ( !quit ) {

		/ *
		SpaceObject * look = fight->front();
		fight_hold.push_back( look );
		fight->erase( fight->begin() );
		* /
		SpaceObject * look = (*fight)[ rnd( fight->size() ) ];
		fight_hold.push_back( look );
		vector< SpaceObject * >::iterator erase_it;
		for ( erase_it = fight->begin(); *erase_it != look; erase_it++ ); 
		
		// fight->erase( erase_it );

		if ( look->CanbeHit( &gay ) ) {

			ang = gang( x, y, look->getX(), look->getY() );
			if ( ang > 70 && ang < 110 ) {
				quit = true;
				use = look;
			}
 
		}

		quit = quit || fight->empty();

	}
	*/

	double dx, dy;
	dx = 0;
	const double speed = 22;
	dy = -speed;
	if ( use != NULL ) {
		ang = getAngle( x, y, use->getX(), use->getY() );
		dx = Tcos( ang ) * speed;
		dy = Tsine( ang) * speed;
	}

	Ammo->push_back( new LaserBullet( x, y, dx, dy, hwho, al ) );

	/*
	for ( vector<SpaceObject *>::iterator it = fight_hold.begin(); it != fight_hold.end(); ) {
		fight->push_back( *it );
		fight_hold.erase( it );
	}
	*/

}


void WeaponLaser::MakeShot(int x, int y, vector< SpaceObject * > * Ammo, const vector< SpaceObject * > * fight ) {

	shot_counter = 7;

	switch( strength ) {
		case 0  : {
			produceLaser( Ammo, fight, x, y, new Laser_WHull(0), alignment );
			break;
		}
		case 1  : {
			produceLaser( Ammo, fight, x-4*3, y, new Laser_WHull(0), alignment );
			produceLaser( Ammo, fight, x+4*3, y, new Laser_WHull(0), alignment );
			break;
		}
		case 2  : {
			produceLaser( Ammo, fight, x-8*3, y, new Laser_WHull(0), alignment );
			produceLaser( Ammo, fight, x+8*3, y, new Laser_WHull(0), alignment );
			produceLaser( Ammo, fight, x-3*3, y, new Laser_WHull(0), alignment );
			produceLaser( Ammo, fight, x+3*3, y, new Laser_WHull(0), alignment );

			break;
		}
		case 3  : {
			produceLaser( Ammo, fight, x, y, new Laser_WHull(1), alignment );
			produceLaser( Ammo, fight, x-4*4, y, new Laser_WHull(0), alignment );
			produceLaser( Ammo, fight, x+4*4, y, new Laser_WHull(0), alignment );
			break;
		}
		case 4  : {
			produceLaser( Ammo, fight, x, y, new Laser_WHull(1), alignment );
			produceLaser( Ammo, fight, x-4*4, y, new Laser_WHull(1), alignment );
			produceLaser( Ammo, fight, x+4*4, y, new Laser_WHull(1), alignment );
			break;
		}
	}
}