Source

BASIC-RoBots / src / robot / woodcutter.py

##
## woodcutter.py for BASIC-RoBots
## 
## Copyright (C) 2012 Pierre Surply
## <pierre.surply@gmail.com>
##
## This file is part of BASIC-RoBots.
##
##    BASIC-RoBots 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.
##
##    BASIC-RoBots 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 BASIC-RoBots.  If not, see <http://www.gnu.org/licenses/>.
## 
## Started on  Tue Jul  3 14:38:15 2012 Pierre Surply
## Last update Wed Sep  5 12:16:39 2012 Pierre Surply
##

import robot

class Woodcutter(robot.Robot):
    def __init__(self, new, world, name, env, (x, y), events):
        robot.Robot.__init__(self, new, world, name, env, (x, y), events)
        self.inv.capacity = 100000
        self.id_sprite = 1
        self.ext_cmd["cuttree"] = (self.cut_wood,\
                                       "Cut a tree to make wood",\
                                       "1 if a tree has been cut, 0 otherwise", \
                                       (2, []), \
                                       {})

    def cut_wood(self):
        pos = self.get_pos_forward()
        elt = self.env.tile_elts[(pos[1]*self.env.size)+pos[0]]
        if elt in [0, 1, 2, 3, 4]:
            if elt == 4: 
                self.env.tile_elts[(pos[1]*self.env.size)+pos[0]] = None
                self.add_item(0, 2)
            else:
                self.env.tile_elts[(pos[1]*self.env.size)+pos[0]] = 4
                if elt in [2, 3]:
                    self.add_item(0, 4)
                    self.add_item_rnd(1, 2, 3)
                else:
                    self.add_item(0, 8)
                    self.add_item_rnd(1, 2, 2)
            return 1
        else:
            return 0
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.