File: region.cpp

package info (click to toggle)
sludge 2.2.2-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,852 kB
  • sloc: cpp: 32,432; sh: 1,237; makefile: 634; xml: 284
file content (142 lines) | stat: -rw-r--r-- 3,775 bytes parent folder | download | duplicates (7)
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
136
137
138
139
140
141
142
#include "allfiles.h"
#include "objtypes.h"
#include "region.h"
#include "newfatal.h"
#include "sludger.h"
#include "moreio.h"
#include "backdrop.h"

screenRegion * allScreenRegions = NULL;
screenRegion * overRegion = NULL;
extern inputType input;
extern int cameraX, cameraY;

void showBoxes () {
	screenRegion * huntRegion = allScreenRegions;

	while (huntRegion) {
		drawVerticalLine (huntRegion -> x1, huntRegion -> y1, huntRegion -> y2);
		drawVerticalLine (huntRegion -> x2, huntRegion -> y1, huntRegion -> y2);
		drawHorizontalLine (huntRegion -> x1, huntRegion -> y1, huntRegion -> x2);
		drawHorizontalLine (huntRegion -> x1, huntRegion -> y2, huntRegion -> x2);
		huntRegion = huntRegion -> next;
	}
}

void removeScreenRegion (int objectNum) {
	screenRegion * * huntRegion = & allScreenRegions;
	screenRegion * killMe;

	while (* huntRegion) {
		if ((* huntRegion) -> thisType -> objectNum == objectNum) {
			killMe = * huntRegion;
			* huntRegion = killMe -> next;
			removeObjectType (killMe -> thisType);
			if (killMe == overRegion) overRegion = NULL;
			delete killMe;
			killMe = NULL;
		} else {
			huntRegion = & ((* huntRegion) -> next);
		}
	}
}

void saveRegions (FILE * fp) {
	int numRegions = 0;
	screenRegion * thisRegion = allScreenRegions;
	while (thisRegion) {
		thisRegion = thisRegion -> next;
		numRegions ++;
	}
	put2bytes (numRegions, fp);
	thisRegion = allScreenRegions;
	while (thisRegion) {
		put2bytes (thisRegion -> x1, fp);
		put2bytes (thisRegion -> y1, fp);
		put2bytes (thisRegion -> x2, fp);
		put2bytes (thisRegion -> y2, fp);
		put2bytes (thisRegion -> sX, fp);
		put2bytes (thisRegion -> sY, fp);
		put2bytes (thisRegion -> di, fp);
		saveObjectRef (thisRegion -> thisType, fp);

		thisRegion = thisRegion -> next;
	}
}

void loadRegions (FILE * fp) {
	int numRegions = get2bytes (fp);

	screenRegion * newRegion;
	screenRegion * * pointy = & allScreenRegions;

	while (numRegions --) {
		newRegion = new screenRegion;
		* pointy = newRegion;
		pointy = & (newRegion -> next);

		newRegion -> x1 = get2bytes (fp);
		newRegion -> y1 = get2bytes (fp);
		newRegion -> x2 = get2bytes (fp);
		newRegion -> y2 = get2bytes (fp);
		newRegion -> sX = get2bytes (fp);
		newRegion -> sY = get2bytes (fp);
		newRegion -> di = get2bytes (fp);
		newRegion -> thisType = loadObjectRef (fp);
	}
	* pointy = NULL;
}

void killAllRegions () {
	screenRegion * killRegion;
	while (allScreenRegions) {
		killRegion = allScreenRegions;
		allScreenRegions = allScreenRegions -> next;
		removeObjectType (killRegion -> thisType);
		delete killRegion;
	}
	overRegion = NULL;
}

bool addScreenRegion (int x1, int y1, int x2, int y2, int sX, int sY, int di, int objectNum) {
	screenRegion * newRegion = new screenRegion;
	if (! checkNew (newRegion)) return false;
	newRegion -> di = di;
	newRegion -> x1 = x1;
	newRegion -> y1 = y1;
	newRegion -> x2 = x2;
	newRegion -> y2 = y2;
	newRegion -> sX = sX;
	newRegion -> sY = sY;
	newRegion -> thisType = loadObjectType (objectNum);
	newRegion -> next = allScreenRegions;
	allScreenRegions = newRegion;
	return (bool) (newRegion -> thisType != NULL);
}

void getOverRegion () {
	screenRegion * thisRegion = allScreenRegions;
	while (thisRegion) {
		if ((input.mouseX >= thisRegion -> x1 - cameraX) && (input.mouseY >= thisRegion -> y1 - cameraY) &&
			 (input.mouseX <= thisRegion -> x2 - cameraX) && (input.mouseY <= thisRegion -> y2 - cameraY)) {
			overRegion = thisRegion;
			return;
		}
		thisRegion = thisRegion -> next;
	}
	overRegion = NULL;
	return;
}

screenRegion * getRegionForObject (int obj) {
	screenRegion * thisRegion = allScreenRegions;

	while (thisRegion) {
		if (obj == thisRegion -> thisType -> objectNum) {
			return thisRegion;
		}
		thisRegion = thisRegion -> next;
	}

	return NULL;
}