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