File: rand_poly.c

package info (click to toggle)
liquidwar 5.6.3-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 15,960 kB
  • ctags: 2,583
  • sloc: ansic: 25,365; xml: 4,001; sh: 3,053; makefile: 1,353; asm: 1,344; python: 537; php: 486; sql: 22
file content (69 lines) | stat: -rw-r--r-- 1,299 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
/*
* One big, solid, random polygon that takes up most of the map.
*
* Copyright (C) 2003, David Redick
* Released under the GNU General Public License (v2)
*/

#include "map.h"
#include "misc.h"

#define PAD     5

void rand_poly()
{
     int r, c;
     int num_vert;
     int *vert;
     int v;

    
     /* -4 is for the corners */
     num_vert = (2*map.num_col) + (2*map.num_row) - 4;
     vert = create_array(num_vert*2, sizeof(int));

     v = 0;

     /* top */
     r = 0;
     for( c = 0; c < map.num_col; c++ )
     {
          rand_point_section_offset(&vert[v], &vert[v+1], r, c, PAD);
          v += 2;
     }


     /* right side */
     c = map.num_col-1;
     for( r = 1; r < map.num_row; r++ )
     {
          rand_point_section_offset(&vert[v], &vert[v+1], r, c, PAD);
          v += 2;
     }


     /* bottom */
     r = map.num_row-1;
     for( c = map.num_col-2; c >= 0; c-- )
     {
          rand_point_section_offset(&vert[v], &vert[v+1], r, c, PAD);
          v += 2;
     }


     /* left side */
     c = 0;
     for( r = map.num_row-2; r >= 1; r-- )
     {
          rand_point_section_offset(&vert[v], &vert[v+1], r, c, PAD);
          v += 2;
     }


     /* draw poly */
     polygon(map.map, num_vert, vert, map.color);

     delete_array(vert);
     
return;
}