Wolf3D-Mac/Doors.c

1 line
8.3 KiB
C
Raw Permalink Normal View History

#include "Wolfdef.h" #include <string.h> /********************************** Rules for door operation door->position holds the amount the door is open, ranging from 0 to TILEGLOBAL-1 The number of doors is limited to 64 because various fields are only 6 bits Open doors conect two areas, so sounds will travel between them and sight will be checked when the player is in a connected area. areaconnect has a list of connected area #'s, used to create the table areabyplayer Every time a door opens or closes the areabyplayer matrix gets recalculated. An area is True if it connects with the player's current spor. **********************************/ /********************************** Insert a connection between two rooms Note: I can have MORE than one connection between rooms so it is VALID to have duplicate entries (1,6) & (1,6) Each call to AddConnection must be balanced with a call to RemoveConnection **********************************/ void AddConnection(Word Area1,Word Area2) { connect_t *DestPtr; DestPtr = &areaconnect[ConnectCount]; /* Make pointer to the last record */ DestPtr->Area1 = Area1; /* Init the struct */ DestPtr->Area2 = Area2; ++ConnectCount; /* Add 1 to the valid list */ } /********************************** Remove a connection between two rooms Note: I can have MORE than one connection between rooms so it is VALID to have duplicate entries (1,6) & (1,6) **********************************/ void RemoveConnection(Word Area1,Word Area2) { Word i; connect_t *DestPtr; DestPtr = &areaconnect[0]; /* Init the scan pointer */ i = ConnectCount; /* Init the count */ if (!i) { return; } do { if (DestPtr->Area1 == Area1 && /* Match? */ DestPtr->Area2 == Area2) { --ConnectCount; /* Remove the count */ DestPtr[0] = areaconnect[ConnectCount]; /* Copy last to current */ break; /* I'm done! */ } ++DestPtr; /* Next entry to scan */ } while (--i); /* Should NEVER fall out! */ } /********************************** Recursive routine to properly set the areabyplayer array by using the contents of the areaconnect array. Scans outward from playerarea, marking all connected areas. **********************************/ void RecursiveConnect(Word areanumber) { Word i; Word j; connect_t *AreaPtr; areabyplayer[areanumber] = TRUE; /* Mark this spot (Prevent overflow) */ i = ConnectCount; /* Init index */ if (i) { /* No doors available? */ AreaPtr = &areaconnect[0]; /* Get a local pointer */ do { if (AreaPtr->Area1 == areanumber) { /* Am I in this pair? */ j = AreaPtr->Area2; /* Follow this path */ goto TryIt; } if (AreaPtr->Area2 == areanumber) { /* The other side? */ j = AreaPtr->Area1; /* Follow this side */ TryIt: if (!areabyplayer[j]) { /* Already been here? */ RecursiveConnect(j); /* Link it in... */ } } ++AreaPtr; /* Next entry */ } while (--i); /* All done? */ } } /********************************** Properly set the areabyplayer record **********************************/ void ConnectAreas(void) { memset(areabyplayer,0,sizeof(areabyplayer)); /* Zap the memory */ RecursiveConnect(MapPtr->areasoundnum[actors[0].areanumber]); /* Start here */ } /********************************** Start a door opening **********************************/ void OpenDoor(door_t *door) { if (door->action == DR_OPEN) { /* Already open? */ door->ticcount = 0; /* Reset open time (Keep open) */ } else { door->action = DR_OPENING; /* start it opening*/ } /* The door will be made passable when it is totally open */ } /********************************** Start a door closing **********************************/ void CloseDoor(door_t *door) { Word tile,tilex,tiley; Word *TilePtr; int delta; /* don't close on anything solid */ tilex = door->tilex; /* Get the current tile */ tiley = door->tiley; TilePtr = &tilemap[tiley][tilex]; /* Get pointer to tile map */ if (door->action != DR_OPENING) { /* In the middle of opening? */ /* don't close on an actor or bonus item */