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

Last change on this file since 80 was 80, checked in by Sam Hocevar, 12 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: 2.6 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 "lisp/lisp.hh"
10#include "map.hh"
11#include "lisp/li_init.hh"
12#include "map_man.hh"
13#include "math/pi.hh"
14#include "math/angle.hh"
15#include "map_cell.hh"
16#include "map_vert.hh"
17
18int g1_rotate_remap[4]={0, 1, 2, 3};
19
20li_object *g1_rotate_map_90(li_object *o, li_environment *env)
21{
22  if (!g1_map_is_loaded()) return 0; 
23  g1_map_class *map=g1_get_map();
24
25 
26  int ow=map->width(), oh=map->height(), nw=map->height(), nh=map->width(), size;
27
28  size=sizeof(g1_map_cell_class)*nw*nh;
29  if (size>i4_largest_free_block())
30  {
31    i4_warning("not enough memory");
32    return 0;
33  }
34 
35  g1_map_cell_class *ncells=(g1_map_cell_class *)i4_malloc(size,"");
36
37
38  size=sizeof(g1_map_vertex_class)*(nw+1)*(nh+1);
39  if (size>i4_largest_free_block())
40  {
41    i4_free(ncells);
42    i4_warning("not enough memory");
43    return 0;
44  }     
45  g1_map_vertex_class *nverts=(g1_map_vertex_class *)i4_malloc(size,"");
46
47  li_call("add_undo", li_make_list(new li_int(G1_MAP_ALL)));
48 
49  g1_object_class *olist[G1_MAX_OBJECTS];
50  int t=map->make_object_list(olist, G1_MAX_OBJECTS), i,x,y;
51
52  for (i=0; i<t; i++)
53    olist[i]->unoccupy_location();
54
55 
56
57  // move the cells
58  g1_map_cell_class *ocells=map->cell(0,0);
59  for (y=0; y<oh; y++)
60    for (x=0; x<ow; x++, ocells++)
61    {
62      int ns=y+x*nw;
63      ncells[ns]=*ocells;
64
65      ncells[ns].set_rotation((g1_rotation_type)((g1_rotate_remap[ncells[ns].get_rotation()])));
66    }
67
68  // move the vertexes
69  g1_map_vertex_class *overts=map->vertex(0,0);
70  for (y=0; y<oh+1; y++)
71    for (x=0; x<ow+1; x++, overts++)
72    {
73      int ns=y+x*(nw+1);
74      nverts[ns]=*overts;     
75    }
76
77
78  map->change_map(nw, nh, ncells, nverts);
79
80  // move the objects and rotate them
81  for (i=0; i<t; i++)
82  {
83    float x=olist[i]->x;
84    olist[i]->x=olist[i]->y;
85    olist[i]->y=x;
86
87    olist[i]->theta += i4_pi()/3.0/2.0;
88    i4_normalize_angle(olist[i]->theta);
89   
90    olist[i]->grab_old();
91  }
92 
93
94  for (i=0; i<t; i++)
95    olist[i]->occupy_location();
96
97 
98  li_call("editor_refresh");
99  li_call("editor_changed");
100  return 0;
101}
102
103
104li_automatic_add_function(g1_rotate_map_90, "Map/Rotate 90");
Note: See TracBrowser for help on using the repository browser.