Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakky89 committed Jul 19, 2013
1 parent be59b59 commit ae7171e
Show file tree
Hide file tree
Showing 9 changed files with 370 additions and 116 deletions.
4 changes: 2 additions & 2 deletions cuwo/bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def read(self, size = None):
return data

def open_editor(self):
print 'Opening editor ...'
if raw_input('Open editor? y/n ').strip().lower() != 'y':
return False
import tempfile
Expand All @@ -132,7 +133,6 @@ def open_editor(self):
fp.write(self.fp.getvalue())
fp.close()
name = fp.name

try:
subprocess.Popen(['010editor', '%s@%s' % (name, self.tell())])
except IOError:
Expand Down Expand Up @@ -201,4 +201,4 @@ def read_qvec3(self):
x = self.read_int64()
y = self.read_int64()
z = self.read_int64()
return Vector3(x, y, z)
return Vector3(x, y, z)
33 changes: 23 additions & 10 deletions cuwo/common.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
# Copyright (c) Mathias Kaerlev 2013.
#
# This file is part of cuwo.
#
#
# cuwo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# cuwo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with cuwo. If not, see <http://www.gnu.org/licenses/>.

from cuwo import constants

import shlex
import math
import os

def get_hex_string(value):
Expand All @@ -41,23 +42,33 @@ def set_bit(mask, index, value):

def get_clock_string(value):
hour = (value * 24) / constants.MAX_TIME
minute = ((value * 24 * 60) / constants.MAX_TIME) % 60
minute = ((value * 1440) / constants.MAX_TIME) % 60
return '%02d:%02d' % (hour, minute)

def parse_clock(value):
h, m = value.split(':')
h = int(h)
m = int(m)
v = (h * constants.MAX_TIME) / 24 + (m * constants.MAX_TIME) / (24 * 60)
v = (h * constants.MAX_TIME) / 24 + (m * constants.MAX_TIME) / 1440
return v

def get_chunk(vec):
return (int(vec.x / constants.CHUNK_SCALE),
int(vec.y / constants.CHUNK_SCALE))
return (int(vec.x / constants.CHUNK_SCALE), int(vec.y / constants.CHUNK_SCALE))

def get_sector(vec):
return (int(vec.x / constants.SECTOR_SCALE),
int(vec.y / constants.SECTOR_SCALE))
return (int(vec.x / constants.SECTOR_SCALE), int(vec.y / constants.SECTOR_SCALE))

def get_needed_xp(level):
return math.floor((1050 * level - 50) / (level + 19))

def get_needed_total_xp(level):
return math.floor(50 * (21 * (level - 1) + 400 * math.log(20) - 400 * math.log(19 + level)))

def get_xp_from_to(levelFrom, levelTo):
return math.floor(50 * (21 * (levelTo - levelFrom) + 400 * math.log(19 + levelFrom) - 400 * math.log(19 + levelTo)))

def get_power_level(level):
return math.floor(100 - 99 * ((1 + 0.0536) / (1 + 0.0536 * level)))

def parse_command(message):
try:
Expand All @@ -74,6 +85,7 @@ def parse_command(message):
def create_path(path):
if path:
try:
print 'Creating directory structure: %s' % path
os.makedirs(os.path.dirname(path))
except OSError:
pass
Expand All @@ -83,4 +95,5 @@ def create_file_path(path):

def open_create(filename, mode):
create_file_path(filename)
return open(filename, mode)
print 'Creating file: %s' % filename
return open(filename, mode)
14 changes: 9 additions & 5 deletions cuwo/constants.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
# Copyright (c) Mathias Kaerlev 2013.
#
# This file is part of cuwo.
#
#
# cuwo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# cuwo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with cuwo. If not, see <http://www.gnu.org/licenses/>.

CLIENT_VERSION = 3
SERVER_PORT = 12345

MAX_TIME = 24 * 60 * 60 * 1000
MAX_TIME = 86400000.0
NORMAL_TIME_SPEED = 10.0
SLEEP_TIME_SPEED = 100.0
UPDATE_FPS = 50 # 50FPS in the code, 100FPS when measured-- odd.

MAX_ITEM_LIFETIME = 60.0 # Life Time in seconds

BLOCK_SCALE = 0xFFFF
CHUNK_SCALE = 0xFFFFFF
SECTOR_SCALE = 0x3FFFFFFF
MAX_POS = 0xFFFFFFFFFF
MAX_POS = 0xFFFFFFFFFF

ENTITY_TYPE_PLAYER_MAX_ID = 16
8 changes: 4 additions & 4 deletions cuwo/cub.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Copyright (c) Mathias Kaerlev 2013.
#
# This file is part of cuwo.
#
#
# cuwo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# cuwo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with cuwo. If not, see <http://www.gnu.org/licenses/>.

Expand Down Expand Up @@ -43,4 +43,4 @@ def write(self, writer):
r, g, b = self.blocks.get((x, y, z), (0, 0, 0))
writer.write_uint8(r)
writer.write_uint8(g)
writer.write_uint8(b)
writer.write_uint8(b)
Loading

0 comments on commit ae7171e

Please sign in to comment.