File: map.cpp

package info (click to toggle)
openssn 1.4-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 7,340 kB
  • sloc: cpp: 10,973; makefile: 80
file content (168 lines) | stat: -rw-r--r-- 3,325 bytes parent folder | download | duplicates (3)
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
#include <stdio.h>
#include <stdlib.h>
#include "map.h"


MAP::MAP()
{
   Init();
}



MAP::~MAP()
{

}



int MAP::Init()
{
   int status;
   int index;

   // init stuff ahead of time   
   for (index = 0; index < MAX_THERMALS; index++)
       thermals[index] = 0;

   status = Create_Thermal_Layers(MAX_THERMALS);
   return status;
}



// This function creates thermal layers spaced (more or less)
// eveningly. The function returns the number of thermals created. 
int MAP::Create_Thermal_Layers(int how_many)
{
   int base_range;
   int current_range;
   int index;

   base_range = MAX_THERMAL_DEPTH / how_many;
   current_range = 0;
   index = 0;
   while ( (index < MAX_THERMALS) && (index < how_many) )
   {
       current_range += base_range;
       thermals[index] = current_range + ( rand() % 150 ) - 75;
       index++;
   } 

   return index;
}


// At this point the ocean depth is the same everywhere, so
// we ignore the passed coordinaes and just return MAX_DEPTH
int MAP::Get_Ocean_Depth(int x, int y)
{
   return MAX_DEPTH;
}



// This function returns the number of thermal layers
// between depth1 and depth2
// If no thermals exist then the function returns zero.
int MAP::Thermals_Between(int depth_1, int depth_2)
{
   int start_point, end_point;
   int index, thermal_count;

   // if depths are the same, just return
   if (depth_1 == depth_2)
       return 0;

   // we need to make sure start_point is the higher depth
   if (depth_1 <= depth_2)
   {
      start_point = depth_1;
      end_point = depth_2;
   }
   else
   {
        start_point = depth_2;
        end_point = depth_1;
   }

   // move through each thermal layer and see if it lies between
   // the two depths.
   index = thermal_count = 0;
   while (index < MAX_THERMALS)
   {
      if ( (start_point < thermals[index]) && (thermals[index] < end_point) )
          thermal_count++;
      index++;
   }

   return thermal_count;
}


/*
This function finds the next themral above the current depth. If
no thermal lies above this position then we return "from_depth".
*/
int MAP::Next_Up(int from_depth)
{
   int index = MAX_THERMALS - 1;
   int found = FALSE;

   while ( (!found) && (index >= 0) )
   {
      if ( (thermals[index] > 0) && (thermals[index] < from_depth) )
         found = TRUE;
      else
         index--;
   }
   if (found)
      return thermals[index];
   else
      return from_depth;
}


/*
This function finds the next themral below the current depth. If
no thermal lies below this position then we return "from_depth".
*/
int MAP::Next_Down(int from_depth)
{
   int index = 0;
   int found = FALSE;

   while ( (!found) && (index < MAX_THERMALS) )
   {
        if ( (thermals[index] > 0) && (thermals[index] > from_depth) )
            found = TRUE;
        else
           index++;
   }
   if (found)
       return thermals[index];
   else
      return from_depth;
}







#ifdef DEBUGMAP
void MAP::Test_Map()
{
   int index;

   for (index = 0; index < MAX_THERMALS; index++)
     printf("Map termal %d: %d\n", index, thermals[index]);
   index = Thermals_Between(MIN_DEPTH, MAX_DEPTH);
   printf("Thermals between %d and %d: %d\n", MIN_DEPTH, MAX_DEPTH, index);
   index = Thermals_Between(MAX_DEPTH, MIN_DEPTH);
   printf("Thermals between %d and %d: %d\n", MAX_DEPTH, MIN_DEPTH, index);
}

#endif