def OnCVarChanged(self, name, oldvalue, newvalue): if name == self.CVAR_CAPOVERRIDE: overridetime = float(newvalue) self.rules_overrideTime = 0 if overridetime < 0 else overridetime elif name == self.CVAR_CAPPOINTS: points = int(newvalue) self.rules_playerCapPoints = 0 if points < 0 else points elif name == self.CVAR_SPEEDMULT: self.rules_speedMultiplier = float(newvalue) elif name == self.CVAR_ALLOWTOSS: self.rules_allowToss = True if int(newvalue) > 0 else False elif name == self.CVAR_FLAGMI6 and int(newvalue) != self.rules_flagmi6: self.rules_flagmi6 = int(newvalue) GEWeapon.ToGEWeapon( self.game_tokens[Glb.TEAM_JANUS].GetTokenEnt()).SetSkin( self.rules_flagmi6) elif name == self.CVAR_FLAGJANUS and int( newvalue) != self.rules_flagjanus: self.rules_flagjanus = int(newvalue) GEWeapon.ToGEWeapon( self.game_tokens[Glb.TEAM_MI6].GetTokenEnt()).SetSkin( self.rules_flagjanus) elif name == self.CVAR_WARMUP: self.rules_warmupTime = int(newvalue) if self.warmupTimer.IsInWarmup(): self.warmupTimer.StartWarmup(self.rules_warmupTime) if self.rules_warmupTime <= 0: GERules.EndRound(False)
def bot_MemoryCallback(self, ent): weap = GEWeapon.ToGEWeapon(ent) if weap is not None and not weap.GetClassname().startswith("token_"): assert isinstance(weap, GEWeapon.CGEWeapon) weap_info = GEWeapon.WeaponInfo(weap.GetWeaponId()) if weap.GetPlayerOwner(): # Don't remember player owned weapons return (Memory.PRIORITY_NONE, 0) elif weap.GetOwner(): # These are weapons owned by a spawner if weap.GetWeight() >= Weapons.Weight.HIGH: return (Memory.PRIORITY_ULTRA, weap_info) elif weap.GetWeight() >= Weapons.Weight.MEDIUM: return (Memory.PRIORITY_HIGH, weap_info) # Dropped weapons and low weight weapons get this weap_info = GEWeapon.WeaponInfo(weap.GetWeaponId()) return (Memory.PRIORITY_LOW, weap_info) elif ent.GetClassname() == "ge_ammocrate": return (Memory.PRIORITY_HIGH, None) elif ent.GetClassname().startswith("item_armorvest"): return (Memory.PRIORITY_ULTRA, None) else: return (Memory.PRIORITY_LOW, None)
def gt_SubSwapWeapon( self, player1, player2 ): if not player1 or not player2: return self.gt_SwapWeapons( player1, player2 ) oldwep = self.pltracker[player1][TR_WEPINDEX] newwep = self.gt_IssueWeapon( player1 ) msg = _( "#GES_GP_GT_SWAP", GEWeapon.WeaponPrintName(weaponList[oldwep]), GEWeapon.WeaponPrintName(weaponList[newwep]) ) GEUtil.PostDeathMessage( msg )
def GetBestWeapon(self, melee_bonus=0, explosive_bonus=0, thrown_bonus=0): # Get all the NPC's held weapons self._weapons = self._npc.GetHeldWeaponIds() # Get the easy cases out of the way first if len(self._weapons) == 0: if self.debug: print( "[WeaponManager] ERROR - Best weapon called with no weapons in set" ) return None elif len(self._weapons) == 1: return self._weapons[0] # Choose the base weapon hierarchy based on our enemy location to us if self._npc.HasCondition(Cond.GES_ENEMY_CLOSE): base_list = WEAP_SHORT_RANGE elif self._npc.HasCondition(Cond.GES_ENEMY_FAR): base_list = WEAP_LONG_RANGE else: base_list = WEAP_MID_RANGE # Generate a list a weapons based on our conditions weap_list = [] for weap in base_list: # we only pull out weapons that we currently hold if weap not in self._weapons: continue # do not pull out an weapon without ammo ammoType = GEWeapon.WeaponInfo(weap)['ammo_type'] if self._npc.GetAmmoCount( ammoType) <= 0 and self._npc.GetMaxAmmoCount(ammoType) > 0: continue # Base weight will decrease as we go down our list of weapons weight = len(base_list) - len(weap_list) weap_list.append((weap, weight)) weap_list.sort(key=lambda x: x[1], reverse=True) if self.debug and len(weap_list) > 0: print("") for weap, weight in weap_list: print("%s given %.1f" % (GEWeapon.WeaponClassname(weap), weight)) print("") if len(weap_list) > 0 and weap_list[0][1] > 0: return weap_list[0][0] else: if self.debug: print("[WeaponManager] No weapons found to switch to!") return None
def giveAllWeapons(self, player, giveArmor): if giveArmor: player.SetArmor(player.GetMaxArmor()) for i in range(0, 8): player.GiveNamedWeapon( GEWeapon.WeaponClassname(GEMPGameRules.GetWeaponInSlot(i)), 800)
def identifyWeapon(self, info): weaponTemp = info.GetWeapon() if weaponTemp != None: weapon = GEWeapon.ToGEWeapon(weaponTemp) if weapon != None: return weapon.GetClassname().lower() return "weapon_paintbrush"
def ep_weapon_by_info( info ): weaponsurrogate = info.GetWeapon() if weaponsurrogate != None: weapon = GEWeapon.ToGEWeapon( weaponsurrogate ) if weapon != None: return weapon.GetClassname().lower() return "weapon_paintbrush"
def PrintCurLevel(self, player): if not player: return lvl = self.GetLevel(player) name = GEWeapon.WeaponPrintName(weaponList[lvl][0]) GEUtil.ClientPrint(player, GEGlobal.HUD_PRINTTALK, "#GES_GP_GUNGAME_LEVEL", str(lvl + 1), name)
def Start(self, npc, data): from Ai import PYBaseNPC, AiSystems from Ai.Utils import Memory assert isinstance(npc, PYBaseNPC) if data <= 0: data = 512 memory = npc.GetSystem(AiSystems.MEMORY) my_pos = npc.GetAbsOrigin() # If we have a memory, try to find the best weapon we remember if memory is not None: weap_memories = memory.FindMemoriesByType(Memory.TYPE_WEAPON) for m in weap_memories: assert isinstance(m, Memory.Memory) if self.WantsWeapon(npc, memory=m): # print "Going for weapon %s from memory!" % m.classname npc.SetTargetPos(m.location) self.Complete(npc) return # If we get here we either don't have a memory or didn't remember any valid weapons weaps = GEEntity.GetEntitiesInBox("weapon_*", my_pos, GEUtil.Vector(-data, -data, -10), GEUtil.Vector(data, data, 120)) # Sort by closest ammo weight_cmp = lambda x, y: cmp( GEWeapon.ToGEWeapon(x).GetWeight(), GEWeapon.ToGEWeapon(y).GetWeight()) weaps.sort(weight_cmp) for weap in weaps: if self.WantsWeapon(npc, weapon=weap): # print "Going for weapon %s that I found!" % weap.GetClassname() npc.SetTarget(weap) self.Complete(npc) return # We failed to find anything, fail the task npc.TaskFail(GEAiTasks.TaskFail.NO_TARGET)
def CanPlayerHaveItem( self, player, item ): weapon = GEWeapon.ToGEWeapon( item ) if weapon: name = weapon.GetClassname().lower() wI = self.pltracker[player][TR_WEPINDEX] if name == weaponList[wI] or name == "weapon_slappers": return True return False return True
def PrintWeapons(self, player): if not player: return curr_level = self.GetLevel(player) # Players above the max level don't see anything if curr_level > maxLevel: return # Players at the max level see this message only if curr_level == maxLevel: GEUtil.PopupMessage(player, "#GES_GP_ARSENAL_NAME", "You are on the final level!") return # Start with the player's current level arWeapons = "Current level %i: #%s\n" % ( curr_level + 1, GEWeapon.WeaponPrintName( weaponList[curr_level][0])) # Output up to the next 4 weapons for this player, not including the final weapon count = 0 for i in range(curr_level + 1, maxLevel): count += 1 arWeapons += "Level %i: #%s\n" % ( i + 1, GEWeapon.WeaponPrintName(weaponList[i][0])) if count == 4: break # Tack on the final weapon if curr_level >= maxLevel - 5: arWeapons += "Final level %i: #%s\n" % ( len(weaponList), GEWeapon.WeaponPrintName(weaponList[-1][0])) else: arWeapons += "\nFinal level %i: #%s\n" % ( len(weaponList), GEWeapon.WeaponPrintName(weaponList[-1][0])) # Finally show the message to the requesting player GEUtil.PopupMessage(player, "#GES_GP_ARSENAL_NAME", arWeapons)
def ar_PrintCurLevel(self, player): if not player: return lvl = self.ar_GetLevel(player) if lvl < maxLevel: name = GEWeapon.WeaponPrintName(self.weaponList[lvl]) else: name = "Hunting Knife" msg = _("#GES_GP_GUNGAME_LEVEL", str(lvl + 1), name) GEUtil.HudMessage(player, msg, -1, 0.71, GEUtil.Color(220, 220, 220, 255), 3.0, 2)
def OnSpawn(self): PYBaseNPC.OnSpawn(self) min_weight = Weapons.Weight.BEST max_weight = Weapons.Weight.WORST loadout = GERules.GetWeaponLoadout() for id_ in loadout: weap_info = GEWeapon.WeaponInfo(id_) if "weight" in weap_info: if weap_info["weight"] < min_weight: min_weight = weap_info["weight"] elif weap_info["weight"] > max_weight: max_weight = weap_info["weight"] self._min_weap_weight = min_weight self._max_weap_weight = max_weight
def CanPlayerHaveItem(self, player, item): weapon = GEWeapon.ToGEWeapon(item) if weapon: name = weapon.GetClassname().lower() pL = self.pltracker[player][TR_LEVEL] if pL > maxLevel: return True if name == weaponList[pL][ 0] or name == "weapon_knife" or name == "weapon_slappers": return True return False return True
def OnDebugCommand(self, cmd): memory = self.GetSystem(AiSystems.MEMORY) weapons = self.GetSystem(AiSystems.WEAPONS) if cmd == "dump_memory" and memory: memory.DumpMemories() elif cmd == "dump_weapon": weap = self.GetActiveWeapon() assert isinstance(weap, GEWeapon.CGEWeapon) if weap is not None: print GEWeapon.WeaponInfo(weap.GetWeaponId(), self.GetNPC()) elif cmd == "debug_memory" and memory: memory.debug = ~(memory.debug) elif cmd == "debug_weapons" and weapons: weapons.debug = ~(weapons.debug) else: super(bot_deathmatch, self).OnDebugCommand(cmd)
def OnSpawn(self): PYBaseNPC.OnSpawn(self) min_weight = Weapons.Weight.BEST max_weight = Weapons.Weight.WORST loadout = GERules.GetWeaponLoadout() for id_ in loadout: weap_info = GEWeapon.WeaponInfo(id_) if "weight" in weap_info: if weap_info["weight"] < min_weight: min_weight = weap_info["weight"] elif weap_info["weight"] > max_weight: max_weight = weap_info["weight"] self._min_weap_weight = min_weight self._max_weap_weight = max_weight self._medium_weap_weight = (min_weight + max_weight) / 2.0 self.ClearSchedule() self.justSpawned = False
def CanPlayerHaveItem(self, player, item): weapon = GEWeapon.ToGEWeapon(item) if weapon: name = weapon.GetClassname().lower() pL = self.pltracker[player][TR_LEVEL] if name == "weapon_slappers": return True if len(self.weaponList) < pL: return True if len(self.weaponList) == pL: return name == "weapon_knife" if name == self.weaponList[pL]: return True return False return True
def CanPlayerHaveItem(self, player, item): if self.RoundActive: weapon = GEWeapon.ToGEWeapon(item) if weapon: name = weapon.GetClassname().lower() if player.GetUID() == self.BondUID or player.GetUID( ) == self.OurumovUID: if name == "weapon_shotgun" or name == "weapon_knife" or name == "weapon_slappers": return True elif player.GetTeamNumber() == GEGlobal.TEAM_MI6: lvl = self.MI6Level if name == mi6WeaponList[lvl][ 0] or name == "weapon_knife" or name == "weapon_slappers": return True elif player.GetTeamNumber() == GEGlobal.TEAM_JANUS: lvl = self.JanusLevel if name == janusWeaponList[lvl][ 0] or name == "weapon_knife" or name == "weapon_slappers": return True return False return True
def WantsWeapon(self, npc, weapon=None, memory=None): from Ai.Utils import Memory assert isinstance(weapon, GEWeapon.CGEWeapon) assert isinstance(memory, Memory.Memory) weapon = GEWeapon.ToGEWeapon(weapon) my_pos = npc.GetAbsOrigin() curr_weap = npc.GetActiveWeapon() if not curr_weap: return True elif weapon: return not weapon.GetPlayerOwner() and \ weapon.GetWeight() >= curr_weap.GetWeight() and \ weapon.GetAbsOrigin().DistTo( my_pos ) < 2048. and \ npc.GetAmmoCount( weapon.GetAmmoType() ) < weapon.GetMaxAmmoCount() elif memory and type(memory.data) is dict: try: dist = memory.location.DistTo(my_pos) # If we are close, see if there is actually a weapon there! if dist < 500.: weaps = GEEntity.GetEntitiesInBox( "weapon_*", memory.location, GEUtil.Vector(-64, -64, -10), GEUtil.Vector(64, 64, 32)) if len(weaps) == 0: return False # Otherwise do a heuristic check return memory.data["weight"] >= curr_weap.GetWeight() and \ dist < 2048. and \ npc.GetAmmoCount( memory.data["ammo_type"] ) < npc.GetMaxAmmoCount( memory.data["ammo_type"] ) except: return False else: return False
def OnRoundBegin(self): GEScenario.OnRoundBegin(self) GERules.AllowRoundTimer(False) GERules.DisableWeaponSpawns() GERules.DisableAmmoSpawns() GERules.DisableArmorSpawns() self.weaponList = [] #Clear our weapon list # Store all the current weaponset's weapons in a list for easy access. for i in range(0, 8): self.weaponList.append( GEWeapon.WeaponClassname(GERules.GetWeaponInSlot(i))) # Reset all player's statistics self.pltracker.SetValueAll(TR_LEVEL, 0) self.pltracker.SetValueAll(TR_LEVELKILLS, 0) for player in GetPlayers(): self.ar_SetLevel(player, 0) self.ar_SetKills(player, 0) if player.GetTeamNumber() != Glb.TEAM_SPECTATOR: self.ar_PrintCurLevel(player)
def RefreshMemory( self, mem, ent ): assert isinstance( mem, Memory ) assert isinstance( ent, GEEntity.CBaseEntity ) mem.Refresh() mem.hEnt = GEEntity.EntityHandle( ent ) mem.location = ent.GetAbsOrigin() mem.team = ent.GetTeamNumber() # Set player specific flags player = GEPlayer.ToCombatCharacter( ent ) if player: weapon = GEWeapon.ToGEWeapon( player.GetActiveWeapon() ) if weapon and weapon.GetWeaponId() != GEGlobal.WEAPON_SLAPPERS: mem.AddFlag( Memory.FL_ARMED ) else: mem.RemoveFlag( Memory.FL_ARMED ) # Set objective flag based on radar if GERules.GetRadar().IsObjective( ent ): mem.AddFlag( Memory.FL_OBJECTIVE ) else: mem.RemoveFlag( Memory.FL_OBJECTIVE )
def ep_loadout_slot( index ): weapon = GEMPGameRules.GetWeaponInSlot( index ) if weapon != None: return GEWeapon.WeaponClassname( weapon ).lower() return "weapon_paintbrush"
def GetBestWeapon(self, melee_bonus=0, explosive_bonus=0, thrown_bonus=0): # Get all the NPC's held weapons self._weapons = self._npc.GetHeldWeaponIds() # Get the easy cases out of the way first if len(self._weapons) == 0: if self.debug: print "[WeaponManager] ERROR - Best weapon called with no weapons in set" return None elif len(self._weapons) == 1: return self._weapons[0] # Choose the base weapon hierarchy based on our enemy location to us if self._npc.HasCondition(Cond.GES_ENEMY_CLOSE): base_list = WEAP_SHORT_RANGE elif self._npc.HasCondition(Cond.GES_ENEMY_FAR): base_list = WEAP_LONG_RANGE else: base_list = WEAP_MID_RANGE # Generate a list a weapons based on our conditions weap_list = [] for weap in base_list: # we only pull out weapons that we currently hold if weap not in self._weapons: continue # Base weight will decrease as we go down our list of weapons weight = len(base_list) - len(weap_list) info = GEWeapon.WeaponInfo(int(weap), self._npc.GetNPC()) if info["ammo_count"] > 0: # Bonus points for the number of clips of ammo we have if info["uses_clip"]: weight += min( 3, float(info["ammo_count"]) / info["clip_size"]) else: weight += min(3, info["ammo_count"]) elif weap != Glb.WEAPON_MOONRAKER and not info["melee"]: # Weapons with no ammo are not even considered continue if info["melee"]: weight += melee_bonus if weap in WEAP_EXPLOSIVES: weight += explosive_bonus if weap in WEAP_THROWN: weight += thrown_bonus weap_list.append((weap, weight)) weap_sort = lambda x, y: cmp(y[1], x[1]) weap_list.sort(weap_sort) if self.debug and len(weap_list) > 0: print "" for weap, weight in weap_list: print "%s given %.1f" % (GEWeapon.WeaponClassname(weap), weight) print "" if len(weap_list) > 0 and weap_list[0][1] > 0: return weap_list[0][0] else: if self.debug: print "[WeaponManager] No weapons found to switch to!" return None