File: map.lua

package info (click to toggle)
spring 103.0%2Bdfsg2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 43,720 kB
  • ctags: 63,685
  • sloc: cpp: 368,283; ansic: 33,988; python: 12,417; java: 12,203; awk: 5,879; sh: 1,846; xml: 655; perl: 405; php: 211; objc: 194; makefile: 77; sed: 2
file content (141 lines) | stat: -rw-r--r-- 3,363 bytes parent folder | download
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
map = {}

	-- function map:FindClosestBuildSite(unittype,builderpos, searchradius, minimumdistance)
	-- function map:CanBuildHere(unittype,position)
	-- function map:GetMapFeatures()
	-- function map:GetMapFeaturesAt(position,radius)
	-- function map:SpotCount()
	-- function map:GetSpot(idx)
	-- function map:GetMetalSpots()
	-- function map:MapDimensions()
	-- function map:MapName()
	-- function map:AverageWind()
	-- function map:MinimumWindSpeed()
	-- function map:MaximumWindSpeed()
	-- function map:TidalStrength()
	-- function map:MaximumHeight()
	-- function map:MinimumHeight()

-- ###################

	function map:FindClosestBuildSite(unittype,builderpos, searchradius, minimumdistance) -- returns Position
		-- needs spring gadget implementation, perhaps https://github.com/spring1944/spring1944/blob/master/LuaRules/Gadgets/craig/buildsite.lua ?
		return nil
		-- return game_engine:Map():FindClosestBuildSite(unittype,builderpos, searchradius, minimumdistance)
	end

	function map:CanBuildHere(unittype,position) -- returns boolean
		local unitName = unittype:Name()
		local def = UnitDefNames[unitName]
		local newX, newY, newZ = Spring.Pos2BuildPos(def.id, position.x, position.y, position.z)

		local blocked = Spring.TestBuildOrder(def.id, newX, newY, newZ, 1) == 0
		return ( not blocked )
	end

	function map:GetMapFeatures()
		return nil

		--[[local fv = game_engine:Map():GetMapFeatures()
		local f = {}
		local i = 0
		while i  < fv:size() do
			table.insert(f,fv[i])
			i = i + 1
		end
		fv = nil
		return f]]--
	end

	function map:GetMapFeaturesAt(position,radius)
		return nil

		--[[local m = game_engine:Map()
		local fv = m:GetMapFeaturesAt(position,radius)
		local f = {}
		local i = 0
		while i  < fv:size() do
			table.insert(f,fv[i])
			i = i + 1
		end
		fv = nil
		return f]]--
	end

	function map:SpotCount() -- returns the nubmer of metal spots
		return 0

		--local m = game_engine:Map()
		--return m:SpotCount()
	end

	function map:GetSpot(idx) -- returns a Position for the given spot
		return nil

		--local m = game_engine:Map()
		--return m:GetSpot(idx)
	end

	function map:GetMetalSpots() -- returns a table of spot positions
		return nil

		--[[
		local m = game_engine:Map()
		local fv = game_engine:Map():GetMetalSpots()
		local count = m:SpotCount()
		local f = {}
		local i = 0
		while i  < count do
			table.insert( f, m:GetSpot(i) )
			i = i + 1
		end
		fv = nil
		return f
		]]--
	end

	function map:MapDimensions() -- returns a Position holding the dimensions of the map
		return {
			x = Game.mapX,
			y = Game.mapY,
			z = 0
		}
	end

	function map:MapName() -- returns the name of this map
		return Game.mapName
	end

	function map:AverageWind() -- returns (minwind+maxwind)/2
		return ( Game.windMin + (Game.windMax - game.windMin)/2 )
	end


	function map:MinimumWindSpeed() -- returns minimum windspeed
		return Game.windMin
	end

	function map:MaximumWindSpeed() -- returns maximum wind speed
		return Game.windMax
	end

	function map:MaximumHeight() -- returns maximum map height
		return 0

		-- local m = game_engine:Map()
		-- return m:MaximumHeight()
	end

	function map:MinimumHeight() -- returns minimum map height
		return 0

		-- local m = game_engine:Map()
		-- return m:MinimumHeight()
	end


	function map:TidalStrength() -- returns tidal strength
		return Game.tidal
	end

	game.map = map