]> icculus.org git repositories - btb/d2x.git/blob - main/editor/kbuild.c
imported missing editor files from d1x
[btb/d2x.git] / main / editor / kbuild.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
11 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13 /*
14  * $Source: /cvs/cvsroot/d2x/main/editor/kbuild.c,v $
15  * $Revision: 1.1 $
16  * $Author: btb $
17  * $Date: 2004-12-19 13:54:27 $
18  *
19  * Functions for building parts of mines.
20  *
21  * $Log: not supported by cvs2svn $
22  * Revision 1.1.1.1  1999/06/14 22:03:19  donut
23  * Import of d1x 1.37 source.
24  *
25  * Revision 2.0  1995/02/27  11:35:43  john
26  * Version 2.0! No anonymous unions, Watcom 10.0, with no need
27  * for bitmaps.tbl.
28  * 
29  * Revision 1.20  1995/02/22  11:00:47  yuan
30  * prototype include.
31  * 
32  * Revision 1.19  1995/02/22  10:59:01  yuan
33  * Save sloppy mine before punching.
34  * 
35  * Revision 1.18  1994/08/25  21:57:56  mike
36  * IS_CHILD stuff.
37  * 
38  * Revision 1.17  1994/05/16  12:00:52  mike
39  * Call med_combine_duplicate_vertices before various build functions.
40  * 
41  * Revision 1.16  1994/05/09  23:34:31  mike
42  * Punch all sloppy sides in a group.
43  * 
44  * Revision 1.15  1994/02/16  15:23:06  yuan
45  * Checking in for editor make.
46  * 
47  * Revision 1.14  1994/01/21  12:01:31  yuan
48  * Added clearer editor_status messages (sloppy joint vs. joint)
49  * 
50  * Revision 1.13  1994/01/14  11:59:52  yuan
51  * New function in build menu. 
52  * "Punch" through walls to force a joint formation with
53  * closest segment:side, if the closest segment:side allows
54  * a connection.
55  * 
56  * Revision 1.12  1994/01/07  17:45:05  yuan
57  * Just changed some tabs and formatting I believe.
58  * 
59  * Revision 1.11  1993/12/06  19:33:36  yuan
60  * Fixed autosave stuff so that undo restores Cursegp and
61  * Markedsegp
62  * 
63  * Revision 1.10  1993/12/02  12:39:15  matt
64  * Removed extra includes
65  * 
66  * Revision 1.9  1993/11/12  14:31:31  yuan
67  * Added warn_if_concave_segments.
68  * 
69  * Revision 1.8  1993/11/11  17:12:45  yuan
70  * Fixed display of messages, so that concave segment
71  * warning doesn't wipe them out immediately.
72  * 
73  * Revision 1.7  1993/11/09  12:09:28  mike
74  * Remove extern for mine_filename, put it in editor.h
75  * 
76  * Revision 1.6  1993/11/08  19:14:06  yuan
77  * Added Undo command (not working yet)
78  * 
79  * Revision 1.5  1993/11/05  17:32:36  john
80  * added funcs
81  * .,
82  * 
83  * Revision 1.4  1993/11/01  16:53:51  mike
84  * Add CreateAdjacentJointsSegment and CreateAdjacentJointsAll
85  * 
86  * Revision 1.3  1993/11/01  11:24:59  mike
87  * Add CreateJointAdjacent
88  * 
89  * Revision 1.2  1993/10/29  19:13:11  yuan
90  * Added diagnostic messages
91  * 
92  * Revision 1.1  1993/10/13  18:53:27  john
93  * Initial revision
94  * 
95  *
96  */
97
98 #ifdef RCS
99 static char rcsid[] = "$Id: kbuild.c,v 1.1 2004-12-19 13:54:27 btb Exp $";
100 #endif
101
102 #include <string.h>
103
104 #include "inferno.h"
105 #include "editor/editor.h"
106 #include "gameseg.h"
107 #include "gamesave.h"
108 #include "mono.h"
109
110 //  ---------- Create a bridge segment between current segment/side and marked segment/side ----------
111 int CreateBridge()
112 {
113     if (!med_form_bridge_segment(Cursegp,Curside,Markedsegp,Markedside)) {
114                 Update_flags |= UF_WORLD_CHANGED;
115                 mine_changed = 1;
116         autosave_mine(mine_filename);
117         diagnostic_message("Bridge segment formed.");
118         strcpy(undo_status[Autosave_count], "Bridge segment UNDONE.");
119         warn_if_concave_segments();
120         }
121     return 1;
122 }
123
124
125
126 // ---------- Form a joint between current segment:side and marked segment:side, modifying marked segment ----------
127 int FormJoint()
128 {
129         if (!Markedsegp)
130                 diagnostic_message("Marked segment not set -- unable to form joint.");
131         else {
132         if (!med_form_joint(Cursegp,Curside,Markedsegp,Markedside)) {
133             Update_flags |= UF_WORLD_CHANGED;
134             mine_changed = 1;
135             autosave_mine(mine_filename);
136             diagnostic_message("Joint formed.");
137             strcpy(undo_status[Autosave_count], "Joint undone.");
138                         warn_if_concave_segments();
139         }
140         }
141
142         return 1;
143
144 }
145
146 //  ---------- Create a bridge segment between current segment:side adjacent segment:side ----------
147 int CreateAdjacentJoint()
148 {
149         int             adj_side;
150         segment *adj_sp;
151
152         if (med_find_adjacent_segment_side(Cursegp, Curside, &adj_sp, &adj_side)) {
153                 if (Cursegp->children[Curside] != adj_sp-Segments) {
154                         med_form_joint(Cursegp,Curside,adj_sp,adj_side);
155                         Update_flags |= UF_WORLD_CHANGED;
156                         mine_changed = 1;
157          autosave_mine(mine_filename);
158          diagnostic_message("Joint segment formed.");
159          strcpy(undo_status[Autosave_count], "Joint segment undone.");
160                 warn_if_concave_segments();
161                 } else
162                         editor_status("Attempted to form joint through connected side -- joint segment not formed (you bozo).");
163         } else
164                 editor_status("Could not find adjacent segment -- joint segment not formed.");
165
166         return 1;
167 }
168
169 //  ---------- Create a bridge segment between current segment:side adjacent segment:side ----------
170 int CreateSloppyAdjacentJoint()
171 {
172         int             adj_side;
173         segment *adj_sp;
174
175         save_level("SLOPPY.LVL");
176
177         if (med_find_closest_threshold_segment_side(Cursegp, Curside, &adj_sp, &adj_side, 20*F1_0)) {
178                 if (Cursegp->children[Curside] != adj_sp-Segments) {
179                         if (!med_form_joint(Cursegp,Curside,adj_sp,adj_side))
180                                 {
181                                 Update_flags |= UF_WORLD_CHANGED;
182                                 mine_changed = 1;
183                  autosave_mine(mine_filename);
184                  diagnostic_message("Sloppy Joint segment formed.");
185                  strcpy(undo_status[Autosave_count], "Sloppy Joint segment undone.");
186                         warn_if_concave_segments();
187                                 }
188                         else editor_status("Couldn't form sloppy joint.\n");
189                 } else
190                         editor_status("Attempted to form sloppy joint through connected side -- joint segment not formed (you bozo).");
191         } else
192                 editor_status("Could not find close threshold segment -- joint segment not formed.");
193
194         return 1;
195 }
196
197
198 //  -------------- Create all sloppy joints within CurrentGroup ------------------
199 int CreateSloppyAdjacentJointsGroup()
200 {
201         int             adj_side;
202         segment *adj_sp;
203         int             num_segs = GroupList[current_group].num_segments;
204         short           *segs = GroupList[current_group].segments;
205         segment *segp;
206         int             done_been_a_change = 0;
207         int             segind, sidenum;
208
209         for (segind=0; segind<num_segs; segind++) {
210                 segp = &Segments[segs[segind]];
211
212                 for (sidenum=0; sidenum < MAX_SIDES_PER_SEGMENT; sidenum++)
213                         if (!IS_CHILD(segp->children[sidenum]))
214                                 if (med_find_closest_threshold_segment_side(segp, sidenum, &adj_sp, &adj_side, 5*F1_0)) {
215                                         if (adj_sp->group == segp->group) {
216                                                 if (segp->children[sidenum] != adj_sp-Segments)
217                                                         if (!med_form_joint(segp, sidenum, adj_sp,adj_side))
218                                                                 done_been_a_change = 1;
219                                         }
220                                 }
221         }
222
223         if (done_been_a_change) {
224                 Update_flags |= UF_WORLD_CHANGED;
225                 mine_changed = 1;
226                 autosave_mine(mine_filename);
227                 diagnostic_message("Sloppy Joint segment formed.");
228                 strcpy(undo_status[Autosave_count], "Sloppy Joint segment undone.");
229                 warn_if_concave_segments();
230         }
231
232         return 1;
233 }
234
235
236 //  ---------- Create a bridge segment between current segment and all adjacent segment:side ----------
237 int CreateAdjacentJointsSegment()
238 {
239         int             adj_side,s;
240         segment *adj_sp;
241
242         med_combine_duplicate_vertices(Vertex_active);
243
244         for (s=0; s<MAX_SIDES_PER_SEGMENT; s++) {
245                 if (med_find_adjacent_segment_side(Cursegp, s, &adj_sp, &adj_side))
246                         if (Cursegp->children[s] != adj_sp-Segments)
247                                         {
248                                         med_form_joint(Cursegp,s,adj_sp,adj_side);
249                                         Update_flags |= UF_WORLD_CHANGED;
250                                         mine_changed = 1;
251                     autosave_mine(mine_filename);
252                     diagnostic_message("Adjacent Joint segment formed.");
253                     strcpy(undo_status[Autosave_count], "Adjacent Joint segment UNDONE.");
254                                 warn_if_concave_segments();
255                                         }
256         }
257
258         return 1;
259 }
260
261 //  ---------- Create a bridge segment between all segment:side and all adjacent segment:side ----------
262 int CreateAdjacentJointsAll()
263 {
264         int             adj_side,seg,s;
265         segment *adj_sp;
266
267         med_combine_duplicate_vertices(Vertex_active);
268
269         for (seg=0; seg<=Highest_segment_index; seg++)
270                 for (s=0; s<MAX_SIDES_PER_SEGMENT; s++)
271                         if (med_find_adjacent_segment_side(&Segments[seg], s, &adj_sp, &adj_side))
272                                 if (Segments[seg].children[s] != adj_sp-Segments)
273                                                 med_form_joint(&Segments[seg],s,adj_sp,adj_side);
274
275         Update_flags |= UF_WORLD_CHANGED;
276         mine_changed = 1;
277    autosave_mine(mine_filename);
278    diagnostic_message("All Adjacent Joint segments formed.");
279    strcpy(undo_status[Autosave_count], "All Adjacent Joint segments UNDONE.");
280         warn_if_concave_segments();
281    return 1;
282 }
283
284