summaryrefslogtreecommitdiff
path: root/src/ring.c
blob: 909a90fbbd142b9e934cc5944a1d9388ac400dd3 (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
#include <assert.h>
#include <stdlib.h>

#include "ring.h"
#include "tower.h"

void pickup_ring() {
	int i;
	int pickup = -1;

	// should not be called if we are already holding a ring
	assert(held == NULL);

	// find the smallest ring on the currently hovered tower (if there is one)
	for(i = 2; i >= 0; --i) {
		if(rings[i].location == hover) {
			pickup = i;
			break;
		}
	}

	if(pickup >= 0) {
		held = &rings[pickup];
		held->held = true;
		towers[hover].rings[pickup] = false;
	}
}

bool drop_ring() {
	int i;

	// should not be called if we are not holding a ring
	assert(held != NULL);

	//determine if we are allowed to drop the ring here
	for(i = 2; i > held->size; --i) {
		if(towers[held->location].rings[i]) {
			return false;
		}
	}

	held->held = false;
	towers[held->location].rings[i] = true;
	held = NULL;
	return true;
}

bool check_win_condition() {
	int i;

	for(i = 0; i < 3; ++i) {
		if(rings[i].location != 2) return false;
	}

	return true;
}