Author Topic: Tracking targets  (Read 43370 times)

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Tracking targets
« Reply #45 on: January 11, 2011, 08:53:13 PM »
It's like me writing in C because I like the old-fashioned hardcore-ness of C.

No, it's not like that. I don't like hardcore. I'm simply aware of problems in C++ and I pretty much know how to handle them - without boost or smart pointers which I think just makes things more confusing. The results of my programming style can be seen in Teemu which has zero known bugs.

siob

  • Rogueliker
  • ***
  • Posts: 64
  • Karma: +0/-0
  • blit(brain)
    • View Profile
    • gamejs
Re: Tracking targets
« Reply #46 on: January 11, 2011, 11:05:06 PM »
I'm basically with roguedjack. thanks for the solid advice: http://www.roguetemple.com/forums/index.php?topic=1425.msg10297#msg10297

I don't care if looking up in hash table costs me time. But that's a given, because I write most my code in JavaScript and only very small parts in C or Java if necessary.

Fenrir

  • Rogueliker
  • ***
  • Posts: 473
  • Karma: +1/-2
  • The Monstrous Wolf
    • View Profile
Re: Tracking targets
« Reply #47 on: January 12, 2011, 12:13:54 AM »
The results of my programming style can be seen in Teemu which has zero known bugs.
Well then make it bigger and better until it does have bugs! You're not pushing the limits of what you can do.

If something or someone isn't on fire, you haven't tried hard enough.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Tracking targets
« Reply #48 on: January 13, 2011, 02:14:51 PM »
You're not pushing the limits of what you can do.

Maybe. But you can't deny that even the project size of Teemu is pretty good with its zero known bugs. The current development version 1.3 has total of 33 bugs by the way, but 30 of them are fixed. In fact I believe that the code quality will become better even the size and complexity is growing, because minor refactoring going on.

Fenrir

  • Rogueliker
  • ***
  • Posts: 473
  • Karma: +1/-2
  • The Monstrous Wolf
    • View Profile
Re: Tracking targets
« Reply #49 on: January 13, 2011, 03:40:09 PM »
That is true. Sorry, I didn't mean to imply that you weren't very good at what you do.

Anyway, don't let me derail the thread...

wire_hall_medic

  • Rogueliker
  • ***
  • Posts: 160
  • Karma: +0/-0
    • View Profile
Re: Tracking targets
« Reply #50 on: March 13, 2011, 06:31:33 AM »
So, bringing it back, then.

I'm assuming that you have some random variable in your AI decision-making, and that you sometimes assign actions which take more than one turn.  Otherwise, you don't need anything.

You could store the current action as "Get item X" (well, "currentAcion = GET_ITEM" and "currentTarget = item").  Then each turn, the AI checks to see if there is an item of the type within sight, then moves as close as possible, picking it up if possible.  This also works for things like slow melee guys (you don't want them charging dead targets), etc.

This is a pretty clean solution, as you can just let the AI figure the best way to accomplish its current goal each turn; this has the emergent behavior of making the NPCs look smart.  The only thing is that this means the AI will repath each turn; this can be computationally expensive when the target is far away, or if you have a very large number of NPCs acting.

If you experience slowdown, you could save the path.  When the AI checks if its current action is still valid, part of that check is if the item is on the last step of the path.  If it is, then the NPC continues to step.  If not, it chooses a new task.