Jump to content

Photo

Detecting if enemy`s shield (like Darknut`s one) is broken.

enemy shield

  • Please log in to reply
6 replies to this topic

#1 Alucard648

Alucard648

    Wizard

  • Members
  • Location:castle Dracula

Posted 16 April 2014 - 03:47 PM

While writing the portion of stdWeapons.zh header that handles special interaction with enemies I have stumbled upon a little (or not) problem: enemy`s shield can be intact or broken (by hammer or via "npc->BreakShield()" function). And my function that checks if Lweapon hits shielded side of the enemy may return false positive if enemy`s shield is broken and any scripted weapon that uses this function will behave like if it`s blocked by (non-existent) enemy shield. Here is the function:

// Returns a counter-clockwise direction in 4-way compass
int CCWDir4way (int dir){
	if (dir == DIR_UP) return DIR_LEFT;
	if (dir == DIR_LEFT) return DIR_DOWN;
	if (dir == DIR_DOWN) return DIR_RIGHT;
	if (dir == DIR_RIGHT) return DIR_UP;
	else return -1;
}

// Returns a clockwise direction in 4-way compass
int CWDir4way (int dir){
	if (dir == DIR_UP) return DIR_RIGHT;
	if (dir == DIR_RIGHT) return DIR_DOWN;
	if (dir == DIR_DOWN) return DIR_LEFT;
	if (dir == DIR_LEFT) return DIR_UP;
	else return -1;
}

// Returns TRUE if lweapon collides with shielded side of the enemy.
bool BlockedByShield(lweapon l, npc n){
	if (!Collision(l,n)) return false;
	if (GetNPCMiscFlag(n, 0x0200)){
		if (l->Dir== OppositeDir(n->Dir)) return true;
		else return false;
	}
	else if (GetNPCMiscFlag(n, 0x1000)){
		if (l->Dir == n->Dir) return true;
		else return false;
	}
	else if (GetNPCMiscFlag(n, 0x0400)){
		if (l->Dir==CCWDir4Way(n->Dir)) return true;
		else return false;
	}
	else if (GetNPCMiscFlag(n, 0x0800)){
		if (l->Dir==CWDir4way(n->Dir)) return true;
		else return false;
	}
	return false;
}
 

Any way to make that fuction work propely with breakable enemy`s shields?


Edited by Alucard648, 17 April 2014 - 03:28 PM.


#2 MoscowModder

MoscowModder

    Sometimes lurking. Rarely posting.

  • Members
  • Location:Wisconsin

Posted 16 April 2014 - 04:10 PM

As far as I know, there's no way for a script to tell if an enemy's shield is broken unless the script does it itself and remembers it.

 

Now, it might be possible to check the "Shielded on ___" flags. Those should be un-set when the shield breaks.



#3 Avaro

Avaro

    o_o

  • Members
  • Real Name:Robin
  • Location:Germany

Posted 16 April 2014 - 04:12 PM

Maybe you'd have to script breaking enemies shield by yourself, meaning that you'd have to uncheck "Hammer can break shield". Then you script the shieldbreak for when the player uses the hammer on the enemy, with the shield break function and at the same time you set one of the misc variables (which are for use with scripts) to 1. Then, if an enemy has that misc variable set to 1, you can know for sure that it's shield is broken.

#4 Mero

Mero

    Touch Fluffy Tail

  • Banned
  • Real Name:Tamamo No Mae
  • Location:Rainbow Factory

Posted 16 April 2014 - 04:31 PM

Internally when an enemies shield is broken it's MiscFlags are cleared. So it's actually possible to restore a shield by setting them! The flags decimal values are 512, 1024, 2048, and 4096 respective to the order they appear in the enemy error. The below checks the state of a Darknut's shield. :)
 

if((npc->MiscFlags&512)!=0)
    //Has Shield
else
    //Shield is Broken

Edited by Zecora, 16 April 2014 - 04:32 PM.


#5 Alucard648

Alucard648

    Wizard

  • Members
  • Location:castle Dracula

Posted 17 April 2014 - 04:36 AM

Zscript read-me file says that NPC misc flags are read-only

 

/**
* The npc's Misc. Flags as 14 bits ORed together, starting with 'Damaged by Power 0 Weapons', * and working down the flags in the order they are shown in the Enemy Editor.
* npc->MiscFlags is read-only; while setting it is not syntactically incorrect, it does nothing.
* If you are not comfortable with binary operations, you can use 'GetNPCMiscFlag' from std.zh
*/
int MiscFlags;

 

 

Internally when an enemies shield is broken it's MiscFlags are cleared. So it's actually possible to restore a shield by setting them! The flags decimal values are 512, 1024, 2048, and 4096 respective to the order they appear in the enemy error. The below checks the state of a Darknut's shield. :)
 

if((npc->MiscFlags&512)!=0)
    //Has Shield
else
    //Shield is Broken

Either you are not correct, or it`s an error in Zscript read-me.



#6 Mero

Mero

    Touch Fluffy Tail

  • Banned
  • Real Name:Tamamo No Mae
  • Location:Rainbow Factory

Posted 17 April 2014 - 10:05 AM

You might be right about it not being able to be set. Never the less the flag is cleared internally and you'll be able to detect when a shield is broken by reading for that flag to be cleared. Also for some reason the order of the flags is messed up. I forget the order of the flags but I remember seeing constants for them in stdextra.zh.


Edited by Zecora, 17 April 2014 - 10:24 AM.


#7 MoscowModder

MoscowModder

    Sometimes lurking. Rarely posting.

  • Members
  • Location:Wisconsin

Posted 17 April 2014 - 02:40 PM

I thought you put them there :P

 

Yes, stdExtra does have constants for enemy misc flags. I think you'll probably want to check the flags for all sides, just in case you have some enemy that's shielded on only the back for example.





Also tagged with one or more of these keywords: enemy, shield

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users