dxx-rebirth/similar/editor/kbuild.cpp

224 lines
6.7 KiB
C++
Raw Normal View History

2006-03-20 16:43:15 +00:00
/*
2014-06-01 17:55:23 +00:00
* Portions of this file are copyright Rebirth contributors and licensed as
* described in COPYING.txt.
* Portions of this file are copyright Parallax Software and licensed
* according to the Parallax license below.
* See COPYING.txt for license details.
2006-03-20 16:43:15 +00:00
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
2006-03-20 16:43:15 +00:00
COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
*/
2006-03-20 16:43:15 +00:00
/*
*
* Functions for building parts of mines.
*
*/
#include <string.h>
#include "editor/editor.h"
2013-03-16 03:10:55 +00:00
#include "editor/esegment.h"
2006-03-20 16:43:15 +00:00
#include "gamesave.h"
#include "kdefs.h"
2013-12-21 05:12:38 +00:00
#include "compiler-range_for.h"
2006-03-20 16:43:15 +00:00
// ---------- Create a bridge segment between current segment/side and marked segment/side ----------
int CreateBridge()
{
if (!Markedsegp) {
editor_status("No marked side.");
return 0;
}
2006-03-20 16:43:15 +00:00
if (!med_form_bridge_segment(Cursegp,Curside,Markedsegp,Markedside)) {
Update_flags |= UF_WORLD_CHANGED;
mine_changed = 1;
autosave_mine(mine_filename);
diagnostic_message("Bridge segment formed.");
2015-04-02 02:36:56 +00:00
undo_status[Autosave_count] = "Bridge segment UNDONE.";
2006-03-20 16:43:15 +00:00
warn_if_concave_segments();
}
return 1;
}
// ---------- Form a joint between current segment:side and marked segment:side, modifying marked segment ----------
int FormJoint()
{
if (!Markedsegp)
diagnostic_message("Marked segment not set -- unable to form joint.");
else {
if (!med_form_joint(Cursegp,Curside,Markedsegp,Markedside)) {
Update_flags |= UF_WORLD_CHANGED;
mine_changed = 1;
autosave_mine(mine_filename);
diagnostic_message("Joint formed.");
2015-04-02 02:36:56 +00:00
undo_status[Autosave_count] = "Joint undone.";
2006-03-20 16:43:15 +00:00
warn_if_concave_segments();
}
}
return 1;
}
// ---------- Create a bridge segment between current segment:side adjacent segment:side ----------
int CreateAdjacentJoint()
{
if (const auto o = med_find_adjacent_segment_side(Cursegp, Curside))
{
const auto [adj_sp, adj_side] = *o;
2014-10-02 03:02:34 +00:00
if (Cursegp->children[Curside] != adj_sp) {
2006-03-20 16:43:15 +00:00
med_form_joint(Cursegp,Curside,adj_sp,adj_side);
Update_flags |= UF_WORLD_CHANGED;
mine_changed = 1;
autosave_mine(mine_filename);
diagnostic_message("Joint segment formed.");
2015-04-02 02:36:56 +00:00
undo_status[Autosave_count] = "Joint segment undone.";
2006-03-20 16:43:15 +00:00
warn_if_concave_segments();
} else
editor_status("Attempted to form joint through connected side -- joint segment not formed (you bozo).");
} else
editor_status("Could not find adjacent segment -- joint segment not formed.");
return 1;
}
// ---------- Create a bridge segment between current segment:side adjacent segment:side ----------
int CreateSloppyAdjacentJoint()
{
2018-12-30 00:43:57 +00:00
save_level(
#if defined(DXX_BUILD_DESCENT_II)
LevelSharedSegmentState.DestructibleLights,
2018-12-30 00:43:57 +00:00
#endif
"SLOPPY.LVL");
2006-03-20 16:43:15 +00:00
if (const auto o = med_find_closest_threshold_segment_side(Cursegp, Curside, 20*F1_0))
{
const auto [adj_sp, adj_side] = *o;
2014-10-02 03:02:34 +00:00
if (Cursegp->children[Curside] != adj_sp) {
2006-03-20 16:43:15 +00:00
if (!med_form_joint(Cursegp,Curside,adj_sp,adj_side))
{
Update_flags |= UF_WORLD_CHANGED;
mine_changed = 1;
autosave_mine(mine_filename);
diagnostic_message("Sloppy Joint segment formed.");
2015-04-02 02:36:56 +00:00
undo_status[Autosave_count] = "Sloppy Joint segment undone.";
2006-03-20 16:43:15 +00:00
warn_if_concave_segments();
}
else editor_status("Could not form sloppy joint.\n");
2006-03-20 16:43:15 +00:00
} else
editor_status("Attempted to form sloppy joint through connected side -- joint segment not formed.");
2006-03-20 16:43:15 +00:00
} else
editor_status("Could not find close threshold segment -- joint segment not formed.");
return 1;
}
// -------------- Create all sloppy joints within CurrentGroup ------------------
int CreateSloppyAdjacentJointsGroup()
{
int done_been_a_change = 0;
range_for(const auto &gs, GroupList[current_group].segments)
{
auto segp = vmsegptridx(gs);
2006-03-20 16:43:15 +00:00
for (const auto sidenum : MAX_SIDES_PER_SEGMENT)
2006-03-20 16:43:15 +00:00
if (!IS_CHILD(segp->children[sidenum]))
2014-10-02 03:02:34 +00:00
{
if (const auto o = med_find_closest_threshold_segment_side(segp, sidenum, 5*F1_0))
{
const auto [adj_sp, adj_side] = *o;
2006-03-20 16:43:15 +00:00
if (adj_sp->group == segp->group) {
2014-10-02 03:02:34 +00:00
if (segp->children[sidenum] != adj_sp)
2006-03-20 16:43:15 +00:00
if (!med_form_joint(segp, sidenum, adj_sp,adj_side))
done_been_a_change = 1;
}
}
2014-10-02 03:02:34 +00:00
}
2006-03-20 16:43:15 +00:00
}
if (done_been_a_change) {
Update_flags |= UF_WORLD_CHANGED;
mine_changed = 1;
autosave_mine(mine_filename);
diagnostic_message("Sloppy Joint segment formed.");
2015-04-02 02:36:56 +00:00
undo_status[Autosave_count] = "Sloppy Joint segment undone.";
2006-03-20 16:43:15 +00:00
warn_if_concave_segments();
}
return 1;
}
// ---------- Create a bridge segment between current segment and all adjacent segment:side ----------
int CreateAdjacentJointsSegment()
{
auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state();
2006-03-20 16:43:15 +00:00
2018-12-30 00:43:57 +00:00
auto &Vertex_active = LevelSharedVertexState.get_vertex_active();
2006-03-20 16:43:15 +00:00
med_combine_duplicate_vertices(Vertex_active);
for (const auto s : MAX_SIDES_PER_SEGMENT)
{
if (const auto o = med_find_adjacent_segment_side(Cursegp, s))
{
const auto [adj_sp, adj_side] = *o;
2014-10-02 03:02:34 +00:00
if (Cursegp->children[s] != adj_sp)
2006-03-20 16:43:15 +00:00
{
med_form_joint(Cursegp,s,adj_sp,adj_side);
Update_flags |= UF_WORLD_CHANGED;
mine_changed = 1;
autosave_mine(mine_filename);
diagnostic_message("Adjacent Joint segment formed.");
2015-04-02 02:36:56 +00:00
undo_status[Autosave_count] = "Adjacent Joint segment UNDONE.";
2006-03-20 16:43:15 +00:00
warn_if_concave_segments();
}
}
2006-03-20 16:43:15 +00:00
}
return 1;
}
// ---------- Create a bridge segment between all segment:side and all adjacent segment:side ----------
int CreateAdjacentJointsAll()
{
auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state();
2006-03-20 16:43:15 +00:00
2018-12-30 00:43:57 +00:00
auto &Vertex_active = LevelSharedVertexState.get_vertex_active();
2006-03-20 16:43:15 +00:00
med_combine_duplicate_vertices(Vertex_active);
range_for (const auto &&segp, vmsegptridx)
2015-06-13 22:42:17 +00:00
{
for (const auto s : MAX_SIDES_PER_SEGMENT)
2014-10-02 03:02:34 +00:00
{
if (const auto o = med_find_adjacent_segment_side(segp, s))
{
const auto [adj_sp, adj_side] = *o;
2015-06-13 22:42:17 +00:00
if (segp->children[s] != adj_sp)
med_form_joint(segp,s,adj_sp,adj_side);
}
2014-10-02 03:02:34 +00:00
}
2015-06-13 22:42:17 +00:00
}
2006-03-20 16:43:15 +00:00
Update_flags |= UF_WORLD_CHANGED;
mine_changed = 1;
autosave_mine(mine_filename);
diagnostic_message("All Adjacent Joint segments formed.");
2015-04-02 02:36:56 +00:00
undo_status[Autosave_count] = "All Adjacent Joint segments UNDONE.";
2006-03-20 16:43:15 +00:00
warn_if_concave_segments();
return 1;
}