home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / medsel.c < prev    next >
Text File  |  1998-06-08  |  4KB  |  162 lines

  1. /*
  2.  * $Source: f:/miner/source/main/editor/rcs/medsel.c $
  3.  * $Revision: 2.0 $
  4.  * $Author: john $
  5.  * $Date: 1995/02/27 11:35:20 $
  6.  * 
  7.  * Routines stripped from med.c for segment selection
  8.  * 
  9.  * $Log: medsel.c $
  10.  * Revision 2.0  1995/02/27  11:35:20  john
  11.  * Version 2.0! No anonymous unions, Watcom 10.0, with no need
  12.  * for bitmaps.tbl.
  13.  * 
  14.  * Revision 1.10  1994/08/09  16:05:59  john
  15.  * Added the ability to place players.  Made old
  16.  * Player variable be ConsoleObject.
  17.  * 
  18.  * Revision 1.9  1994/05/23  14:56:27  mike
  19.  * make current segment be add segment.
  20.  * 
  21.  * Revision 1.8  1994/05/14  18:00:50  matt
  22.  * Got rid of externs in source (non-header) files
  23.  * 
  24.  * Revision 1.7  1994/03/31  12:03:33  matt
  25.  * Cleaned up includes
  26.  * 
  27.  * Revision 1.6  1994/02/17  12:52:13  yuan
  28.  * Unbackdated
  29.  * y
  30.  * 
  31.  * Revision 1.4  1994/02/17  09:46:53  matt
  32.  * Removed include of slew.h
  33.  * 
  34.  * Revision 1.3  1994/01/05  10:54:23  john
  35.  * New object code by John
  36.  * 
  37.  * Revision 1.2  1993/12/17  12:18:22  john
  38.  * Moved selection stuff out of med.c
  39.  * 
  40.  * Revision 1.1  1993/12/17  09:29:34  john
  41.  * Initial revision
  42.  * 
  43.  * 
  44.  */
  45.  
  46.  
  47. #pragma off (unreferenced)
  48. static char rcsid[] = "$Id: medsel.c 2.0 1995/02/27 11:35:20 john Exp $";
  49. #pragma on (unreferenced)
  50.  
  51. #include <stdio.h>
  52. #include <stdlib.h>
  53. #include <stdarg.h>
  54. #include <string.h>
  55. #include <process.h>
  56.  
  57. #include "gr.h"
  58. #include "ui.h"
  59. #include "key.h"
  60. #include "mono.h"
  61. #include "error.h"
  62. #include "mem.h"
  63.  
  64. #include "inferno.h"
  65. #include "editor.h"
  66. #include "segment.h"
  67. #include "object.h"
  68.  
  69. typedef struct sort_element {
  70.     short segnum;
  71.     fix dist;
  72. } sort_element;
  73.  
  74. //compare the distance of two segments.  slow, since it computes the
  75. //distance each time
  76. segdist_cmp(sort_element *s0,sort_element *s1)
  77. {
  78.     return (s0->dist==s1->dist)?0:((s0->dist<s1->dist)?-1:1);
  79.  
  80. }
  81.  
  82.  
  83. //find the distance between a segment and a point
  84. fix compute_dist(segment *seg,vms_vector *pos)
  85. {
  86.     vms_vector delta;
  87.  
  88.     compute_segment_center(&delta,seg);
  89.     vm_vec_sub2(&delta,pos);
  90.  
  91.     return vm_vec_mag(&delta);
  92.  
  93. }
  94.  
  95. //sort a list of segments, in order of closeness to pos
  96. void sort_seg_list(int n_segs,short *segnumlist,vms_vector *pos)
  97. {
  98.     int i;
  99.     sort_element *sortlist;
  100.  
  101.     sortlist = calloc(n_segs,sizeof(*sortlist));
  102.  
  103.     for (i=0;i<n_segs;i++) {
  104.         sortlist[i].segnum = segnumlist[i];
  105.         sortlist[i].dist = compute_dist(&Segments[segnumlist[i]],pos);
  106.     }
  107.  
  108.     qsort(sortlist,n_segs,sizeof(*sortlist),segdist_cmp);
  109.  
  110.     for (i=0;i<n_segs;i++)
  111.         segnumlist[i] = sortlist[i].segnum;
  112.  
  113.     free(sortlist);
  114. }
  115.  
  116. int SortSelectedList(void)
  117. {
  118.     sort_seg_list(N_selected_segs,Selected_segs,&ConsoleObject->pos);
  119.     editor_status("%i element selected list sorted.",N_selected_segs);
  120.  
  121.     return 1;
  122. }
  123.  
  124. int SelectNextFoundSeg(void)
  125. {
  126.     if (++Found_seg_index >= N_found_segs)
  127.         Found_seg_index = 0;
  128.  
  129.     Cursegp = &Segments[Found_segs[Found_seg_index]];
  130.     med_create_new_segment_from_cursegp();
  131.  
  132.     Update_flags |= UF_WORLD_CHANGED;
  133.  
  134.     if (Lock_view_to_cursegp)
  135.         set_view_target_from_segment(Cursegp);
  136.  
  137.     editor_status("Curseg assigned to next found segment.");
  138.  
  139.     return 1;
  140. }
  141.  
  142. int SelectPreviousFoundSeg(void)
  143. {
  144.     if (Found_seg_index > 0)
  145.         Found_seg_index--;
  146.     else
  147.         Found_seg_index = N_found_segs-1;
  148.  
  149.     Cursegp = &Segments[Found_segs[Found_seg_index]];
  150.     med_create_new_segment_from_cursegp();
  151.  
  152.     Update_flags |= UF_WORLD_CHANGED;
  153.  
  154.     if (Lock_view_to_cursegp)
  155.         set_view_target_from_segment(Cursegp);
  156.  
  157.     editor_status("Curseg assigned to previous found segment.");
  158.  
  159.     return 1;
  160. }
  161.  
  162.