Commits

Pierre Surply committed 065a31b

TPS : Added burn and disten commands

  • Participants
  • Parent commits 76e0ae4

Comments (0)

Files changed (6)

 *.pyc
 *.py~
-*~
+*~
+saves/

src/robot/inventory.py

 ##    along with BASIC-RoBots.  If not, see <http://www.gnu.org/licenses/>.
 ##  
 ## Started on  Sun Jul  8 21:20:03 2012 Pierre Surply
-## Last update Wed Aug  1 17:59:48 2012 Pierre Surply
+## Last update Sat Aug 11 13:41:25 2012 Pierre Surply
 ##
 import os
 
             if self.temp_items[i][0] == name:
                 return i
 
+    def id2item(self, id_item):
+        if id_item < len(self.temp_items):
+            return self.temp_items[id_item]
+        else:
+            return None
+
     def __str__(self):
         s = ""
         for i in self.items.keys():

src/robot/robot.py

 ##    along with BASIC-RoBots.  If not, see <http://www.gnu.org/licenses/>.
 ## 
 ## Started on  Sun Jul  1 15:34:10 2012 Pierre Surply
-## Last update Wed Aug  1 18:00:26 2012 Pierre Surply
+## Last update Sat Aug 11 17:50:15 2012 Pierre Surply
 ##
 
 import os

src/robot/robotsos.py

 ##    along with BASIC-RoBots.  If not, see <http://www.gnu.org/licenses/>.
 ##  
 ## Started on  Wed May  9 22:56:00 2012 Pierre Surply
-## Last update Wed Aug  1 18:00:54 2012 Pierre Surply
+## Last update Sat Aug 11 14:24:40 2012 Pierre Surply
 ##
 
 import os

src/robot/thermalpowerstation.py

 ##    along with BASIC-RoBots.  If not, see <http://www.gnu.org/licenses/>.
 ## 
 ## Started on  Mon Jul 23 11:55:10 2012 Pierre Surply
-## Last update Wed Aug  1 18:01:22 2012 Pierre Surply
+## Last update Sat Aug 11 16:18:08 2012 Pierre Surply
 ##
 
 import robot
 
 class ThermalPowerStation(robot.Robot):
+    list_comb = [(0, 50)]
     def __init__(self, new, world, name, env, (x, y), events):
         robot.Robot.__init__(self, new, world, name, env, (x, y), events)
         self.inv.capacity = 8000000
         self.id_sprite = 3
+        self.ext_cmd["burn"] = (self.burn,\
+                                    "Burn fuel to produce energy",\
+                                    "",\
+                                    (0, []),\
+                                    {"A" : "item id"})
+        self.ext_cmd["fuels"] = (self.fuels,\
+                                     "List all types of fuels",\
+                                     "Always returns 0",\
+                                     (0, []),\
+                                     {})
+        self.ext_cmd["disten"] = (self.disten,\
+                                     "",\
+                                     "Always returns 0",\
+                                     (0, []),\
+                                     {})
+    def incr_energy(self, incr):
+        self.energy += incr
+        if self.energy <= 0:
+            self.energy = 1
+        elif self.energy > 255:
+            self.energy = 255
+
+    def burn(self):
+        id_comb = self.mem["A"]
+        for i in self.list_comb:
+            if i[0] == id_comb:
+                if self.del_item(id_comb, 1):
+                    self.incr_energy(i[1])
+                    return i[1]
+                else:
+                    return 0
+        return 0
+
+    def fuels(self):
+        self.os.terminal.write("Id", 1)
+        self.os.terminal.write("  ")
+        self.os.terminal.write("Item", 1)
+        self.os.terminal.write("        ")
+        self.os.terminal.write("Energy\n", 1)
+        s = ""
+        for i in self.list_comb:
+            item = self.inv.id2item(i[0])
+            s_id = str(i[0])
+            s += s_id + (" " * (4-len(s_id))) + item[0] + (" " * (12-len(item[0]))) + str(i[1]) + "\n"
+        self.os.terminal.write(s)
+        return 0
+
+    def disten(self):
+        for i in self.env.robots:
+            if ((i.pos_x - self.pos_x) ** 2 + \
+                    (i.pos_y - self.pos_y) ** 2 < 100) and \
+                    i.energy < 0xFF:
+                i.incr_energy(1)
+                self.incr_energy(-1)
 ##    along with BASIC-RoBots.  If not, see <http://www.gnu.org/licenses/>.
 ## 
 ## Started on  Wed May  9 18:57:29 2012 Pierre Surply
-## Last update Wed Aug  1 17:51:09 2012 Pierre Surply
+## Last update Sat Aug 11 14:24:51 2012 Pierre Surply
 ##
 
 import time
             x = 0
             for i in sorted(info_bottom[0].keys()):
                 self.display_line(display, \
-                                      self.str2charlist(i+": "+str(info_bottom[0][i]), 1), (org_x+x, h))
+                                      self.str2charlist(i+":"+hex(info_bottom[0][i]), 1), (org_x+x, h))
                 x += info_bottom[1]
         if info_top != None:
             x = w-16
             for i in info_top[0].keys():
                 self.display_line(display, \
-                                      self.str2charlist(i+": "+str(info_top[0][i]), 1), (org_x+x, 0))
+                                      self.str2charlist(i+":"+hex(info_top[0][i]), 1), (org_x+x, 0))
                 x += info_top[1]
         self.display_lines(display, (org_x+1, org_y+1, w-1, h-2))