source: golgotha/src/golg/editor/commands/new_level.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.1 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/pmenu.hh"
11#include "gui/create_dialog.hh"
12#include "gui/text_input.hh"                                       
13#include "remove_man.hh"
14#include "m_flow.hh"
15#include "app/app.hh"
16#include "level_load.hh"
17#include "window/colorwin.hh"
18#include "file/file_open.hh"
19#include "app/app.hh"
20#include "light.hh"
21#include "tile.hh"
22#include "player.hh"
23#include "map.hh"
24#include "editor/e_res.hh"
25#include "saver.hh"
26#include "map_vert.hh"
27#include "level_load.hh"
28
29void g1_editor_class::open_new_level_window()
30{
31  enum { MIN_DIM=10, MAX_DIM=150 };
32  int uw=g1_map_is_loaded() ? get_map()->width() : 100;
33  int uh=g1_map_is_loaded() ? get_map()->height() : 100;
34
35  i4_color_window_class *cw=new i4_color_window_class(500,500,
36                                                      style->color_hint->neutral(), style);
37  i4_create_dialog(g1_ges("new_level_dialog"),
38                   cw,
39                   style,
40                   &new_dialog.name,
41                   MIN_DIM, MAX_DIM,  &new_dialog.w, uw,
42                   MIN_DIM, MAX_DIM,  &new_dialog.h, uh,
43                   this, G1_EDITOR_NEW_OK,
44                   this, G1_EDITOR_MODAL_BOX_CANCEL);
45
46  cw->resize_to_fit_children();
47  create_modal(cw->width(), cw->height(), "new_title");
48  modal_window.get()->add_child(0,0,cw); 
49}
50
51
52
53g1_map_class *g1_editor_class::create_default_map(int w, int h,
54                                                  const i4_const_str &name)
55{
56  g1_map_class *map=new g1_map_class(i4gets("tmp_savename"));
57
58
59  map->verts=(g1_map_vertex_class *)i4_malloc((w+1) * (h+1) *
60                                                    sizeof (g1_map_vertex_class),
61                                                    "map_verts");
62
63  map->cells=(g1_map_cell_class *)i4_malloc(w * h * sizeof (g1_map_cell_class), "map cells");
64  map->w=w;
65  map->h=h;
66
67  g1_set_map(map);
68
69
70  int default_tile_type=g1_tile_man.get_default_tile_type();
71
72
73  w32 x,y,mw=map->width(),mh=map->height();
74  for (x=0; x<mw; x++)
75  {
76    for (y=0; y<mh; y++)
77    {
78      g1_map_cell_class *c=map->cell(x,y);
79      c->init(default_tile_type, G1_ROTATE_0, i4_F);
80
81      if (x==0 || y==0 || x==mw-1 || y==mh-1)
82        c->flags=0;
83      else
84        c->flags=g1_map_cell_class::IS_GROUND;
85    }
86  }
87
88  for (x=0; x<mw+1; x++)
89    for (y=0; y<mh+1; y++)
90      map->vertex(x,y)->init();
91
92  map->current_movie=new g1_movie_flow_class;
93  map->current_movie->set_scene(0);
94
95
96  int old_allow=undo.allow;
97  undo.allow=0;
98  map->recalc_static_stuff();
99  undo.allow=old_allow;
100
101  for (int i=0; i<MAX_VIEWS; i++)
102  {
103    view_states[i].defaults();
104    view_states[i].suggest_camera_mode(G1_EDIT_MODE);
105
106    if (views[i])
107      views[i]->view=view_states[i];
108  }
109
110  map->set_filename(name);
111
112  g1_lights.defaults();
113
114  g1_player_man.load(0);
115
116  g1_object_type factory_pad=g1_get_object_type("factory_pad");
117  if (factory_pad && w>25 && h>25 && G1_MAX_PLAYERS>=4)
118  {
119    g1_object_class *o;
120
121    o=g1_create_object(factory_pad);   
122    if (o)
123    {
124      o->x=o->lx=w/2;
125      o->y=o->ly=h/2;
126      o->h=o->lh=map->terrain_height(o->x, o->y);
127      o->player_num=g1_player_man.get_local()->get_player_num();
128
129      o->occupy_location();
130      o->request_think();
131      g1_player_man.get(o->player_num)->add_object(o->global_id);
132    }
133  }
134
135
136  return map;
137}
138
139
140
141
142void g1_editor_class::new_level_from_dialog()
143{
144
145  int w,h;
146
147  i4_str::iterator is=new_dialog.w->get_edit_string()->begin();
148  w=is.read_number();
149  is=new_dialog.h->get_edit_string()->begin();
150  h=is.read_number();
151
152
153  if (!(w>=G1_MIN_MAP_DIMENSION && h>=G1_MIN_MAP_DIMENSION
154        && w<=G1_MAX_MAP_DIMENSION && h<=G1_MAX_MAP_DIMENSION))
155  {
156    close_modal();
157
158    create_modal(300, 50, "bad_w_h_title");
159    i4_create_dialog(g1_ges("bad_map_w_h_dialog"),
160                     modal_window.get(), style, w, h,
161                     G1_MIN_MAP_DIMENSION,
162                     G1_MAX_MAP_DIMENSION,
163                     this, G1_EDITOR_MODAL_BOX_CANCEL);
164  }
165  else 
166  {
167    add_undo(G1_MAP_ALL);
168
169    close_windows();
170     
171    changed();
172
173    if (g1_map_is_loaded())
174      g1_destroy_map();
175
176    i4_str *res_name=g1_get_res_filnename(*new_dialog.name->get_edit_string());
177    i4_file_class *fp=i4_open(*res_name);
178    delete res_name;
179   
180    if (fp)
181    {
182      g1_load_res_info(fp);
183      delete fp;
184    }
185
186
187
188    g1_initialize_loaded_objects();
189
190    g1_map_class *map=create_default_map(w,h,
191                                         *new_dialog.name->get_edit_string());
192  }
193 
194  close_modal();
195}
196
197
198
Note: See TracBrowser for help on using the repository browser.