-
Notifications
You must be signed in to change notification settings - Fork 3
/
Level-Obj.cpp
2075 lines (1790 loc) · 46 KB
/
Level-Obj.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Editing utilities
// Most of the code in this file has been taken from DEU, although it
// has been heavily rewritten and enhanced. However, the original copyright
// and license are still valid!
// Doom Editor Utility, by Brendon Wyber and Raphaël Quinet.
// You are allowed to use any parts of this code in another program, as
// long as you give credits to the authors in the documentation and in
// the program itself. Read the file README.1ST for more information.
// This program comes with absolutely no warranty.
// Changes to original code (c) 1995-2008 by Christoph Oelckers
#include "StdAfx.h"
#include "ZEd.h"
#include "View2D.h"
/*
#include "RotateInput.h"
*/
#include "texture.h"
#include "Level.h"
//==========================================================================
//
//
//
//==========================================================================
static bool IsSelected(void *_array,void * ptr,int arcount)
{
void **array=(void**)_array;
for(int i=0;i<arcount;i++) if (array[i]==ptr) return true;
return false;
}
static bool IsSelected(int *array,int ptr,int arcount)
{
for(int i=0;i<arcount;i++) if (array[i]==ptr) return true;
return false;
}
static bool IsSelectedS(short *array,int ptr,int arcount)
{
for(int i=0;i<arcount;i++) if (array[i]==ptr) return true;
return false;
}
//==========================================================================
/*
check if there is something of interest inside the given box
*/
//==========================================================================
int CLevel::GetCurSector(int x0, int y0, int x1, int y1)
{
int n, m, cur, curx;
int lx0, ly0, lx1, ly1;
int midx, midy;
cur = -1;
if (x1 < x0)
{
n = x0;
x0 = x1;
x1 = n;
}
if (y1 < y0)
{
n = y0;
y0 = y1;
y1 = n;
}
/* hack, hack... I look for the first LineDef crossing an horizontal half-line drawn from the cursor */
curx = 65535;
cur = -1;
midx = (x0 + x1) / 2;
midy = (y0 + y1) / 2;
for (n = 0; n < NumLines(); n++)
{
if ((StVt(n)->Y() > midy) != (EnVt(n)->Y() > midy))
{
lx0 = int(StVt(n)->X());
ly0 = int(StVt(n)->Y());
lx1 = int(EnVt(n)->X());
ly1 = int(EnVt(n)->Y());
m = lx0 + (int) ((long) (midy - ly0) * (long) (lx1 - lx0) / (long) (ly1 - ly0));
if (m >= midx && m < curx)
{
curx = m;
cur = n;
}
}
}
/* now look if this LineDef has a SideDef bound to one sector */
if (cur >= 0)
{
if (StVt(cur)->Y() > EnVt(cur)->Y())
cur = FrontSecNo(cur);
else
cur = BackSecNo(cur);
}
else
cur = -1;
return cur;
}
bool CLevel::IsLDInSector(int ld, bool paranoid)
{
if (FrontSecNo(ld)==-1 || BackSecNo(ld)==-1 ) return false;
if (FrontSecNo(ld) != BackSecNo(ld)) return false;
return !paranoid;
}
//==========================================================================
/*
get the Sector number of the SideDef opposite to this SideDef
(returns -1 if it cannot be found)
*/
//==========================================================================
int CLevel::GetOppositeSector(int ld1, bool firstside,int * pBest, bool paranoid) /* SWAP! */
{
double x0, y0, dx0, dy0;
double x1, y1, dx1, dy1;
double x2, y2, dx2, dy2;
double dist;
int ld2;
int bestld;
double bestdist, bestmdist;
double xy1;
/* get the coords for this LineDef */
x0 = StVt(ld1)->X();
y0 = StVt(ld1)->Y();
dx0 = EnVt(ld1)->X() - x0;
dy0 = EnVt(ld1)->Y() - y0;
/* find the normal vector for this LineDef */
x1 = (dx0 + x0 + x0) / 2;
y1 = (dy0 + y0 + y0) / 2;
if (firstside)
{
dx1 = dy0;
dy1 = -dx0;
}
else
{
dx1 = -dy0;
dy1 = dx0;
}
bestld = -1;
/* use a parallel to an axis instead of the normal vector (faster method) */
if (fabs( dy1) > fabs( dx1))
{
xy1=x1+0.25; // Don't let it go through integer coordinates
// If the projected line goes through a vertex it might
// miss either line connected to it.
if (dy1 > 0)
{
/* get the nearest LineDef in that direction (increasing Y's: North) */
bestdist = 32767;
bestmdist = 32767;
for (ld2 = 0; ld2 < NumLines(); ld2++)
{
if (ld2 != ld1 && ((StVt(ld2)->X() > xy1) != (EnVt(ld2)->X() > xy1)))
{
// Ignore linedefs with the same sector on both sides
if (IsLDInSector(ld2, paranoid)) continue;
x2 = StVt(ld2)->X();
y2 = StVt(ld2)->Y();
dx2 = EnVt(ld2)->X() - x2;
dy2 = EnVt(ld2)->Y() - y2;
dist = y2 + (xy1 - x2) * dy2 / dx2;
if (dist > y1 && (dist < bestdist || (dist == bestdist && (y2 + dy2 / 2) < bestmdist)))
{
bestld = ld2;
bestdist = dist;
bestmdist = y2 + dy2 / 2;
}
}
}
}
else
{
/* get the nearest LineDef in that direction (decreasing Y's: South) */
bestdist = -32767;
bestmdist = -32767;
for (ld2 = 0; ld2 < NumLines(); ld2++)
{
if (ld2 != ld1 && ((StVt(ld2)->X() > xy1) != (EnVt(ld2)->X() > xy1)))
{
// Ignore linedefs with the same sector on both sides
if (IsLDInSector(ld2, paranoid)) continue;
x2 = StVt(ld2)->X();
y2 = StVt(ld2)->Y();
dx2 = EnVt(ld2)->X() - x2;
dy2 = EnVt(ld2)->Y() - y2;
dist = y2 + ( double(xy1 - x2) * double(dy2) / double(dx2));
if (dist < y1 && (dist > bestdist || (dist == bestdist && (y2 + dy2 / 2) > bestmdist)))
{
bestld = ld2;
bestdist = dist;
bestmdist = y2 + dy2 / 2;
}
}
}
}
}
else
{
xy1=y1+0.25;
if (dx1 > 0)
{
/* get the nearest LineDef in that direction (increasing X's: East) */
bestdist = 32767;
bestmdist = 32767;
for (ld2 = 0; ld2 < NumLines(); ld2++)
{
if (ld2 != ld1 && ((StVt(ld2)->Y() > xy1) != (EnVt(ld2)->Y() > xy1)))
{
// Ignore linedefs with the same sector on both sides
if (IsLDInSector(ld2, paranoid)) continue;
x2 = StVt(ld2)->X();
y2 = StVt(ld2)->Y();
dx2 = EnVt(ld2)->X() - x2;
dy2 = EnVt(ld2)->Y() - y2;
dist = x2 + (double(xy1 - y2) * double(dx2) / double(dy2));
if (dist > x1 && (dist < bestdist || (dist == bestdist && (x2 + dx2 / 2) < bestmdist)))
{
bestld = ld2;
bestdist = dist;
bestmdist = x2 + dx2 / 2;
}
}
}
}
else
{
/* get the nearest LineDef in that direction (decreasing X's: West) */
bestdist = -32767;
bestmdist = -32767;
for (ld2 = 0; ld2 < NumLines(); ld2++)
{
if (ld2 != ld1 && ((StVt(ld2)->Y() > xy1) != (EnVt(ld2)->Y() > xy1)))
{
// Ignore linedefs with the same sector on both sides
if (IsLDInSector(ld2, paranoid)) continue;
x2 = StVt(ld2)->X();
y2 = StVt(ld2)->Y();
dx2 = EnVt(ld2)->X() - x2;
dy2 = EnVt(ld2)->Y() - y2;
dist = x2 + (double(xy1 - y2) * double(dx2) / double(dy2));
if (dist < x1 && (dist > bestdist || (dist == bestdist && (x2 + dx2 / 2) > bestmdist)))
{
bestld = ld2;
bestdist = dist;
bestmdist = x2 + dx2 / 2;
}
else if (dist==bestdist && bestmdist==x2+dx2/2)
{
int v11=GetLine(ld1)->line.Start;
int v12=GetLine(ld1)->line.End;
int v21=GetLine(ld2)->line.Start;
int v22=GetLine(ld2)->line.End;
if (v11==v21 || v12==v21 || v11==v22 || v12==v22) bestld=ld2;
}
}
}
}
}
/* no intersection: the LineDef was pointing outwards! */
if (bestld < 0)
return -1;
if (pBest) *pBest=bestld;
/* OK, we got it -- return the Sector number */
if (fabs( dy1) > fabs( dx1))
{
if ((StVt(bestld)->X() < EnVt(bestld)->Y()) == (dy1 > 0))
ld2= FrontSecNo(bestld);
else
ld2= BackSecNo(bestld);
}
else
{
if ((StVt(bestld)->Y() < EnVt(bestld)->Y()) != (dx1 > 0))
ld2= FrontSecNo(bestld);
else
ld2= BackSecNo(bestld);
}
return ld2;
}
//==========================================================================
//
//
//
//==========================================================================
void CLevel::OnCmdTag(wxCommandEvent & event)
{
int tag=FindFreeTag();
if (!m_Extended)
wxMessageBox(wxString::Format("First free tag is %d",tag), ZED_CAPTION);
else
wxMessageBox(wxString::Format("First free tag is %d\nFirst free tid is %d\nFirst free line ID is %d", tag,
FindFreeTid(), FindFreeLineId()), ZED_CAPTION);
}
//==========================================================================
//
//
//
//==========================================================================
int CLevel::FindFreeTag()
{
int tag;
int n;
bool ok;
tag = 1;
ok = false;
while (! ok)
{
ok = true;
if (!m_Extended)
{
for (n = 0; n < NumLines(); n++)
{
if (GetLine(n)->line.tag == tag)
{
ok = false;
break;
}
}
}
else
{
for (n = 0; n < NumLines(); n++)
{
int spec = GetLine(n)->line.type;
if (spec>0 && spec<=255 && cgc->LineMap[spec])
{
for(int j=0;j<5;j++)
{
if (GetLine(n)->line.args[j] == tag)
{
wxString str = cgc->LineMap[spec]->args[j];
if (!strnicmp(str.c_str(), "Tag:", 4))
{
ok = false;
goto break2;
}
}
}
}
}
break2: ;
}
if (ok)
{
for (n = 0; n < NumSectors(); n++)
{
if (GetSector(n)->tag == tag)
{
ok = false;
break;
}
}
}
tag++;
}
return tag - 1;
}
//==========================================================================
//
//
//
//==========================================================================
int CLevel::FindFreeTid()
{
int tag;
int n;
bool ok;
if (!m_Extended) return 0;
tag = 1;
ok = false;
while (! ok)
{
ok=true;
for (n = 0; n < NumLines(); n++)
{
int spec = GetLine(n)->line.type;
if (spec>0 && spec<=255 && cgc->LineMap[spec])
{
for(int j=0;j<5;j++)
{
if (GetLine(n)->line.args[j] == tag)
{
wxString str = cgc->LineMap[spec]->args[j];
if (!strnicmp(str.c_str(), "Tid:", 4))
{
ok = false;
goto break2;
}
}
}
}
}
break2:
for(n=0;n<NumThings();n++)
{
if (GetThing(n)->thingid==tag)
{
ok=false;
break;
}
}
tag++;
}
return tag - 1;
}
//==========================================================================
//
//
//
//==========================================================================
int CLevel::FindFreeLineId()
{
int tag;
int n;
bool ok;
if (!m_Extended) return 0;
tag = 1;
ok = false;
while (! ok)
{
ok=true;
for (n = 0; n < NumLines(); n++)
{
int spec = GetLine(n)->line.type;
if (spec>0 && spec<=255 && cgc->LineMap[spec])
{
for(int j=0;j<5;j++)
{
if (GetLine(n)->line.args[j] == tag)
{
wxString str = cgc->LineMap[spec]->args[j];
if (!strnicmp(str.c_str(), "LineID:", 7))
{
ok = false;
goto break2;
}
}
}
}
}
break2:
tag++;
}
return tag - 1;
}
//==========================================================================
//
//
//
//==========================================================================
void CLevel::OnCmdJoinLD(wxCommandEvent & event)
{
int i;
int done=false;
if (m_Mode!=modeVertexes) return;
MakeBackup("Join Linedefs", true, true, true, false);
if (m_Selection<0) m_Selection=0;
for (i=NumVertices()-1;i>=0;i--)
{
if (checked[i])
{
DeleteVerticesJoinLineDefs(i);
done=true;
}
}
if (!done) DeleteVerticesJoinLineDefs(m_Selection);
m_DrawWindow->Refresh();
m_Selection=0;
UpdateStatusBar();
}
//==========================================================================
//
//
//
//==========================================================================
void CLevel::OnCmdJoinLD2(wxCommandEvent & event)
{
int sel[2];
int selc=0;
int done=false;
if (m_Mode!=modeLineDefs) return;
MakeBackup("Join Linedefs", true, true, true, false);
/* change the LineDefs starts & ends */
for (int l = 0; l < NumLines(); l++)
{
if (checked[l])
{
if (selc < 2)
{
sel[selc++] = l;
}
else
{
wxMessageBox("You must select exactly 2 lines", ZED_CAPTION);
return;
}
}
}
if (selc != 2)
{
wxMessageBox("You must select exactly 2 lines", ZED_CAPTION);
return;
}
CLine * ln1=GetLine(sel[0]);
CLine * ln2=GetLine(sel[1]);
if (strnicmp(ln1->sides[0].texLower, ln2->sides[0].texLower,8) ||
strnicmp(ln1->sides[0].texNormal, ln2->sides[0].texNormal,8) ||
strnicmp(ln1->sides[0].texUpper, ln2->sides[0].texUpper,8) ||
ln1->sides[0].yoff != ln2->sides[0].yoff ||
strnicmp(ln1->sides[1].texLower, ln2->sides[1].texLower,8) ||
strnicmp(ln1->sides[1].texNormal, ln2->sides[1].texNormal,8) ||
strnicmp(ln1->sides[1].texUpper, ln2->sides[1].texUpper,8) ||
ln1->sides[1].yoff != ln2->sides[1].yoff)
{
wxMessageBox("Lines dont match.", ZED_CAPTION);
return;
}
if (ln2->line.Start == ln1->line.End)
{
ln1->line.End = ln2->line.End;
ln1->sides[1] = ln2->sides[1];
DeleteOneLineDef(sel[1]);
}
else if (ln1->line.Start == ln2->line.End)
{
ln2->line.End = ln1->line.End;
ln2->sides[1] = ln1->sides[1];
DeleteOneLineDef(sel[0]);
}
else
{
wxMessageBox("Lines are not connected.", ZED_CAPTION);
return;
}
m_DrawWindow->Refresh();
m_Selection=0;
checked.Clear();
UpdateStatusBar();
}
//==========================================================================
//
//
//
//==========================================================================
void CLevel::DeleteVerticesJoinLineDefs(int vert)
{
int lstart, lend, l;
lstart = -1;
lend = -1;
for (l = 0; l < NumLines(); l++)
{
CLine * ln=GetLine(l);
if (ln->line.Start == vert)
{
if (lstart == -1) lstart = l;
else lstart = -2;
}
if (ln->line.End == vert)
{
if (lend == -1) lend = l;
else lend = -2;
}
}
if (lstart < 0 || lend < 0)
{
wxMessageBox(wxString::Format(
"Cannot delete Vertex #%d and join the LineDefs.\n"
"The Vertex must be the start of one LineDef and the end of another one", vert), ZED_CAPTION);
return;
}
GetLine(lend)->line.End = GetLine(lstart)->line.End;
DeleteOneLineDef(lstart);
DeleteOneVertex(vert);
}
//==========================================================================
//
//
//
//==========================================================================
void CLevel::OnCmdMergeVertices(wxCommandEvent & event)
{
TArray<int> vtlist(100);
int cvtlist=0;
int i;
int done=false;
int newsel=-1;
if (m_Mode!=modeVertexes) return;
MakeBackup("Merge Vertices", true, true, true, false);
for (i=0;i<NumVertices();i++)
{
if (checked[i])
{
vtlist.Push(i);
if (!done) newsel=i;
done=true;
}
}
if (done)
{
MergeVertices(&vtlist[0],vtlist.Size());
m_DrawWindow->Refresh();
m_Selection=newsel;
UpdateStatusBar();
}
}
//==========================================================================
//
//
//
//==========================================================================
void CLevel::MergeVertices(int vtlist[],int cvtlist)
{
int v, l;
if (cvtlist<2)
{
wxMessageBox("You must select at least two vertices", ZED_CAPTION);
return;
}
/* change the LineDefs starts & ends */
for (l = 0; l < NumLines(); l++)
{
CLine * ln=GetLine(l);
if (IsSelected( vtlist, ln->line.Start,cvtlist))
{
/* don't change a LineDef that has both ends on the same spot */
if (!IsSelected(vtlist, ln->line.End, cvtlist) && ln->line.End != vtlist[0])
ln->line.Start = vtlist[0];
}
else if (IsSelected( vtlist, ln->line.End, cvtlist))
{
/* idem */
if (ln->line.Start != vtlist[0])
ln->line.End = vtlist[0];
}
}
for (v=cvtlist-1;v>0;v--) DeleteOneVertex(vtlist[v]);
UncheckAll();
}
//==========================================================================
//
//
//
//==========================================================================
void CLevel::OnCmdSplitSector(wxCommandEvent & event)
{
int i;
int done=false;
int ldlist[2];
int cldlist=0;
if (m_Mode!=modeVertexes) return;
MakeBackup("Split Sector", false, true, true, false);
for (i=0;i<(int)NumVertices();i++)
{
if (checked[i])
{
if (cldlist<2) ldlist[cldlist++]=i;
else
{
wxMessageBox("You must select exactly 2 Vertexes for this function", ZED_CAPTION);
return;
}
}
}
if (cldlist<2) wxMessageBox("You must select exactly 2 Vertexes for this function", ZED_CAPTION);
else SplitSector(ldlist[0],ldlist[1]);
m_DrawWindow->Refresh();
m_Selection=NumSectors()-1;
UpdateStatusBar();
}
///////////////////////////////////////////////////////////////
void CLevel::SplitSector(int v1,int v2)
{
TArray<CLine *>llist;
int s3,s2,s, l;
int curv;
CSideDef * sd;
CVertex * vertex1 = GetVertex(v1);
CVertex * vertex2 = GetVertex(v2);
/* check if there is a Sector between the two Vertices (in the middle) */
s = GetCurSector(int(vertex1->X()),int(vertex1->Y()),int(vertex2->X()),int(vertex2->Y()));
if (s < 0)
{
wxMessageBox(wxString::Format("There is no Sector between Vertex #%d and Vertex #%d", v1, v2), ZED_CAPTION);
return;
}
/* check if there is a closed path from vertex1 to vertex2, along the edge of the Sector s */
curv = v1;
while (curv != v2)
{
for (l = 0; l < NumLines(); l++)
{
CLine * ln = GetLine(l);
sd = &ln->sides[0];
if (sd && sd->sector == s && ln->line.Start == curv)
{
curv = ln->line.End;
llist.Push(ln);
break;
}
sd = &ln->sides[1];
if (sd && sd->sector == s && ln->line.End == curv)
{
curv = ln->line.Start;
llist.Push(ln);
break;
}
}
if (l >= NumLines())
{
wxString msg1 = wxString::Format("Cannot find a closed path from Vertex #%d to Vertex #%d", v1, v2);
if (curv == v1)
msg1+=wxString::Format("\nThere is no SideDef starting from Vertex #%d on Sector #%d", msg1,v1, s);
else
msg1+=wxString::Format("\nCheck if Sector #%d is closed (cannot go past Vertex #%d)", msg1,s, curv);
wxMessageBox(msg1, ZED_CAPTION);
return;
}
if (curv == v1)
{
wxMessageBox(wxString::Format("Vertex #%d is not on the same Sector (#%d) as Vertex #%d", v2, s, v1), ZED_CAPTION);
return;
}
}
/* now, the list of LineDefs for the new Sector is in llist */
/* add the new Sector, LineDef and SideDefs */
s2=InsertSector(GetSector(s));
l=InsertLineDef(NULL);
CLine * ln=GetLine(l);
ln->line.Start = v1;
ln->line.End = v2;
int bit = 2;
if (m_TextMap) bit = cgc->CheckTextMapThingFlag("twosided");
ln->line.Flags.SetBit(bit);
ln->sides[0].sector=s;
ln->sides[1].sector=s2;
/* bind all LineDefs in llist to the new Sector */
for(l=0;l<(int)llist.Size();l++)
{
if (llist[l]->sides[0].sector==s) llist[l]->sides[0].sector=s2;
if (llist[l]->sides[1].sector==s) llist[l]->sides[1].sector=s2;
}
/* second check... useful for Sectors within Sectors */
for (l = 0; l < NumLines(); l++)
{
CLine * ln=GetLine(l);
sd = &ln->sides[0];
if (sd && sd->sector == s)
{
s3 = GetOppositeSector(l, true);
if (s3 == s2) sd->sector=s2;
}
sd = &ln->sides[1];
if (sd && sd->sector == s)
{
s3 = GetOppositeSector(l, false);
if (s3 == s2) sd->sector=s2;
}
}
}
//==========================================================================
//
//
//
//==========================================================================
void CLevel::OnCmdSplitLinedefs(wxCommandEvent & event)
{
int i;
int done=false;
if (m_Mode!=modeLineDefs) return;
MakeBackup("Split Linedefs", true, true, true, false);
for (i=0;i<NumLines();i++)
{
if (checked[i])
{
SplitLineDefs(i);
done=true;
}
}
if (!done) SplitLineDefs(m_Selection);
m_DrawWindow->Refresh();
UncheckAll();
UpdateStatusBar();
}
//==========================================================================
//
//
//
//==========================================================================
void CLevel::SplitLineDefs( int ld)
{
int nv,nl;
CVertex * VStart, * VEnd;
VStart=StVt(ld);
VEnd=EnVt(ld);
nv=InsertVertex((VStart->X()+VEnd->X())/2,(VStart->Y()+VEnd->Y())/2);
nl=InsertLineDef(GetLine(ld));
GetLine(ld)->line.End=nv;
GetLine(nl)->line.Start=nv;
}
//==========================================================================
//
//
//
//==========================================================================
void CLevel::OnCmdSplitLinedefsAndSector(wxCommandEvent & event)
{
int i;
int done=false;
int ldlist[2];
int cldlist=0;
if (m_Mode!=modeLineDefs) return;
MakeBackup("Split Linedefs and Sector", true, true, true, false);
for (i=0;i<NumLines();i++)
{
if (checked[i])
{
if (cldlist<2) ldlist[cldlist++]=i;
else
{
wxMessageBox("You must select exactly 2 Linedefs for this function", ZED_CAPTION);
return;
}
}
}
if (cldlist<2) wxMessageBox("You must select exactly 2 Linedefs for this function", ZED_CAPTION);
else SplitLineDefsAndSector(ldlist[0],ldlist[1]);
m_DrawWindow->Refresh();
UncheckAll();
UpdateStatusBar();
}
//==========================================================================
//
//
//
//==========================================================================
void CLevel::SplitLineDefsAndSector(int L1,int L2)
{
int se1,se2,se3,se4;
/* check if the two LineDefs are adjacent to the same Sector */
se1 = FrontSecNo(L1);
se2 = BackSecNo(L1);
se3 = FrontSecNo(L2);
se4 = BackSecNo(L2);
if ((se1==-1 || (se1 != se3 && se1 != se4)) && (se2 == -1 || (se2 != se3 && se2 != se4)))
{
wxMessageBox(wxString::Format("LineDefs #%d and #%d are not adjacent to the same Sector", L1,L2), ZED_CAPTION);
return;
}
/* split the two LineDefs and create two new Vertices */
SplitLineDefs(L1);
SplitLineDefs(L2);
/* split the Sector and create a LineDef between the two Vertices */
SplitSector(NumVertices()-1,NumVertices()-2);
}
//==========================================================================
//
//
//
//==========================================================================
void CLevel::OnJoinsectors(wxCommandEvent & event)
{
if (Selection.Size()>1 && m_Mode==modeSectors)
{
MakeBackup("Join Sectors", false, true, true, false);
for(int i=0;i<NumLines();i++)
{
CLine * ln = GetLine(i);
for(unsigned j=1;j<Selection.Size();j++)
{
if (ln->sides[0].sector==Selection[j]) ln->sides[0].sector=Selection[0];
if (ln->sides[1].sector==Selection[j]) ln->sides[1].sector=Selection[0];
}
}
m_Selection=Selection[0];
for(int i=NumSectors()-1;i>=0;i--)