Pulling data from item "use_action" for monster special attack

Heavy coder question here!

I’m working on making some kamikaze robots. However, to avoid hardcoding every single one I’m attempting my hand at a generic “blow yourself up with the first item in your ammo list” monattack. (It’s actually a combination of two monattacks, one that works as the “activate the bomb countdown” and the other that actually blows the monster up).

I’m running into one big problem though; I can’t for the life of me figure out how to pull data from an item’s “use_action” when all I have access to is the item type. Specifically I’d like to grab the “target” and “target_charges” from the ammo item use_action data as well as then grab data on the size/power/type of the explosion from the “target” use_action data.

Barring this I could just set some basic hardcoded limits for the range finding, but then we could easily end up with the kamikazes exploding way before they reach their target or hovering around them for several turns before exploding which isn’t exactly what I’m looking for. (Ideally I’ll be able to fine tune the countdown range calculation based on the monster speed and explosion sizes such that the player could hypothetically outrun the bot just barely, but that’s not going to happen without access to the explosion data of the item.) Anybody know of any easy ways? (Or hard ones, if those are all that exist).

You could probably use use_function *itype::get_use( const std::string &iuse_name )

Like:

const explosion_iuse *actor = dynamic_cast<const explosion_iuse *>( item_type.get_use( "explosion" ).get_actor_ptr() )

Then you could access all the explosion info like actor->explosion_power.

Or you could just have the mon spawn itself a fake bomb item type with zero charges per turn but non-zero current charges. When it’s time to explode, you could just set the charges to 0 and activate the item, causing the explosion.

The hardest part will probably be adding non-hardcoded items into mon’s inventory. Do we have support for that?

I was just gonna use an ammo item entry (which isn’t a real item, just a string you input through the JSON) to track what we used to explode, letting it be set by the player (and not messing with the actual monster inventory at all). That would mean that all the data required to make your own kamikaze bot with any given explosive would be accessible in the JSON file; you could make bots carrying anything from fireworks to dynamite to mininukes if you wanted to without having to change the code at all.

I originally considered just using a fake item (and I almost certainly will for the actual explosion part), but the problem is that I needed to access the data on how large the explosion was to determine how close to the player the bot had to get before starting the countdown. Without that data to adjust the “range” on their activation special you end up with the bots carrying small explosives not necessarily being able to reach the player before the bomb goes off, or bots carrying mininukes waiting until they get right next to the player, thus removing any chance of escape at all (This would, of course, remove the epic scene of you seeing the bot activate, taking off running away from the bot, and then barely escaping the edge of the huge explosion as the zombies around you are consumed in fire).

That said the way you outlined there looks like it could work, I’ll take a shot at implementing it tomorrow. Thanks.

You have no idea what you have just done. >:)[/quote]

Oh god.

[quote=“i2amroy, post:3, topic:9444”]I was just gonna use an ammo item entry (which isn’t a real item, just a string you input through the JSON) to track what we used to explode, letting it be set by the player (and not messing with the actual monster inventory at all). That would mean that all the data required to make your own kamikaze bot with any given explosive would be accessible in the JSON file; you could make bots carrying anything from fireworks to dynamite to mininukes if you wanted to without having to change the code at all.

I originally considered just using a fake item (and I almost certainly will for the actual explosion part), but the problem is that I needed to access the data on how large the explosion was to determine how close to the player the bot had to get before starting the countdown. Without that data to adjust the “range” on their activation special you end up with the bots carrying small explosives not necessarily being able to reach the player before the bomb goes off, or bots carrying mininukes waiting until they get right next to the player, thus removing any chance of escape at all (This would, of course, remove the epic scene of you seeing the bot activate, taking off running away from the bot, and then barely escaping the edge of the huge explosion as the zombies around you are consumed in fire).

That said the way you outlined there looks like it could work, I’ll take a shot at implementing it tomorrow. Thanks.[/quote]
You could always create a fake npc, carrying a ‘fake’ bomb, like the tank-drones do. They have someway to store their ammo.

Carrying ammo != fake NPC. The fake npc is just used for shooting the ammo, we already have a system in place for the monster to actually track how much ammo it has. Everything for what I want to do is already there, I just needed access to the explosion data for AI purposes. :stuck_out_tongue: