Wolf3d Haven Forum

Please log in or register. Smile

Join the forum, it's quick and easy

Wolf3d Haven Forum

Please log in or register. Smile

Wolf3d Haven Forum

Would you like to react to this message? Create an account in a few clicks or log in to continue.
Wolf3d Haven Forum

A friendly Wolfenstein 3D community, about Wolfenstein 3D, the game that gave birth to first person shooters...


2 posters

    Help with enemies respawning elsewhere in map

    racquetball1987
    racquetball1987
    Freshmen
    Freshmen


    Number of posts : 11
    Age : 36
    Registration date : 2011-03-05

    Help with enemies respawning elsewhere in map Empty Help with enemies respawning elsewhere in map

    Post by racquetball1987 Sat May 13, 2017 7:06 pm

    Most of my code is a big mess with a lot of inefficient fixes. What I'm trying to do right now is no exception.. So imagine that in the last level of my TC, there are "gates" drawn on the wall and whenever you kill and enemy their body disappears and a new enemy is spawned in front of one of the gates at random. The purpose of the body disappearing is to prevent too many actors from crashing the game. The 22 positions that the new actors spawn are hard coded in front of these "gates".

    I tried my best to implement this without asking for help, but I'm at a loss. The two problems I'm having are as follows:

    1) the enemies are disappearing before their death animation is shown, ideally I'd like them to die, hit the floor and sit for like 10 seconds then disappear, and only after all this would the new enemy spawn.

    2) Sometimes when an enemy spawns the game crashes with "MoveObj: bad dir!"


    This is at the end of KillActor in WL_STATE.C. 

    OH! And I'm using the DOS version of the game.

    Code:
    if (gamestate.mapon == 9) RemoveObj(ob);
    if (gamestate.mapon == 9)
    {
    int RandomSpawn = US_RndT()%22;
    if (RandomSpawn == 0 && tilemap[53][30] == 0)  {SpawnStand(en_guard,53,30,116); }
    if (RandomSpawn == 1 && tilemap[53][35] == 0)  { SpawnGift(53,35); }
    if (RandomSpawn == 2 && tilemap[52][42] == 0)  { SpawnStand(en_officer,52,42,116); }
    if (RandomSpawn == 3 && tilemap[49][51] == 0)  { SpawnStand(en_guard,49,51,116); }
    if (RandomSpawn == 4 && tilemap[43][54] == 0)  { SpawnStand(en_dog,43,54,116); }
    if (RandomSpawn == 5 && tilemap[36][55] == 0)  { SpawnGift(36,55); }
    if (RandomSpawn == 6 && tilemap[29][55] == 0)  { SpawnStand(en_guard,29,55,116); }
    if (RandomSpawn == 7 && tilemap[22][54] == 0)  { SpawnStand(en_officer,22,54,116); }
    if (RandomSpawn == 8 && tilemap[15][52] == 0)  { SpawnStand(en_guard,15,52,116); }
    if (RandomSpawn == 9 && tilemap[11][46] == 0)  { SpawnStand(en_ss,11,46,116); }
    if (RandomSpawn == 10 && tilemap[9][37] == 0)  { SpawnStand(en_guard,9,37,116); }
    if (RandomSpawn == 11 && tilemap[9][31] == 0)  { SpawnStand(en_dog,9,31,116); }
    if (RandomSpawn == 12 && tilemap[9][25] == 0)  { SpawnGift(9,25); }
    if (RandomSpawn == 13 && tilemap[10][19] == 0)  { SpawnSchabbs(10,19); }
    if (RandomSpawn == 14 && tilemap[12][14] == 0)  { SpawnStand(en_guard,12,14,116); }
    if (RandomSpawn == 15 && tilemap[17][10] == 0)  { SpawnFakeHitler(17,10); }
    if (RandomSpawn == 16 && tilemap[27][8] == 0)  { SpawnStand(en_officer,27,8,116); }
    if (RandomSpawn == 17 && tilemap[33][8] == 0)  { SpawnStand(en_guard,33,8,116); }
    if (RandomSpawn == 18 && tilemap[40][9] == 0)  { SpawnHitler(40,9); }
    if (RandomSpawn == 19 && tilemap[49][13] == 0)  { SpawnStand(en_ss,49,13,116); }
    if (RandomSpawn == 20 && tilemap[52][18] == 0)  { SpawnBoss(52,18); }
    if (RandomSpawn == 21 && tilemap[53][25] == 0)  { SpawnGretel(53,25); }
    }
    Mega Luigi
    Mega Luigi
    Bring em' On!
    Bring em' On!


    Number of posts : 161
    Age : 14
    Registration date : 2012-11-01

    Help with enemies respawning elsewhere in map Empty Re: Help with enemies respawning elsewhere in map

    Post by Mega Luigi Wed May 17, 2017 6:02 pm

    Hello,

    I guess the problems you seem to be having make sense in the end. Here's what I can tell you about those problems:

    1) The KillActor function is called when the enemy dies, i.e, when he begins his death animation. You can think of it as if it's called the next instant after the enemy's health dropped to 0. So, yeah, the moment you finish your enemy, he is going to disappear. If you want them to disappear after being actually dead, you'll have to do this some other way. In fact, there are various ways of doing that. You can make a special death state for each enemy, specifically for that level (although I wouldn't recommend that, considering you're using DOS).
    You could create a new function that would be called on every last death state, and that function would only remove the dead guys on the level you wanted, for example.
    You could create some conditions comparing the current state of the enemy with its last death state in the DoActor function call, which would remove the bodies in a certain situation.
    Anyway, like I said, there are many ways you can do that. You just got to choose what you want, if it's something functional, something good looking or whatever you priorities are.

    2) Hmm, I'm not sure what was your intention in your SpawnStand calls.
    Code:
     SpawnStand(en_guard,12,14,116);
    The fourth parameter is the "dir" parameter. By the way, whenever you come across some function you don't know, it's usually a good start to look at its prototype. For example, look:
    Code:
    void SpawnStand (enemy_t which, int tilex, int tiley, int dir)
    So, yeah, that's why it is a bad dir. 116 is indeed bad. SpawnStand wants an integer value contained in [0,3], 0 being east and going to 3 counterclockwise, each number being one of the four cardinal directions. I guess that is most likely the reason for your problems. The error you're receiving simply means that the direction variable an actor does not belong to the expected values (which are the four cardinal directions plus the 4 intercardinal directions).

    Anyway, everything I said here can be confirmed by yourself if you look in the code. That'd be a nice exercise, I guess. Hope I helped you a little bit, at least.

    Luigi
    racquetball1987
    racquetball1987
    Freshmen
    Freshmen


    Number of posts : 11
    Age : 36
    Registration date : 2011-03-05

    Help with enemies respawning elsewhere in map Empty Re: Help with enemies respawning elsewhere in map

    Post by racquetball1987 Sat May 20, 2017 12:47 pm

    For some reason I thought the range 'dir' would be 0 - 360. That seems stupid now that I'm thinking about it. Thanks Luigi, that completely fixed the crash I was having.
    Mega Luigi
    Mega Luigi
    Bring em' On!
    Bring em' On!


    Number of posts : 161
    Age : 14
    Registration date : 2012-11-01

    Help with enemies respawning elsewhere in map Empty Re: Help with enemies respawning elsewhere in map

    Post by Mega Luigi Mon May 22, 2017 5:06 pm

    Good to hear Smile. Lemme know if you need any more help concerning the other problem.

    Luigi

    Sponsored content


    Help with enemies respawning elsewhere in map Empty Re: Help with enemies respawning elsewhere in map

    Post by Sponsored content


      Current date/time is Thu Nov 21, 2024 2:45 am