User Tag List

Results 1 to 8 of 8

Thread: Managing multiple enemies

  1. #1
    Lynel
    ZC Developer
    pkmnfrk's Avatar
    Join Date
    Jan 2004
    Location
    Toronto
    Age
    37
    Posts
    1,248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    3,142
    Level
    18
    vBActivity - Bars
    Lv. Percent
    10.61%

    Managing multiple enemies

    Let's say you've got a totally awesome, fully scripted boss. Let's pretend, theoretically that its name is "King Gleeok". And that it's awesome, etc.

    A possible implementation, which is totally theoretical, mind you, is as such:

    Each head spawns an enemy (Head) which is invisible, and has HP corresponding to the head's HP. The script, each frame, places the enemy onto the location of its FFC, so that Link may attack the head, and do damage. Fine.

    There is also a separate enemy (Body) which is also invisible, invincible, has 1 HP, and sits in the very top-left corner. It is marked as the boss. Each head, upon having its enemy die, checks to see if there is only one enemy left in the room before terminating. If so, it sets the Body's HP to 0. The Body dies, the door opens, etc.

    Further, the head script (the only script needed), checks to see if there are any enemies in the room in the first place, to avoid spawning heads without a body, if its already been defeated.

    Problems

    1. Each head keeps a pointer to its enemy:

    Code:
    npc nme = Screen->CreateNPC(178);
    The idea is that each head checks to see if all heads are dead, and kills the body if so:

    Code:
    if(Screen->NumNPCs() < nmes) {
    	//something died.
    	if(nme->HP > 0) {
    		//phew, not us. update, and ignore
    		nmes = Screen->NumNPCs();
    	} else {
    		//crap, it's us. We bite the dust.
    		npc master = Screen->LoadNPC(1);
    		if(Screen->NumNPCs() == 1) {
    			master->HP = 0;
    		}
    		break;
    	}
    }
    Right now, when Link kills a Head enemy, each Head after it moves down a slot, and the head script is none the wiser. Which ever head had the last enemy then notices that its enemy is now dead. The net result is that after Link kills X heads, X being the total number of heads, the body dies, and he wins. However, they die in the wrong order.

    Is there some way to fix this? (DD, you would be the best to answer this, I think)

    2. If #1 is not possible, can anyone else think of a workable solution? I don't care about changing the structure, I just want it to, overall, act like any other boss (the door opens when all heads are dead, does not return when killed, etc.)

    I do have a script written that mostly works (except for the above issues), but there is no point in posting it, since 99% of everything I haven't posted above is just presentation.
    Tale of the Cave - a web comic - Updates Monday, Wednesday, Friday
    ZC Tutorials - Tutorials and Script Library - Updated July 30, 2008
    ZeldaGuard - Corruption in my save files? It's more likely than you think!
    I do script requests!

  2. #2
    Wizrobe C-Dawg's Avatar
    Join Date
    Jan 2002
    Posts
    4,205
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    6,612
    Level
    24
    vBActivity - Bars
    Lv. Percent
    99.93%

    Re: Managing multiple enemies

    You can probably get around your problem by letting FFCs communicate with each other through their location or their Combo. I've found this is a great way to synergize multiple-scripted-FFC entities. I call it "letting the FFCs talk."

    First, you could have each head create its own enemy with exactly 100 more hit points than you really want. Then, all each head does is checks its own enemy to see if it has less than 100 hit points. If it does, the script plays the enemy death noise, maybe goes through a death animation routine, moves the enemy and the FFC to -16,-16, stops its own behavior.

    Then, you can have your body FFC watch the location of the head FFCs rather than whether the enemies are alive or not. That is, the head checks the (x,y) location of each head FFC. When they are all (-16,-16), the body goes through death animation, then sends Link through a scripted warp to the victory screen.

    Alternatively, you could set the combo for each head FFC to be combo 0 or some other pre-arranged combo, and have the body FFC look at the combos being used, rather than moving it. But you have to move the enemy out of the way or the player can still hit it.

    So what this does? You avoid ever actually killling one of your enemies, so you never have a problem with the enemy pointers "slipping" from killed enemies to live ones. Just make sure that the threshold hit points for each head (100 in this case) is so high that the player can't kill them before the script spirits them safely away to -16,-16.

  3. #3
    Lynel
    ZC Developer
    pkmnfrk's Avatar
    Join Date
    Jan 2004
    Location
    Toronto
    Age
    37
    Posts
    1,248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    3,142
    Level
    18
    vBActivity - Bars
    Lv. Percent
    10.61%

    Re: Managing multiple enemies

    Hmmm.... Tricky, but workable. I'll see if I can do that.

    Edit: Yup, worked like a charm:

    Code:
    ffc script kinggleeokbody {
    	void run(int num) {
    		npc nme;
    		int i;
    		Waitframe();
    		if(Screen->NumNPCs() < 1) {
    			Quit();
    		}
    		nme = Screen->LoadNPC(1);
    		nme->X = -16;
    		while(true) {
    			for(i = 1; i <= Screen->NumNPCs(); i++) {
    				nme = Screen->LoadNPC(i);
    				if(nme->X != -16) {
    					i = -1;
    					break;
    				}
    			}
    			if(i != -1) {
    				break;
    			}
    			Waitframe();
    		}
    		
    		for(i = 1; i <= Screen->NumNPCs(); i++) {
    			nme = Screen->LoadNPC(i);
    			nme->HP = 0;
    		}
    	}
    }
    The body enemy (the first one in the room) moves itself to -16 (since I can't place it there), and when all enemies are at -16, then it kills itself, along with all the head enemies.

    Now, my only problem is that if I give the head enemy a projectile (say, a fireball), the "dead" heads still fire, from somewhere to the left. Is there some way to freeze an enemy, so that it doesn't use its weapon any more?
    Tale of the Cave - a web comic - Updates Monday, Wednesday, Friday
    ZC Tutorials - Tutorials and Script Library - Updated July 30, 2008
    ZeldaGuard - Corruption in my save files? It's more likely than you think!
    I do script requests!

  4. #4
    Octorok
    Join Date
    May 2007
    Posts
    331
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    1,506
    Level
    13
    vBActivity - Bars
    Lv. Percent
    11.33%

    Re: Managing multiple enemies

    npc->Weapon = WPN_NONE

    Just null out the enemys abilty to fire a weapon

  5. #5
    Lynel
    ZC Developer
    pkmnfrk's Avatar
    Join Date
    Jan 2004
    Location
    Toronto
    Age
    37
    Posts
    1,248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    3,142
    Level
    18
    vBActivity - Bars
    Lv. Percent
    10.61%

    Re: Managing multiple enemies

    Wow, I didn't even see that variable. Now I have to kill you. That said...

    ...it seems that DD's recent changes to NPC pointers should make this a lot easier. Since I spawn all the enemies at once, they will all have the unique IDs, and so I can keep track of them properly.
    Tale of the Cave - a web comic - Updates Monday, Wednesday, Friday
    ZC Tutorials - Tutorials and Script Library - Updated July 30, 2008
    ZeldaGuard - Corruption in my save files? It's more likely than you think!
    I do script requests!

  6. #6
    Wizrobe C-Dawg's Avatar
    Join Date
    Jan 2002
    Posts
    4,205
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    6,612
    Level
    24
    vBActivity - Bars
    Lv. Percent
    99.93%

    Re: Managing multiple enemies

    Ah, well, maybe. Sounds like Dark Dragon's method will shuffle enemy IDs if more enemies spawn. Might not affect this particular code, but its worth remembering for the future. The "almost dead" method should keep working.

  7. #7
    Administrator DarkDragon's Avatar
    Join Date
    Oct 2001
    Posts
    6,228
    Mentioned
    70 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    11,028
    Level
    31
    vBActivity - Bars
    Lv. Percent
    8.53%

    Re: Managing multiple enemies

    No shuffling should take place. The ID is assigned to an enemy at creation, and won't change until its death.

  8. #8
    Lynel
    ZC Developer
    pkmnfrk's Avatar
    Join Date
    Jan 2004
    Location
    Toronto
    Age
    37
    Posts
    1,248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    3,142
    Level
    18
    vBActivity - Bars
    Lv. Percent
    10.61%

    Re: Managing multiple enemies

    Exactly. I create the enemies at the start of the room, and do not spawn any more while running. So, no issues.

    (That said, a Screen->IsValidNPC(npc p) would be nice)
    Tale of the Cave - a web comic - Updates Monday, Wednesday, Friday
    ZC Tutorials - Tutorials and Script Library - Updated July 30, 2008
    ZeldaGuard - Corruption in my save files? It's more likely than you think!
    I do script requests!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Armageddon Games is a game development group founded in 1997. We are extremely passionate about our work and our inspirations are mostly drawn from games of the 8-bit and 16-bit era.
Social