File: formation.cc

package info (click to toggle)
enemylines7 0.6-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,636 kB
  • sloc: cpp: 21,756; makefile: 24
file content (135 lines) | stat: -rw-r--r-- 2,114 bytes parent folder | download | duplicates (5)
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
135


#include "formation.h"
#include "entity.h"

#include "random.h"

namespace PRJID {

Entity * clone(Entity *e) {
	return e->clone();
}

void rv(Entity *e,int dir) {
	Entity *n;

	float dist=Tweak::formation_dist_f();
	float xd[]={dist*-2,dist*-1,dist*1,dist*2};
	float zd[]={dist*2,dist,dist,dist*2};

	int i;
	C3f pos;
	for (i=0;i<4;i++) {
		n=clone(e);
		pos=n->position.get_position();
		if (dir==1) {
			pos.x+=xd[i];
			pos.z+=zd[i];
		} else {
			pos.z+=xd[i];
			pos.x+=zd[i];
		}
		n->position.set_position(pos);
	}
}

void v(Entity *e,int dir) {
	Entity *n;

	float dist=Tweak::formation_dist_f();
	float xd[]={dist*-2,dist*-1,dist*1,dist*2};
	float zd[]={dist*2,dist,dist,dist*2};

	int i;
	C3f pos;
	for (i=0;i<4;i++) {
		n=clone(e);

		pos=n->position.get_position();
		//pos.x+=xd[i];
		//pos.z-=zd[i];
		if (dir==1) {
			pos.x+=xd[i];
			pos.z+=zd[i];
		} else {
			pos.z+=xd[i];
			pos.x+=zd[i];
		}
		n->position.set_position(pos);
	}
}
void line(Entity *e,int dir) {
	Entity *n;

	float dist=Tweak::formation_dist_f()*1.5;
	float xd[]={dist*-2,dist*-1,dist*1,dist*2};

	int i;
	C3f pos;
	for (i=0;i<4;i++) {
		n=clone(e);

		pos=n->position.get_position();
		//pos.x+=xd[i];
		if (dir==1) {
			pos.x+=xd[i];
		} else {
			pos.z+=xd[i];
		}
		n->position.set_position(pos);
	}
}

void parallel(Entity *e,int dir) {
	Entity *n;

	float dist=Tweak::formation_dist_f()*1.5;
	float xd[]={0,dist};
	float zd[]={0,dist,dist*2};

	C3f pos;
	int x,z;

	for (x=0;x<2;x++) {
		for (z=0;z<3;z++) {
			if (x==0&&z==0) continue;
			n=clone(e);

			pos=n->position.get_position();
			if (dir==1) {
				pos.x+=xd[x];
				pos.z+=zd[z];
			} else {
				pos.z+=xd[x];
				pos.x+=zd[z];
			}
			n->position.set_position(pos);


		}
	}


}


void Formation::apply(Entity *e) {
	switch (Random::sget(4)) {
		case 0: v(e,1); break;
		case 1: rv(e,1); break;
		case 2: line(e,1); break;
		case 3: parallel(e,1); break;
	}
}

void Formation::apply2(Entity *e) {
	switch (Random::sget(4)) {
		case 0: v(e,2); break;
		case 1: rv(e,2); break;
		case 2: line(e,2); break;
		case 3: parallel(e,2); break;
	}
}

} //namespace