Author Topic: 'House Robots'??  (Read 967 times)

Offline WhamettNuht

  • *
  • Posts: 1302
  • Rep: 12
  • Robot Building Drag Queen
    • View Profile
    • Awards
  • Discord: WhamettNuht #1457
'House Robots'??
« on: February 07, 2018, 02:25:22 PM »
Hi all! Long time no see!

Just a quickie - I can remember from ages and ages ago I was told how to edit a value in some sort of file so that AI robots don't go after human players, but for the life of me and all of my poking around in RA2's files I cannot remember where this value lies.... Just wondering if someone would happen to know where one might find such a thing??

Also - can someone super savvy advise me on whether it would be possible to alter the Action Cam to only focus on say 2 robots when there's 3 in the arena?

Thanks guys!!
Damn I should probably put something fancy in this bit huh?

Online apanx

Re: 'House Robots'??
« Reply #1 on: February 07, 2018, 02:45:39 PM »
in init.py for the SuperAI-class
Code: [Select]
    def GetNearestEnemy(self):
        closest = None
        min_dist = 9999
        min_weighted_dist = 9999

        enemies = self.GetEnemies()

        # target human players first
        for enemy in enemies:
            dist = self.GetDistanceToID(enemy)
            weighted_dist = dist
            if not plus.isHuman(enemy): weighted_dist += 3
            if weighted_dist < min_weighted_dist:
                closest = enemy
                min_weighted_dist = weighted_dist
                min_dist = dist

        return closest, min_dist

Invert the weighted_dist modifier.

For action cam, in actioncam.py
Code: [Select]
        for p in self.players:
            if plus.isEliminated(p) or plus.isDefeated(p):
                if p in self.expiration:
                    if self.expiration[p]  <= plus.getTimeElapsed():
                        self.players.remove(p)
                        self.playerCount -= 1
                else:
                    self.expiration[p] = plus.getTimeElapsed() + self.defeatedDelay
Add a line after to remove robots you want to ignore
Code: [Select]
        self.players.remove(id)

Offline Jaydee99

  • Waltuhweight
  • *
  • Posts: 1938
  • Rep: -23
  • :/
    • View Profile
    • Awards
  • See profile for gamer tags: Yes
Re: 'House Robots'??
« Reply #2 on: February 07, 2018, 03:30:20 PM »
holy crap, this is awesome!!
Can I create a separate PY file and add this? Like will it still work?



Offline WhamettNuht

  • *
  • Posts: 1302
  • Rep: 12
  • Robot Building Drag Queen
    • View Profile
    • Awards
  • Discord: WhamettNuht #1457
Re: 'House Robots'??
« Reply #3 on: February 07, 2018, 03:31:20 PM »
Thank you for the fast reply!

Been having a tinker, but it's still not quite right, just wanted to make sure I'm getting it right (been a while since I've done all of this advanced coding lark lol)

When you say 'Invert the weighted_dist modifier' am I inverting this value:

Code: [Select]
            if not plus.isHuman(enemy): weighted_dist += 3
As for the Action Cam, am I adding the self.players.remove value straight after the 'self.expiration' line?
Also, does the (id) value work on a 1-4 basis (as in 4 is robot number 4) or the typical RA2 method of 0-3 (so that 3 is robot number 4)?

Apologies for my newbness! (There's a word I haven't used for some years lol)
Damn I should probably put something fancy in this bit huh?

Online apanx

Re: 'House Robots'??
« Reply #4 on: February 11, 2018, 08:18:54 PM »
Just change this
Code: [Select]
if not plus.isHuman(enemy): weighted_dist += 3to something like this
Code: [Select]
if plus.isHuman(enemy): weighted_dist += 9999
For the actioncam, make it look like this. id is a player id between 0-3. Also, there are more than one place where the code is used, so make sure you change it everywhere. Observe the indentation.
Code: [Select]
        for p in self.players:
            if plus.isEliminated(p) or plus.isDefeated(p):
                if p in self.expiration:
                    if self.expiration[p]  <= plus.getTimeElapsed():
                        self.players.remove(p)
                        self.playerCount -= 1
                else:
                    self.expiration[p] = plus.getTimeElapsed() + self.defeatedDelay
        self.players.remove(id)
        self.playerCount -= 1
I haven't tried any of these, but it should work, so: :cancer::cancer::cancer::cancer::cancer: