KSEGSEL.C 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * $Source: f:/miner/source/main/editor/rcs/ksegsel.c $
  3. * $Revision: 2.0 $
  4. * $Author: john $
  5. * $Date: 1995/02/27 11:35:33 $
  6. *
  7. * Functions for selecting segments
  8. *
  9. * $Log: ksegsel.c $
  10. * Revision 2.0 1995/02/27 11:35:33 john
  11. * Version 2.0! No anonymous unions, Watcom 10.0, with no need
  12. * for bitmaps.tbl.
  13. *
  14. * Revision 1.12 1994/08/25 21:57:02 mike
  15. * IS_CHILD stuff.
  16. *
  17. * Revision 1.11 1994/05/23 14:48:35 mike
  18. * make current segment be add segment.
  19. *
  20. * Revision 1.10 1993/12/06 19:33:43 yuan
  21. * Fixed autosave stuff so that undo restores Cursegp and
  22. * Markedsegp
  23. *
  24. * Revision 1.9 1993/12/02 12:39:37 matt
  25. * Removed extra includes
  26. *
  27. * Revision 1.8 1993/11/12 13:08:17 yuan
  28. * Fixed warning for concave segment so it appears after any
  29. * "less important" diagnostic messages.
  30. *
  31. * Revision 1.7 1993/11/05 17:32:49 john
  32. * added funcs
  33. * .,
  34. *
  35. * Revision 1.6 1993/11/01 09:53:18 mike
  36. * Write functions get_next_segment and get_previous_segment.
  37. *
  38. * Revision 1.5 1993/10/31 18:06:56 mike
  39. * Only set_view_target_from_segment if in that mode.
  40. *
  41. * Revision 1.4 1993/10/28 15:01:09 matt
  42. * Mucked with update flags
  43. *
  44. * Revision 1.3 1993/10/14 18:07:47 mike
  45. * Change use of CONNECTIVITY to MAX_SIDES_PER_SEGMENT
  46. *
  47. * Revision 1.2 1993/10/14 11:47:34 john
  48. * *** empty log message ***
  49. *
  50. * Revision 1.1 1993/10/13 18:53:39 john
  51. * Initial revision
  52. *
  53. *
  54. */
  55. #pragma off (unreferenced)
  56. static char rcsid[] = "$Id: ksegsel.c 2.0 1995/02/27 11:35:33 john Exp $";
  57. #pragma on (unreferenced)
  58. #include <string.h>
  59. #include "inferno.h"
  60. #include "editor.h"
  61. // ---------------------------------------------------------------------------------------
  62. // Select previous segment.
  63. // If there is a connection on the side opposite to the current side, then choose that segment.
  64. // If there is no connecting segment on the opposite face, try any segment.
  65. void get_previous_segment(int curseg_num, int curside,int *newseg_num, int *newside)
  66. {
  67. int s;
  68. *newseg_num = curseg_num;
  69. if (IS_CHILD(Segments[curseg_num].children[Side_opposite[curside]]))
  70. *newseg_num = Segments[curseg_num].children[Side_opposite[curside]];
  71. else // no segment on opposite face, connect to anything
  72. for (s=0; s<MAX_SIDES_PER_SEGMENT; s++)
  73. if ((s != curside) && IS_CHILD(Segments[curseg_num].children[s]))
  74. *newseg_num = Segments[curseg_num].children[s];
  75. // Now make Curside point at the segment we just left (unless we couldn't leave it).
  76. if (*newseg_num != curseg_num)
  77. *newside = find_connect_side(&Segments[curseg_num],&Segments[*newseg_num]);
  78. else
  79. *newside = curside;
  80. }
  81. // --------------------------------------------------------------------------------------
  82. // Select next segment.
  83. // If there is a connection on the current side, then choose that segment.
  84. // If there is no connecting segment on the current side, try any segment.
  85. void get_next_segment(int curseg_num, int curside, int *newseg_num, int *newside)
  86. {
  87. int s;
  88. if (IS_CHILD(Segments[curseg_num].children[curside])) {
  89. *newseg_num = Segments[curseg_num].children[Curside];
  90. // Find out what side we came in through and favor side opposite that
  91. *newside = Side_opposite[find_connect_side(&Segments[curseg_num],&Segments[*newseg_num])];
  92. // If there is nothing attached on the side opposite to what we came in (*newside), pick any other side
  93. if (!IS_CHILD(Segments[*newseg_num].children[*newside]))
  94. for (s=0; s<MAX_SIDES_PER_SEGMENT; s++)
  95. if ((Segments[*newseg_num].children[s] != curseg_num) && IS_CHILD(Segments[*newseg_num].children[s]))
  96. *newside = s;
  97. } else {
  98. *newseg_num = curseg_num;
  99. *newside = curside;
  100. }
  101. }
  102. // ---------- select current segment ----------
  103. int SelectCurrentSegForward()
  104. {
  105. int newseg_num,newside;
  106. get_next_segment(Cursegp-Segments,Curside,&newseg_num,&newside);
  107. if (newseg_num != Cursegp-Segments) {
  108. Cursegp = &Segments[newseg_num];
  109. Curside = newside;
  110. Update_flags |= UF_ED_STATE_CHANGED;
  111. if (Lock_view_to_cursegp)
  112. set_view_target_from_segment(Cursegp);
  113. med_create_new_segment_from_cursegp();
  114. mine_changed = 1;
  115. }
  116. return 1;
  117. }
  118. // -------------------------------------------------------------------------------------
  119. int SelectCurrentSegBackward()
  120. {
  121. int newseg_num,newside;
  122. get_previous_segment(Cursegp-Segments,Curside,&newseg_num,&newside);
  123. Cursegp = &Segments[newseg_num];
  124. Curside = newside;
  125. if (Lock_view_to_cursegp)
  126. set_view_target_from_segment(Cursegp);
  127. Update_flags |= UF_ED_STATE_CHANGED;
  128. mine_changed = 1;
  129. med_create_new_segment_from_cursegp();
  130. return 1;
  131. }
  132. // ---------- select next/previous side on current segment ----------
  133. int SelectNextSide()
  134. {
  135. if (++Curside >= MAX_SIDES_PER_SEGMENT)
  136. Curside = 0;
  137. Update_flags |= UF_ED_STATE_CHANGED;
  138. mine_changed = 1;
  139. return 1;
  140. }
  141. int SelectPrevSide()
  142. {
  143. if (--Curside < 0)
  144. Curside = MAX_SIDES_PER_SEGMENT-1;
  145. Update_flags |= UF_ED_STATE_CHANGED;
  146. mine_changed = 1;
  147. return 1;
  148. }
  149. // ---------- Copy current segment and side to marked segment and side ----------
  150. int CopySegToMarked()
  151. {
  152. autosave_mine(mine_filename);
  153. strcpy(undo_status[Autosave_count], "Mark Segment UNDONE.");
  154. Markedsegp = Cursegp;
  155. Markedside = Curside;
  156. Update_flags |= UF_ED_STATE_CHANGED;
  157. mine_changed = 1;
  158. return 1;
  159. }
  160. // ---------- select absolute face on segment ----------
  161. int SelectBottom()
  162. {
  163. Curside = WBOTTOM;
  164. Update_flags |= UF_ED_STATE_CHANGED;
  165. mine_changed = 1;
  166. return 1;
  167. }
  168. int SelectFront()
  169. {
  170. Curside = WFRONT;
  171. Update_flags |= UF_ED_STATE_CHANGED;
  172. mine_changed = 1;
  173. return 1;
  174. }
  175. int SelectTop()
  176. {
  177. Curside = WTOP;
  178. Update_flags |= UF_ED_STATE_CHANGED;
  179. mine_changed = 1;
  180. return 1;
  181. }
  182. int SelectBack()
  183. {
  184. Curside = WBACK;
  185. Update_flags |= UF_ED_STATE_CHANGED;
  186. mine_changed = 1;
  187. return 1;
  188. }
  189. int SelectLeft()
  190. {
  191. Curside = WLEFT;
  192. Update_flags |= UF_ED_STATE_CHANGED;
  193. mine_changed = 1;
  194. return 1;
  195. }
  196. int SelectRight()
  197. {
  198. Curside = WRIGHT;
  199. Update_flags |= UF_ED_STATE_CHANGED;
  200. mine_changed = 1;
  201. return 1;
  202. }