-
Notifications
You must be signed in to change notification settings - Fork 0
/
Resource_Placer.cs
296 lines (217 loc) · 11.8 KB
/
Resource_Placer.cs
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Resource_Placer : MonoBehaviour
{
public List<Vector3> GrassTilePosition = new List<Vector3>();
public List<Vector3> RiverTilePosition = new List<Vector3>();
public List<Vector3> HillTilePosition = new List<Vector3>();
public List<Vector3> MountainTilePosition = new List<Vector3>();
public List<Vector3> DesertTilePosition = new List<Vector3>();
public GameObject woods1;
public GameObject iron1;
public GameObject stone1;
public GameObject mana1;
public GameObject food1;
//private int x=0;
//private int z=0;
//private int skip=0;
private RaycastHit hit;
public IEnumerator placeWoods (int xmapmax, int zmapmax){
//int density = 8; might use later to add randomness
//woods should only place on grassland tiles. More patterns can be added later.
int pos = Random.Range(0, GrassTilePosition.Count);
//private RayCast hit.collider.gameObject.name;
//add a check to see what is there
if (Physics.Raycast(GrassTilePosition[pos] + new Vector3(0,2,0), Vector3.down,out hit, 3f)){
//print("can place:"+hit.collider.gameObject.name);
if (hit.collider.gameObject.name == "Grass_Clutter1(Clone)" || hit.collider.gameObject.name == "Grass_Clutter2(Clone)" || hit.collider.gameObject.name == "Grass_Clutter3(Clone)" || hit.collider.gameObject.name == "Grass(Clone)"){
hit.transform.gameObject.SendMessage("clearClutter");
Instantiate(woods1, GrassTilePosition[pos], Quaternion.Euler(new Vector3(0,Random.Range(0,6)*60,0)));
gameObject.GetComponent<Town_Placer>().WoodsPosition.Add(hit.transform.position);
}
else {
//print ("not the right tile:" +hit.collider.gameObject.name);
}
}
if (Physics.Raycast(GrassTilePosition[pos+1] + new Vector3(0,2,0), Vector3.down,out hit, 3f)){
//print("can place:"+hit.collider.gameObject.name);
if (hit.collider.gameObject.name == "Grass_Clutter1(Clone)" || hit.collider.gameObject.name == "Grass_Clutter2(Clone)" || hit.collider.gameObject.name == "Grass_Clutter3(Clone)" || hit.collider.gameObject.name == "Grass(Clone)"){
hit.transform.gameObject.SendMessage("clearClutter");
Instantiate(woods1, GrassTilePosition[pos+1], Quaternion.Euler(new Vector3(0,Random.Range(0,6)*60,0)));
gameObject.GetComponent<Town_Placer>().WoodsPosition.Add(hit.transform.position);
}
else {
//print ("not the right tile:" +hit.collider.gameObject.name);
}
}
if (Physics.Raycast(GrassTilePosition[pos+2] + new Vector3(0,2,0), Vector3.down,out hit, 3f)){
//print("can place:"+hit.collider.gameObject.name);
if (hit.collider.gameObject.name == "Grass_Clutter1(Clone)" || hit.collider.gameObject.name == "Grass_Clutter2(Clone)" || hit.collider.gameObject.name == "Grass_Clutter3(Clone)" || hit.collider.gameObject.name == "Grass(Clone)"){
hit.transform.gameObject.SendMessage("clearClutter");
Instantiate(woods1, GrassTilePosition[pos+2], Quaternion.Euler(new Vector3(0,Random.Range(0,6)*60,0)));
gameObject.GetComponent<Town_Placer>().WoodsPosition.Add(hit.transform.position);
}
else {
//print ("not the right tile:" +hit.collider.gameObject.name);
}
}
if (Physics.Raycast(GrassTilePosition[pos+29] + new Vector3(0,2,0), Vector3.down,out hit, 3f)){
//print("can place:"+hit.collider.gameObject.name);
if (hit.collider.gameObject.name == "Grass_Clutter1(Clone)" || hit.collider.gameObject.name == "Grass_Clutter2(Clone)" || hit.collider.gameObject.name == "Grass_Clutter3(Clone)" || hit.collider.gameObject.name == "Grass(Clone)"){
hit.transform.gameObject.SendMessage("clearClutter");
Instantiate(woods1, GrassTilePosition[pos+29], Quaternion.Euler(new Vector3(0,Random.Range(0,6)*60,0)));
gameObject.GetComponent<Town_Placer>().WoodsPosition.Add(hit.transform.position);
}
else {
// print ("not the right tile:" +hit.collider.gameObject.name);
}
}
if (Physics.Raycast(GrassTilePosition[pos+30] + new Vector3(0,2,0), Vector3.down,out hit, 3f)){
//print("can place:"+hit.collider.gameObject.name);
if (hit.collider.gameObject.name == "Grass_Clutter1(Clone)" || hit.collider.gameObject.name == "Grass_Clutter2(Clone)" || hit.collider.gameObject.name == "Grass_Clutter3(Clone)" || hit.collider.gameObject.name == "Grass(Clone)"){
hit.transform.gameObject.SendMessage("clearClutter");
Instantiate(woods1, GrassTilePosition[pos+30], Quaternion.Euler(new Vector3(0,Random.Range(0,6)*60,0)));
gameObject.GetComponent<Town_Placer>().WoodsPosition.Add(hit.transform.position);
}
else {
//print ("not the right tile:" +hit.collider.gameObject.name);
}
}
if (Physics.Raycast(GrassTilePosition[pos+31] + new Vector3(0,2,0), Vector3.down,out hit, 3f)){
//print("can place:"+hit.collider.gameObject.name);
if (hit.collider.gameObject.name == "Grass_Clutter1(Clone)" || hit.collider.gameObject.name == "Grass_Clutter2(Clone)" || hit.collider.gameObject.name == "Grass_Clutter3(Clone)" || hit.collider.gameObject.name == "Grass(Clone)"){
hit.transform.gameObject.SendMessage("clearClutter");
Instantiate(woods1, GrassTilePosition[pos+31], Quaternion.Euler(new Vector3(0,Random.Range(0,6)*60,0)));
gameObject.GetComponent<Town_Placer>().WoodsPosition.Add(hit.transform.position);
}
else {
//print ("not the right tile:" +hit.collider.gameObject.name);
}
}
if (Physics.Raycast(GrassTilePosition[pos-29] + new Vector3(0,2,0), Vector3.down,out hit, 3f)){
//print("can place:"+hit.collider.gameObject.name);
if (hit.collider.gameObject.name == "Grass_Clutter1(Clone)" || hit.collider.gameObject.name == "Grass_Clutter2(Clone)" || hit.collider.gameObject.name == "Grass_Clutter3(Clone)" || hit.collider.gameObject.name == "Grass(Clone)"){
hit.transform.gameObject.SendMessage("clearClutter");
Instantiate(woods1, GrassTilePosition[pos-29], Quaternion.Euler(new Vector3(0,Random.Range(0,6)*60,0)));
gameObject.GetComponent<Town_Placer>().WoodsPosition.Add(hit.transform.position);
}
else {
//print ("not the right tile:" +hit.collider.gameObject.name);
}
}
if (Physics.Raycast(GrassTilePosition[pos-30] + new Vector3(0,2,0), Vector3.down,out hit, 3f)){
//print("can place:"+hit.collider.gameObject.name);
if (hit.collider.gameObject.name == "Grass_Clutter1(Clone)" || hit.collider.gameObject.name == "Grass_Clutter2(Clone)" || hit.collider.gameObject.name == "Grass_Clutter3(Clone)" || hit.collider.gameObject.name == "Grass(Clone)"){
hit.transform.gameObject.SendMessage("clearClutter");
Instantiate(woods1, GrassTilePosition[pos-30], Quaternion.Euler(new Vector3(0,Random.Range(0,6)*60,0)));
gameObject.GetComponent<Town_Placer>().WoodsPosition.Add(hit.transform.position);
}
else {
//print ("not the right tile:" +hit.collider.gameObject.name);
}
}
if (Physics.Raycast(GrassTilePosition[pos-31] + new Vector3(0,2,0), Vector3.down,out hit, 3f)){
//print("can place:"+hit.collider.gameObject.name);
if (hit.collider.gameObject.name == "Grass_Clutter1(Clone)" || hit.collider.gameObject.name == "Grass_Clutter2(Clone)" || hit.collider.gameObject.name == "Grass_Clutter3(Clone)" || hit.collider.gameObject.name == "Grass(Clone)"){
hit.transform.gameObject.SendMessage("clearClutter");
Instantiate(woods1, GrassTilePosition[pos-31], Quaternion.Euler(new Vector3(0,Random.Range(0,6)*60,0)));
gameObject.GetComponent<Town_Placer>().WoodsPosition.Add(hit.transform.position);
}
else {
//print ("not the right tile:" +hit.collider.gameObject.name);
}
}
//repeat for however many woods there needs to be
//place iron next
yield return StartCoroutine(placeIron());
}
private IEnumerator placeIron (/*int xmapmax, int zmapmax*/) {
//iron will place on mountains tiles
int pos = Random.Range(1, 3);
for (int i=0; i< 2; i++){
if (Physics.Raycast(MountainTilePosition[pos+i] + new Vector3(0,2,0), Vector3.down,out hit, 3f)){
//print("can place:"+hit.collider.gameObject.name);
if (hit.collider.gameObject.name == "Mountain_Clutter1(Clone)" || hit.collider.gameObject.name == "Rock" || hit.collider.gameObject.name == "Dirt"){
hit.transform.gameObject.SendMessage("clearClutter");
Instantiate(iron1, hit.transform.position, Quaternion.Euler(new Vector3(0,Random.Range(0,6)*60,0)));
gameObject.GetComponent<Town_Placer>().IronPosition.Add(hit.transform.position);
}
else {
//print ("not the right tile:" +hit.collider.gameObject.name);
}
}
}
//save location to town placer list
//repeat for as many as desired
//place stone next
yield return StartCoroutine(placeStone());
}
private IEnumerator placeStone (){
//stone will place next to hill tiles, above or below them
int pos = 0; /*Random.Range(0, HillTilePosition.Count);*/
for (int i=0; i< 1; i++){
if (Physics.Raycast(HillTilePosition[pos+i] + new Vector3(0,2,0), Vector3.down,out hit, 3f)){
//print("can place:"+hit.collider.gameObject.name);
//need to add a check for all the tiles. Maybe checking the parent works better?
//then can place randomly in the area
if (hit.collider.gameObject.name == "Grass"){
hit.transform.gameObject.SendMessage("clearClutter");
Instantiate(stone1, hit.transform.position, Quaternion.Euler(new Vector3(0,Random.Range(0,6)*60,0)));
gameObject.GetComponent<Town_Placer>().StonePosition.Add(hit.transform.position);
}
else {
//print ("not the right tile:" +hit.collider.gameObject.name);
}
}
}
//save location to town placer list
//place as many stone as desired
//place mana next
yield return StartCoroutine(placeMana());
}
private IEnumerator placeMana(){
int which = Random.Range(0,2);
if (which == 1){
if (Physics.Raycast(MountainTilePosition[0] + new Vector3(0,2,0), Vector3.down,out hit, 3f)){
//print("can place:"+hit.collider.gameObject.name);
//need to add a check for all the tiles. Maybe checking the parent works better?
//then can place randomly in the area
if (hit.collider.gameObject.name == "Rock" || hit.collider.gameObject.name == "Mountain_Clutter1(Clone)"){
hit.transform.gameObject.SendMessage("clearClutter");
Instantiate(mana1, hit.transform.position, Quaternion.Euler(new Vector3(0,Random.Range(0,6)*60,0)));
gameObject.GetComponent<Town_Placer>().ManaPosition.Add(hit.transform.position);
}
else {
//print ("not the right tile:" +hit.collider.gameObject.name);
}
}
}
if (which == 0){
int pos= Random.Range(0, DesertTilePosition.Count);
if (Physics.Raycast(DesertTilePosition[pos] + new Vector3(0,2,0), Vector3.down,out hit, 3f)){
//print("can place:"+hit.collider.gameObject.name);
//need to add a check for all the tiles. Maybe checking the parent works better?
//then can place randomly in the area
if (hit.collider.gameObject.name == "Sand(Clone)" || hit.collider.gameObject.name == "Desert_Clutter1(Clone)"){
hit.transform.gameObject.SendMessage("clearClutter");
Instantiate(mana1, hit.transform.position, Quaternion.Euler(new Vector3(0,Random.Range(0,6)*60,0)));
gameObject.GetComponent<Town_Placer>().ManaPosition.Add(hit.transform.position);
}
else {
//print ("not the right tile:" +hit.collider.gameObject.name);
}
}
}
//mana spawns in deserts and on mountain peaks at height 7-9
//save location to town palcer list
//place as many as desired
//place towns next
yield return null;
StartCoroutine(gameObject.GetComponent<Town_Placer>().placeVillages());
}
private IEnumerator placeFood (int xmapmax, int zmapmax){
//this needs to be moved to the town manager on individual towns
yield return null;
}
}