Subversion Repositories Games.Descent

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 pmbaty 1
/*
2
 * Portions of this file are copyright Rebirth contributors and licensed as
3
 * described in COPYING.txt.
4
 * Portions of this file are copyright Parallax Software and licensed
5
 * according to the Parallax license below.
6
 * See COPYING.txt for license details.
7
 
8
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
9
SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
10
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
11
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
12
IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
13
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
14
FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
15
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
16
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
17
COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
18
*/
19
 
20
/*
21
 *
22
 * Functions for building parts of mines.
23
 *
24
 */
25
 
26
#include <string.h>
27
#include "inferno.h"
28
#include "editor/editor.h"
29
#include "editor/esegment.h"
30
#include "gameseg.h"
31
#include "gamesave.h"
32
#include "kdefs.h"
33
#include "compiler-range_for.h"
34
 
35
//  ---------- Create a bridge segment between current segment/side and marked segment/side ----------
36
int CreateBridge()
37
{
38
        if (!Markedsegp) {
39
                editor_status("No marked side.");
40
                return 0;
41
        }
42
 
43
    if (!med_form_bridge_segment(Cursegp,Curside,Markedsegp,Markedside)) {
44
                Update_flags |= UF_WORLD_CHANGED;
45
                mine_changed = 1;
46
        autosave_mine(mine_filename);
47
        diagnostic_message("Bridge segment formed.");
48
                undo_status[Autosave_count] = "Bridge segment UNDONE.";
49
        warn_if_concave_segments();
50
        }
51
    return 1;
52
}
53
 
54
 
55
 
56
// ---------- Form a joint between current segment:side and marked segment:side, modifying marked segment ----------
57
int FormJoint()
58
{
59
        if (!Markedsegp)
60
                diagnostic_message("Marked segment not set -- unable to form joint.");
61
        else {
62
        if (!med_form_joint(Cursegp,Curside,Markedsegp,Markedside)) {
63
            Update_flags |= UF_WORLD_CHANGED;
64
            mine_changed = 1;
65
            autosave_mine(mine_filename);
66
            diagnostic_message("Joint formed.");
67
                        undo_status[Autosave_count] = "Joint undone.";
68
                        warn_if_concave_segments();
69
        }
70
        }
71
 
72
        return 1;
73
 
74
}
75
 
76
//  ---------- Create a bridge segment between current segment:side adjacent segment:side ----------
77
int CreateAdjacentJoint()
78
{
79
        int             adj_side;
80
        imsegptridx_t adj_sp = segment_none;
81
 
82
        if (med_find_adjacent_segment_side(Cursegp, Curside, adj_sp, &adj_side)) {
83
                if (Cursegp->children[Curside] != adj_sp) {
84
                        med_form_joint(Cursegp,Curside,adj_sp,adj_side);
85
                        Update_flags |= UF_WORLD_CHANGED;
86
                        mine_changed = 1;
87
         autosave_mine(mine_filename);
88
         diagnostic_message("Joint segment formed.");
89
                        undo_status[Autosave_count] = "Joint segment undone.";
90
                warn_if_concave_segments();
91
                } else
92
                        editor_status("Attempted to form joint through connected side -- joint segment not formed (you bozo).");
93
        } else
94
                editor_status("Could not find adjacent segment -- joint segment not formed.");
95
 
96
        return 1;
97
}
98
 
99
//  ---------- Create a bridge segment between current segment:side adjacent segment:side ----------
100
int CreateSloppyAdjacentJoint()
101
{
102
        int             adj_side;
103
        imsegptridx_t adj_sp = segment_none;
104
 
105
        save_level(
106
#if defined(DXX_BUILD_DESCENT_II)
107
                LevelSharedSegmentState.DestructibleLights,
108
#endif
109
                "SLOPPY.LVL");
110
 
111
        if (med_find_closest_threshold_segment_side(Cursegp, Curside, adj_sp, &adj_side, 20*F1_0)) {
112
                if (Cursegp->children[Curside] != adj_sp) {
113
                        if (!med_form_joint(Cursegp,Curside,adj_sp,adj_side))
114
                                {
115
                                Update_flags |= UF_WORLD_CHANGED;
116
                                mine_changed = 1;
117
                 autosave_mine(mine_filename);
118
                 diagnostic_message("Sloppy Joint segment formed.");
119
                                undo_status[Autosave_count] = "Sloppy Joint segment undone.";
120
                        warn_if_concave_segments();
121
                                }
122
                        else editor_status("Could not form sloppy joint.\n");
123
                } else
124
                        editor_status("Attempted to form sloppy joint through connected side -- joint segment not formed.");
125
        } else
126
                editor_status("Could not find close threshold segment -- joint segment not formed.");
127
 
128
        return 1;
129
}
130
 
131
 
132
//  -------------- Create all sloppy joints within CurrentGroup ------------------
133
int CreateSloppyAdjacentJointsGroup()
134
{
135
        int             adj_side;
136
        int             done_been_a_change = 0;
137
        range_for(const auto &gs, GroupList[current_group].segments)
138
        {
139
                auto segp = vmsegptridx(gs);
140
 
141
                for (int sidenum=0; sidenum < MAX_SIDES_PER_SEGMENT; sidenum++)
142
                        if (!IS_CHILD(segp->children[sidenum]))
143
                        {
144
                                imsegptridx_t adj_sp = segment_none;
145
                                if (med_find_closest_threshold_segment_side(segp, sidenum, adj_sp, &adj_side, 5*F1_0)) {
146
                                        if (adj_sp->group == segp->group) {
147
                                                if (segp->children[sidenum] != adj_sp)
148
                                                        if (!med_form_joint(segp, sidenum, adj_sp,adj_side))
149
                                                                done_been_a_change = 1;
150
                                        }
151
                                }
152
                        }
153
        }
154
 
155
        if (done_been_a_change) {
156
                Update_flags |= UF_WORLD_CHANGED;
157
                mine_changed = 1;
158
                autosave_mine(mine_filename);
159
                diagnostic_message("Sloppy Joint segment formed.");
160
                undo_status[Autosave_count] = "Sloppy Joint segment undone.";
161
                warn_if_concave_segments();
162
        }
163
 
164
        return 1;
165
}
166
 
167
 
168
//  ---------- Create a bridge segment between current segment and all adjacent segment:side ----------
169
int CreateAdjacentJointsSegment()
170
{
171
        auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state();
172
        int             adj_side;
173
 
174
        auto &Vertex_active = LevelSharedVertexState.get_vertex_active();
175
        med_combine_duplicate_vertices(Vertex_active);
176
 
177
        for (int s=0; s<MAX_SIDES_PER_SEGMENT; s++) {
178
                imsegptridx_t adj_sp = segment_none;
179
                if (med_find_adjacent_segment_side(Cursegp, s, adj_sp, &adj_side))
180
                        if (Cursegp->children[s] != adj_sp)
181
                                        {
182
                                        med_form_joint(Cursegp,s,adj_sp,adj_side);
183
                                        Update_flags |= UF_WORLD_CHANGED;
184
                                        mine_changed = 1;
185
                    autosave_mine(mine_filename);
186
                    diagnostic_message("Adjacent Joint segment formed.");
187
                                undo_status[Autosave_count] = "Adjacent Joint segment UNDONE.";
188
                                warn_if_concave_segments();
189
                                        }
190
        }
191
 
192
        return 1;
193
}
194
 
195
//  ---------- Create a bridge segment between all segment:side and all adjacent segment:side ----------
196
int CreateAdjacentJointsAll()
197
{
198
        auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state();
199
        int             adj_side;
200
 
201
        auto &Vertex_active = LevelSharedVertexState.get_vertex_active();
202
        med_combine_duplicate_vertices(Vertex_active);
203
 
204
        range_for (const auto &&segp, vmsegptridx)
205
        {
206
                for (int s=0; s<MAX_SIDES_PER_SEGMENT; s++)
207
                {
208
                        imsegptridx_t adj_sp = segment_none;
209
                        if (med_find_adjacent_segment_side(segp, s, adj_sp, &adj_side))
210
                                if (segp->children[s] != adj_sp)
211
                                                med_form_joint(segp,s,adj_sp,adj_side);
212
                }
213
        }
214
 
215
        Update_flags |= UF_WORLD_CHANGED;
216
        mine_changed = 1;
217
   autosave_mine(mine_filename);
218
   diagnostic_message("All Adjacent Joint segments formed.");
219
        undo_status[Autosave_count] = "All Adjacent Joint segments UNDONE.";
220
        warn_if_concave_segments();
221
   return 1;
222
}
223
 
224