1 import craw
, os
, sys
, utility
3 def get_flag(flags
, offset
):
4 return ((flags
>> offset
) & 1) != 0
6 def draw_box(coordinate
, colour
):
19 for i
in range(0, len(coordinates
) - 1):
20 start_x
, start_y
= coordinates
[i
]
21 end_x
, end_y
= coordinates
[i
+ 1]
23 start_x
*= square_size
24 start_y
*= square_size
29 craw
.draw_line(x
+ start_x
, y
+ start_y
, x
+ end_x
, y
+ end_y
, colour
)
31 def draw_automap_text(string
, coordinate
):
32 craw
.draw_text(string
, coordinate
[0] - 5, coordinate
[1] - 2, True)
34 def read_bytes(bytes
, offset
, size
):
36 for i
in range(1, size
+ 1):
38 output |
= bytes
[offset
+ size
- i
]
41 def pack_number(number
, size
):
43 for i
in range(0, size
):
44 output
+= chr(number
& 0xff)
48 def get_packet_string(packet
):
54 if type(packet
[0]) != str:
55 packet
= map(chr, packet
)
63 output
+= '%02x' % ord(byte
)
67 level
= craw
.get_player_level()
70 return level
in [0x01, 0x28, 0x4b, 0x67, 0x6d]
72 def get_configuration_directory():
73 return os
.path
.join(sys
.path
[-1], '..', 'configuration')
75 def read_name(bytes
, offset
):
87 def get_character_class_string(character_class
):
98 return strings
[character_class
]
100 def get_character_string(character
):
101 return 'Level %d %s' % (character
.level
, get_character_class_string(character
.character_class
))
103 def get_player_data_by_name(name
):
104 players
= craw
.get_players()
105 for player
in players
:
106 if player
.name
== name
:
111 players
= craw
.get_players()
112 if len(players
) == 0:
117 def get_player_by_name(name
):
118 players
= craw
.get_players()
119 for player
in players
:
120 if player
.name
== name
:
124 def get_player_by_id(player_id
):
125 players
= craw
.get_players()
126 for player
in players
:
127 if player
.id == player_id
:
131 def distance(coordinate1
, coordinate2
):
132 return ((coordinate1
[0] - coordinate2
[0]) ** 2 + (coordinate1
[1] - coordinate2
[1]) ** 2) ** 0.5
135 players
= craw
.get_players()
136 if players
== None or len(players
) == 0:
147 def is_mercenary(id):
148 return id in mercenary_map
150 def same_party(player1
, player2
):
151 not_in_party
= 0x0000ffff
152 return not_in_party
not in [player1
.party
, player2
.party
] and player1
.party
== player2
.party
154 def get_party_players():
155 my_player
= get_my_player()
156 if my_player
== None:
159 players
= filter(lambda x
: x
.id != my_player
.id and same_party(my_player
, x
), craw
.get_players())
162 def get_d2_distance(player1
, player2
):
163 dx
= abs(player1
.x
- player2
.x
)
164 dy
= abs(player1
.y
- player2
.y
)
165 return (dx
+ dy
+ max(dx
, dy
)) / 2.0
167 def get_euclidean_distance(player1
, player2
):
168 dx
= player1
.x
- player2
.x
169 dy
= player1
.y
- player2
.y
171 return (dx
**2 + dy
**2)**0.5
173 def sort_units(left
, right
):
174 difference
= left
[0] - right
[0]
177 return 1 if difference
> 0 else -1
180 player
= get_my_player()
183 return craw
.get_unit(player
.id, 0)