$HOME/Sandpit/chisel/python/tiny.map
// entity 1 { "classname" "info_player_start" "name" "info_player_start_1" "origin" "-120.000000 -72.000000 12.000000" "angle" "180" } // entity 2 { "classname" "python_doommarine_mp" "name" "python_doommarine_mp_1" "anim" "idle" "origin" "-552.000000 -72.000000 12.000000" "ambush" "1" } ... // entity 40 { "classname" "item_default" "name" "label_1" "label" "the_ammo_loc" "origin" "-1320.000000 -312.000000 12.000000" }
$HOME/Sandpit/chisel/python/pen2map.py
def generateLabels (o, e): n = 1 for r in list(rooms.keys ()): if debugging: print (rooms[r].labels) for label_desc, xy in rooms[r].labels: o.write ("// entity " + str (e) + '\n') o.write ("{\n") o.write (' "classname" "item_default"\n') o.write (' "name" "label_' + str (n) + '"\n') o.write (' "label" "' + label_desc + '"\n') o.write (' "origin" "') xyz = toIntList (xy) + [-invSpawnHeight] xyz = subVec (xyz, [minx, miny, getFloorLevel (r)]) v = midReposition (xyz) o.write ('%f %f %f"\n' % (v[0], v[1], v[2])) o.write ("}\n") n += 1 e += 1 return o, e
$HOME/Sandpit/git-doom/pybot/python_doommarine_find_label.py
def botMain (b): global me print("success! python doom marine is alive") print("trying to get my id...", end=' ') me = b.me () print("yes") print("the python marine id is", me) # an ugly hack to test entity label lookup label_entity_map = b._cache.getEntityNo ("label", "the_ammo_loc") print ("map entity number of label =", label_entity_map) print ("map entity position =", b._cache.getEntityPos (label_entity_map))
$HOME/Sandpit/git-doom/pybot/python_doommarine_find_label.py
# end of an ugly hack to test entity label lookup while True: print ("map label", label_entity_map) label_entity_no = b._cache._basic.mapToRunTimeEntity (label_entity_map) print ("runtime entity label", label_entity_no) b._cache.reset () print ("can I see", label_entity_no, "?") if b.isvisible (label_entity_no): print ("yes I can see the label") b.face (label_entity_no) print ("moving towards the label") moveTowards (label_entity_no) time.sleep (5) moveTowards (1) time.sleep (5) else: print ("no I cannot") b.face (1) # turn towards human player time.sleep (1)
$HOME/Sandpit/git-doom3/pybot-dhewm3/neo/game/Game_local.h
int MapToRunTimeEntity (int id); // (convert map to runtime entity)
$HOME/Sandpit/git-doom3/pybot-dhewm3/neo/game/Game_local.cpp
int idGameLocal::MapToRunTimeEntity (int id) { idMapEntity *mapEnt = mapFile->GetEntity (id); if (mapEnt && mapEnt->epairs.FindKey ("name")) { idStr name = mapEnt->epairs.FindKey ("name")->GetKey (); for (int i = 0; i < num_entities; i++) if (entities[i] && (idStr::Cmp (name, entities[i]->name) == 0)) return i; } return -1; }
$HOME/Sandpit/git-doom3/pybot-dhewm3/neo/game/ai/pybot.cpp
void pyBotClass::interpretRemoteProcedureCall (char *data) ... else if (idStr::Cmpn (data, "change_weapon ", 14) == 0) rpcChangeWeapon (&data[14]); else if (idStr::Cmpn (data, "map_to_runtime_entity ", 21) == 0) rpcMapToRunTimeEntity (&data[21]); ...
$HOME/Sandpit/git-doom3/pybot-dhewm3/python-bot/botbasic.py
# # mapToRunTimeEntity - converts a static map entity into a dynamic entity. # def mapToRunTimeEntity (self, entity_no): if debug_protocol: print("requesting map_to_runtime_entity", entity_no) l = "map_to_runtime_entity %d \n" % (entity_no) self.s.send (l.encode ('utf-8')) l = self.getLine () if debug_protocol: print("doom returned", l) return int (l)
$HOME/Sandpit/git-doom3/pybot-dhewm3/python-bot/botbasic.py
# # isvisible - returns True if entity_no is visible by the bot. # def isvisible (self, entity_no): if entity_no >= 0: if debug_protocol: print("requesting canSeeEntity", entity_no) l = "can_see_entity %d \n" % (entity_no) self.s.send (l.encode ('utf-8')) l = self.getLine () if debug_protocol: print("doom returned", l) return int (l) == 1 return False
$HOME/Sandpit/git-doom3/pybot-dhewm3/neo/game/ai/pybot.h
void rpcGetEntityName (char *data); void rpcCanSeeEntity (char *data); void rpcMapToRunTimeEntity (char *data);
$HOME/Sandpit/git-doom3/pybot-dhewm3/neo/game/ai/pybot.cpp
/* * rpcCanSeeEntity - returns 1 if this bot can see entity, entNo, * returns 0 otherwise. */ void pyBotClass::rpcCanSeeEntity (char *data) { if (protocol_debugging) gameLocal.Printf ("rpcCanSeeEntity (%s) call by python0, data); char buf[1024]; int entNo = atoi (data); int result = 0; if (entNo >= 0) result = dictionary->canSeeEntity (rpcId, entNo); idStr::snPrintf (buf, sizeof (buf), "%d0, result); if (protocol_debugging) gameLocal.Printf ("rpcCanSeeEntity responding with: %s0, buf); buffer.pyput (buf); state = toWrite; }
$HOME/Sandpit/git-doom3/pybot-dhewm3/neo/game/ai/pybot.cpp
/* * canSeeEntity - returns true if bot id can see entity entNo. */ bool dict::canSeeEntity (int id, int entNo) { return entry[id]->canSeeEntity (entNo); }
$HOME/Sandpit/git-doom3/pybot-dhewm3/neo/game/ai/pybot.cpp
bool dict::aim (int id, int enemy) { if (enemy <= maxId) return entry[id]->aim (entry[enemy]->getIdEntity ()); else return entry[id]->aim (gameLocal.GetEntity (enemy)); }
$HOME/Sandpit/git-doom3/pybot-dhewm3/neo/game/ai/pybot.cpp
void pyBotClass::rpcGetPos (char *data) { if (protocol_debugging) gameLocal.Printf ("rpcGetPos (%s) call by python\n", data); char buf[1024]; int id = checkId (atoi (data)); if (id > 0) { if (id <= maxId) { /* A pybot or human player. */ const idVec3 &org = dictionary->getPos (id); idStr::snPrintf (buf, sizeof (buf), "%g %g %g\n", org.x, org.y, org.z); } else if (id < gameLocal.num_entities) { /* A doom3 entity. */ const idVec3 &org = gameLocal.entities[id]->GetPhysics ()->GetOrigin (); idStr::snPrintf (buf, sizeof (buf), "%g %g %g\n", org.x, org.y, org.z); } else strcpy (buf, "None0); } else strcpy (buf, "None0); if (protocol_debugging) gameLocal.Printf ("rpcGetPos responding with: %s\n", buf); buffer.pyput (buf); state = toWrite; }
$HOME/Sandpit/git-doom3/pybot-dhewm3/neo/game/ai/pybot.cpp
static unsigned int maxId = 0;
$HOME/Sandpit/git-doom3/pybot-dhewm3/neo/game/ai/pybot.cpp:doRegisterName
... active.include (b, instance); allbots.include (b, instance); b->setInstanceId (instance); b->setRpcId (rid); if (rid > maxId) maxId = rid; return b; }
$HOME/Sandpit/git-doom3/pybot-dhewm3/neo/game/ai/pybot.cpp
... else if (idStr::Cmpn (data, "can_see_entity ", 15) == 0) rpcCanSeeEntity (&data[15]); else if (idStr::Cmpn (data, "map_to_runtime_entity ", 21) == 0) rpcMapToRunTimeEntity (&data[21]); ...
This document was produced using groff-1.22.