102 -- If flush is false, FlushPoints() is not called. |
102 -- If flush is false, FlushPoints() is not called. |
103 function eraseMap(flush) |
103 function eraseMap(flush) |
104 drawFullMap(true, flush) |
104 drawFullMap(true, flush) |
105 end |
105 end |
106 |
106 |
|
107 -- Approximative but desync-safe version of square root. This function follows the Babylonian method. |
|
108 function integerSqrt(num) |
|
109 local temp = num |
|
110 while (temp*temp - div(temp, 2) > num) |
|
111 do |
|
112 temp = div((temp + div(num, temp)), 2) |
|
113 end |
|
114 return math.abs(temp) |
|
115 end |
|
116 |
|
117 -- Integer square root of (x^2, y^2), works without desyncs. Is approximative. |
|
118 -- This is the same as the length of the hypotenuse of a triangle with legs x, y. |
|
119 function integerHypotenuse(x, y) |
|
120 -- To fix overflows |
|
121 if(((math.abs(x)^2) + (math.abs(y)^2)) > 2^26) |
|
122 then |
|
123 local bitr = 2^13 |
|
124 return integerSqrt((div(math.abs(x), bitr)^2) + (div(math.abs(y), bitr)^2)) * bitr |
|
125 else |
|
126 return integerSqrt((math.abs(x)^2) + (math.abs(y) ^ 2)) |
|
127 end |
|
128 end |
107 |
129 |
108 --[[ GLOBAL VARIABLES ]] |
130 --[[ GLOBAL VARIABLES ]] |
109 |
131 |
110 -- Shared common land color values for land sprites. |
132 -- Shared common land color values for land sprites. |
111 -- These are useful if you want to make the land type visible. |
133 -- These are useful if you want to make the land type visible. |