summaryrefslogtreecommitdiff
path: root/src/elements/figh.c
blob: 74dcf14dc3a9c9293bbe66bb6040a6a6dab11381 (plain)
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
#include <element.h>

int update_FIGH(UPDATE_FUNC_ARGS)
{
	float* figh = fighters[(unsigned char)parts[i].tmp];

	float tarx, tary;

	parts[i].tmp2 = 0; //0 - stay in place, 1 - seek a stick man

	//Set target cords
	if (player[27])
	{
		if (player2[27])
			if ((pow(player[5]-x, 2) + pow(player[6]-y, 2))<=
					(pow(player2[5]-x, 2) + pow(player2[6]-y, 2)))
			{
				tarx = player[5];
				tary = player[6];
			}
			else
			{
				tarx = player2[5];
				tary = player2[6];
			}
		else
		{
			tarx = player[5];
			tary = player[6];
		}

		parts[i].tmp2 = 1;
	}
	else
		if (player2[27])
		{
			tarx = player2[5];
			tary = player2[6];

			parts[i].tmp2 = 1;
		}

	switch (parts[i].tmp2)
	{
		case 1:
			if ((pow(tarx-x, 2) + pow(tary-y, 2))<600)
			{
				if (figh[2] == PT_FIRE || figh[2] == PT_LIGH)
					figh[0] = (int)figh[0] | 0x08;
			}
			else
				if (tarx<x)
				{
					figh[0] = 0x01;
					if (!eval_move(PT_DUST, figh[7]-4, figh[8]-1, NULL) || !eval_move(PT_DUST, figh[15]-4, figh[16]-1, NULL))
						figh[0] = (int)figh[0] | 0x04;
				}
				else
				{
					figh[0] = 0x02;
					if (!eval_move(PT_DUST, figh[7]+4, figh[8]-1, NULL) || !eval_move(PT_DUST, figh[15]+4, figh[16]-1, NULL))
						figh[0] = (int)figh[0] | 0x04;
				}
			break;
		default:
			figh[0] = 0;
			break;
	}

	figh[1] = figh[0];

	run_stickman(figh, UPDATE_FUNC_SUBCALL_ARGS);
	return 0;
}