home
·
contact
·
privacy
projects
/
plomrogue2-experiments
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
cffcecf
)
Use tuples for positions; fix inventory saving bug.
author
Christian Heller
<c.heller@plomlompom.de>
Thu, 28 Feb 2019 01:13:41 +0000
(
02:13
+0100)
committer
Christian Heller
<c.heller@plomlompom.de>
Thu, 28 Feb 2019 01:13:41 +0000
(
02:13
+0100)
new/plomrogue/commands.py
patch
|
blob
|
history
new/plomrogue/game.py
patch
|
blob
|
history
new/plomrogue/mapping.py
patch
|
blob
|
history
new/plomrogue/tasks.py
patch
|
blob
|
history
new/plomrogue/things.py
patch
|
blob
|
history
diff --git
a/new/plomrogue/commands.py
b/new/plomrogue/commands.py
index ad53438b75974759b19a4bb29394a60b581b2e84..3ae59583799f4c3283ac5b20b8d0df0f87a5299b 100644
(file)
--- a/
new/plomrogue/commands.py
+++ b/
new/plomrogue/commands.py
@@
-38,13
+38,13
@@
cmd_THING_TYPE.argtypes = 'int:nonneg string:thingtype'
def cmd_THING_POS(game, i, yx):
t = game.world.get_thing(i)
def cmd_THING_POS(game, i, yx):
t = game.world.get_thing(i)
- t.position =
list
(yx)
+ t.position =
tuple
(yx)
cmd_THING_POS.argtypes = 'int:nonneg yx_tuple:nonneg'
def cmd_THING_INVENTORY(game, id_, ids):
t = game.world.get_thing(id_)
cmd_THING_POS.argtypes = 'int:nonneg yx_tuple:nonneg'
def cmd_THING_INVENTORY(game, id_, ids):
t = game.world.get_thing(id_)
- t.inventory =
[ids]
# TODO: test whether valid IDs
-cmd_THING_INVENTORY.argtypes = 'int:nonneg
,
seq:int:nonneg'
+ t.inventory =
ids
# TODO: test whether valid IDs
+cmd_THING_INVENTORY.argtypes = 'int:nonneg seq:int:nonneg'
def cmd_TERRAIN_LINE(game, y, terrain_line):
game.world.map_.set_line(y, terrain_line)
def cmd_TERRAIN_LINE(game, y, terrain_line):
game.world.map_.set_line(y, terrain_line)
@@
-84,8
+84,11
@@
def cmd_SAVE(game):
write(f, 'THING_TYPE %s %s' % (thing.id_, thing.type_))
write(f, 'THING_POS %s %s' % (thing.id_,
stringify_yx(thing.position)))
write(f, 'THING_TYPE %s %s' % (thing.id_, thing.type_))
write(f, 'THING_POS %s %s' % (thing.id_,
stringify_yx(thing.position)))
- write(f, 'THING_INVENTORY %s %s' %
- (thing.id_,','.join([str(i) for i in thing.inventory])))
+ if len(thing.inventory) > 0:
+ write(f, 'THING_INVENTORY %s %s' %
+ (thing.id_,','.join([str(i) for i in thing.inventory])))
+ else:
+ write(f, 'THING_INVENTORY %s ,' % thing.id_)
if hasattr(thing, 'task'):
task = thing.task
if task is not None:
if hasattr(thing, 'task'):
task = thing.task
if task is not None:
diff --git
a/new/plomrogue/game.py
b/new/plomrogue/game.py
index bc5b8c3a5ec58a4776e6642e76fb7f4353a92e7b..e24edbb5404543e9c10a212556bd92972af152fd 100755
(executable)
--- a/
new/plomrogue/game.py
+++ b/
new/plomrogue/game.py
@@
-2,6
+2,7
@@
from plomrogue.tasks import Task_WAIT, Task_MOVE, Task_PICKUP, Task_DROP
from plomrogue.errors import ArgError
from plomrogue.commands import (cmd_GEN_WORLD, cmd_GET_GAMESTATE, cmd_MAP,
cmd_MAP, cmd_THING_TYPE, cmd_THING_POS,
from plomrogue.errors import ArgError
from plomrogue.commands import (cmd_GEN_WORLD, cmd_GET_GAMESTATE, cmd_MAP,
cmd_MAP, cmd_THING_TYPE, cmd_THING_POS,
+ cmd_THING_INVENTORY,
cmd_TERRAIN_LINE, cmd_PLAYER_ID, cmd_TURN,
cmd_SWITCH_PLAYER, cmd_SAVE)
from plomrogue.mapping import MapHex
cmd_TERRAIN_LINE, cmd_PLAYER_ID, cmd_TURN,
cmd_SWITCH_PLAYER, cmd_SAVE)
from plomrogue.mapping import MapHex
@@
-77,8
+78,8
@@
class World(WorldBase):
def add_thing(type_):
t = self.game.thing_types[type_](self)
def add_thing(type_):
t = self.game.thing_types[type_](self)
- t.position =
[
random.randint(0, yx[0] -1),
- random.randint(0, yx[1] - 1)
]
+ t.position =
(
random.randint(0, yx[0] -1),
+ random.randint(0, yx[1] - 1)
)
self.things += [t]
return t
self.things += [t]
return t
@@
-116,6
+117,7
@@
class Game:
'MAP': cmd_MAP,
'THING_TYPE': cmd_THING_TYPE,
'THING_POS': cmd_THING_POS,
'MAP': cmd_MAP,
'THING_TYPE': cmd_THING_TYPE,
'THING_POS': cmd_THING_POS,
+ 'THING_INVENTORY': cmd_THING_INVENTORY,
'TERRAIN_LINE': cmd_TERRAIN_LINE,
'PLAYER_ID': cmd_PLAYER_ID,
'TURN': cmd_TURN,
'TERRAIN_LINE': cmd_TERRAIN_LINE,
'PLAYER_ID': cmd_PLAYER_ID,
'TURN': cmd_TURN,
diff --git
a/new/plomrogue/mapping.py
b/new/plomrogue/mapping.py
index e21def88a96dbecfda2b3196e5c7e62c68d2cb7c..64dad7c8a5ac0490c1f440dc3909876de4d5aa36 100644
(file)
--- a/
new/plomrogue/mapping.py
+++ b/
new/plomrogue/mapping.py
@@
-43,7
+43,7
@@
class Map(MapBase):
"""Iterate over YX position coordinates."""
for y in range(self.size[0]):
for x in range(self.size[1]):
"""Iterate over YX position coordinates."""
for y in range(self.size[0]):
for x in range(self.size[1]):
- yield
[y, x]
+ yield
(y, x)
def lines(self):
width = self.size[1]
def lines(self):
width = self.size[1]
@@
-96,20
+96,20
@@
class Map(MapBase):
class MapWithLeftRightMoves(Map):
def move_LEFT(self, start_pos):
class MapWithLeftRightMoves(Map):
def move_LEFT(self, start_pos):
- return
[start_pos[0], start_pos[1] - 1]
+ return
(start_pos[0], start_pos[1] - 1)
def move_RIGHT(self, start_pos):
def move_RIGHT(self, start_pos):
- return
[start_pos[0], start_pos[1] + 1]
+ return
(start_pos[0], start_pos[1] + 1)
class MapSquare(MapWithLeftRightMoves):
def move_UP(self, start_pos):
class MapSquare(MapWithLeftRightMoves):
def move_UP(self, start_pos):
- return
[start_pos[0] - 1, start_pos[1]]
+ return
(start_pos[0] - 1, start_pos[1])
def move_DOWN(self, start_pos):
def move_DOWN(self, start_pos):
- return
[start_pos[0] + 1, start_pos[1]]
+ return
(start_pos[0] + 1, start_pos[1])
@@
-121,27
+121,27
@@
class MapHex(MapWithLeftRightMoves):
def move_UPLEFT(self, start_pos):
if start_pos[0] % 2 == 1:
def move_UPLEFT(self, start_pos):
if start_pos[0] % 2 == 1:
- return
[start_pos[0] - 1, start_pos[1] - 1]
+ return
(start_pos[0] - 1, start_pos[1] - 1)
else:
else:
- return
[start_pos[0] - 1, start_pos[1]]
+ return
(start_pos[0] - 1, start_pos[1])
def move_UPRIGHT(self, start_pos):
if start_pos[0] % 2 == 1:
def move_UPRIGHT(self, start_pos):
if start_pos[0] % 2 == 1:
- return
[start_pos[0] - 1, start_pos[1]]
+ return
(start_pos[0] - 1, start_pos[1])
else:
else:
- return
[start_pos[0] - 1, start_pos[1] + 1]
+ return
(start_pos[0] - 1, start_pos[1] + 1)
def move_DOWNLEFT(self, start_pos):
if start_pos[0] % 2 == 1:
def move_DOWNLEFT(self, start_pos):
if start_pos[0] % 2 == 1:
- return
[start_pos[0] + 1, start_pos[1] - 1]
+ return
(start_pos[0] + 1, start_pos[1] - 1)
else:
else:
- return
[start_pos[0] + 1, start_pos[1]]
+ return
(start_pos[0] + 1, start_pos[1])
def move_DOWNRIGHT(self, start_pos):
if start_pos[0] % 2 == 1:
def move_DOWNRIGHT(self, start_pos):
if start_pos[0] % 2 == 1:
- return
[start_pos[0] + 1, start_pos[1]]
+ return
(start_pos[0] + 1, start_pos[1])
else:
else:
- return
[start_pos[0] + 1, start_pos[1] + 1]
+ return
(start_pos[0] + 1, start_pos[1] + 1)
@@
-225,11
+225,11
@@
class FovMap:
def basic_circle_out_move(self, pos, direction):
"""Move position pos into direction. Return whether still in map."""
mover = getattr(self, 'move_' + direction)
def basic_circle_out_move(self, pos, direction):
"""Move position pos into direction. Return whether still in map."""
mover = getattr(self, 'move_' + direction)
- pos
[:]
= mover(pos)
+ pos = mover(pos)
if pos[0] < 0 or pos[1] < 0 or \
pos[0] >= self.size[0] or pos[1] >= self.size[1]:
if pos[0] < 0 or pos[1] < 0 or \
pos[0] >= self.size[0] or pos[1] >= self.size[1]:
- return False
- return True
+ return
pos,
False
+ return
pos,
True
def circle_out(self, yx, f):
# Optimization potential: Precalculate movement positions. (How to check
def circle_out(self, yx, f):
# Optimization potential: Precalculate movement positions. (How to check
@@
-246,11
+246,12
@@
class FovMap:
#print('DEBUG CIRCLE_OUT', yx)
while circle_in_map:
circle_in_map = False
#print('DEBUG CIRCLE_OUT', yx)
while circle_in_map:
circle_in_map = False
- self.basic_circle_out_move(yx, 'RIGHT')
+
yx, _ =
self.basic_circle_out_move(yx, 'RIGHT')
for dir_i in range(len(self.circle_out_directions)):
for dir_progress in range(distance):
direction = self.circle_out_directions[dir_i]
for dir_i in range(len(self.circle_out_directions)):
for dir_progress in range(distance):
direction = self.circle_out_directions[dir_i]
- if self.circle_out_move(yx, direction):
+ yx, test = self.circle_out_move(yx, direction)
+ if test:
f(yx, distance, dir_i, dir_progress)
circle_in_map = True
distance += 1
f(yx, distance, dir_i, dir_progress)
circle_in_map = True
distance += 1
diff --git
a/new/plomrogue/tasks.py
b/new/plomrogue/tasks.py
index 5dc2f82a1db6b206827f2b6a1c23be5daaf8cf2d..1be5b6da40b2c757fccd08541fbea6002f6809aa 100644
(file)
--- a/
new/plomrogue/tasks.py
+++ b/
new/plomrogue/tasks.py
@@
-48,7
+48,7
@@
class Task_MOVE(Task):
self.args[0])
for id_ in self.thing.inventory:
t = self.thing.world.get_thing(id_)
self.args[0])
for id_ in self.thing.inventory:
t = self.thing.world.get_thing(id_)
- t.position
[:]
= self.thing.position
+ t.position = self.thing.position
diff --git
a/new/plomrogue/things.py
b/new/plomrogue/things.py
index 9bc84907bb757fe0251b47ca7808f1d64cebe4a2..a631b174f9292dde5ab047b98836bd2820939137 100644
(file)
--- a/
new/plomrogue/things.py
+++ b/
new/plomrogue/things.py
@@
-5,7
+5,7
@@
from plomrogue.errors import GameError
class ThingBase:
type_ = '?'
class ThingBase:
type_ = '?'
- def __init__(self, world, id_=None, position=
[0,0]
):
+ def __init__(self, world, id_=None, position=
(0,0)
):
self.world = world
self.position = position
if id_ is None:
self.world = world
self.position = position
if id_ is None: