]> icculus.org git repositories - btb/d2x.git/blob - main/editor/ktmap.c
fix misleading indentation, add explicit braces, etc
[btb/d2x.git] / main / editor / ktmap.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14 /*
15  *
16  * Texture map key bindings.
17  *
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include "conf.h"
22 #endif
23
24 #include <string.h>
25
26 #include "inferno.h"
27 #include "editor.h"
28 #include "mono.h"
29
30
31 //      Assign CurrentTexture to Curside in *Cursegp
32 int AssignTexture(void)
33 {
34    autosave_mine( mine_filename );
35    strcpy(undo_status[Autosave_count], "Assign Texture UNDONE.");
36
37         Cursegp->sides[Curside].tmap_num = CurrentTexture;
38
39         New_segment.sides[Curside].tmap_num = CurrentTexture;
40
41 //      propagate_light_intensity(Cursegp, Curside, CurrentTexture, 0); 
42                                                                                                                                                                          
43         Update_flags |= UF_WORLD_CHANGED;
44
45         return 1;
46 }
47
48 //      Assign CurrentTexture to Curside in *Cursegp
49 int AssignTexture2(void)
50 {
51         int texnum, orient, ctexnum, newtexnum;
52
53    autosave_mine( mine_filename );
54    strcpy(undo_status[Autosave_count], "Assign Texture 2 UNDONE.");
55
56         texnum = Cursegp->sides[Curside].tmap_num2 & 0x3FFF;
57         orient = ((Cursegp->sides[Curside].tmap_num2 & 0xC000) >> 14) & 3;
58         ctexnum = CurrentTexture;
59         
60         if ( ctexnum == texnum )        {
61                 orient = (orient+1) & 3;
62                 newtexnum = (orient<<14) | texnum;
63         } else {
64                 newtexnum = ctexnum;
65         }
66
67         Cursegp->sides[Curside].tmap_num2 = newtexnum;
68         New_segment.sides[Curside].tmap_num2 = newtexnum;
69
70         Update_flags |= UF_WORLD_CHANGED;
71
72         return 1;
73 }
74
75 int ClearTexture2(void)
76 {
77    autosave_mine( mine_filename );
78    strcpy(undo_status[Autosave_count], "Clear Texture 2 UNDONE.");
79
80         Cursegp->sides[Curside].tmap_num2 = 0;
81
82         New_segment.sides[Curside].tmap_num2 = 0;
83
84         Update_flags |= UF_WORLD_CHANGED;
85
86         return 1;
87 }
88
89
90 //      --------------------------------------------------------------------------------------------------
91 //      Propagate textures from Cursegp through Curside.
92 //      If uv_flag !0, then only propagate uv coordinates (if 0, then propagate textures as well)
93 //      If move_flag !0, then move forward to new segment after propagation, else don't
94 int propagate_textures_common(int uv_flag, int move_flag)
95 {
96    autosave_mine( mine_filename );
97    strcpy(undo_status[Autosave_count], "Propogate Textures UNDONE.");
98         
99         if (IS_CHILD(Cursegp->children[Curside]))
100                 med_propagate_tmaps_to_segments(Cursegp, &Segments[Cursegp->children[Curside]], uv_flag);
101
102         if (move_flag)
103                 SelectCurrentSegForward();
104
105         Update_flags |= UF_WORLD_CHANGED;
106
107         return 1;
108 }
109
110 //      Propagate texture maps from current segment, through current side
111 int PropagateTextures(void)
112 {
113         return propagate_textures_common(0, 0);
114 }
115
116 //      Propagate texture maps from current segment, through current side
117 int PropagateTexturesUVs(void)
118 {
119         return propagate_textures_common(-1, 0);
120 }
121
122 //      Propagate texture maps from current segment, through current side
123 // And move to that segment.
124 int PropagateTexturesMove(void)
125 {
126         return propagate_textures_common(0, 1);
127 }
128
129 //      Propagate uv coordinate from current segment, through current side
130 // And move to that segment.
131 int PropagateTexturesMoveUVs(void)
132 {
133         return propagate_textures_common(-1, 1);
134 }
135
136
137 //      -------------------------------------------------------------------------------------
138 int is_selected_segment(int segnum)
139 {
140         int     i;
141
142         for (i=0; i<N_selected_segs; i++)
143                 if (Selected_segs[i] == segnum)
144                         return 1;
145
146         return 0;
147
148 }
149
150 //      -------------------------------------------------------------------------------------
151 //      Auxiliary function for PropagateTexturesSelected.
152 //      Recursive parse.
153 void pts_aux(segment *sp)
154 {
155         int             side;
156
157         Been_visited[SEGMENT_NUMBER(sp)] = 1;
158
159         for (side=0; side<MAX_SIDES_PER_SEGMENT; side++) {
160                 if (IS_CHILD(sp->children[side])) {
161                         while ((!Been_visited[sp->children[side]]) && is_selected_segment(sp->children[side])) {
162                                 med_propagate_tmaps_to_segments(sp,&Segments[sp->children[side]],0);
163                                 pts_aux(&Segments[sp->children[side]]);
164                         }
165                 }
166         }
167 }
168
169 //      -------------------------------------------------------------------------------------
170 //      Propagate texture maps from current segment recursively exploring all children, to all segments in Selected_list
171 //      until a segment not in Selected_list is reached.
172 int PropagateTexturesSelected(void)
173 {
174         int             i;
175
176    autosave_mine( mine_filename );
177    strcpy(undo_status[Autosave_count], "Propogate Textures Selected UNDONE.");
178
179         for (i=0; i<MAX_SEGMENTS; i++) Been_visited[i] = 0;     //clear visited list
180         Been_visited[SEGMENT_NUMBER(Cursegp)] = 1;
181
182         pts_aux(Cursegp);
183
184         Update_flags |= UF_WORLD_CHANGED;
185
186         return 1;
187 }
188