File: shape.c

package info (click to toggle)
xbattle 5.4.1-9
  • links: PTS
  • area: main
  • in suites: potato
  • size: 736 kB
  • ctags: 1,086
  • sloc: ansic: 9,102; sh: 845; makefile: 493
file content (1095 lines) | stat: -rw-r--r-- 29,553 bytes parent folder | download | duplicates (7)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
#include <stdio.h>

#include "constant.h"
  
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/keysym.h>
#include <X11/keysymdef.h>

#include "extern.h"


/******************************************************************************
  shape_initialize ()

  Initialize all the shapes necessary for a given tiling method. Set all
  positions, connection, horizons, selection and direction charts.
******************************************************************************/

shape_initialize ()
{
  int i, j,
      side;
  cell_type *cell;
  double factor;
  shape_type *shape, *shape2;

  /** Create an initialize the basic shape structures **/

  for (side=0; side<Config->side_count; side++)
  {
    Board->shapes[side][0] = (shape_type *)(malloc(sizeof(shape_type)));

    /** Set maximum values **/

    Board->shapes[side][0]->max_value = Config->max_value[side];
    Board->shapes[side][0]->max_max_value = Config->max_max_value;

    switch (Config->tile_type)
    {
      case TILE_HEX:

        hex_set_dimensions (Board->shapes[side][0],
				Config->cell_size[side], side);
        shape_set_chart (Board->shapes[side][0]);
        Board->shape_count = 1;
        break;

      /** Octagon tiling interleaves octagons (shape index 0) and small	**/
      /** squares (shape index 1).					**/

      case TILE_OCTAGON:

        octagon_set_dimensions (Board->shapes[side][0],
				Config->cell_size[side], side);

        Board->shapes[side][1] = (shape_type *)(malloc(sizeof(shape_type)));

        Board->shapes[side][1]->max_value = Board->shapes[side][0]->max_value;
        Board->shapes[side][1]->max_max_value =
				Board->shapes[side][0]->max_max_value;

        square_set_dimensions (Board->shapes[side][1],
				Board->shapes[side][0]->helper.x+2, side, TRUE);

        octagon_set_square_troops
			(Board->shapes[side][0], Board->shapes[side][1]);

        shape_set_chart (Board->shapes[side][0]);
        shape_set_chart (Board->shapes[side][1]);
        Board->shape_count = 2;
        break;

      case TILE_DIAMOND:

        diamond_set_dimensions (Board->shapes[side][0],
				Config->cell_size[side], side);
        shape_set_chart (Board->shapes[side][0]);
        Board->shape_count = 1;
        break;

      /** Triangle tiling interleaves triangles with points up (shape	**/
      /** index 0) and triangles with points down (shape index 1).	**/

      case TILE_TRIANGLE:

        triangle_set_dimensions (Board->shapes[side][0],
				Config->cell_size[side], side, TRUE);

        Board->shapes[side][1] = (shape_type *)(malloc(sizeof(shape_type)));

        Board->shapes[side][1]->max_value = Board->shapes[side][0]->max_value;
        Board->shapes[side][1]->max_max_value =
				Board->shapes[side][0]->max_max_value;

        triangle_set_dimensions (Board->shapes[side][1],
				Config->cell_size[side], side, FALSE);
        shape_set_chart (Board->shapes[side][0]);
        shape_set_chart (Board->shapes[side][1]);
        Board->shape_count = 2;
        break;

      case TILE_SQUARE:

        square_set_dimensions (Board->shapes[side][0],
				Config->cell_size[side], side, FALSE);
        shape_set_chart (Board->shapes[side][0]);
        Board->shape_count = 1;
        break;
    }
  }

  /** Set each cell's position and shape index, dependent upon its	**/
  /** position in the board grid.					**/

  for (j=0; j<Config->board_y_size; j++)
  {
    for (i=0; i<Config->board_x_size; i++)
    {
      for (side=0; side<Config->side_count; side++)
      {
        switch (Config->tile_type)
        {
          case TILE_HEX:
            hex_set_center (CELL2(i,j), Board->shapes[side][0], side);
            break;

          case TILE_OCTAGON:
            octagon_set_center (CELL2(i,j), Board->shapes[side][0],
				Board->shapes[side][1], side);
            break;

          case TILE_DIAMOND:
            diamond_set_center (CELL2(i,j), Board->shapes[side][0], side);
            break;

          case TILE_TRIANGLE:
            triangle_set_center (CELL2(i,j), Board->shapes[side][0],
				Board->shapes[side][1], side);
            break;

          case TILE_SQUARE:
            square_set_center (CELL2(i,j), Board->shapes[side][0], side);
            break;
        }
      }
    }
  }

  /** Initialize pointers to neighboring cells **/

  switch (Config->tile_type)
  {
    case TILE_HEX:
      hex_set_connections ();
      break;

    case TILE_OCTAGON:
      octagon_set_connections ();
      break;

    case TILE_DIAMOND:
      diamond_set_connections ();
      break;

    case TILE_TRIANGLE:
      triangle_set_connections ();
      break;

    case TILE_SQUARE:
      square_set_connections ();
      break;
  }

  /** Initialize horizon arrays **/

  if (Config->enable_all[OPTION_HORIZON])
  {
    for (side=0; side<Config->side_count; side++)
    {
      switch (Config->tile_type)
      {
        case TILE_HEX:
          hex_set_horizons (Board->shapes[side][0]);
          break;

        case TILE_OCTAGON:
          octagon_set_horizons (Board->shapes[side][0],
				Board->shapes[side][1]);
          break;

        case TILE_DIAMOND:
          diamond_set_horizons (Board->shapes[side][0]);
          break;

        case TILE_TRIANGLE:
          triangle_set_horizons (Board->shapes[side][0], TRUE);
          triangle_set_horizons (Board->shapes[side][1], FALSE);
          break;

        case TILE_SQUARE:
          square_set_horizons (Board->shapes[side][0]);
          break;
      }
    }
  }

  /** Initialize selection grid which is used to determine which cell	**/
  /** corresponds to an arbitrary (x,y) coordinate.			**/

  for (side=0; side<Config->side_count; side++)
  {
    Config->selects[side] = (select_type *)(malloc(sizeof(select_type)));

    switch (Config->tile_type)
    {
      case TILE_HEX:
        hex_set_selects (Board->shapes[side][0], Config->selects[side], side);
        break;

      case TILE_OCTAGON:
        octagon_set_selects (Board->shapes[side][0],
			Board->shapes[side][1], Config->selects[side], side);
        break;

      case TILE_DIAMOND:
        diamond_set_selects (Board->shapes[side][0],
			Config->selects[side], side);
        break;

      case TILE_TRIANGLE:
        triangle_set_selects (Board->shapes[side][0],
			Config->selects[side], side);
        break;

      case TILE_SQUARE:
        square_set_selects (Board->shapes[side][0],
			Config->selects[side], side);
        break;
    }
  }

  /** Initialize size of playing board.  Depending on the tiling method	**/
  /** this may involve some complexities involving even and odd board	**/
  /** dimenions.							**/

  for (side=0; side<Config->side_count; side++)
  {
    shape = Board->shapes[side][0];
    shape2 = Board->shapes[side][1];

    switch (Config->tile_type)
    {
      case TILE_HEX:

        Board->size[side].x =
                (Config->board_x_size-1)*3*(shape->side/2) + 2*shape->side;
        Board->size[side].y = Config->board_y_size*shape->size_bound.y +
                                shape->center_bound.y + 1;
        break;

      case TILE_OCTAGON:

        Board->size[side].x = (Config->board_x_size/2) *
		 (shape->size_bound.x + shape2->size_bound.x - 2) +
		 (Config->board_x_size%2) * (shape->size_bound.x - 1) +
		 (1 - Config->board_x_size%2) * shape->corner_vertex.x + 1;

        Board->size[side].y = (Config->board_y_size/2) *
		 (shape->size_bound.y + shape2->size_bound.y - 2) +
		 (Config->board_y_size%2) * (shape->size_bound.y - 1) +
		 (1 - Config->board_y_size%2) * shape->corner_vertex.x + 1;
        break;

      case TILE_DIAMOND:

        Board->size[side].x = (Config->board_x_size+1) * (shape->side/2) + 1;
        Board->size[side].y = Config->board_y_size * (shape->side-1) +
					shape->side/2 + 1;
        break;

      case TILE_TRIANGLE:

        Board->size[side].x = (Config->board_x_size/2) *
			(shape->size_bound.x - 1);
        Board->size[side].y = Config->board_y_size * shape->size_bound.y + 1;

        if (Config->board_x_size%2)
          Board->size[side].x += shape->size_bound.x - 1;
        else
          Board->size[side].x += shape->size_bound.x/2;
        break;

      case TILE_SQUARE:

        if (Config->enable[OPTION_GRID][side])
        {  
          Board->size[side].x = Config->board_x_size * (shape->side-1) + 1;
          Board->size[side].y = Config->board_y_size * (shape->side-1) + 1;
        }  
        else
        {   
          Board->size[side].x = Config->board_x_size * shape->side + 1;
          Board->size[side].y = Config->board_y_size * shape->side + 1;
        }
        break;
    }
  }
}



/******************************************************************************
  shape_set_draw_method (shape, side, disallow_pixmap)

  Based on OPTION_DRAW, as specified in the command line (or by default),
  set up the correct drawing method for <side>'s <shape>.  If <disallow_pixmap>
  then don't allow the DRAW_PIXMAP method (which is really only valid for
  rectangular cells).
******************************************************************************/

shape_set_draw_method (shape, side, disallow_pixmap)
  shape_type *shape;
  int side,
      disallow_pixmap;
{

  /** Send warning message if user tries invalid method **/

  if (disallow_pixmap &&
		Config->value_int[OPTION_DRAW][side] == DRAW_PIXMAP)
  {
    throw_warning ("Cannot use DRAW_PIXMAP method, using DRAW_SIMPLE", NULL);
    Config->value_int[OPTION_DRAW][side] = DRAW_SIMPLE;
  }

  switch (Config->value_int[OPTION_DRAW][side])
  {
    /** 1 erase, 0 copy **/

    case DRAW_SIMPLE:

      shape->copy_method =	COPY_NONE;
      shape->erase_method =	ERASE_DRAW;
      break;

    /** 1 erase, 1 copy **/

    case DRAW_BACKING:

      shape->copy_method =	COPY_BACK;
      shape->erase_method =	ERASE_DRAW;
      break;

    /** 0 erase, 2 copy **/

    case DRAW_PIXMAP:

      shape->copy_method =	COPY_PIXMAP;
      shape->erase_method =	ERASE_NONE;
      break;

    /** 1 erase, 2 copy **/

    case DRAW_WINDOW:

      shape->copy_method =	COPY_WINDOW;
      shape->erase_method =	ERASE_DRAW;
      break;

    /** 0 erase, 4 copy **/

    case DRAW_MASKING:

      shape->copy_method =	COPY_WINDOW;
      shape->erase_method =	ERASE_MASK;
      break;
  }
}



/******************************************************************************
  shape_set_growth (shape)

  Set the array for <shape> which maps a town's growth factor into a radius,
  based on <shape->circle_bound>.  Might want to change this to use some
  fraction of <shape->center_erase.x>.
******************************************************************************/

shape_set_growth (shape)
  shape_type *shape;
{
  int i,
      min_radius,
      max_radius;

  double growth_step,
         growth_radius;

  /** Compute the minimum and maximum radii **/

  min_radius = (int)(TOWN_MIN_FRACTION * shape->circle_bound);
  if (min_radius < TOWN_MIN_RADIUS)
    min_radius = TOWN_MIN_RADIUS;
  max_radius = (int)(TOWN_MAX_FRACTION * shape->circle_bound);

  /** Compute the floating point step between each growth factor **/

  growth_step = ((double)(max_radius - min_radius))/
				(TOWN_MAX - TOWN_MIN);
  growth_radius = TOWN_MIN_RADIUS;

  /** For each valid growth factor, set mapping **/

  for (i=TOWN_MIN; i<=TOWN_MAX; i++)
  {
    shape->growth_to_radius[i] = (int)(growth_radius + 0.5);
    growth_radius += growth_step;
  }
}



/******************************************************************************
  shape_set_troops (shape)

  Set the array for <shape> which maps the number of troops into a radius
  based on <shape->circle_bound>.  Might want to change this to use some
  fraction of <shape->center_erase.x>.
******************************************************************************/

shape_set_troops (shape)
  shape_type *shape;
{
  int i,
      min_size,
      max_size;

  double troop_step,
         troop_size,
         full,
         sqrt();

  /** Compute the minimum and maximum radii **/

  min_size = (int)(TROOP_MIN_FRACTION * 2 * shape->circle_bound);
  max_size = (int)(TROOP_MAX_FRACTION * 2 * shape->circle_bound);

  if (min_size < TROOP_MIN_SIZE)
    min_size = TROOP_MIN_SIZE;
  if (max_size > 2*shape->circle_bound - TROOP_MIN_BUFFER)
    max_size = 2*shape->circle_bound - TROOP_MIN_BUFFER;

  /** Compute the floating point step between each troop **/

  troop_step = ((double)(max_size - min_size))/shape->max_max_value;
  troop_size = min_size;

  /** For each valid number of troops (and then some), set mapping **/

  if (Config->enable_all[OPTION_AREA])
  {
    full = ((double)(shape->max_max_value))/((shape->max_max_value+4)*
                        (shape->max_max_value+4));

    for (i=0; i<=shape->max_max_value+2; i++)
      shape->troop_to_size[i] =  (int)(max_size * sqrt (full*i) + 0.5);
  }
  else
  {
    shape->troop_to_size[0] = 0;
    for (i=1; i<=shape->max_max_value+2; i++)
    {
      shape->troop_to_size[i] =  (int)(troop_size + 0.5);
      troop_size += troop_step;
    }
  }
}



/******************************************************************************
  shape_set_chart (shape)

  Compute <shape->chart>, which determines how arbitrary (x,y) coordinates
  map into directions.  This routine assumes that directions are evenly
  distributed (by angle) around <shape->center_bound> and that direction 0
  begins at <shape->angle_offset>.
******************************************************************************/

shape_set_chart (shape)
  shape_type *shape;
{
  int x, y,
      i, j, k,
      x_limit, y_limit,
      is_done,
      int_angle, mod_angle,
      sector_angle;

  double angle,
         base_angle,
         vertex_angle,
         secondary_angle,
         diff_angle,
         atan2();

  /** Set the angle subtended by each side **/

  sector_angle = 360/shape->direction_count;

  /** Set the upper limits on x and y offsets **/

  x_limit = shape->size_bound.x - shape->center_bound.x;
  y_limit = shape->size_bound.y - shape->center_bound.y;

  /** Step through each point in the cell bounding box.  Note that y	**/
  /** must be negated to accound for the fact that on the screen, y 	**/
  /** values increase going down.					**/

  for (y = -shape->center_bound.y, j=0; y <= y_limit; y++, j++)
  {
    for (x = -shape->center_bound.x, i=0; x <= x_limit; x++, i++)
    {
      /** Determine the angle from the center of the cell to the position **/

      if (x == 0)
      {
        if (y < 0)
          base_angle = 90.0;
        else
          base_angle = 270.0;
      }
      else
      {
        base_angle = atan2 (((double)(-y)), ((double)(x)));
        base_angle = base_angle * 180.0 / 3.1415927;
      }

      /** Subtract offset to Nth vertex **/

      angle = base_angle - shape->angle_offset;

      /** Put angle in range (0,360) **/
      
      if (angle < 0)
        angle = 360.0 + angle;
      else if (angle >= 360.0)
        angle = angle - 360.0;

      /** Round angle into one of shape->direction_count directions **/

      int_angle = (int)(angle);
      mod_angle = int_angle/sector_angle;

      /** Based on rounded angle, set vector direction **/

      shape->chart[i][j][0] = mod_angle;

      /** Now we must set the "secondary" angles which determine the	**/
      /** location of corner clicks which yield dual vectors.		**/

      /** Set the angle to the counterclockwise vertex of the 0 side **/

      angle = base_angle - shape->angle_offset - sector_angle;

      /** Put angle in range (0,360) **/
      
      if (angle < 0)
        angle = 360.0 + angle;
      else if (angle >= 360.0)
        angle = angle - 360.0;

      /** Compute the range of the secondary angle **/

      secondary_angle = ((double)(sector_angle))/4.0;
      vertex_angle = 0.0;

      /** Step through each vertex and see if angle falls within the	**/
      /** secondary angle of it.					**/

      for (k=0, is_done=FALSE; k<shape->direction_count && !is_done; k++)
      {
        diff_angle = angle - vertex_angle;

        if (diff_angle > 180.0)
          diff_angle = diff_angle - 360.0;

        if (diff_angle < 0 && diff_angle > -secondary_angle)
        {
          shape->chart[i][j][1] = (k + 1)%(shape->direction_count);
          is_done = TRUE;
        }
        else if (diff_angle >= 0 && diff_angle < secondary_angle)
        {
          shape->chart[i][j][1] = k;
          is_done = TRUE;
        }

        vertex_angle += sector_angle;        
      }

      /** If point doesn't fall within angle, set to null **/

      if (!is_done)
        shape->chart[i][j][1] = -1;

      /** If position is closer than <Config->center_size> to the	**/
      /** center of the cell, eliminate all directions.			**/

      if (x*x + y*y < 2*Config->center_size*Config->center_size)
      {
        shape->chart[i][j][0] = -1;
        shape->chart[i][j][1] = -1;
      }
    }
  }

  /** Uncomment this stuff if you want to print out primary and/or	**/
  /** secondary direction charts.					**/

/**
  printf ("\n");
  for (y = -shape->center_bound.y, j=0; y <= y_limit; y++, j++)
  {
    for (x = -shape->center_bound.x, i=0; x <= x_limit; x++, i++)
    {
      if (shape->chart[i][j][0] < 0)
        printf (".");
      else
        printf ("%1d", shape->chart[i][j][0]);
    }
    printf ("\n");
  }
  printf ("\n");
  printf ("\n");

  for (y = -shape->center_bound.y, j=0; y <= y_limit; y++, j++)
  {
    for (x = -shape->center_bound.x, i=0; x <= x_limit; x++, i++)
    {
      if (shape->chart[i][j][1] < 0)
        fprintf (stderr, ".");
      else
        fprintf (stderr, "%1d", shape->chart[i][j][1]);
    }
    fprintf (stderr, "\n");
  }
  printf ("\n");
**/
}



/******************************************************************************
  shape_set_arrows (shape, offset)

  Assuming that <shape> is a regular polygon, set the coordinates for all its
  direction and marching vectors.  If dealing with an oblique angle, subtract
  <offset> from the arrow length.  This is currently used for octagon
  diagonals, when OCTAGON_OFFSET can warp the octagon such that it is not
  a regular polygon.
******************************************************************************/

shape_set_arrows (shape, offset)
  shape_type *shape;
  int offset;
{
  int i, k,
      angle, angle_step, angle_base,
      width,
      troop_size,
      max_troop_size;

  /** Determine the step between vector angles and the starting angle **/

  angle_step = 360/shape->direction_count;
  angle_base = (int)(shape->angle_offset + (180.0/shape->direction_count) + 0.5);

  /** Have to set full-length and half-length direction vectors **/

  for (i=0; i<2; i++)
  {
    /** Set length of direction vector **/

    if (i == 0)
      width = shape->center_erase.x;
    else
      width = shape->center_erase.x/2;

    /** For each direction **/

    angle = angle_base;
    for (k=0; k<shape->direction_count; k++)
    {
      /** Set direction vector, subtracting offset when appropriate **/

      if (i == 1 || angle == 0 || angle == 90 || angle == 180 ||
			angle == 270 || angle == 360)
        shape_set_single_arrow (width, 0, FALSE, angle,
			shape->arrow_source[k][i], shape->arrow_dester[k][i]);
      else
        shape_set_single_arrow (width-offset, 0, FALSE, angle,
			shape->arrow_source[k][i], shape->arrow_dester[k][i]);

      /** Increment angle **/

      angle += angle_step;
      if (angle >= 360)
        angle -= 360;
    }
  }

  /** Set length of direction vector **/

  width = shape->center_erase.x;
  max_troop_size = shape->troop_to_size[shape->max_max_value+2];

  for (i=0; i<=max_troop_size/2; i++)
  {
    /** Set inset vector length **/

    troop_size = i;

    /** For each direction **/

    angle = angle_base;
    for (k=0; k<shape->direction_count; k++)
    {
      /** Set direction vector, subtracting offset when appropriate **/

      if (i == 1 || angle == 0 || angle == 90 || angle == 180 ||
			angle == 270 || angle == 360)
        shape_set_single_arrow (width, troop_size, TRUE, angle,
		shape->arrow_source_x[i][k], shape->arrow_dester_x[i][k]);
      else
        shape_set_single_arrow (width-offset, troop_size, TRUE, angle,
		shape->arrow_source_x[i][k], shape->arrow_dester_x[i][k]);

      /** Increment angle **/

      angle += angle_step;
      if (angle > 360)
        angle -= 360;
    }
  }

  /** For each direction **/

  angle = angle_base;
  for (k=0; k<shape->direction_count; k++)
  {
    /** Set march vector, subtracting offset when appropriate **/

    if (i == 1 || angle == 0 || angle == 90 || angle == 180 ||
			angle == 270 || angle == 360)
      shape_set_single_march (width, angle,
		shape->march_source[k], shape->march_dester[k]);
    else
      shape_set_single_march (width-offset, angle,
		shape->march_source[k], shape->march_dester[k]);

    /** Increment angle **/

    angle += angle_step;
    if (angle > 360)
      angle -= 360;
  }
}



/******************************************************************************
  shape_set_single_arrow (length, aux_length,
		use_split, angle, arrow_source, arrow_dester)

  Set endpoint coordinates for a single direction vector of <length> and
  <angle>, using inset length of <aux_length> if <use_split>.  <arrow_source>
  and <arrow_dester> are the coordinate arrays to be used.
******************************************************************************/

shape_set_single_arrow (length, aux_length,
		use_split, angle, arrow_source, arrow_dester)
  int length,
      aux_length,
      use_split,
      angle;
  XPoint arrow_source[],
         arrow_dester[];
{
  int x_offset, y_offset,
      x_aux_offset, y_aux_offset;

  double rad_angle,
         cos(), sin();

  /** Handle horizontal and vertical vectors explicitly to ensure that	**/
  /** rounding errors in floating point conversion don't hurt things.	**/

  switch (angle)
  {
    case 0:
      x_offset =		 length;
      y_offset =		 0;
      x_aux_offset =		 aux_length;
      y_aux_offset =		 0;
      break;

    case 90:
      x_offset =		 0;
      y_offset =		-length;
      x_aux_offset =		 0;
      y_aux_offset =		-aux_length;
      break;

    case 180:
      x_offset =		-length;
      y_offset =		 0;
      x_aux_offset =		-aux_length;
      y_aux_offset =		 0;
      break;

    case 270:
      x_offset =		 0;
      y_offset =		 length;
      x_aux_offset =		 0;
      y_aux_offset =		 aux_length;
      break;

    /** Handle generic angle, determining (xoffset, y_offset) endpoints **/
  
    default:
      rad_angle =		 ((double)(angle)) * PI/180.0;
      x_offset =		 (int)(cos(rad_angle) * length);
      y_offset =		-(int)(sin(rad_angle) * length);
      x_aux_offset =		 (int)(cos(rad_angle) * aux_length);
      y_aux_offset =		-(int)(sin(rad_angle) * aux_length);
      break;
  }

  /** If <use_split> just set middle vector and inset and exit **/

  if (use_split)
  {
    arrow_source[0].x =		 0;
    arrow_source[0].y =		 0;
    arrow_dester[0].x =		 x_aux_offset;
    arrow_dester[0].y =		 y_aux_offset;

    arrow_source[1].x =		 x_aux_offset;
    arrow_source[1].y =		 y_aux_offset;
    arrow_dester[1].x =		 x_offset;
    arrow_dester[1].y =		 y_offset;

    return;
  }

  /** Set middle vector **/
  
  arrow_source[1].x =		 0;
  arrow_source[1].y =		 0;
  arrow_dester[1].x =		 x_offset;
  arrow_dester[1].y =		 y_offset;

  /** Set the flanking vectors, handling special cases explicitly **/

  /** If vertical vector **/

  if (x_offset == 0)
  {
    arrow_source[0].x =		-1;
    arrow_source[0].y =		 0;
    arrow_dester[0].x =		-1;
    arrow_dester[0].y =		 y_offset;

    arrow_source[2].x =		 1;
    arrow_source[2].y =		 0;
    arrow_dester[2].x =		 1;
    arrow_dester[2].y =		 y_offset;
  }
  else if (y_offset == 0)
  {
    /** Else if horizontal vector **/

    arrow_source[0].x =		  0;
    arrow_source[0].y =		 -1;
    arrow_dester[0].x =		  x_offset;
    arrow_dester[0].y =		 -1;

    arrow_source[2].x =		  0;
    arrow_source[2].y =		  1;
    arrow_dester[2].x =		  x_offset;
    arrow_dester[2].y =		  1;
  }
  else if (angle == 45 || angle == 135 || angle == 225 || angle == 315)
  {
    /** Else if diagonal vector **/

    arrow_source[0].x =		  0;
    arrow_source[0].y =		  (y_offset < 0) ? -1 : 1;
    arrow_dester[0].x =		  x_offset + ((x_offset < 0) ? 1 : -1);
    arrow_dester[0].y =		  y_offset;

    arrow_source[2].x =		  (x_offset < 0) ? -1 : 1;
    arrow_source[2].y =		  0;
    arrow_dester[2].x =		  x_offset;
    arrow_dester[2].y =		  y_offset + ((y_offset < 0) ? 1 : -1);
  }
  else
  {
    /** Else generic vector **/

    arrow_source[0].x =		  (x_offset < 0) ? 1 : -1;
    arrow_source[0].y =		  0;
    arrow_dester[0].x =		  x_offset + ((x_offset < 0) ? 1 : -1);
    arrow_dester[0].y =		  y_offset;

    arrow_source[2].x =		  0;
    arrow_source[2].y =		  (y_offset < 0) ? 1 : -1;
    arrow_dester[2].x =		  x_offset;
    arrow_dester[2].y =		  y_offset + ((y_offset < 0) ? 1 : -1);
  }
}



/******************************************************************************
  shape_set_single_march (length, angle, march_source, march_dester)

  Set endpoint coordinates for a single march vector of <length> and <angle>,
  using <march_source> and <march_dester> as coordinate arrays.
******************************************************************************/

shape_set_single_march (length, angle, march_source, march_dester)
  int length,
      angle;
  XPoint march_source[],
         march_dester[];
{
  int x_offset, y_offset,
      x_aux_offset, y_aux_offset,
      multer;

  double rad_angle,
         rad_aux_angle,
         cos(), sin();

  /** Handle horizontal and vertical vectors explicitly to ensure that	**/
  /** rounding errors in floating point conversion don't hurt things.	**/

  switch (angle)
  {
    case 0:
      x_offset =		 length;
      y_offset =		 0;
      break;

    case 90:
      x_offset =		 0;
      y_offset =		-length;
      break;

    case 180:
      x_offset =		-length;
      y_offset =		 0;
      break;

    case 270:
      x_offset =		 0;
      y_offset =		 length;
      break;

    /** Handle generic angle, determining (xoffset, y_offset) endpoints **/
  
    default:
      if (angle%45 != 0)
        length -= 1;
      rad_angle = ((double)(angle)) * PI/180.0;
      x_offset =		 (int)(cos(rad_angle) * length);
      y_offset =		-(int)(sin(rad_angle) * length);
      break;
  }

  /** If vertical vector **/

  if (x_offset == 0)
  {
    march_source[0].x =		-2;
    march_source[0].y =		 0;
    march_dester[0].x =		-2;
    march_dester[0].y =		 y_offset;

    march_source[1].x =		-3;
    march_source[1].y =		 0;
    march_dester[1].x =		-3;
    march_dester[1].y =		 y_offset;

    march_source[2].x =		 2;
    march_source[2].y =		 0;
    march_dester[2].x =		 2;
    march_dester[2].y =		 y_offset;

    march_source[3].x =		 3;
    march_source[3].y =		 0;
    march_dester[3].x =		 3;
    march_dester[3].y =		 y_offset;
  }
  else if (y_offset == 0)
  {
    /** Else if horizontal vector **/

    march_source[0].x =		  0;
    march_source[0].y =		 -2;
    march_dester[0].x =		  x_offset;
    march_dester[0].y =		 -2;

    march_source[1].x =		  0;
    march_source[1].y =		 -3;
    march_dester[1].x =		  x_offset;
    march_dester[1].y =		 -3;

    march_source[2].x =		  0;
    march_source[2].y =		  2;
    march_dester[2].x =		  x_offset;
    march_dester[2].y =		  2;

    march_source[3].x =		  0;
    march_source[3].y =		  3;
    march_dester[3].x =		  x_offset;
    march_dester[3].y =		  3;
  }
  else if (angle == 45 || angle == 135 || angle == 225 || angle == 315)
  {
    /** Else if diagonal vector **/

    if ((x_offset < 0 && y_offset < 0) || (x_offset > 0 && y_offset > 0))
      multer = -1;
    else
      multer = 1;

    march_source[0].x =		  2;
    march_source[0].y =		  2*multer;
    march_dester[0].x =		  2 + x_offset;
    march_dester[0].y =		  2*multer + y_offset;

    march_source[1].x =		  3;
    march_source[1].y =		  3*multer;
    march_dester[1].x =		  3 + x_offset;
    march_dester[1].y =		  3*multer + y_offset;

    march_source[2].x =		 -2;
    march_source[2].y =		 -2*multer;
    march_dester[2].x =		 -2 + x_offset;
    march_dester[2].y =		 -2*multer + y_offset;

    march_source[3].x =		 -3;
    march_source[3].y =		 -3*multer;
    march_dester[3].x =		 -3 + x_offset;
    march_dester[3].y =		 -3*multer + y_offset;
  }
  else
  {
    /** Else generic vector, define orthogonal points **/

    rad_aux_angle =		 rad_angle + PI/2.0;
    x_aux_offset =		 (int)(cos(rad_aux_angle) * 3);
    y_aux_offset =		-(int)(sin(rad_aux_angle) * 3);

    march_source[0].x =		  x_aux_offset;
    march_source[0].y =		  y_aux_offset;
    march_dester[0].x =		  x_aux_offset + x_offset;
    march_dester[0].y =		  y_aux_offset + y_offset;

    march_source[2].x =		 -x_aux_offset;
    march_source[2].y =		 -y_aux_offset;
    march_dester[2].x =		 -x_aux_offset + x_offset;
    march_dester[2].y =		 -y_aux_offset + y_offset;

    march_source[1].x =		  march_source[0].x +
					((x_offset < 0) ? 1 : -1);
    march_source[1].y =		  march_source[0].y;
    march_dester[1].x =		  march_dester[0].x +
					((x_offset < 0) ? 1 : -1);
    march_dester[1].y =		  march_dester[0].y;

    march_source[3].x =		  march_source[2].x -
					((x_offset < 0) ? 1 : -1);
    march_source[3].y =		  march_source[2].y;
    march_dester[3].x =		  march_dester[2].x -
					((x_offset < 0) ? 1 : -1);
    march_dester[3].y =		  march_dester[2].y;
  }
}