Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Noob question on hashmaps


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Orymus3   Crossbones+   -  Reputation: 15234

Like
1Likes
Like

Posted 21 June 2014 - 10:31 PM

Hi,

 

I'm currently programming a system where a series of AI-governed units have to make an assessment of what their best target to attack is.

They are looking at a hashmap that contains all AI units and check if these are hostile towards them.

The problem I'm faced with is that I also have a 'player' which is a different class that I would like to be listed in there, but quite unsurprisingly, the hashmap is typed and won't allow for my player class to be included.

 

My best solution so far is to make two standalone checks (one with the hashmap, and a single one with the player) but I'm assuming there must be an easier way (perhaps an untyped hashmap?).

 

Any way to solve this easily without having to rebuild a matrix that contains data that is similar between AIs and the player?

 

Thanks


-=- My Articles -=-
Getting Games Done - Method and tools on how to start a hobby project and get it Done!

Retro Mortis - "RTS" - Article Series (3 Parts) on the history of RTS development


Sponsor:

#2 thok   Members   -  Reputation: 693

Like
6Likes
Like

Posted 22 June 2014 - 02:12 AM

If you want to have the player object in the hashmap as well, and the hashmap is typed, the player needs to have the same interface as the other objects. That means, for example, that all of the objects could inherit from the same superclass, provided that there are enough similarities for this to make sense, of course. Otherwise, they could just explicitly implement the same interface. Then you should type the hashmap with the superclass or interface.

 

Make sense?



#3 Orymus3   Crossbones+   -  Reputation: 15234

Like
0Likes
Like

Posted 22 June 2014 - 05:43 AM

I thought about this actually.
Started looking into interfaces a few weeks ago actually (never used them yet).
I will try it thanks!

-=- My Articles -=-
Getting Games Done - Method and tools on how to start a hobby project and get it Done!

Retro Mortis - "RTS" - Article Series (3 Parts) on the history of RTS development


#4 zee_ola05   Members   -  Reputation: 334

Like
0Likes
Like

Posted 24 June 2014 - 11:46 AM

Yes, Interface. :)






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS