source: golgotha/src/golg/editor/commands/terrain.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 5.2 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#include "editor/editor.hh"
10#include "editor/e_state.hh"
11#include "gui/create_dialog.hh"
12#include "gui/text_input.hh"
13#include "math/random.hh"
14#include "status/status.hh"
15#include "editor/e_res.hh"
16#include "map_vert.hh"
17#include "lisp/lisp.hh"
18
19void g1_editor_class::flatten_terrain()
20{
21  g1_editor_instance.unmark_all_selected_verts_for_undo_save();
22  g1_editor_instance.mark_selected_verts_for_undo_save();
23  g1_editor_instance.add_undo(G1_MAP_SELECTED_VERTS);
24
25
26  g1_edit_state.hide_focus();
27
28  int w=get_map()->width()+1, h=get_map()->height()+1;
29
30  w16 lowest=0xffff;
31
32  int t=0,x,y,i;
33
34  i4_status_class *status=i4_create_status(g1_ges("applying_flatten"));
35
36  g1_object_class *olist[G1_MAX_OBJECTS];
37  sw32 to=get_map()->make_object_list(olist, G1_MAX_OBJECTS);
38  for (i=0; i<to; i++)
39    olist[i]->unoccupy_location();
40
41  for (y=0; y<h; y++)
42  {
43    for (x=0; x<w; x++)
44    {
45      g1_map_vertex_class *v=get_map()->vertex(x,y);
46      if (v->is_selected())
47      {
48        if (v->height<lowest)
49          lowest=v->height;
50
51        t++;
52      }
53    }
54  }
55
56
57  if (t)
58  {
59    for (y=0; y<h; y++)
60    {
61      if (status)
62        status->update(y/(float)h);
63
64      for (x=0; x<w; x++)
65      {
66        g1_map_vertex_class *v=get_map()->vertex(x,y);
67        if (v->is_selected())
68          get_map()->change_vert_height(x,y, lowest);
69      }
70    }
71  }
72 
73  if (status)
74    delete status;
75
76  for (i=0; i<to; i++)
77    olist[i]->occupy_location();
78
79  g1_edit_state.show_focus();
80
81
82  changed();
83
84  li_call("redraw");
85}
86
87void g1_editor_class::smooth_terrain()
88{
89  g1_editor_instance.unmark_all_selected_verts_for_undo_save();
90  g1_editor_instance.mark_selected_verts_for_undo_save();
91  g1_editor_instance.add_undo(G1_MAP_SELECTED_VERTS);
92
93  g1_edit_state.hide_focus();
94
95  int w=get_map()->width()+1, h=get_map()->height()+1;
96
97  w16 lowest=0xffff;
98
99  int t=0,x,y,i;
100
101  i4_status_class *status=i4_create_status(g1_ges("applying_smooth"));
102
103  g1_object_class *olist[G1_MAX_OBJECTS];
104  sw32 to=get_map()->make_object_list(olist, G1_MAX_OBJECTS);
105  for (i=0; i<to; i++)
106    olist[i]->unoccupy_location();
107
108
109  for (y=0; y<h; y++)
110  {
111    if (status)
112      status->update(y/(float)h);
113    for (x=0; x<w; x++)
114    {
115      g1_map_vertex_class *v=get_map()->vertex(x,y);
116      if (v->is_selected())
117      {
118        int t=1;
119        float sum=v->get_height();
120       
121        if (x>0) { t++; sum+=v[-1].get_height(); }
122        if (x<w-1) { t++; sum+=v[1].get_height(); }
123
124        if (y>0) { t++; sum+=v[-w].get_height(); }
125        if (y<h-1) { t++; sum+=v[w].get_height(); }
126
127        sw32 avg=(sw32)(sum/(t  * 0.05));
128        if (avg<0) avg=0;
129        if (avg>255) avg=255;
130
131        get_map()->change_vert_height(x,y, avg);
132      }
133    }
134  }
135
136  if (status)
137    delete status;
138
139  for (i=0; i<to; i++)
140    olist[i]->occupy_location();
141
142  g1_edit_state.show_focus();
143
144
145  changed();
146
147  li_call("redraw");
148
149}
150
151
152void g1_editor_class::noise_terrain()
153{
154
155  create_modal(300, 150, "terrain_noise_title");
156
157   i4_create_dialog(g1_ges("terrain_noise_dialog"),
158                    modal_window.get(),
159                    style,
160                    &terrain_noise_dialog.amount,
161                    vert_noise_amount,
162                    this, G1_EDITOR_TERRAIN_NOISE_OK,
163                    this, G1_EDITOR_MODAL_BOX_CANCEL); 
164}
165
166
167void g1_editor_class::noise_terrain_ok()
168{
169  g1_editor_instance.unmark_all_selected_verts_for_undo_save();
170  g1_editor_instance.mark_selected_verts_for_undo_save();
171  g1_editor_instance.add_undo(G1_MAP_SELECTED_VERTS);
172
173
174
175  g1_edit_state.hide_focus();
176
177  i4_str::iterator i=terrain_noise_dialog.amount->get_edit_string()->begin();
178  int am=i.read_number(),x,y;
179  int w=get_map()->width()+1, h=get_map()->height()+1, j;
180
181  i4_status_class *status=i4_create_status(g1_ges("applying_noise"));
182
183 
184  g1_object_class *olist[G1_MAX_OBJECTS];
185  sw32 to=get_map()->make_object_list(olist, G1_MAX_OBJECTS);
186
187  for (j=0; j<to; j++)
188    olist[j]->unoccupy_location();
189
190 
191  if (am>=1 && am<=64)
192  {
193    for (y=0; y<h; y++)
194    {
195      if (status)
196        status->update(y/(float)h);
197
198      for (x=0; x<w; x++)
199      {
200        g1_map_vertex_class *v=get_map()->vertex(x,y);
201        if (v->is_selected())
202        {
203          int h=(int)v->height + (i4_rand() % am) - am/2;
204          if (h<0) h=0;
205          if (h>255) h=255;
206          get_map()->change_vert_height(x,y, h);
207        }
208      }
209    }
210  }
211
212
213  for (j=0; j<to; j++)
214    olist[j]->occupy_location();
215
216  if (status)
217    delete status;
218
219  g1_edit_state.show_focus();
220  changed();
221  li_call("redraw");
222  close_modal();
223}
224
225
Note: See TracBrowser for help on using the repository browser.