Mercurial > hg > forks > yadex
annotate src/gotoobj.cc @ 89:99242b34e6dc
Fix some cosmetics and warnings.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 06 Oct 2014 00:13:11 +0300 |
parents | 2f1ecc1c5f72 |
children | 20aa5a515896 |
rev | line source |
---|---|
0 | 1 /* |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
2 * gotoobj.cc |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
3 * AYM 1998-09-06 |
0 | 4 */ |
5 | |
6 | |
7 /* | |
8 This file is part of Yadex. | |
9 | |
10 Yadex incorporates code from DEU 5.21 that was put in the public domain in | |
11 1994 by Raphaël Quinet and Brendon Wyber. | |
12 | |
13 The rest of Yadex is Copyright © 1997-2003 André Majorel and others. | |
14 | |
15 This program is free software; you can redistribute it and/or modify it under | |
16 the terms of the GNU General Public License as published by the Free Software | |
17 Foundation; either version 2 of the License, or (at your option) any later | |
18 version. | |
19 | |
20 This program is distributed in the hope that it will be useful, but WITHOUT | |
21 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
22 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | |
23 | |
24 You should have received a copy of the GNU General Public License along with | |
25 this program; if not, write to the Free Software Foundation, Inc., 59 Temple | |
26 Place, Suite 330, Boston, MA 02111-1307, USA. | |
27 */ | |
28 | |
29 | |
30 #include "yadex.h" | |
31 #include "gfx.h" | |
32 #include "gotoobj.h" | |
33 #include "levels.h" | |
34 #include "objects.h" | |
35 #include "objid.h" | |
36 #include "x_hover.h" | |
37 | |
38 | |
39 /* | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
40 * CenterMapAroundCoords |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
41 * Change the view so that the map coordinates (xpos, ypos) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
42 * appear at the centre of the window |
0 | 43 */ |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
44 void CenterMapAroundCoords(int xpos, int ypos) |
0 | 45 { |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
33
diff
changeset
|
46 cfg.OrigX = xpos; |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
33
diff
changeset
|
47 cfg.OrigY = ypos; |
0 | 48 /* AYM 1998-09-20 This is a DOS-ism. IIRC, the ICCCM says an |
49 application program should generally not mess with the | |
50 pointer. */ | |
51 #if 0 | |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
33
diff
changeset
|
52 is.x = cfg.ScrCenterX; |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
33
diff
changeset
|
53 is.y = cfg.ScrCenterY; |
0 | 54 #endif |
55 } | |
56 | |
57 | |
58 /* | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
59 * focus_on_map_coords |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
60 * Change the view so that the map coordinates (xpos, ypos) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
61 * appear under the pointer |
0 | 62 */ |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
63 void focus_on_map_coords(int x, int y) |
0 | 64 { |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
33
diff
changeset
|
65 cfg.OrigX = x - (MAPX(is.x) - cfg.OrigX); |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
33
diff
changeset
|
66 cfg.OrigY = y - (MAPY(is.y) - cfg.OrigY); |
0 | 67 } |
68 | |
69 | |
70 /* | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
71 * sector_under_pointer |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
72 * Convenience function |
0 | 73 */ |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
74 inline int sector_under_pointer() |
0 | 75 { |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
76 Objid o; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
77 GetCurObject(o, OBJ_SECTORS, MAPX(is.x), MAPY(is.y)); |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
78 return o.num; |
0 | 79 } |
80 | |
81 | |
82 /* | |
83 centre the map around the object and zoom in if necessary | |
84 */ | |
85 | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
86 void GoToObject(const Objid & objid) /* SWAP! */ |
0 | 87 { |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
88 int xpos, ypos; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
89 int xpos2, ypos2; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
90 int sd1, sd2; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
91 float oldscale; |
0 | 92 |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
93 GetObjectCoords(objid.type, objid.num, &xpos, &ypos); |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
94 focus_on_map_coords(xpos, ypos); |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
33
diff
changeset
|
95 oldscale = cfg.Scale; |
0 | 96 |
97 /* I ifdef'd out this block because the only thing it really | |
98 does is (uselessly) messing the zoom factor up when there are | |
99 superimposed objects and we're trying to focus on the | |
100 highest-numbered (and therefore hidden) one. AYM 1999-07-26 */ | |
101 #if 0 | |
102 /* zoom in until the object can be selected */ | |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
33
diff
changeset
|
103 while (cfg.Scale < 8.0 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
104 && GetCurObject(objid.type, MAPX(is.x), MAPY(is.y)) != objid.num) |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
105 { |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
33
diff
changeset
|
106 if (cfg.Scale < 1.0) |
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
33
diff
changeset
|
107 cfg.Scale = 1.0 / ((1.0 / cfg.Scale) - 1.0); |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
108 else |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
33
diff
changeset
|
109 cfg.Scale *= 2.0; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
110 } |
0 | 111 #endif |
112 | |
113 /* Special case for sectors: if a sector contains other sectors, | |
114 or if its shape is such that it does not contain its own | |
115 geometric centre, zooming in on the centre won't help. So I | |
116 choose a linedef that borders the sector and focus on a point | |
117 between the centre of the linedef and the centre of the | |
118 sector. If that doesn't help, I try another linedef. | |
119 | |
120 This algorithm is not perfect but it works rather well with | |
121 most well-constituted sectors. It does not work so well for | |
122 unclosed sectors, though (but it's partly GetCurObject()'s | |
123 fault). */ | |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
124 if (objid.type == OBJ_SECTORS && sector_under_pointer() != objid.num) |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
125 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
126 /* restore the Scale */ |
80
2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
33
diff
changeset
|
127 cfg.Scale = oldscale; |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
128 for (int n = 0; n < NumLineDefs; n++) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
129 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
130 sd1 = LineDefs[n].sidedef1; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
131 sd2 = LineDefs[n].sidedef2; |
89
99242b34e6dc
Fix some cosmetics and warnings.
Matti Hamalainen <ccr@tnsp.org>
parents:
80
diff
changeset
|
132 if ((sd1 >= 0 && SideDefs[sd1].sector == objid.num) || |
99242b34e6dc
Fix some cosmetics and warnings.
Matti Hamalainen <ccr@tnsp.org>
parents:
80
diff
changeset
|
133 (sd2 >= 0 && SideDefs[sd2].sector == objid.num)) |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
134 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
135 GetObjectCoords(OBJ_LINEDEFS, n, &xpos2, &ypos2); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
136 int d = ComputeDist(abs(xpos - xpos2), abs(ypos - ypos2)) / 7; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
137 if (d <= 1) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
138 d = 2; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
139 xpos = xpos2 + (xpos - xpos2) / d; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
140 ypos = ypos2 + (ypos - ypos2) / d; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
141 focus_on_map_coords(xpos, ypos); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
142 if (sector_under_pointer() == objid.num) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
143 break; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
144 } |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
145 } |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
146 } |
0 | 147 } |