/
mapcreation.py
611 lines (526 loc) · 26.7 KB
/
mapcreation.py
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
#==============================================================================
# Level and map creation
#==============================================================================
import libtcodpy as libtcod
from constants import *
from utility_methods import MAP_WIDTH, MAP_HEIGHT, switch, is_blocked, choose_random_unblocked_spot, \
random_choice_index, random_choice, cast_heal
from classes import GamePiece, Fighter, Item, Equipment
from ai import BasicNPC, BasicExplorer, BasicBuilder, player_death, NPC_death, namegenerator
class GameMap(object):
"""
This class holds all the information needed for processing a map, as well as the map itself.
GameMaps have qualities which apply to an entire play area.
GameMaps have a unique id which is a sequential integer starting from 0, a location specifying
whether the map is predominately on the surface or inside the planet.
GameMaps contain a list of all objects within them. If an object moves between maps, such as the player
going to a different area, the origin map needs to hand the player object to the destination map.
"""
def __init__(self, id_number, level, location='surface', objects=None):
self.id_number = id_number
self.level = level # this is the actual map.
self.fov_map = None
self.location = location
if objects is None:
self.objects = []
else:
self.objects = objects
def __getitem__(self, index):
return self.level[index]
def initialize_fov(self):
"""This is needed to allow field of view stuff. It requires the GameMap instance to already have
a level (a Tile array)."""
#create the FOV map according to the generated map
self.fov_map = libtcod.map_new(MAP_WIDTH, MAP_HEIGHT)
for y in range(MAP_HEIGHT):
for x in range(MAP_WIDTH):
libtcod.map_set_properties(self.fov_map, x, y, not self.level[x][y].block_sight, not self.level[x][y].blocked)
class Tile(object):
"""
A tile in the map and its properties. These are the properties that an individual square has,
not to be confused with the properties that an entire game level might have.
A map is a 2D array of Tiles.
"""
def __init__(self, blocked, block_sight=True, char=' ', fore=libtcod.white, back=libtcod.black, outdoors=True):
self.blocked = blocked #is it passable?
self.block_sight = block_sight
self.char = char
self.fore = fore #foreground color
self.back = back #background color
self.outdoors = outdoors
self.mapedge = False
self.explored = False
# A tile can be designated for construction of some sort. If it is designated, it will blink.
# designation_type determines more details like how it blinks or what it needs to be made into.
# Valid designation_types are:
# 'clearing' when it needs to have all blocking walls removed
# 'build wall' to build the wall of a building
# 'clean floor' to lay the floor of a building (designate it as indoors and remove debris)
# 'install airlock' to place a door
self.designated = False
self.designation_type = None
self.designation_char = None
self.being_worked_on = False
class Rect(object):
"""A rectangle, with a center."""
def __init__(self, x, y, w, h):
self.x1 = x
self.y1 = y
self.x2 = x + w
self.y2 = y + h
def center(self):
"""Returns the coordinates for the center of the rectangle."""
center_x = (self.x1 + self.x2) / 2
center_y = (self.y1 + self.y2) / 2
return (center_x, center_y)
def intersect(self, other):
"""Returns true if this rectangle intersects with another one. """
return (self.x1 <= other.x2 and self.x2 >= other.x1 and
self.y1 <= other.y2 and self.y2 >= other.y1)
def middle_of_wall(self, side):
"""Returns the coordinates of the middle of a wall of a rectangle. Useful for placing a door there."""
for case in switch(side):
if case('left'): return ( self.x1, int((self.y1 + self.y2) / 2) )
if case('right'): return ( self.x2, int((self.y1+self.y2)/2) )
if case('top'): return (int((self.x1 + self.x2)/2), self.y1)
if case('bottom'): return (int((self.x1 + self.x2)/2), self.y2)
if case(): print 'Error: invalid side specified in Rect.middle_of_wall'
#-------------------------------------------------------------
def create_room(room):
"""Makes the tiles in a rectangle passable."""
global map
for x in range(room.x1 + 1, room.x2):
for y in range(room.y1 + 1, room.y2):
map[x][y].blocked = False
map[x][y].block_sight = False
def create_building(mymap, building):
"""Very similar to create_room but puts a border around it.
Currently it makes a double pass over some of the tiles, first assigning them to be
cleared and then putting a wall there (un-clearing them). That could probably be cleaned up.
"""
# Clear the whole footprint
for x in range(building.x1, building.x2+1):
for y in range(building.y1, building.y2+1):
mymap[x][y].blocked = False
mymap[x][y].block_sight = False
mymap[x][y].fore = color_ground
mymap[x][y].back = color_ground
mymap[x][y].outdoors = False
#Create walls of building
for x in range(building.x1, building.x2+1):
mymap[x][building.y1].blocked = True
mymap[x][building.y1].block_sight = True
mymap[x][building.y1].fore = color_building
mymap[x][building.y1].back = color_building
mymap[x][building.y2].blocked = True
mymap[x][building.y2].block_sight = True
mymap[x][building.y2].fore = color_building
mymap[x][building.y2].back = color_building
for y in range(building.y1, building.y2+1):
mymap[building.x1][y].blocked = True
mymap[building.x1][y].block_sight = True
mymap[building.x1][y].fore = color_building
mymap[building.x1][y].back = color_building
mymap[building.x2][y].blocked = True
mymap[building.x2][y].block_sight = True
mymap[building.x2][y].fore = color_building
mymap[building.x2][y].back = color_building
def create_h_tunnel(x1, x2, y):
global map
for x in range(min(x1, x2), max(x1, x2) + 1):
map[x][y].blocked = False
map[x][y].block_sight = False
def create_v_tunnel(y1, y2, x):
global map
for y in range(min(y1, y2), max(y1, y2) + 1):
map[x][y].blocked = False
map[x][y].block_sight = False
def make_bare_surface_map(player=None):
"""
Creates a map which is open by default, and then filled with boulders, mesas and rocks.
Uses a 2D noise generator. The map has an impenetrable border.
"""
objects_for_this_map = []
if player is None:
#Creating the object representing the player:
fighter_component = Fighter(hp=30, defense=2, power=5, xp=0, death_function=player_death) #creating the fighter aspect of the player
player = GamePiece(0, 0, 219, 'player', libtcod.white, blocks=False, fighter=fighter_component, speed=PLAYER_SPEED)
player.level = 1
objects_for_this_map.append(player)
else:
# This must not be a new game. We need to put the pre-existing player into the list and later give them an
# appropriate spot in the map to have spatial translation continuity.
objects_for_this_map.append(player)
noise2d = libtcod.noise_new(2) #create a 2D noise generator
libtcod.noise_set_type(noise2d, libtcod.NOISE_SIMPLEX) #tell it to use simplex noise for higher contrast
# Create the map with a default tile choice of empty unblocked squares.
newmap = [[ Tile(blocked=False, block_sight=False, char=' ', fore=color_ground, back=color_ground)
for y in range(MAP_HEIGHT)]
for x in range(MAP_WIDTH) ]
#Put a border around the map so the characters can't go off the edge of the world
for x in range(0, MAP_WIDTH):
newmap[x][0].blocked = True
newmap[x][0].block_sight = True
newmap[x][0].mapedge = True
newmap[x][0].fore = color_wall
newmap[x][0].back = color_wall
newmap[x][MAP_HEIGHT-1].blocked = True
newmap[x][MAP_HEIGHT-1].block_sight = True
newmap[x][MAP_HEIGHT-1].mapedge = True
newmap[x][MAP_HEIGHT-1].fore = color_wall
newmap[x][MAP_HEIGHT-1].back = color_wall
for y in range(0, MAP_HEIGHT):
newmap[0][y].blocked = True
newmap[0][y].block_sight = True
newmap[0][y].mapedge = True
newmap[0][y].fore = color_wall
newmap[0][y].back = color_wall
newmap[MAP_WIDTH-1][y].blocked = True
newmap[MAP_WIDTH-1][y].block_sight = True
newmap[MAP_WIDTH-1][y].mapedge = True
newmap[MAP_WIDTH-1][y].fore = color_wall
newmap[MAP_WIDTH-1][y].back = color_wall
# Create natural looking landscape
for x in range(1, MAP_WIDTH-1):
for y in range(1, MAP_HEIGHT-1):
if libtcod.noise_get_turbulence(noise2d, [x, y], 128.0, libtcod.NOISE_SIMPLEX) < 0.4:
#Turbulent simplex noise returns values between 0.0 and 1.0, with many values greater than 0.9.
newmap[x][y].blocked = True
newmap[x][y].block_sight = True
newmap[x][y].fore = color_wall
newmap[x][y].back = color_wall
# Scatter debris around the map to add flavor:
place_junk(newmap)
# Choose a spot for the player to start
player.x, player.y = choose_random_unblocked_spot(newmap)
return newmap, objects_for_this_map
def make_surface_map(player=None):
"""
Creates a map which is open by default, and then filled with boulders, mesas and buildings.
Uses a 2D noise generator. The map has an impenetrable border.
"""
objects_for_this_map = []
new_objects = []
more_objects = []
if player is None:
#Creating the object representing the player:
fighter_component = Fighter(hp=30, defense=2, power=5, xp=0, death_function=player_death) #creating the fighter aspect of the player
player = GamePiece(0, 0, 219, 'player', libtcod.white, blocks=False, fighter=fighter_component, speed=PLAYER_SPEED)
player.level = 1
objects_for_this_map.append(player)
else:
# This must not be a new game. We need to put the pre-existing player into the list and later give them an
# appropriate spot in the map to have spatial translation continuity.
objects_for_this_map.append(player)
noise2d = libtcod.noise_new(2) #create a 2D noise generator
libtcod.noise_set_type(noise2d, libtcod.NOISE_SIMPLEX) #tell it to use simplex noise for higher contrast
# Create the map with a default tile choice of empty unblocked squares.
newmap = [[ Tile(blocked=False, block_sight=False, char=' ', fore=color_ground, back=color_ground)
for y in range(MAP_HEIGHT)]
for x in range(MAP_WIDTH) ]
#Put a border around the map so the characters can't go off the edge of the world
for x in range(0, MAP_WIDTH):
newmap[x][0].blocked = True
newmap[x][0].block_sight = True
newmap[x][0].mapedge = True
newmap[x][0].fore = color_wall
newmap[x][0].back = color_wall
newmap[x][MAP_HEIGHT-1].blocked = True
newmap[x][MAP_HEIGHT-1].block_sight = True
newmap[x][MAP_HEIGHT-1].mapedge = True
newmap[x][MAP_HEIGHT-1].fore = color_wall
newmap[x][MAP_HEIGHT-1].back = color_wall
for y in range(0, MAP_HEIGHT):
newmap[0][y].blocked = True
newmap[0][y].block_sight = True
newmap[0][y].mapedge = True
newmap[0][y].fore = color_wall
newmap[0][y].back = color_wall
newmap[MAP_WIDTH-1][y].blocked = True
newmap[MAP_WIDTH-1][y].block_sight = True
newmap[MAP_WIDTH-1][y].mapedge = True
newmap[MAP_WIDTH-1][y].fore = color_wall
newmap[MAP_WIDTH-1][y].back = color_wall
# Create natural looking landscape
for x in range(1, MAP_WIDTH-1):
for y in range(1, MAP_HEIGHT-1):
if libtcod.noise_get_turbulence(noise2d, [x, y], 128.0, libtcod.NOISE_SIMPLEX) < 0.4:
#Turbulent simplex noise returns values between 0.0 and 1.0, with many values greater than 0.9.
newmap[x][y].blocked = True
newmap[x][y].block_sight = True
newmap[x][y].fore = color_wall
newmap[x][y].back = color_wall
# Place buildings
buildings = []
num_buildings = 0
for r in range(MAX_BUILDINGS):
w = libtcod.random_get_int(0, BUILDING_MIN_SIZE, BUILDING_MAX_SIZE)
h = libtcod.random_get_int(0, BUILDING_MIN_SIZE, BUILDING_MAX_SIZE)
x = libtcod.random_get_int(0, 0, MAP_WIDTH - w - 1)
y = libtcod.random_get_int(0, 0, MAP_HEIGHT - h - 1)
new_building = Rect(x, y, w, h)
create_building(newmap, new_building)
buildings.append(new_building)
num_buildings += 1
#Create stairs in the last building
if num_buildings == MAX_BUILDINGS:
new_x, new_y = new_building.center()
stairs = GamePiece(new_x, new_y, '>', 'stairs', libtcod.white, always_visible=True)
objects_for_this_map.append(stairs)
#stairs.send_to_back(newmap.objects) #so that it gets drawn below NPCs. I commented this out because
# it should be at the end anyway, since its being appended.
#Put doors in buildings. Have to do this AFTER they are built or later ones will overwrite earlier ones
# door_chances = { 'left': 25, 'right': 25, 'top': 25, 'bottom': 25 }
for place in buildings:
# num_doors = libtcod.random_get_int(0, 2, 4)
# for case in switch(num_doors):
# if case(2):
# choice = random_choice(door_chances)
doorx, doory = place.middle_of_wall('left')
if newmap[doorx][doory].blocked and not newmap[doorx][doory].mapedge:
newmap[doorx][doory].char = LEFT_DOOR
newmap[doorx][doory].blocked = False
newmap[doorx][doory].fore = libtcod.white
newmap[doorx][doory].back = libtcod.grey
doorx, doory = place.middle_of_wall('top')
if newmap[doorx][doory].blocked and not newmap[doorx][doory].mapedge:
newmap[doorx][doory].char = TOP_DOOR
newmap[doorx][doory].blocked = False
newmap[doorx][doory].fore = libtcod.white
newmap[doorx][doory].back = libtcod.grey
doorx, doory = place.middle_of_wall('right')
if newmap[doorx][doory].blocked and not newmap[doorx][doory].mapedge:
newmap[doorx][doory].char = RIGHT_DOOR
newmap[doorx][doory].blocked = False
newmap[doorx][doory].fore = libtcod.white
newmap[doorx][doory].back = libtcod.grey
doorx, doory = place.middle_of_wall('bottom')
if newmap[doorx][doory].blocked and not newmap[doorx][doory].mapedge:
newmap[doorx][doory].char = BOTTOM_DOOR
newmap[doorx][doory].blocked = False
newmap[doorx][doory].fore = libtcod.white
newmap[doorx][doory].back = libtcod.grey
more_objects = place_objects(newmap, place) #add some contents to this room
if more_objects is not None:
for item in more_objects:
new_objects.append(item)
# Scatter debris around the map to add flavor:
place_junk(newmap)
# Choose a spot for the player to start
player.x, player.y = choose_random_unblocked_spot(newmap)
for item in new_objects:
objects_for_this_map.append(item)
return newmap, objects_for_this_map
def place_objects(mymap, room):
"""Puts stuff all over the map AFTER the map has been created."""
objects = []
# max number of NPCs per room:
#max_NPCs = from_difficulty_level( [ [2, 1], [3, 4], [5, 6] ] )
max_NPCs = 3
#chance of each NPC
NPC_chances = {} # so that we can build the dict below
NPC_chances['robot'] = 80 #this means that orcs always show up, even if other NPCs have 0 chance
#NPC_chances['security bot'] = from_difficulty_level( [ [10, 1], [15, 3], [30, 5], [60, 7] ] )
NPC_chances['security bot'] = 10
NPC_chances['explorer'] = 80
#maximum number of items per room
#max_items = from_difficulty_level( [ [1, 1], [2, 4] ] )
max_items = 1
#chance of each item. By default they have a chance of 0 at level 1, which then increases.
item_chances = {}
item_chances['heal'] = 35 #heal pots always show up
#item_chances['lightning'] = from_difficulty_level([[25, 4]])
#item_chances['fireball'] = from_difficulty_level([[25, 6]])
#item_chances['confuse'] = from_difficulty_level([[10, 2]])
item_chances['sword'] = 25
item_chances['shield'] = 15
#choose a random number of NPCs
num_NPCs = libtcod.random_get_int(0, 0, max_NPCs)
for i in range(num_NPCs):
#choose a spot for the NPC
x = libtcod.random_get_int(0, room.x1+1, room.x2-1)
y = libtcod.random_get_int(0, room.y1+1, room.y2-1)
#Create the NPC
if not is_blocked(mymap, objects, x, y):
choice = random_choice(NPC_chances)
if choice == 'robot':
#Create an minor enemy
fighter_component = Fighter(hp=10, defense=0, power=3, xp=35, death_function=NPC_death)
ai_component = BasicNPC()
NPC = GamePiece(x, y, 'r', 'robot', libtcod.desaturated_green, blocks=True,
fighter=fighter_component, ai=ai_component)
NPC.scifi_name = namegenerator()
print 'Created robot named ' + str(NPC.scifi_name)
elif choice == 'security bot':
#Create a major enemy
fighter_component = Fighter(hp=16, defense=1, power=4, xp=100, death_function=NPC_death)
ai_component = BasicNPC()
NPC = GamePiece(x, y, 'S', 'security bot', libtcod.darker_green, blocks=True,
fighter=fighter_component, ai=ai_component)
NPC.scifi_name = namegenerator()
print 'Created security bot named ' + str(NPC.scifi_name)
else:
fighter_component = Fighter(hp=10, defense=0, power=3, xp=35, death_function=NPC_death)
ai_component = BasicExplorer()
NPC = GamePiece(x, y, '@', 'explorer', libtcod.green, blocks=True,
fighter=fighter_component, ai=ai_component)
print 'Created Explorer'
objects.append(NPC)
#Create and place items
num_items = libtcod.random_get_int(0, 0, max_items)
for i in range(num_items):
x = libtcod.random_get_int(0, room.x1+1, room.x2-1)
y = libtcod.random_get_int(0, room.y1+1, room.y2-1)
if not is_blocked(mymap, objects, x, y):
choice = random_choice(item_chances)
if choice == 'heal':
#creating a healing potion:
item_component = Item(use_function=cast_heal)
item = GamePiece(x, y, '!', 'healing potion', libtcod.violet, always_visible=True, item=item_component)
# elif choice == 'lightning':
# # chance of lightning scroll
# item_component = Item(use_function=cast_lightning)
# item = GamePiece(x, y, '?', 'lightning scroll', libtcod.light_azure, always_visible=True, item=item_component)
# elif choice == 'fireball':
# item_component = Item(use_function=cast_fireball)
# item = GamePiece(x, y, '*', 'fireball scroll', libtcod.orange, always_visible=True, item=item_component)
elif choice == 'sword':
equipment_component = Equipment(slot='right hand', power_bonus=3)
item = GamePiece(x, y, '/', 'sword', libtcod.sky, equipment=equipment_component, always_visible=True,)
elif choice == 'shield':
equipment_component = Equipment(slot='left hand', defense_bonus=1, max_hp_bonus=10)
item = GamePiece(x, y, '0', 'shield', libtcod.brass, equipment=equipment_component, always_visible=True,)
else:
item_component = Item(use_function=cast_confuse)
item = GamePiece(x, y, '#', 'scroll of confusion', libtcod.light_yellow, always_visible=True, item=item_component)
objects.append(item)
#item.send_to_back(objects) #make items appear below other objects
print 'objects is ' + str(len(objects)) + ' long.'
for item in objects:
print 'Returning objects in place_objects: ' + str(item)
return objects
def land_astronauts(gamemap_instance):
"""
This function places 9 astronauts on the map, in a lander. The lander lands anywhere and becomes
a permanent addition to the map.
"""
landingx = libtcod.random_get_int(0, 7, MAP_WIDTH-7)
landingy = libtcod.random_get_int(0, 7, MAP_HEIGHT-7)
mymap = gamemap_instance.level
objects_for_this_map = gamemap_instance.objects
martian_lander = Rect(landingx-2, landingy-2, 4, 4)
# Make the walls
for x in range(landingx-2, landingx+3):
mymap[x][landingy-2].blocked = True
mymap[x][landingy-2].block_sight = True
mymap[x][landingy-2].char = ' '
mymap[x][landingy-2].fore = libtcod.darkest_grey
mymap[x][landingy-2].back = libtcod.darkest_grey
mymap[x][landingy-2].outdoors = False
mymap[x][landingy-2].explored = False
mymap[x][landingy-2].designated = False
mymap[x][landingy-2].designation_type = None
mymap[x][landingy-2].designation_char = None
mymap[x][landingy+2].blocked = True
mymap[x][landingy+2].block_sight = True
mymap[x][landingy+2].char = ' '
mymap[x][landingy+2].fore = libtcod.darkest_grey
mymap[x][landingy+2].back = libtcod.darkest_grey
mymap[x][landingy+2].outdoors = False
mymap[x][landingy+2].explored = False
mymap[x][landingy+2].designated = False
mymap[x][landingy+2].designation_type = None
mymap[x][landingy+2].designation_char = None
for y in range(landingy-2, landingy+3):
mymap[landingx-2][y].blocked = True
mymap[landingx-2][y].block_sight = True
mymap[landingx-2][y].char = ' '
mymap[landingx-2][y].fore = libtcod.darkest_grey
mymap[landingx-2][y].back = libtcod.darkest_grey
mymap[landingx-2][y].outdoors = False
mymap[landingx-2][y].explored = False
mymap[landingx-2][y].designated = False
mymap[landingx-2][y].designation_type = None
mymap[landingx-2][y].designation_char = None
mymap[landingx+2][y].blocked = True
mymap[landingx+2][y].block_sight = True
mymap[landingx+2][y].char = ' '
mymap[landingx+2][y].fore = libtcod.darkest_grey
mymap[landingx+2][y].back = libtcod.darkest_grey
mymap[landingx+2][y].outdoors = False
mymap[landingx+2][y].explored = False
mymap[landingx+2][y].designated = False
mymap[landingx+2][y].designation_type = None
mymap[landingx+2][y].designation_char = None
# Make the floor inside
for x in range(landingx-1, landingx+2):
for y in range(landingy-1, landingy+2):
mymap[x][y].blocked = False
mymap[x][y].block_sight = False
mymap[x][y].char = ' '
mymap[x][y].fore = libtcod.grey
mymap[x][y].back = libtcod.grey
mymap[x][y].outdoors = False
mymap[x][y].explored = False
mymap[x][y].designated = False
mymap[x][y].designation_type = None
mymap[x][y].designation_char = None
# Put airlocks in all four sides
doorx, doory = martian_lander.middle_of_wall('left')
mymap[doorx][doory].char = LEFT_DOOR
mymap[doorx][doory].blocked = False
mymap[doorx][doory].fore = libtcod.white
mymap[doorx][doory].back = libtcod.grey
doorx, doory = martian_lander.middle_of_wall('top')
mymap[doorx][doory].char = TOP_DOOR
mymap[doorx][doory].blocked = False
mymap[doorx][doory].fore = libtcod.white
mymap[doorx][doory].back = libtcod.grey
doorx, doory = martian_lander.middle_of_wall('right')
mymap[doorx][doory].char = RIGHT_DOOR
mymap[doorx][doory].blocked = False
mymap[doorx][doory].fore = libtcod.white
mymap[doorx][doory].back = libtcod.grey
doorx, doory = martian_lander.middle_of_wall('bottom')
mymap[doorx][doory].char = BOTTOM_DOOR
mymap[doorx][doory].blocked = False
mymap[doorx][doory].fore = libtcod.white
mymap[doorx][doory].back = libtcod.grey
# Place the astronauts inside:
for x in range(landingx-1, landingx+2):
for y in range(landingy-1, landingy+2):
fighter_component = Fighter(hp=10, defense=0, power=3, xp=35, death_function=NPC_death)
ai_component = BasicBuilder()
NPC = GamePiece(x, y, '@', 'civil engineer', libtcod.white, blocks=True,
fighter=fighter_component, ai=ai_component)
print 'Created BasicBuilder'
objects_for_this_map.append(NPC)
print 'Appended ' + str(NPC) + ' to this map.'
def place_junk(mymap):
"""
Puts boulders, rocks, junk and/or plants around the map. Eventually I want it to accept a map as an
argument and depending on the type of map, (outdoors vs indoors, surface vs cavern, etc) place
different debris. For example, indoors would have equipment and trash rather than rocks and plants.
"""
# Ideally I can eventually get rid of this global statement and just accept a map object when we
# get to the point where there are many different maps stored (to allow returning to previous areas).
debris = {}
debris['nothing'] = 100
debris['stone'] = 10
debris['boulder'] = 10
debris['gravel'] = 10
for y in range(MAP_HEIGHT):
for x in range(MAP_WIDTH):
if mymap[x][y].outdoors and not mymap[x][y].blocked:
choice = random_choice(debris)
if choice == 'nothing':
pass
elif choice == 'stone':
mymap[x][y].char = '.'
mymap[x][y].fore = libtcod.dark_sepia
elif choice == 'boulder':
mymap[x][y].char = BOULDER # bullet point
mymap[x][y].fore = libtcod.dark_sepia
else:
mymap[x][y].char = GRAVEL
mymap[x][y].fore = libtcod.dark_red