diff --git a/id_sd.c b/id_sd.c index 4d881b1..d42ef0d 100644 --- a/id_sd.c +++ b/id_sd.c @@ -71,18 +71,19 @@ static byte *SoundBuffers[STARTMUSIC - STARTDIGISOUNDS]; globalsoundpos channelSoundPos[MIX_CHANNELS]; -// Global variables - boolean AdLibPresent, - SoundBlasterPresent,SBProPresent, - SoundPositioned; - SDMode SoundMode; - SMMode MusicMode; - SDSMode DigiMode; +/* Global variables */ +boolean AdLibPresent, + SoundBlasterPresent,SBProPresent, + SoundPositioned; +SDMode SoundMode; +SMMode MusicMode; +SDSMode DigiMode; + static byte **SoundTable; int DigiMap[LASTSOUND]; int DigiChannel[STARTMUSIC - STARTDIGISOUNDS]; -// Internal variables +/* Internal variables */ static boolean SD_Started; static boolean nextsoundpos; static soundnames SoundNumber; @@ -119,230 +120,241 @@ static longword sqHackTime; static void SDL_SoundFinished(void) { - SoundNumber = (soundnames)0; - SoundPriority = 0; + SoundNumber = (soundnames)0; + SoundPriority = 0; } -void -SD_StopDigitized(void) +void SD_StopDigitized(void) { - DigiPlaying = false; - DigiNumber = (soundnames) 0; - DigiPriority = 0; - SoundPositioned = false; - if ((DigiMode == sds_PC) && (SoundMode == sdm_PC)) - SDL_SoundFinished(); + DigiPlaying = false; + DigiNumber = (soundnames) 0; + DigiPriority = 0; + SoundPositioned = false; + if ((DigiMode == sds_PC) && (SoundMode == sdm_PC)) + SDL_SoundFinished(); - switch (DigiMode) - { - case sds_PC: - break; - case sds_SoundBlaster: - Mix_HaltChannel(-1); - break; - } + switch (DigiMode) + { + case sds_PC: + break; + case sds_SoundBlaster: + Mix_HaltChannel(-1); + break; + } } int SD_GetChannelForDigi(int which) { - if(DigiChannel[which] != -1) return DigiChannel[which]; + int channel; + if(DigiChannel[which] != -1) + return DigiChannel[which]; - int channel = Mix_GroupAvailable(1); - if(channel == -1) channel = Mix_GroupOldest(1); - if(channel == -1) // All sounds stopped in the meantime? - return Mix_GroupAvailable(1); - return channel; + channel = Mix_GroupAvailable(1); + if(channel == -1) + channel = Mix_GroupOldest(1); + + if(channel == -1) /* All sounds stopped in the meantime? */ + return Mix_GroupAvailable(1); + return channel; } void SD_SetPosition(int channel, int leftpos, int rightpos) { - if((leftpos < 0) || (leftpos > 15) || (rightpos < 0) || (rightpos > 15) - || ((leftpos == 15) && (rightpos == 15))) - Quit("SD_SetPosition: Illegal position"); + if((leftpos < 0) || (leftpos > 15) || (rightpos < 0) || (rightpos > 15) + || ((leftpos == 15) && (rightpos == 15))) + Quit("SD_SetPosition: Illegal position"); - switch (DigiMode) - { - case sds_SoundBlaster: - Mix_SetPanning(channel, ((15 - leftpos) << 4) + 15, - ((15 - rightpos) << 4) + 15); - break; - } + switch (DigiMode) + { + case sds_SoundBlaster: + Mix_SetPanning(channel, ((15 - leftpos) << 4) + 15, + ((15 - rightpos) << 4) + 15); + break; + } } Sint16 GetSample(float csample, byte *samples, int size) { - float s0=0, s1=0, s2=0; - int cursample = (int) csample; - float sf = csample - (float) cursample; + float val; + int32_t intval; + float s0=0, s1=0, s2=0; + int cursample = (int) csample; + float sf = csample - (float) cursample; - if(cursample-1 >= 0) s0 = (float) (samples[cursample-1] - 128); - s1 = (float) (samples[cursample] - 128); - if(cursample+1 < size) s2 = (float) (samples[cursample+1] - 128); + if(cursample-1 >= 0) + s0 = (float) (samples[cursample-1] - 128); - float val = s0*sf*(sf-1)/2 - s1*(sf*sf-1) + s2*(sf+1)*sf/2; - int32_t intval = (int32_t) (val * 256); - if(intval < -32768) intval = -32768; - else if(intval > 32767) intval = 32767; - return (Sint16) intval; + s1 = (float) (samples[cursample] - 128); + + if(cursample+1 < size) + s2 = (float) (samples[cursample+1] - 128); + + val = s0*sf*(sf-1)/2 - s1*(sf*sf-1) + s2*(sf+1)*sf/2; + intval = (int32_t) (val * 256); + + if(intval < -32768) + intval = -32768; + else if(intval > 32767) + intval = 32767; + return (Sint16) intval; } void SD_PrepareSound(int which) { unsigned i; - if(DigiList == NULL) - Quit("SD_PrepareSound(%i): DigiList not initialized!\n", which); + if(DigiList == NULL) + Quit("SD_PrepareSound(%i): DigiList not initialized!\n", which); - int page = DigiList[which].startpage; - int size = DigiList[which].length; + int page = DigiList[which].startpage; + int size = DigiList[which].length; - byte *origsamples = PM_GetSound(page); - if(origsamples + size >= PM_GetEnd()) - Quit("SD_PrepareSound(%i): Sound reaches out of page file!\n", which); + byte *origsamples = PM_GetSound(page); + if(origsamples + size >= PM_GetEnd()) + Quit("SD_PrepareSound(%i): Sound reaches out of page file!\n", which); - int destsamples = (int) ((float) size * (float) param_samplerate - / (float) ORIGSAMPLERATE); + int destsamples = (int) ((float) size * (float) param_samplerate + / (float) ORIGSAMPLERATE); - byte *wavebuffer = (byte *) malloc(sizeof(headchunk) + sizeof(wavechunk) - + destsamples * 2); // dest are 16-bit samples - if(wavebuffer == NULL) - Quit("Unable to allocate wave buffer for sound %i!\n", which); + byte *wavebuffer = (byte *) malloc(sizeof(headchunk) + sizeof(wavechunk) + + destsamples * 2); // dest are 16-bit samples + if(wavebuffer == NULL) + Quit("Unable to allocate wave buffer for sound %i!\n", which); - headchunk head = {{'R','I','F','F'}, 0, {'W','A','V','E'}, - {'f','m','t',' '}, 0x10, 0x0001, 1, param_samplerate, param_samplerate*2, 2, 16}; - wavechunk dhead = {{'d', 'a', 't', 'a'}, destsamples*2}; - head.filelenminus8 = sizeof(head) + destsamples*2; // (sizeof(dhead)-8 = 0) - memcpy(wavebuffer, &head, sizeof(head)); - memcpy(wavebuffer+sizeof(head), &dhead, sizeof(dhead)); + headchunk head = {{'R','I','F','F'}, 0, {'W','A','V','E'}, + {'f','m','t',' '}, 0x10, 0x0001, 1, param_samplerate, param_samplerate*2, 2, 16}; + wavechunk dhead = {{'d', 'a', 't', 'a'}, destsamples*2}; + head.filelenminus8 = sizeof(head) + destsamples*2; // (sizeof(dhead)-8 = 0) + memcpy(wavebuffer, &head, sizeof(head)); + memcpy(wavebuffer+sizeof(head), &dhead, sizeof(dhead)); - // alignment is correct, as wavebuffer comes from malloc - // and sizeof(headchunk) % 4 == 0 and sizeof(wavechunk) % 4 == 0 - Sint16 *newsamples = (Sint16 *)(void *) (wavebuffer + sizeof(headchunk) - + sizeof(wavechunk)); - float cursample = 0.F; - float samplestep = (float) ORIGSAMPLERATE / (float) param_samplerate; - for(i=0; i= NumDigi) - Quit("SD_PlayDigitized: bad sound number %i", which); + if (which >= NumDigi) + Quit("SD_PlayDigitized: bad sound number %i", which); - int channel = SD_GetChannelForDigi(which); - SD_SetPosition(channel, leftpos,rightpos); + int channel = SD_GetChannelForDigi(which); + SD_SetPosition(channel, leftpos,rightpos); - DigiPlaying = true; + DigiPlaying = true; - Mix_Chunk *sample = SoundChunks[which]; - if(sample == NULL) - { - printf("SoundChunks[%i] is NULL!\n", which); - return 0; - } + Mix_Chunk *sample = SoundChunks[which]; + if(sample == NULL) + { + printf("SoundChunks[%i] is NULL!\n", which); + return 0; + } - if(Mix_PlayChannel(channel, sample, 0) == -1) - { - printf("Unable to play sound: %s\n", Mix_GetError()); - return 0; - } + if(Mix_PlayChannel(channel, sample, 0) == -1) + { + printf("Unable to play sound: %s\n", Mix_GetError()); + return 0; + } - return channel; + return channel; } void SD_ChannelFinished(int channel) { - channelSoundPos[channel].valid = 0; + channelSoundPos[channel].valid = 0; } -void -SD_SetDigiDevice(SDSMode mode) +void SD_SetDigiDevice(SDSMode mode) { - boolean devicenotpresent; + boolean devicenotpresent; - if (mode == DigiMode) - return; + if (mode == DigiMode) + return; - SD_StopDigitized(); + SD_StopDigitized(); - devicenotpresent = false; - switch (mode) - { - case sds_SoundBlaster: - if (!SoundBlasterPresent) - devicenotpresent = true; - break; - } + devicenotpresent = false; + switch (mode) + { + case sds_SoundBlaster: + if (!SoundBlasterPresent) + devicenotpresent = true; + break; + } - if (!devicenotpresent) - { - DigiMode = mode; - } + if (!devicenotpresent) + DigiMode = mode; } void SDL_SetupDigi(void) { - // Correct padding enforced by PM_Startup() - word *soundInfoPage = (word *) (void *) PM_GetPage(ChunksInFile-1); - NumDigi = (word) PM_GetPageSize(ChunksInFile - 1) / 4; + /* Correct padding enforced by PM_Startup() */ + int i; + word *soundInfoPage = (word *) (void *) PM_GetPage(ChunksInFile-1); + NumDigi = (word) PM_GetPageSize(ChunksInFile - 1) / 4; - DigiList = (digiinfo *) malloc(NumDigi * sizeof(digiinfo)); - int i; - for(i = 0; i < NumDigi; i++) - { - unsigned page; - // Calculate the size of the digi from the sizes of the pages between - // the start page and the start page of the next sound + DigiList = (digiinfo *) malloc(NumDigi * sizeof(digiinfo)); - DigiList[i].startpage = soundInfoPage[i * 2]; - if((int) DigiList[i].startpage >= ChunksInFile - 1) - { - NumDigi = i; - break; - } + for(i = 0; i < NumDigi; i++) + { + unsigned page; + // Calculate the size of the digi from the sizes of the pages between + // the start page and the start page of the next sound - int lastPage; - if(i < NumDigi - 1) - { - lastPage = soundInfoPage[i * 2 + 2]; - if(lastPage == 0 || lastPage + PMSoundStart > ChunksInFile - 1) lastPage = ChunksInFile - 1; - else lastPage += PMSoundStart; - } - else lastPage = ChunksInFile - 1; + DigiList[i].startpage = soundInfoPage[i * 2]; + if((int) DigiList[i].startpage >= ChunksInFile - 1) + { + NumDigi = i; + break; + } - int size = 0; - for(page = PMSoundStart + DigiList[i].startpage; page < lastPage; page++) - size += PM_GetPageSize(page); + int lastPage; + if(i < NumDigi - 1) + { + lastPage = soundInfoPage[i * 2 + 2]; + if(lastPage == 0 || lastPage + PMSoundStart > ChunksInFile - 1) lastPage = ChunksInFile - 1; + else lastPage += PMSoundStart; + } + else lastPage = ChunksInFile - 1; - // Don't include padding of sound info page, if padding was added - if(lastPage == ChunksInFile - 1 && PMSoundInfoPagePadded) size--; + int size = 0; + for(page = PMSoundStart + DigiList[i].startpage; page < lastPage; page++) + size += PM_GetPageSize(page); - // Patch lower 16-bit of size with size from sound info page. - // The original VSWAP contains padding which is included in the page size, - // but not included in the 16-bit size. So we use the more precise value. - if((size & 0xffff0000) != 0 && (size & 0xffff) < soundInfoPage[i * 2 + 1]) - size -= 0x10000; - size = (size & 0xffff0000) | soundInfoPage[i * 2 + 1]; + /* Don't include padding of sound info page, if padding was added */ + if(lastPage == ChunksInFile - 1 && PMSoundInfoPagePadded) + size--; - DigiList[i].length = size; - } + // Patch lower 16-bit of size with size from sound info page. + // The original VSWAP contains padding which is included in the page size, + // but not included in the 16-bit size. So we use the more precise value. + if((size & 0xffff0000) != 0 && (size & 0xffff) < soundInfoPage[i * 2 + 1]) + size -= 0x10000; + size = (size & 0xffff0000) | soundInfoPage[i * 2 + 1]; - for(i = 0; i < LASTSOUND; i++) - { - DigiMap[i] = -1; - DigiChannel[i] = -1; - } + DigiList[i].length = size; + } + + for(i = 0; i < LASTSOUND; i++) + { + DigiMap[i] = -1; + DigiChannel[i] = -1; + } } // AdLib Code @@ -353,32 +365,28 @@ SDL_SetupDigi(void) // AdLib card // /////////////////////////////////////////////////////////////////////////// -static void -SDL_ALStopSound(void) +static void SDL_ALStopSound(void) { - alSound = 0; - YM3812Write(0, alFreqH + 0, 0); + alSound = 0; + YM3812Write(0, alFreqH + 0, 0); } -static void -SDL_AlSetFXInst(Instrument *inst) +static void SDL_AlSetFXInst(Instrument *inst) { - byte c,m; + byte m = 0; // modulator cell for channel 0 + byte c = 3; // carrier cell for channel 0 + YM3812Write(0, m + alChar,inst->mChar); + YM3812Write(0, m + alScale,inst->mScale); + YM3812Write(0, m + alAttack,inst->mAttack); + YM3812Write(0, m + alSus,inst->mSus); + YM3812Write(0, m + alWave,inst->mWave); + YM3812Write(0, c + alChar,inst->cChar); + YM3812Write(0, c + alScale,inst->cScale); + YM3812Write(0, c + alAttack,inst->cAttack); + YM3812Write(0, c + alSus,inst->cSus); + YM3812Write(0, c + alWave,inst->cWave); - m = 0; // modulator cell for channel 0 - c = 3; // carrier cell for channel 0 - YM3812Write(0, m + alChar,inst->mChar); - YM3812Write(0, m + alScale,inst->mScale); - YM3812Write(0, m + alAttack,inst->mAttack); - YM3812Write(0, m + alSus,inst->mSus); - YM3812Write(0, m + alWave,inst->mWave); - YM3812Write(0, c + alChar,inst->cChar); - YM3812Write(0, c + alScale,inst->cScale); - YM3812Write(0, c + alAttack,inst->cAttack); - YM3812Write(0, c + alSus,inst->cSus); - YM3812Write(0, c + alWave,inst->cWave); - - YM3812Write(0, alFeedCon,0); + YM3812Write(0, alFeedCon,0); } /////////////////////////////////////////////////////////////////////////// @@ -386,26 +394,25 @@ SDL_AlSetFXInst(Instrument *inst) // SDL_ALPlaySound() - Plays the specified sound on the AdLib card // /////////////////////////////////////////////////////////////////////////// -static void -SDL_ALPlaySound(AdLibSound *sound) +static void SDL_ALPlaySound(AdLibSound *sound) { - Instrument *inst; - byte *data; + Instrument *inst; + byte *data; - SDL_ALStopSound(); + SDL_ALStopSound(); - alLengthLeft = sound->common.length; - data = sound->data; - alBlock = ((sound->block & 7) << 2) | 0x20; - inst = &sound->inst; + alLengthLeft = sound->common.length; + data = sound->data; + alBlock = ((sound->block & 7) << 2) | 0x20; + inst = &sound->inst; - if (!(inst->mSus | inst->cSus)) - { - Quit("SDL_ALPlaySound() - Bad instrument"); - } + if (!(inst->mSus | inst->cSus)) + { + Quit("SDL_ALPlaySound() - Bad instrument"); + } - SDL_AlSetFXInst(inst); - alSound = (byte *)data; + SDL_AlSetFXInst(inst); + alSound = (byte *)data; } /////////////////////////////////////////////////////////////////////////// @@ -413,13 +420,12 @@ SDL_ALPlaySound(AdLibSound *sound) // SDL_ShutAL() - Shuts down the AdLib card for sound effects // /////////////////////////////////////////////////////////////////////////// -static void -SDL_ShutAL(void) +static void SDL_ShutAL(void) { - alSound = 0; - YM3812Write(0, alEffects,0); - YM3812Write(0, alFreqH + 0,0); - SDL_AlSetFXInst(&alZeroInst); + alSound = 0; + YM3812Write(0, alEffects,0); + YM3812Write(0, alFreqH + 0,0); + SDL_AlSetFXInst(&alZeroInst); } /////////////////////////////////////////////////////////////////////////// @@ -427,14 +433,13 @@ SDL_ShutAL(void) // SDL_CleanAL() - Totally shuts down the AdLib card // /////////////////////////////////////////////////////////////////////////// -static void -SDL_CleanAL(void) +static void SDL_CleanAL(void) { - int i; + int i; - YM3812Write(0, alEffects,0); - for (i = 1; i < 0xf5; i++) - YM3812Write(0, i, 0); + YM3812Write(0, alEffects,0); + for (i = 1; i < 0xf5; i++) + YM3812Write(0, i, 0); } /////////////////////////////////////////////////////////////////////////// @@ -442,11 +447,10 @@ SDL_CleanAL(void) // SDL_StartAL() - Starts up the AdLib card for sound effects // /////////////////////////////////////////////////////////////////////////// -static void -SDL_StartAL(void) +static void SDL_StartAL(void) { - YM3812Write(0, alEffects, 0); - SDL_AlSetFXInst(&alZeroInst); + YM3812Write(0, alEffects, 0); + SDL_AlSetFXInst(&alZeroInst); } /////////////////////////////////////////////////////////////////////////// @@ -455,17 +459,15 @@ SDL_StartAL(void) // emulating an AdLib) present // /////////////////////////////////////////////////////////////////////////// -static boolean -SDL_DetectAdLib(void) +static boolean SDL_DetectAdLib(void) { unsigned i; - for (i = 1; i <= 0xf5; i++) // Zero all the registers - YM3812Write(0, i, 0); + for (i = 1; i <= 0xf5; i++) // Zero all the registers + YM3812Write(0, i, 0); - YM3812Write(0, 1, 0x20); // Set WSE=1 -// YM3812Write(0, 8, 0); // Set CSM=0 & SEL=0 + YM3812Write(0, 1, 0x20); // Set WSE=1 - return true; + return true; } //////////////////////////////////////////////////////////////////////////// @@ -473,19 +475,20 @@ SDL_DetectAdLib(void) // SDL_ShutDevice() - turns off whatever device was being used for sound fx // //////////////////////////////////////////////////////////////////////////// -static void -SDL_ShutDevice(void) +static void SDL_ShutDevice(void) { - switch (SoundMode) - { - case sdm_PC: -// SDL_ShutPC(); - break; - case sdm_AdLib: - SDL_ShutAL(); - break; - } - SoundMode = sdm_Off; + switch (SoundMode) + { + case sdm_PC: +#if 0 + SDL_ShutPC(); +#endif + break; + case sdm_AdLib: + SDL_ShutAL(); + break; + } + SoundMode = sdm_Off; } /////////////////////////////////////////////////////////////////////////// @@ -493,11 +496,10 @@ SDL_ShutDevice(void) // SDL_CleanDevice() - totally shuts down all sound devices // /////////////////////////////////////////////////////////////////////////// -static void -SDL_CleanDevice(void) +static void SDL_CleanDevice(void) { - if ((SoundMode == sdm_AdLib) || (MusicMode == smm_AdLib)) - SDL_CleanAL(); + if ((SoundMode == sdm_AdLib) || (MusicMode == smm_AdLib)) + SDL_CleanAL(); } /////////////////////////////////////////////////////////////////////////// @@ -505,17 +507,16 @@ SDL_CleanDevice(void) // SDL_StartDevice() - turns on whatever device is to be used for sound fx // /////////////////////////////////////////////////////////////////////////// -static void -SDL_StartDevice(void) +static void SDL_StartDevice(void) { - switch (SoundMode) - { - case sdm_AdLib: - SDL_StartAL(); - break; - } - SoundNumber = (soundnames) 0; - SoundPriority = 0; + switch (SoundMode) + { + case sdm_AdLib: + SDL_StartAL(); + break; + } + SoundNumber = (soundnames) 0; + SoundPriority = 0; } // Public routines @@ -525,46 +526,45 @@ SDL_StartDevice(void) // SD_SetSoundMode() - Sets which sound hardware to use for sound effects // /////////////////////////////////////////////////////////////////////////// -boolean -SD_SetSoundMode(SDMode mode) +boolean SD_SetSoundMode(SDMode mode) { - boolean result = false; - word tableoffset; + boolean result = false; + word tableoffset; - SD_StopSound(); + SD_StopSound(); - if ((mode == sdm_AdLib) && !AdLibPresent) - mode = sdm_PC; + if ((mode == sdm_AdLib) && !AdLibPresent) + mode = sdm_PC; - switch (mode) - { - case sdm_Off: - tableoffset = STARTADLIBSOUNDS; + switch (mode) + { + case sdm_Off: + tableoffset = STARTADLIBSOUNDS; + result = true; + break; + case sdm_PC: + tableoffset = STARTPCSOUNDS; + result = true; + break; + case sdm_AdLib: + tableoffset = STARTADLIBSOUNDS; + if (AdLibPresent) result = true; - break; - case sdm_PC: - tableoffset = STARTPCSOUNDS; - result = true; - break; - case sdm_AdLib: - tableoffset = STARTADLIBSOUNDS; - if (AdLibPresent) - result = true; - break; - default: - Quit("SD_SetSoundMode: Invalid sound mode %i", mode); - return false; - } - SoundTable = &audiosegs[tableoffset]; + break; + default: + Quit("SD_SetSoundMode: Invalid sound mode %i", mode); + return false; + } + SoundTable = &audiosegs[tableoffset]; - if (result && (mode != SoundMode)) - { - SDL_ShutDevice(); - SoundMode = mode; - SDL_StartDevice(); - } + if (result && (mode != SoundMode)) + { + SDL_ShutDevice(); + SoundMode = mode; + SDL_StartDevice(); + } - return(result); + return(result); } /////////////////////////////////////////////////////////////////////////// @@ -572,30 +572,29 @@ SD_SetSoundMode(SDMode mode) // SD_SetMusicMode() - sets the device to use for background music // /////////////////////////////////////////////////////////////////////////// -boolean -SD_SetMusicMode(SMMode mode) +boolean SD_SetMusicMode(SMMode mode) { - boolean result = false; + boolean result = false; - SD_FadeOutMusic(); - while (SD_MusicPlaying()) - rarch_sleep(5); + SD_FadeOutMusic(); + while (SD_MusicPlaying()) + rarch_sleep(5); - switch (mode) - { - case smm_Off: + switch (mode) + { + case smm_Off: + result = true; + break; + case smm_AdLib: + if (AdLibPresent) result = true; - break; - case smm_AdLib: - if (AdLibPresent) - result = true; - break; - } + break; + } - if (result) - MusicMode = mode; + if (result) + MusicMode = mode; - return(result); + return(result); } int numreadysamples = 0; @@ -607,77 +606,77 @@ int samplesPerMusicTick; void SDL_IMFMusicPlayer(void *udata, Uint8 *stream, int len) { - int stereolen = len>>1; - int sampleslen = stereolen>>1; - INT16 *stream16 = (INT16 *) (void *) stream; // expect correct alignment + int stereolen = len>>1; + int sampleslen = stereolen>>1; + INT16 *stream16 = (INT16 *) (void *) stream; // expect correct alignment - while(1) - { - if(numreadysamples) - { - if(numreadysamples alTimeCount) break; - sqHackTime = alTimeCount + *(sqHackPtr+1); - YM3812Write(0, *(byte *) sqHackPtr, *(((byte *) sqHackPtr)+1)); - sqHackPtr += 2; - sqHackLen -= 4; - } - while(sqHackLen>0); - alTimeCount++; - if(!sqHackLen) - { - sqHackPtr = sqHack; - sqHackLen = sqHackSeqLen; - sqHackTime = 0; - alTimeCount = 0; - } - } - numreadysamples = samplesPerMusicTick; - } + } + } + if(sqActive) + { + do + { + if(sqHackTime > alTimeCount) break; + sqHackTime = alTimeCount + *(sqHackPtr+1); + YM3812Write(0, *(byte *) sqHackPtr, *(((byte *) sqHackPtr)+1)); + sqHackPtr += 2; + sqHackLen -= 4; + } + while(sqHackLen>0); + alTimeCount++; + if(!sqHackLen) + { + sqHackPtr = sqHack; + sqHackLen = sqHackSeqLen; + sqHackTime = 0; + alTimeCount = 0; + } + } + numreadysamples = samplesPerMusicTick; + } } /////////////////////////////////////////////////////////////////////////// @@ -686,51 +685,49 @@ void SDL_IMFMusicPlayer(void *udata, Uint8 *stream, int len) // Detects all additional sound hardware and installs my ISR // /////////////////////////////////////////////////////////////////////////// -void -SD_Startup(void) +void SD_Startup(void) { - int i; + int i; - if (SD_Started) - return; + if (SD_Started) + return; - if(Mix_OpenAudio(param_samplerate, AUDIO_S16, 2, param_audiobuffer)) - { - printf("Unable to open audio: %s\n", Mix_GetError()); - return; - } + if(Mix_OpenAudio(param_samplerate, AUDIO_S16, 2, param_audiobuffer)) + { + printf("Unable to open audio: %s\n", Mix_GetError()); + return; + } - Mix_ReserveChannels(2); // reserve player and boss weapon channels - Mix_GroupChannels(2, MIX_CHANNELS-1, 1); // group remaining channels + Mix_ReserveChannels(2); // reserve player and boss weapon channels + Mix_GroupChannels(2, MIX_CHANNELS-1, 1); // group remaining channels - // Init music + // Init music - samplesPerMusicTick = param_samplerate / 700; // SDL_t0FastAsmService played at 700Hz + samplesPerMusicTick = param_samplerate / 700; // SDL_t0FastAsmService played at 700Hz - if(YM3812Init(1,3579545,param_samplerate)) - { - printf("Unable to create virtual OPL!!\n"); - } + if(YM3812Init(1,3579545,param_samplerate)) + { + printf("Unable to create virtual OPL!!\n"); + } - for(i=1;i<0xf6;i++) - YM3812Write(0,i,0); + for(i=1;i<0xf6;i++) + YM3812Write(0,i,0); - YM3812Write(0,1,0x20); // Set WSE=1 -// YM3812Write(0,8,0); // Set CSM=0 & SEL=0 // already set in for statement + YM3812Write(0,1,0x20); // Set WSE=1 - Mix_HookMusic(SDL_IMFMusicPlayer, 0); - Mix_ChannelFinished(SD_ChannelFinished); - AdLibPresent = true; - SoundBlasterPresent = true; + Mix_HookMusic(SDL_IMFMusicPlayer, 0); + Mix_ChannelFinished(SD_ChannelFinished); + AdLibPresent = true; + SoundBlasterPresent = true; - alTimeCount = 0; + alTimeCount = 0; - SD_SetSoundMode(sdm_Off); - SD_SetMusicMode(smm_Off); + SD_SetSoundMode(sdm_Off); + SD_SetMusicMode(smm_Off); - SDL_SetupDigi(); + SDL_SetupDigi(); - SD_Started = true; + SD_Started = true; } /////////////////////////////////////////////////////////////////////////// @@ -739,25 +736,26 @@ SD_Startup(void) // Removes sound ISR and turns off whatever sound hardware was active // /////////////////////////////////////////////////////////////////////////// -void -SD_Shutdown(void) +void SD_Shutdown(void) { unsigned i; - if (!SD_Started) - return; + if (!SD_Started) + return; - SD_MusicOff(); - SD_StopSound(); + SD_MusicOff(); + SD_StopSound(); - for(i = 0; i < STARTMUSIC - STARTDIGISOUNDS; i++) - { - if(SoundChunks[i]) Mix_FreeChunk(SoundChunks[i]); - if(SoundBuffers[i]) free(SoundBuffers[i]); - } + for(i = 0; i < STARTMUSIC - STARTDIGISOUNDS; i++) + { + if(SoundChunks[i]) + Mix_FreeChunk(SoundChunks[i]); + if(SoundBuffers[i]) + free(SoundBuffers[i]); + } - free(DigiList); + free(DigiList); - SD_Started = false; + SD_Started = false; } /////////////////////////////////////////////////////////////////////////// @@ -766,12 +764,11 @@ SD_Shutdown(void) // sound to be played. Each channel ranges from 0 to 15. // /////////////////////////////////////////////////////////////////////////// -void -SD_PositionSound(int leftvol,int rightvol) +void SD_PositionSound(int leftvol,int rightvol) { - LeftPosition = leftvol; - RightPosition = rightvol; - nextsoundpos = true; + LeftPosition = leftvol; + RightPosition = rightvol; + nextsoundpos = true; } /////////////////////////////////////////////////////////////////////////// @@ -779,70 +776,65 @@ SD_PositionSound(int leftvol,int rightvol) // SD_PlaySound() - plays the specified sound on the appropriate hardware // /////////////////////////////////////////////////////////////////////////// -boolean -SD_PlaySound(soundnames sound) +boolean SD_PlaySound(soundnames sound) { - boolean ispos; - SoundCommon *s; - int lp,rp; + SoundCommon *s; + int lp = LeftPosition; + int rp = RightPosition; + LeftPosition = 0; + RightPosition = 0; + boolean ispos = nextsoundpos; + nextsoundpos = false; - lp = LeftPosition; - rp = RightPosition; - LeftPosition = 0; - RightPosition = 0; + if (sound == -1 || (DigiMode == sds_Off && SoundMode == sdm_Off)) + return 0; - ispos = nextsoundpos; - nextsoundpos = false; + s = (SoundCommon *) SoundTable[sound]; - if (sound == -1 || (DigiMode == sds_Off && SoundMode == sdm_Off)) - return 0; + if ((SoundMode != sdm_Off) && !s) + Quit("SD_PlaySound() - Uncached sound"); - s = (SoundCommon *) SoundTable[sound]; + if ((DigiMode != sds_Off) && (DigiMap[sound] != -1)) + { + if ((DigiMode == sds_PC) && (SoundMode == sdm_PC)) + { + return 0; + } + else + { - if ((SoundMode != sdm_Off) && !s) - Quit("SD_PlaySound() - Uncached sound"); + int channel = SD_PlayDigitized(DigiMap[sound], lp, rp); + SoundPositioned = ispos; + DigiNumber = sound; + DigiPriority = s->priority; + return channel + 1; + } - if ((DigiMode != sds_Off) && (DigiMap[sound] != -1)) - { - if ((DigiMode == sds_PC) && (SoundMode == sdm_PC)) - { - return 0; - } - else - { + return(true); + } - int channel = SD_PlayDigitized(DigiMap[sound], lp, rp); - SoundPositioned = ispos; - DigiNumber = sound; - DigiPriority = s->priority; - return channel + 1; - } + if (SoundMode == sdm_Off) + return 0; - return(true); - } + if (!s->length) + Quit("SD_PlaySound() - Zero length sound"); + if (s->priority < SoundPriority) + return 0; - if (SoundMode == sdm_Off) - return 0; + switch (SoundMode) + { + case sdm_PC: + // SDL_PCPlaySound((PCSound *)s); + break; + case sdm_AdLib: + SDL_ALPlaySound((AdLibSound *)s); + break; + } - if (!s->length) - Quit("SD_PlaySound() - Zero length sound"); - if (s->priority < SoundPriority) - return 0; + SoundNumber = sound; + SoundPriority = s->priority; - switch (SoundMode) - { - case sdm_PC: -// SDL_PCPlaySound((PCSound *)s); - break; - case sdm_AdLib: - SDL_ALPlaySound((AdLibSound *)s); - break; - } - - SoundNumber = sound; - SoundPriority = s->priority; - - return 0; + return 0; } /////////////////////////////////////////////////////////////////////////// @@ -854,22 +846,21 @@ SD_PlaySound(soundnames sound) word SD_SoundPlaying(void) { - boolean result = false; + boolean result = false; - switch (SoundMode) - { - case sdm_PC: - result = pcSound? true : false; - break; - case sdm_AdLib: - result = alSound? true : false; - break; - } + switch (SoundMode) + { + case sdm_PC: + result = pcSound? true : false; + break; + case sdm_AdLib: + result = alSound? true : false; + break; + } - if (result) - return(SoundNumber); - else - return(false); + if (result) + return(SoundNumber); + return(false); } /////////////////////////////////////////////////////////////////////////// @@ -880,22 +871,24 @@ SD_SoundPlaying(void) void SD_StopSound(void) { - if (DigiPlaying) - SD_StopDigitized(); + if (DigiPlaying) + SD_StopDigitized(); - switch (SoundMode) - { - case sdm_PC: -// SDL_PCStopSound(); - break; - case sdm_AdLib: - SDL_ALStopSound(); - break; - } + switch (SoundMode) + { + case sdm_PC: +#if 0 + SDL_PCStopSound(); +#endif + break; + case sdm_AdLib: + SDL_ALStopSound(); + break; + } - SoundPositioned = false; + SoundPositioned = false; - SDL_SoundFinished(); + SDL_SoundFinished(); } /////////////////////////////////////////////////////////////////////////// @@ -906,8 +899,8 @@ SD_StopSound(void) void SD_WaitSoundDone(void) { - while (SD_SoundPlaying()) - rarch_sleep(5); + while (SD_SoundPlaying()) + rarch_sleep(5); } /////////////////////////////////////////////////////////////////////////// @@ -930,19 +923,19 @@ SD_MusicOn(void) int SD_MusicOff(void) { - word i; + word i; - sqActive = false; - switch (MusicMode) - { - case smm_AdLib: - YM3812Write(0, alEffects, 0); - for (i = 0;i < sqMaxTracks;i++) - YM3812Write(0, alFreqH + i + 1, 0); - break; - } + sqActive = false; + switch (MusicMode) + { + case smm_AdLib: + YM3812Write(0, alEffects, 0); + for (i = 0;i < sqMaxTracks;i++) + YM3812Write(0, alFreqH + i + 1, 0); + break; + } - return (int) (sqHackPtr-sqHack); + return (int) (sqHackPtr-sqHack); } /////////////////////////////////////////////////////////////////////////// @@ -953,59 +946,59 @@ SD_MusicOff(void) void SD_StartMusic(int chunk) { - SD_MusicOff(); + SD_MusicOff(); - if (MusicMode == smm_AdLib) - { - int32_t chunkLen = CA_CacheAudioChunk(chunk); - sqHack = (word *)(void *) audiosegs[chunk]; // alignment is correct - if(*sqHack == 0) sqHackLen = sqHackSeqLen = chunkLen; - else sqHackLen = sqHackSeqLen = *sqHack++; - sqHackPtr = sqHack; - sqHackTime = 0; - alTimeCount = 0; - SD_MusicOn(); - } + if (MusicMode == smm_AdLib) + { + int32_t chunkLen = CA_CacheAudioChunk(chunk); + sqHack = (word *)(void *) audiosegs[chunk]; // alignment is correct + if(*sqHack == 0) sqHackLen = sqHackSeqLen = chunkLen; + else sqHackLen = sqHackSeqLen = *sqHack++; + sqHackPtr = sqHack; + sqHackTime = 0; + alTimeCount = 0; + SD_MusicOn(); + } } void SD_ContinueMusic(int chunk, int startoffs) { - SD_MusicOff(); + SD_MusicOff(); - if (MusicMode == smm_AdLib) - { - unsigned i; - int32_t chunkLen = CA_CacheAudioChunk(chunk); - sqHack = (word *)(void *) audiosegs[chunk]; // alignment is correct - if(*sqHack == 0) sqHackLen = sqHackSeqLen = chunkLen; - else sqHackLen = sqHackSeqLen = *sqHack++; - sqHackPtr = sqHack; + if (MusicMode == smm_AdLib) + { + unsigned i; + int32_t chunkLen = CA_CacheAudioChunk(chunk); + sqHack = (word *)(void *) audiosegs[chunk]; // alignment is correct + if(*sqHack == 0) sqHackLen = sqHackSeqLen = chunkLen; + else sqHackLen = sqHackSeqLen = *sqHack++; + sqHackPtr = sqHack; - if(startoffs >= sqHackLen) - { - Quit("SD_StartMusic: Illegal startoffs provided!"); - } + if(startoffs >= sqHackLen) + { + Quit("SD_StartMusic: Illegal startoffs provided!"); + } - // fast forward to correct position - // (needed to reconstruct the instruments) + // fast forward to correct position + // (needed to reconstruct the instruments) - for(i = 0; i < startoffs; i += 2) - { - byte reg = *(byte *)sqHackPtr; - byte val = *(((byte *)sqHackPtr) + 1); - if(reg >= 0xb1 && reg <= 0xb8) val &= 0xdf; // disable play note flag - else if(reg == 0xbd) val &= 0xe0; // disable drum flags + for(i = 0; i < startoffs; i += 2) + { + byte reg = *(byte *)sqHackPtr; + byte val = *(((byte *)sqHackPtr) + 1); + if(reg >= 0xb1 && reg <= 0xb8) val &= 0xdf; // disable play note flag + else if(reg == 0xbd) val &= 0xe0; // disable drum flags - YM3812Write(0, reg,val); - sqHackPtr += 2; - sqHackLen -= 4; - } - sqHackTime = 0; - alTimeCount = 0; + YM3812Write(0, reg,val); + sqHackPtr += 2; + sqHackLen -= 4; + } + sqHackTime = 0; + alTimeCount = 0; - SD_MusicOn(); - } + SD_MusicOn(); + } } /////////////////////////////////////////////////////////////////////////// @@ -1017,13 +1010,13 @@ SD_ContinueMusic(int chunk, int startoffs) void SD_FadeOutMusic(void) { - switch (MusicMode) - { - case smm_AdLib: - // DEBUG - quick hack to turn the music off - SD_MusicOff(); - break; - } + switch (MusicMode) + { + case smm_AdLib: + // DEBUG - quick hack to turn the music off + SD_MusicOff(); + break; + } } /////////////////////////////////////////////////////////////////////////// @@ -1032,20 +1025,19 @@ SD_FadeOutMusic(void) // not // /////////////////////////////////////////////////////////////////////////// -boolean -SD_MusicPlaying(void) +boolean SD_MusicPlaying(void) { - boolean result; + boolean result; - switch (MusicMode) - { - case smm_AdLib: - result = sqActive; - break; - default: - result = false; - break; - } + switch (MusicMode) + { + case smm_AdLib: + result = sqActive; + break; + default: + result = false; + break; + } - return(result); + return(result); } diff --git a/id_us_1.c b/id_us_1.c index 8e8fd38..0ec73ce 100644 --- a/id_us_1.c +++ b/id_us_1.c @@ -82,14 +82,14 @@ static byte rndtable[] = { // US_Startup() - Starts the User Mgr // /////////////////////////////////////////////////////////////////////////// -void US_Startup() +void US_Startup(void) { - if (US_Started) - return; + if (US_Started) + return; - US_InitRndT(true); // Initialize the random number generator + US_InitRndT(true); // Initialize the random number generator - US_Started = true; + US_Started = true; } @@ -98,13 +98,12 @@ void US_Startup() // US_Shutdown() - Shuts down the User Mgr // /////////////////////////////////////////////////////////////////////////// -void -US_Shutdown(void) +void US_Shutdown(void) { - if (!US_Started) - return; + if (!US_Started) + return; - US_Started = false; + US_Started = false; } // Window/Printing routines @@ -130,40 +129,38 @@ US_SetPrintRoutines(void (*measure)(const char *,word *,word *), // supported. // /////////////////////////////////////////////////////////////////////////// -void -US_Print(const char *sorg) +void US_Print(const char *sorg) { - char c; - char *sstart = strdup(sorg); - char *s = sstart; - char *se; - word w,h; + word w,h; + char c, *se; + char *sstart = strdup(sorg); + char *s = sstart; - while (*s) - { - se = s; - while ((c = *se)!=0 && (c != '\n')) - se++; - *se = '\0'; + while (*s) + { + se = s; + while ((c = *se)!=0 && (c != '\n')) + se++; + *se = '\0'; - USL_MeasureString(s,&w,&h); - px = PrintX; - py = PrintY; - USL_DrawString(s); + USL_MeasureString(s,&w,&h); + px = PrintX; + py = PrintY; + USL_DrawString(s); - s = se; - if (c) - { - *se = c; - s++; + s = se; + if (c) + { + *se = c; + s++; - PrintX = WindowX; - PrintY += h; - } - else - PrintX += w; - } - free(sstart); + PrintX = WindowX; + PrintY += h; + } + else + PrintX += w; + } + free(sstart); } /////////////////////////////////////////////////////////////////////////// @@ -171,13 +168,12 @@ US_Print(const char *sorg) // US_PrintUnsigned() - Prints an unsigned long // /////////////////////////////////////////////////////////////////////////// -void -US_PrintUnsigned(longword n) +void US_PrintUnsigned(longword n) { - char buffer[32]; - sprintf(buffer, "%lu", n); + char buffer[32]; + sprintf(buffer, "%lu", n); - US_Print(buffer); + US_Print(buffer); } /////////////////////////////////////////////////////////////////////////// @@ -185,12 +181,11 @@ US_PrintUnsigned(longword n) // US_PrintSigned() - Prints a signed long // /////////////////////////////////////////////////////////////////////////// -void -US_PrintSigned(int32_t n) +void US_PrintSigned(int32_t n) { - char buffer[32]; + char buffer[32]; - US_Print(ltoa(n,buffer,10)); + US_Print(ltoa(n,buffer,10)); } /////////////////////////////////////////////////////////////////////////// @@ -201,16 +196,15 @@ US_PrintSigned(int32_t n) void USL_PrintInCenter(const char *s,Rect r) { - word w,h, - rw,rh; + word w,h, rw,rh; - USL_MeasureString(s,&w,&h); - rw = r.lr.x - r.ul.x; - rh = r.lr.y - r.ul.y; + USL_MeasureString(s,&w,&h); + rw = r.lr.x - r.ul.x; + rh = r.lr.y - r.ul.y; - px = r.ul.x + ((rw - w) / 2); - py = r.ul.y + ((rh - h) / 2); - USL_DrawString(s); + px = r.ul.x + ((rw - w) / 2); + py = r.ul.y + ((rh - h) / 2); + USL_DrawString(s); } /////////////////////////////////////////////////////////////////////////// @@ -218,17 +212,16 @@ USL_PrintInCenter(const char *s,Rect r) // US_PrintCentered() - Prints a string centered in the current window. // /////////////////////////////////////////////////////////////////////////// -void -US_PrintCentered(const char *s) +void US_PrintCentered(const char *s) { - Rect r; + Rect r; - r.ul.x = WindowX; - r.ul.y = WindowY; - r.lr.x = r.ul.x + WindowW; - r.lr.y = r.ul.y + WindowH; + r.ul.x = WindowX; + r.ul.y = WindowY; + r.lr.x = r.ul.x + WindowW; + r.lr.y = r.ul.y + WindowH; - USL_PrintInCenter(s,r); + USL_PrintInCenter(s,r); } /////////////////////////////////////////////////////////////////////////// @@ -237,19 +230,18 @@ US_PrintCentered(const char *s) // advances to the next line. Newlines are not supported. // /////////////////////////////////////////////////////////////////////////// -void -US_CPrintLine(const char *s) +void US_CPrintLine(const char *s) { - word w,h; + word w,h; - USL_MeasureString(s,&w,&h); + USL_MeasureString(s,&w,&h); - if (w > WindowW) - Quit("US_CPrintLine() - String exceeds width"); - px = WindowX + ((WindowW - w) / 2); - py = PrintY; - USL_DrawString(s); - PrintY += h; + if (w > WindowW) + Quit("US_CPrintLine() - String exceeds width"); + px = WindowX + ((WindowW - w) / 2); + py = PrintY; + USL_DrawString(s); + PrintY += h; } /////////////////////////////////////////////////////////////////////////// @@ -258,31 +250,30 @@ US_CPrintLine(const char *s) // Newlines are supported. // /////////////////////////////////////////////////////////////////////////// -void -US_CPrint(const char *sorg) +void US_CPrint(const char *sorg) { - char c; - char *sstart = strdup(sorg); - char *s = sstart; - char *se; + char c; + char *se; + char *sstart = strdup(sorg); + char *s = sstart; - while (*s) - { - se = s; - while ((c = *se)!=0 && (c != '\n')) - se++; - *se = '\0'; + while (*s) + { + se = s; + while ((c = *se)!=0 && (c != '\n')) + se++; + *se = '\0'; - US_CPrintLine(s); + US_CPrintLine(s); - s = se; - if (c) - { - *se = c; - s++; - } - } - free(sstart); + s = se; + if (c) + { + *se = c; + s++; + } + } + free(sstart); } /////////////////////////////////////////////////////////////////////////// @@ -294,14 +285,14 @@ US_CPrint(const char *sorg) void US_Printf(const char *formatStr, ...) { - char strbuf[256]; - va_list vlist; - va_start(vlist, formatStr); - int len = vsnprintf(strbuf, sizeof(strbuf), formatStr, vlist); - va_end(vlist); - if(len <= -1 || len >= sizeof(strbuf)) - strbuf[sizeof(strbuf) - 1] = 0; - US_Print(strbuf); + char strbuf[256]; + va_list vlist; + va_start(vlist, formatStr); + int len = vsnprintf(strbuf, sizeof(strbuf), formatStr, vlist); + va_end(vlist); + if(len <= -1 || len >= sizeof(strbuf)) + strbuf[sizeof(strbuf) - 1] = 0; + US_Print(strbuf); } /////////////////////////////////////////////////////////////////////////// @@ -313,14 +304,14 @@ void US_Printf(const char *formatStr, ...) void US_CPrintf(const char *formatStr, ...) { - char strbuf[256]; - va_list vlist; - va_start(vlist, formatStr); - int len = vsnprintf(strbuf, sizeof(strbuf), formatStr, vlist); - va_end(vlist); - if(len <= -1 || len >= sizeof(strbuf)) - strbuf[sizeof(strbuf) - 1] = 0; - US_CPrint(strbuf); + char strbuf[256]; + va_list vlist; + va_start(vlist, formatStr); + int len = vsnprintf(strbuf, sizeof(strbuf), formatStr, vlist); + va_end(vlist); + if(len <= -1 || len >= sizeof(strbuf)) + strbuf[sizeof(strbuf) - 1] = 0; + US_CPrint(strbuf); } /////////////////////////////////////////////////////////////////////////// @@ -329,12 +320,11 @@ void US_CPrintf(const char *formatStr, ...) // cursor // /////////////////////////////////////////////////////////////////////////// -void -US_ClearWindow(void) +void US_ClearWindow(void) { - VWB_Bar(WindowX,WindowY,WindowW,WindowH,WHITE); - PrintX = WindowX; - PrintY = WindowY; + VWB_Bar(WindowX,WindowY,WindowW,WindowH,WHITE); + PrintX = WindowX; + PrintY = WindowY; } /////////////////////////////////////////////////////////////////////////// @@ -342,35 +332,32 @@ US_ClearWindow(void) // US_DrawWindow() - Draws a frame and sets the current window parms // /////////////////////////////////////////////////////////////////////////// -void -US_DrawWindow(word x,word y,word w,word h) +void US_DrawWindow(word x,word y,word w,word h) { - - word i, - sx,sy,sw,sh; + word i, sx,sy,sw,sh; - WindowX = x * 8; - WindowY = y * 8; - WindowW = w * 8; - WindowH = h * 8; + WindowX = x * 8; + WindowY = y * 8; + WindowW = w * 8; + WindowH = h * 8; - PrintX = WindowX; - PrintY = WindowY; + PrintX = WindowX; + PrintY = WindowY; - sx = (x - 1) * 8; - sy = (y - 1) * 8; - sw = (w + 1) * 8; - sh = (h + 1) * 8; + sx = (x - 1) * 8; + sy = (y - 1) * 8; + sw = (w + 1) * 8; + sh = (h + 1) * 8; - US_ClearWindow(); + US_ClearWindow(); - VWB_DrawTile8(sx,sy,0),VWB_DrawTile8(sx,sy + sh,5); - for (i = sx + 8;i <= sx + sw - 8;i += 8) - VWB_DrawTile8(i,sy,1),VWB_DrawTile8(i,sy + sh,6); - VWB_DrawTile8(i,sy,2),VWB_DrawTile8(i,sy + sh,7); + VWB_DrawTile8(sx,sy,0),VWB_DrawTile8(sx,sy + sh,5); + for (i = sx + 8;i <= sx + sw - 8;i += 8) + VWB_DrawTile8(i,sy,1),VWB_DrawTile8(i,sy + sh,6); + VWB_DrawTile8(i,sy,2),VWB_DrawTile8(i,sy + sh,7); - for (i = sy + 8;i <= sy + sh - 8;i += 8) - VWB_DrawTile8(sx,i,3),VWB_DrawTile8(sx + sw,i,4); + for (i = sy + 8;i <= sy + sh - 8;i += 8) + VWB_DrawTile8(sx,i,3),VWB_DrawTile8(sx + sw,i,4); } /////////////////////////////////////////////////////////////////////////// @@ -379,8 +366,7 @@ US_DrawWindow(word x,word y,word w,word h) // later restoration // /////////////////////////////////////////////////////////////////////////// -void -US_SaveWindow(WindowRec *win) +void US_SaveWindow(WindowRec *win) { win->x = WindowX; win->y = WindowY; @@ -397,8 +383,7 @@ US_SaveWindow(WindowRec *win) // record // /////////////////////////////////////////////////////////////////////////// -void -US_RestoreWindow(WindowRec *win) +void US_RestoreWindow(WindowRec *win) { WindowX = win->x; WindowY = win->y; @@ -416,47 +401,48 @@ US_RestoreWindow(WindowRec *win) // USL_XORICursor() - XORs the I-bar text cursor. Used by US_LineInput() // /////////////////////////////////////////////////////////////////////////// -static void -USL_XORICursor(int x,int y,const char *s,word cursor) +static void USL_XORICursor(int x,int y,const char *s,word cursor) { - static boolean status; // VGA doesn't XOR... - char buf[MaxString]; - int temp; - word w,h; + static boolean status; // VGA doesn't XOR... + char buf[MaxString]; + int temp; + word w,h; - strcpy(buf,s); - buf[cursor] = '\0'; - USL_MeasureString(buf,&w,&h); + strcpy(buf,s); + buf[cursor] = '\0'; + USL_MeasureString(buf,&w,&h); - px = x + w - 1; - py = y; - if (status^=1) - USL_DrawString("\x80"); - else - { - temp = fontcolor; - fontcolor = backcolor; - USL_DrawString("\x80"); - fontcolor = temp; - } + px = x + w - 1; + py = y; + if (status^=1) + USL_DrawString("\x80"); + else + { + temp = fontcolor; + fontcolor = backcolor; + USL_DrawString("\x80"); + fontcolor = temp; + } } char USL_RotateChar(char ch, int dir) { - static const char charSet[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ.,-!?0123456789"; - const int numChars = sizeof(charSet) / sizeof(char) - 1; - int i; - for(i = 0; i < numChars; i++) - { - if(ch == charSet[i]) break; - } + static const char charSet[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ.,-!?0123456789"; + const int numChars = sizeof(charSet) / sizeof(char) - 1; + int i; + for(i = 0; i < numChars; i++) + { + if(ch == charSet[i]) break; + } - if(i == numChars) i = 0; + if(i == numChars) i = 0; - i += dir; - if(i < 0) i = numChars - 1; - else if(i >= numChars) i = 0; - return charSet[i]; + i += dir; + if(i < 0) + i = numChars - 1; + else if(i >= numChars) + i = 0; + return charSet[i]; } /////////////////////////////////////////////////////////////////////////// @@ -473,280 +459,280 @@ boolean US_LineInput(int x,int y,char *buf,const char *def,boolean escok, int maxchars,int maxwidth) { - boolean redraw, - cursorvis,cursormoved, - done,result, checkkey; - ScanCode sc; - char c; - char s[MaxString],olds[MaxString]; - int cursor,len; - word i, - w,h, - temp; - longword curtime, lasttime, lastdirtime, lastbuttontime, lastdirmovetime; - ControlInfo ci; - Direction lastdir = dir_None; + boolean redraw, + cursorvis,cursormoved, + done,result, checkkey; + ScanCode sc; + char c; + char s[MaxString],olds[MaxString]; + int cursor,len; + word i, + w,h, + temp; + longword curtime, lasttime, lastdirtime, lastbuttontime, lastdirmovetime; + ControlInfo ci; + Direction lastdir = dir_None; - if (def) - strcpy(s,def); - else - *s = '\0'; - *olds = '\0'; - cursor = (int) strlen(s); - cursormoved = redraw = true; + if (def) + strcpy(s,def); + else + *s = '\0'; + *olds = '\0'; + cursor = (int) strlen(s); + cursormoved = redraw = true; - cursorvis = done = false; - lasttime = lastdirtime = lastdirmovetime = GetTimeCount(); - lastbuttontime = lasttime + TickBase / 4; // 250 ms => first button press accepted after 500 ms - LastASCII = key_None; - LastScan = sc_None; + cursorvis = done = false; + lasttime = lastdirtime = lastdirmovetime = GetTimeCount(); + lastbuttontime = lasttime + TickBase / 4; // 250 ms => first button press accepted after 500 ms + LastASCII = key_None; + LastScan = sc_None; - while (!done) - { - ReadAnyControl(&ci); + while (!done) + { + ReadAnyControl(&ci); - if (cursorvis) - USL_XORICursor(x,y,s,cursor); + if (cursorvis) + USL_XORICursor(x,y,s,cursor); - sc = LastScan; - LastScan = sc_None; - c = LastASCII; - LastASCII = key_None; + sc = LastScan; + LastScan = sc_None; + c = LastASCII; + LastASCII = key_None; - checkkey = true; - curtime = GetTimeCount(); + checkkey = true; + curtime = GetTimeCount(); - // After each direction change accept the next change after 250 ms and then everz 125 ms - if(ci.dir != lastdir || curtime - lastdirtime > TickBase / 4 && curtime - lastdirmovetime > TickBase / 8) - { - if(ci.dir != lastdir) + // After each direction change accept the next change after 250 ms and then everz 125 ms + if(ci.dir != lastdir || curtime - lastdirtime > TickBase / 4 && curtime - lastdirmovetime > TickBase / 8) + { + if(ci.dir != lastdir) + { + lastdir = ci.dir; + lastdirtime = curtime; + } + lastdirmovetime = curtime; + + switch(ci.dir) + { + case dir_West: + if(cursor) + { + // Remove trailing whitespace if cursor is at end of string + if(s[cursor] == ' ' && s[cursor + 1] == 0) + s[cursor] = 0; + cursor--; + } + cursormoved = true; + checkkey = false; + break; + case dir_East: + if(cursor >= MaxString - 1) break; + + if(!s[cursor]) + { + USL_MeasureString(s,&w,&h); + if(len >= maxchars || maxwidth && w >= maxwidth) break; + + s[cursor] = ' '; + s[cursor + 1] = 0; + } + cursor++; + cursormoved = true; + checkkey = false; + break; + + case dir_North: + if(!s[cursor]) + { + USL_MeasureString(s,&w,&h); + if(len >= maxchars || maxwidth && w >= maxwidth) break; + s[cursor + 1] = 0; + } + s[cursor] = USL_RotateChar(s[cursor], 1); + redraw = true; + checkkey = false; + break; + + case dir_South: + if(!s[cursor]) + { + USL_MeasureString(s,&w,&h); + if(len >= maxchars || maxwidth && w >= maxwidth) break; + s[cursor + 1] = 0; + } + s[cursor] = USL_RotateChar(s[cursor], -1); + redraw = true; + checkkey = false; + break; + } + } + + if((int)(curtime - lastbuttontime) > TickBase / 4) // 250 ms + { + if(ci.button0) // acts as return + { + strcpy(buf,s); + done = true; + result = true; + checkkey = false; + } + if(ci.button1 && escok) // acts as escape + { + done = true; + result = false; + checkkey = false; + } + if(ci.button2) // acts as backspace + { + lastbuttontime = curtime; + if(cursor) { - lastdir = ci.dir; - lastdirtime = curtime; + strcpy(s + cursor - 1,s + cursor); + cursor--; + redraw = true; } - lastdirmovetime = curtime; + cursormoved = true; + checkkey = false; + } + } - switch(ci.dir) + if(checkkey) + { + switch (sc) + { + case sc_LeftArrow: + if (cursor) + cursor--; + c = key_None; + cursormoved = true; + break; + case sc_RightArrow: + if (s[cursor]) + cursor++; + c = key_None; + cursormoved = true; + break; + case sc_Home: + cursor = 0; + c = key_None; + cursormoved = true; + break; + case sc_End: + cursor = (int) strlen(s); + c = key_None; + cursormoved = true; + break; + + case sc_Return: + strcpy(buf,s); + done = true; + result = true; + c = key_None; + break; + case sc_Escape: + if (escok) + { + done = true; + result = false; + } + c = key_None; + break; + + case sc_BackSpace: + if (cursor) + { + strcpy(s + cursor - 1,s + cursor); + cursor--; + redraw = true; + } + c = key_None; + cursormoved = true; + break; + case sc_Delete: + if (s[cursor]) + { + strcpy(s + cursor,s + cursor + 1); + redraw = true; + } + c = key_None; + cursormoved = true; + break; + + case SDLK_KP5: //0x4c: // Keypad 5 // TODO: hmmm... + case sc_UpArrow: + case sc_DownArrow: + case sc_PgUp: + case sc_PgDn: + case sc_Insert: + c = key_None; + break; + } + + if (c) + { + len = (int) strlen(s); + USL_MeasureString(s,&w,&h); + + if(isprint(c) && (len < MaxString - 1) && ((!maxchars) || (len < maxchars)) + && ((!maxwidth) || (w < maxwidth))) { - case dir_West: - if(cursor) - { - // Remove trailing whitespace if cursor is at end of string - if(s[cursor] == ' ' && s[cursor + 1] == 0) - s[cursor] = 0; - cursor--; - } - cursormoved = true; - checkkey = false; - break; - case dir_East: - if(cursor >= MaxString - 1) break; - - if(!s[cursor]) - { - USL_MeasureString(s,&w,&h); - if(len >= maxchars || maxwidth && w >= maxwidth) break; - - s[cursor] = ' '; - s[cursor + 1] = 0; - } - cursor++; - cursormoved = true; - checkkey = false; - break; - - case dir_North: - if(!s[cursor]) - { - USL_MeasureString(s,&w,&h); - if(len >= maxchars || maxwidth && w >= maxwidth) break; - s[cursor + 1] = 0; - } - s[cursor] = USL_RotateChar(s[cursor], 1); - redraw = true; - checkkey = false; - break; - - case dir_South: - if(!s[cursor]) - { - USL_MeasureString(s,&w,&h); - if(len >= maxchars || maxwidth && w >= maxwidth) break; - s[cursor + 1] = 0; - } - s[cursor] = USL_RotateChar(s[cursor], -1); - redraw = true; - checkkey = false; - break; + for (i = len + 1;i > cursor;i--) + s[i] = s[i - 1]; + s[cursor++] = c; + redraw = true; } - } + } + } - if((int)(curtime - lastbuttontime) > TickBase / 4) // 250 ms - { - if(ci.button0) // acts as return - { - strcpy(buf,s); - done = true; - result = true; - checkkey = false; - } - if(ci.button1 && escok) // acts as escape - { - done = true; - result = false; - checkkey = false; - } - if(ci.button2) // acts as backspace - { - lastbuttontime = curtime; - if(cursor) - { - strcpy(s + cursor - 1,s + cursor); - cursor--; - redraw = true; - } - cursormoved = true; - checkkey = false; - } - } + if (redraw) + { + px = x; + py = y; + temp = fontcolor; + fontcolor = backcolor; + USL_DrawString(olds); + fontcolor = (byte) temp; + strcpy(olds,s); - if(checkkey) - { - switch (sc) - { - case sc_LeftArrow: - if (cursor) - cursor--; - c = key_None; - cursormoved = true; - break; - case sc_RightArrow: - if (s[cursor]) - cursor++; - c = key_None; - cursormoved = true; - break; - case sc_Home: - cursor = 0; - c = key_None; - cursormoved = true; - break; - case sc_End: - cursor = (int) strlen(s); - c = key_None; - cursormoved = true; - break; + px = x; + py = y; + USL_DrawString(s); - case sc_Return: - strcpy(buf,s); - done = true; - result = true; - c = key_None; - break; - case sc_Escape: - if (escok) - { - done = true; - result = false; - } - c = key_None; - break; + redraw = false; + } - case sc_BackSpace: - if (cursor) - { - strcpy(s + cursor - 1,s + cursor); - cursor--; - redraw = true; - } - c = key_None; - cursormoved = true; - break; - case sc_Delete: - if (s[cursor]) - { - strcpy(s + cursor,s + cursor + 1); - redraw = true; - } - c = key_None; - cursormoved = true; - break; + if (cursormoved) + { + cursorvis = false; + lasttime = curtime - TickBase; - case SDLK_KP5: //0x4c: // Keypad 5 // TODO: hmmm... - case sc_UpArrow: - case sc_DownArrow: - case sc_PgUp: - case sc_PgDn: - case sc_Insert: - c = key_None; - break; - } + cursormoved = false; + } + if (curtime - lasttime > TickBase / 2) // 500 ms + { + lasttime = curtime; - if (c) - { - len = (int) strlen(s); - USL_MeasureString(s,&w,&h); + cursorvis ^= true; + } + else rarch_sleep(5); + if (cursorvis) + USL_XORICursor(x,y,s,cursor); - if(isprint(c) && (len < MaxString - 1) && ((!maxchars) || (len < maxchars)) - && ((!maxwidth) || (w < maxwidth))) - { - for (i = len + 1;i > cursor;i--) - s[i] = s[i - 1]; - s[cursor++] = c; - redraw = true; - } - } - } + VW_UpdateScreen(); + } - if (redraw) - { - px = x; - py = y; - temp = fontcolor; - fontcolor = backcolor; - USL_DrawString(olds); - fontcolor = (byte) temp; - strcpy(olds,s); + if (cursorvis) + USL_XORICursor(x,y,s,cursor); + if (!result) + { + px = x; + py = y; + USL_DrawString(olds); + } + VW_UpdateScreen(); - px = x; - py = y; - USL_DrawString(s); - - redraw = false; - } - - if (cursormoved) - { - cursorvis = false; - lasttime = curtime - TickBase; - - cursormoved = false; - } - if (curtime - lasttime > TickBase / 2) // 500 ms - { - lasttime = curtime; - - cursorvis ^= true; - } - else rarch_sleep(5); - if (cursorvis) - USL_XORICursor(x,y,s,cursor); - - VW_UpdateScreen(); - } - - if (cursorvis) - USL_XORICursor(x,y,s,cursor); - if (!result) - { - px = x; - py = y; - USL_DrawString(olds); - } - VW_UpdateScreen(); - - IN_ClearKeysDown(); - return(result); + IN_ClearKeysDown(); + return(result); } /////////////////////////////////////////////////////////////////////////// @@ -758,10 +744,10 @@ US_LineInput(int x,int y,char *buf,const char *def,boolean escok, /////////////////////////////////////////////////////////////////////////// void US_InitRndT(int randomize) { - if(randomize) - rndindex = (SDL_GetTicks() >> 4) & 0xff; - else - rndindex = 0; + if(randomize) + rndindex = (SDL_GetTicks() >> 4) & 0xff; + else + rndindex = 0; } /////////////////////////////////////////////////////////////////////////// @@ -769,8 +755,8 @@ void US_InitRndT(int randomize) // US_RndT - Returns the next 8-bit pseudo random number // /////////////////////////////////////////////////////////////////////////// -int US_RndT() +int US_RndT(void) { - rndindex = (rndindex+1)&0xff; - return rndtable[rndindex]; + rndindex = (rndindex+1)&0xff; + return rndtable[rndindex]; } diff --git a/id_vl.c b/id_vl.c index c3a9b88..79b54fb 100644 --- a/id_vl.c +++ b/id_vl.c @@ -113,7 +113,8 @@ void VL_SetVGAPlaneMode (void) curPitch = bufferPitch; scaleFactor = screenWidth/320; - if(screenHeight/200 < scaleFactor) scaleFactor = screenHeight/200; + if(screenHeight/200 < scaleFactor) + scaleFactor = screenHeight/200; pixelangle = (short *) malloc(screenWidth * sizeof(short)); @@ -515,10 +516,8 @@ void VL_MemToLatch(byte *source, int width, int height, for(ysrc = 0; ysrc < height; ysrc++) { for(xsrc = 0; xsrc < width; xsrc++) - { dest[ysrc * pitch + xsrc] = source[(ysrc * (width >> 2) + (xsrc >> 2)) + (xsrc & 3) * (width >> 2) * height]; - } } VL_UnlockSurface(destSurface); } @@ -556,9 +555,7 @@ void VL_MemToScreenScaledCoord (byte *source, int width, int height, int destx, for(m=0; mshapenum = statinfo[type].picnum; - laststatobj->tilex = tilex; - laststatobj->tiley = tiley; - laststatobj->visspot = &spotvis[tilex][tiley]; + laststatobj->shapenum = statinfo[type].picnum; + laststatobj->tilex = tilex; + laststatobj->tiley = tiley; + laststatobj->visspot = &spotvis[tilex][tiley]; - switch (statinfo[type].type) - { - case block: - actorat[tilex][tiley] = (objtype *) 64; // consider it a blocking tile - case none: - laststatobj->flags = 0; - break; + switch (statinfo[type].type) + { + case block: + actorat[tilex][tiley] = (objtype *) 64; // consider it a blocking tile + case none: + laststatobj->flags = 0; + break; - case bo_cross: - case bo_chalice: - case bo_bible: - case bo_crown: - case bo_fullheal: - if (!loadedgame) - gamestate.treasuretotal++; + case bo_cross: + case bo_chalice: + case bo_bible: + case bo_crown: + case bo_fullheal: + if (!loadedgame) + gamestate.treasuretotal++; - case bo_firstaid: - case bo_key1: - case bo_key2: - case bo_key3: - case bo_key4: - case bo_clip: - case bo_25clip: - case bo_machinegun: - case bo_chaingun: - case bo_food: - case bo_alpo: - case bo_gibs: - case bo_spear: - laststatobj->flags = FL_BONUS; - laststatobj->itemnumber = statinfo[type].type; - break; - } + case bo_firstaid: + case bo_key1: + case bo_key2: + case bo_key3: + case bo_key4: + case bo_clip: + case bo_25clip: + case bo_machinegun: + case bo_chaingun: + case bo_food: + case bo_alpo: + case bo_gibs: + case bo_spear: + laststatobj->flags = FL_BONUS; + laststatobj->itemnumber = statinfo[type].type; + break; + } - laststatobj->flags |= statinfo[type].specialFlags; + laststatobj->flags |= statinfo[type].specialFlags; - laststatobj++; + laststatobj++; - if (laststatobj == &statobjlist[MAXSTATS]) - Quit ("Too many static objects!\n"); + if (laststatobj == &statobjlist[MAXSTATS]) + Quit ("Too many static objects!\n"); } @@ -202,45 +202,40 @@ void SpawnStatic (int tilex, int tiley, int type) void PlaceItemType (int itemtype, int tilex, int tiley) { - int type; - statobj_t *spot; + int type; + statobj_t *spot; - // - // find the item number - // - for (type=0; ; type++) - { - if (statinfo[type].picnum == -1) // end of list - Quit ("PlaceItemType: couldn't find type!"); - if (statinfo[type].type == itemtype) - break; - } + /* find the item number */ + for (type=0; ; type++) + { + if (statinfo[type].picnum == -1) // end of list + Quit ("PlaceItemType: couldn't find type!"); + if (statinfo[type].type == itemtype) + break; + } - // - // find a spot in statobjlist to put it in - // - for (spot=&statobjlist[0]; ; spot++) - { - if (spot==laststatobj) - { - if (spot == &statobjlist[MAXSTATS]) - return; // no free spots - laststatobj++; // space at end - break; - } + /* find a spot in statobjlist to put it in */ + for (spot=&statobjlist[0]; ; spot++) + { + if (spot==laststatobj) + { + if (spot == &statobjlist[MAXSTATS]) + return; // no free spots + laststatobj++; // space at end + break; + } - if (spot->shapenum == -1) // -1 is a free spot - break; - } - // - // place it - // - spot->shapenum = statinfo[type].picnum; - spot->tilex = tilex; - spot->tiley = tiley; - spot->visspot = &spotvis[tilex][tiley]; - spot->flags = FL_BONUS | statinfo[type].specialFlags; - spot->itemnumber = statinfo[type].type; + if (spot->shapenum == -1) // -1 is a free spot + break; + } + + /* place it */ + spot->shapenum = statinfo[type].picnum; + spot->tilex = tilex; + spot->tiley = tiley; + spot->visspot = &spotvis[tilex][tiley]; + spot->flags = FL_BONUS | statinfo[type].specialFlags; + spot->itemnumber = statinfo[type].type; } @@ -368,10 +363,8 @@ void SpawnDoor (int tilex, int tiley, boolean vertical, int lock) actorat[tilex][tiley] = (objtype *)(uintptr_t)(doornum | 0x80); // consider it a solid wall - // // make the door tile a special tile, and mark the adjacent tiles // for door sides - // tilemap[tilex][tiley] = doornum | 0x80; map = mapsegs[0] + (tiley<= 0xffff) { - // // door is all the way open - // position = 0xffff; doorobjlist[door].ticcount = 0; doorobjlist[door].action = dr_open; @@ -624,62 +611,58 @@ void DoorOpening (int door) void DoorClosing (int door) { - unsigned area1,area2; - word *map; - int32_t position; - int tilex,tiley; + unsigned area1,area2; + word *map; + int32_t position; + int tilex,tiley; - tilex = doorobjlist[door].tilex; - tiley = doorobjlist[door].tiley; + tilex = doorobjlist[door].tilex; + tiley = doorobjlist[door].tiley; - if ( ((int)(uintptr_t)actorat[tilex][tiley] != (door | 0x80)) - || (player->tilex == tilex && player->tiley == tiley) ) - { // something got inside the door - OpenDoor (door); - return; - }; + if ( ((int)(uintptr_t)actorat[tilex][tiley] != (door | 0x80)) + || (player->tilex == tilex && player->tiley == tiley) ) + { // something got inside the door + OpenDoor (door); + return; + }; - position = doorposition[door]; + position = doorposition[door]; - // - // slide the door by an adaptive amount - // - position -= tics<<10; - if (position <= 0) - { - // - // door is closed all the way, so disconnect the areas - // - position = 0; + // slide the door by an adaptive amount + position -= tics<<10; + if (position <= 0) + { + // door is closed all the way, so disconnect the areas + position = 0; - doorobjlist[door].action = dr_closed; + doorobjlist[door].action = dr_closed; - map = mapsegs[0] + (doorobjlist[door].tiley<areanumber < NUMAREAS) - ConnectAreas (); - } - } + if (player->areanumber < NUMAREAS) + ConnectAreas (); + } + } - doorposition[door] = (word) position; + doorposition[door] = (word) position; } @@ -697,28 +680,28 @@ void DoorClosing (int door) void MoveDoors (void) { - int door; + int door; - if (gamestate.victoryflag) // don't move door during victory sequence - return; + if (gamestate.victoryflag) // don't move door during victory sequence + return; - for (door = 0; door < doornum; door++) - { - switch (doorobjlist[door].action) - { - case dr_open: - DoorOpen (door); - break; + for (door = 0; door < doornum; door++) + { + switch (doorobjlist[door].action) + { + case dr_open: + DoorOpen (door); + break; - case dr_opening: - DoorOpening(door); - break; + case dr_opening: + DoorOpening(door); + break; - case dr_closing: - DoorClosing(door); - break; - } - } + case dr_closing: + DoorClosing(door); + break; + } + } } @@ -746,38 +729,38 @@ int dirs[4][2]={{0,-1},{1,0},{0,1},{-1,0}}; void PushWall (int checkx, int checky, int dir) { - int oldtile, dx, dy; + int oldtile, dx, dy; - if (pwallstate) - return; + if (pwallstate) + return; - oldtile = tilemap[checkx][checky]; - if (!oldtile) - return; + oldtile = tilemap[checkx][checky]; + if (!oldtile) + return; - dx = dirs[dir][0]; - dy = dirs[dir][1]; + dx = dirs[dir][0]; + dy = dirs[dir][1]; - if (actorat[checkx+dx][checky+dy]) - { - SD_PlaySound (NOWAYSND); - return; - } - actorat[checkx+dx][checky+dy] = (objtype *)(uintptr_t) (tilemap[checkx+dx][checky+dy] = oldtile); + if (actorat[checkx+dx][checky+dy]) + { + SD_PlaySound (NOWAYSND); + return; + } + actorat[checkx+dx][checky+dy] = (objtype *)(uintptr_t) (tilemap[checkx+dx][checky+dy] = oldtile); - gamestate.secretcount++; - pwallx = checkx; - pwally = checky; - pwalldir = dir; - pwallstate = 1; - pwallpos = 0; - pwalltile = tilemap[pwallx][pwally]; - tilemap[pwallx][pwally] = 64; - tilemap[pwallx+dx][pwally+dy] = 64; - *(mapsegs[1]+(pwally<tiley<tilex); // set correct floorcode (BrotherTank's fix) + gamestate.secretcount++; + pwallx = checkx; + pwally = checky; + pwalldir = dir; + pwallstate = 1; + pwallpos = 0; + pwalltile = tilemap[pwallx][pwally]; + tilemap[pwallx][pwally] = 64; + tilemap[pwallx+dx][pwally+dy] = 64; + *(mapsegs[1]+(pwally<tiley<tilex); // set correct floorcode (BrotherTank's fix) - SD_PlaySound (PUSHWALLSND); + SD_PlaySound (PUSHWALLSND); } @@ -792,62 +775,57 @@ void PushWall (int checkx, int checky, int dir) void MovePWalls (void) { - int oldblock,oldtile; + int oldblock,oldtile; - if (!pwallstate) - return; + if (!pwallstate) + return; - oldblock = pwallstate/128; + oldblock = pwallstate/128; - pwallstate += (word)tics; + pwallstate += (word)tics; - if (pwallstate/128 != oldblock) - { - // block crossed into a new block - oldtile = pwalltile; + if (pwallstate/128 != oldblock) + { + // block crossed into a new block + oldtile = pwalltile; - // - // the tile can now be walked into - // - tilemap[pwallx][pwally] = 0; - actorat[pwallx][pwally] = 0; - *(mapsegs[0]+(pwally<areanumber+AREATILE; + // the tile can now be walked into + tilemap[pwallx][pwally] = 0; + actorat[pwallx][pwally] = 0; + *(mapsegs[0]+(pwally<areanumber+AREATILE; - int dx=dirs[pwalldir][0], dy=dirs[pwalldir][1]; - // - // see if it should be pushed farther - // - if (pwallstate>=256) // only move two tiles fix - { - // - // the block has been pushed two tiles - // + int dx=dirs[pwalldir][0], dy=dirs[pwalldir][1]; + + // see if it should be pushed farther + if (pwallstate>=256) // only move two tiles fix + { + // the block has been pushed two tiles + pwallstate = 0; + tilemap[pwallx+dx][pwally+dy] = oldtile; + return; + } + else + { + int xl,yl,xh,yh; + xl = (player->x-PLAYERSIZE) >> TILESHIFT; + yl = (player->y-PLAYERSIZE) >> TILESHIFT; + xh = (player->x+PLAYERSIZE) >> TILESHIFT; + yh = (player->y+PLAYERSIZE) >> TILESHIFT; + + pwallx += dx; + pwally += dy; + + if (actorat[pwallx+dx][pwally+dy] + || xl<=pwallx+dx && pwallx+dx<=xh && yl<=pwally+dy && pwally+dy<=yh) + { pwallstate = 0; - tilemap[pwallx+dx][pwally+dy] = oldtile; + tilemap[pwallx][pwally] = oldtile; return; - } - else - { - int xl,yl,xh,yh; - xl = (player->x-PLAYERSIZE) >> TILESHIFT; - yl = (player->y-PLAYERSIZE) >> TILESHIFT; - xh = (player->x+PLAYERSIZE) >> TILESHIFT; - yh = (player->y+PLAYERSIZE) >> TILESHIFT; + } + actorat[pwallx+dx][pwally+dy] = (objtype *)(uintptr_t) (tilemap[pwallx+dx][pwally+dy] = oldtile); + tilemap[pwallx+dx][pwally+dy] = 64; + } + } - pwallx += dx; - pwally += dy; - - if (actorat[pwallx+dx][pwally+dy] - || xl<=pwallx+dx && pwallx+dx<=xh && yl<=pwally+dy && pwally+dy<=yh) - { - pwallstate = 0; - tilemap[pwallx][pwally] = oldtile; - return; - } - actorat[pwallx+dx][pwally+dy] = (objtype *)(uintptr_t) (tilemap[pwallx+dx][pwally+dy] = oldtile); - tilemap[pwallx+dx][pwally+dy] = 64; - } - } - - pwallpos = (pwallstate/2)&63; + pwallpos = (pwallstate/2)&63; } diff --git a/wl_act2.c b/wl_act2.c index 8d0fc76..cca3c54 100644 --- a/wl_act2.c +++ b/wl_act2.c @@ -237,23 +237,23 @@ void A_MechaSound (objtype *ob); void A_Smoke (objtype *ob) { - GetNewActor (); + GetNewActor (); #ifdef SPEAR - if (ob->obclass == hrocketobj) - newobj->state = &s_hsmoke1; - else + if (ob->obclass == hrocketobj) + newobj->state = &s_hsmoke1; + else #endif - newobj->state = &s_smoke1; - newobj->ticcount = 6; + newobj->state = &s_smoke1; + newobj->ticcount = 6; - newobj->tilex = ob->tilex; - newobj->tiley = ob->tiley; - newobj->x = ob->x; - newobj->y = ob->y; - newobj->obclass = inertobj; - newobj->active = ac_yes; + newobj->tilex = ob->tilex; + newobj->tiley = ob->tiley; + newobj->x = ob->x; + newobj->y = ob->y; + newobj->obclass = inertobj; + newobj->active = ac_yes; - newobj->flags = FL_NEVERMARK; + newobj->flags = FL_NEVERMARK; } @@ -270,31 +270,28 @@ void A_Smoke (objtype *ob) boolean ProjectileTryMove (objtype *ob) { - int xl,yl,xh,yh,x,y; - objtype *check; + int xl,yl,xh,yh,x,y; + objtype *check; - xl = (ob->x-PROJSIZE) >> TILESHIFT; - yl = (ob->y-PROJSIZE) >> TILESHIFT; + xl = (ob->x-PROJSIZE) >> TILESHIFT; + yl = (ob->y-PROJSIZE) >> TILESHIFT; - xh = (ob->x+PROJSIZE) >> TILESHIFT; - yh = (ob->y+PROJSIZE) >> TILESHIFT; + xh = (ob->x+PROJSIZE) >> TILESHIFT; + yh = (ob->y+PROJSIZE) >> TILESHIFT; - // - // check for solid walls - // - for (y=yl;y<=yh;y++) - for (x=xl;x<=xh;x++) - { - check = actorat[x][y]; - if (check && !ISPOINTER(check)) - return false; - } + // check for solid walls + for (y=yl;y<=yh;y++) + for (x=xl;x<=xh;x++) + { + check = actorat[x][y]; + if (check && !ISPOINTER(check)) + return false; + } - return true; + return true; } - /* ================= = @@ -305,72 +302,72 @@ boolean ProjectileTryMove (objtype *ob) void T_Projectile (objtype *ob) { - int32_t deltax,deltay; - int damage; - int32_t speed; + int32_t deltax,deltay; + int damage; + int32_t speed; - speed = (int32_t)ob->speed*tics; + speed = (int32_t)ob->speed*tics; - deltax = FixedMul(speed,costable[ob->angle]); - deltay = -FixedMul(speed,sintable[ob->angle]); + deltax = FixedMul(speed,costable[ob->angle]); + deltay = -FixedMul(speed,sintable[ob->angle]); - if (deltax>0x10000l) - deltax = 0x10000l; - if (deltay>0x10000l) - deltay = 0x10000l; + if (deltax>0x10000l) + deltax = 0x10000l; + if (deltay>0x10000l) + deltay = 0x10000l; - ob->x += deltax; - ob->y += deltay; + ob->x += deltax; + ob->y += deltay; - deltax = LABS(ob->x - player->x); - deltay = LABS(ob->y - player->y); + deltax = LABS(ob->x - player->x); + deltay = LABS(ob->y - player->y); - if (!ProjectileTryMove (ob)) - { + if (!ProjectileTryMove (ob)) + { #ifndef APOGEE_1_0 // actually the whole method is never reached in shareware 1.0 - if (ob->obclass == rocketobj) - { - PlaySoundLocActor(MISSILEHITSND,ob); - ob->state = &s_boom1; - } + if (ob->obclass == rocketobj) + { + PlaySoundLocActor(MISSILEHITSND,ob); + ob->state = &s_boom1; + } #ifdef SPEAR - else if (ob->obclass == hrocketobj) - { - PlaySoundLocActor(MISSILEHITSND,ob); - ob->state = &s_hboom1; - } + else if (ob->obclass == hrocketobj) + { + PlaySoundLocActor(MISSILEHITSND,ob); + ob->state = &s_hboom1; + } #endif - else + else #endif - ob->state = NULL; // mark for removal + ob->state = NULL; // mark for removal - return; - } + return; + } - if (deltax < PROJECTILESIZE && deltay < PROJECTILESIZE) - { // hit the player - switch (ob->obclass) - { - case needleobj: + if (deltax < PROJECTILESIZE && deltay < PROJECTILESIZE) + { // hit the player + switch (ob->obclass) + { + case needleobj: damage = (US_RndT() >>3) + 20; break; - case rocketobj: - case hrocketobj: - case sparkobj: + case rocketobj: + case hrocketobj: + case sparkobj: damage = (US_RndT() >>3) + 30; break; - case fireobj: + case fireobj: damage = (US_RndT() >>3); break; - } + } - TakeDamage (damage,ob); - ob->state = NULL; // mark for removal - return; - } + TakeDamage (damage,ob); + ob->state = NULL; // mark for removal + return; + } - ob->tilex = (short)(ob->x >> TILESHIFT); - ob->tiley = (short)(ob->y >> TILESHIFT); + ob->tilex = (short)(ob->x >> TILESHIFT); + ob->tiley = (short)(ob->y >> TILESHIFT); } @@ -849,70 +846,69 @@ statetype s_gretelshoot8 = {false,SPR_GRETEL_SHOOT1,10,NULL,NULL,&s_grete void SpawnStand (enemy_t which, int tilex, int tiley, int dir) { - word *map; - word tile; + word *map; + word tile; - switch (which) - { - case en_guard: - SpawnNewObj (tilex,tiley,&s_grdstand); - newobj->speed = SPDPATROL; - if (!loadedgame) - gamestate.killtotal++; - break; + switch (which) + { + case en_guard: + SpawnNewObj (tilex,tiley,&s_grdstand); + newobj->speed = SPDPATROL; + if (!loadedgame) + gamestate.killtotal++; + break; - case en_officer: - SpawnNewObj (tilex,tiley,&s_ofcstand); - newobj->speed = SPDPATROL; - if (!loadedgame) - gamestate.killtotal++; - break; + case en_officer: + SpawnNewObj (tilex,tiley,&s_ofcstand); + newobj->speed = SPDPATROL; + if (!loadedgame) + gamestate.killtotal++; + break; - case en_mutant: - SpawnNewObj (tilex,tiley,&s_mutstand); - newobj->speed = SPDPATROL; - if (!loadedgame) - gamestate.killtotal++; - break; + case en_mutant: + SpawnNewObj (tilex,tiley,&s_mutstand); + newobj->speed = SPDPATROL; + if (!loadedgame) + gamestate.killtotal++; + break; - case en_ss: - SpawnNewObj (tilex,tiley,&s_ssstand); - newobj->speed = SPDPATROL; - if (!loadedgame) - gamestate.killtotal++; - break; - } + case en_ss: + SpawnNewObj (tilex,tiley,&s_ssstand); + newobj->speed = SPDPATROL; + if (!loadedgame) + gamestate.killtotal++; + break; + } - map = mapsegs[0]+(tiley<= AREATILE) - tile = *(map+1); - if (*(map-mapwidth) >= AREATILE) - tile = *(map-mapwidth); - if (*(map+mapwidth) >= AREATILE) - tile = *(map+mapwidth); - if ( *(map-1) >= AREATILE) - tile = *(map-1); + if (*(map+1) >= AREATILE) + tile = *(map+1); + if (*(map-mapwidth) >= AREATILE) + tile = *(map-mapwidth); + if (*(map+mapwidth) >= AREATILE) + tile = *(map+mapwidth); + if ( *(map-1) >= AREATILE) + tile = *(map-1); - *map = tile; - newobj->areanumber = tile-AREATILE; + *map = tile; + newobj->areanumber = tile-AREATILE; - newobj->flags |= FL_AMBUSH; - } + newobj->flags |= FL_AMBUSH; + } - newobj->obclass = (classtype)(guardobj + which); - newobj->hitpoints = starthitpoints[gamestate.difficulty][which]; - newobj->dir = (dirtype)(dir * 2); - newobj->flags |= FL_SHOOTABLE; + newobj->obclass = (classtype)(guardobj + which); + newobj->hitpoints = starthitpoints[gamestate.difficulty][which]; + newobj->dir = (dirtype)(dir * 2); + newobj->flags |= FL_SHOOTABLE; } - /* =============== = @@ -923,12 +919,12 @@ void SpawnStand (enemy_t which, int tilex, int tiley, int dir) void SpawnDeadGuard (int tilex, int tiley) { - SpawnNewObj (tilex,tiley,&s_grddie4); - DEMOIF_SDL - { - newobj->flags |= FL_NONMARK; // walk through moving enemy fix - } - newobj->obclass = inertobj; + SpawnNewObj (tilex,tiley,&s_grddie4); + DEMOIF_SDL + { + newobj->flags |= FL_NONMARK; // walk through moving enemy fix + } + newobj->obclass = inertobj; } @@ -965,15 +961,15 @@ void SpawnBoss (int tilex, int tiley) void SpawnGretel (int tilex, int tiley) { - SpawnNewObj (tilex,tiley,&s_gretelstand); - newobj->speed = SPDPATROL; + SpawnNewObj (tilex,tiley,&s_gretelstand); + newobj->speed = SPDPATROL; - newobj->obclass = gretelobj; - newobj->hitpoints = starthitpoints[gamestate.difficulty][en_gretel]; - newobj->dir = nodir; - newobj->flags |= FL_SHOOTABLE|FL_AMBUSH; - if (!loadedgame) - gamestate.killtotal++; + newobj->obclass = gretelobj; + newobj->hitpoints = starthitpoints[gamestate.difficulty][en_gretel]; + newobj->dir = nodir; + newobj->flags |= FL_SHOOTABLE|FL_AMBUSH; + if (!loadedgame) + gamestate.killtotal++; } #endif @@ -987,74 +983,73 @@ void SpawnGretel (int tilex, int tiley) void SpawnPatrol (enemy_t which, int tilex, int tiley, int dir) { - switch (which) - { - case en_guard: - SpawnNewObj (tilex,tiley,&s_grdpath1); - newobj->speed = SPDPATROL; - if (!loadedgame) - gamestate.killtotal++; - break; + switch (which) + { + case en_guard: + SpawnNewObj (tilex,tiley,&s_grdpath1); + newobj->speed = SPDPATROL; + if (!loadedgame) + gamestate.killtotal++; + break; - case en_officer: - SpawnNewObj (tilex,tiley,&s_ofcpath1); - newobj->speed = SPDPATROL; - if (!loadedgame) - gamestate.killtotal++; - break; + case en_officer: + SpawnNewObj (tilex,tiley,&s_ofcpath1); + newobj->speed = SPDPATROL; + if (!loadedgame) + gamestate.killtotal++; + break; - case en_ss: - SpawnNewObj (tilex,tiley,&s_sspath1); - newobj->speed = SPDPATROL; - if (!loadedgame) - gamestate.killtotal++; - break; + case en_ss: + SpawnNewObj (tilex,tiley,&s_sspath1); + newobj->speed = SPDPATROL; + if (!loadedgame) + gamestate.killtotal++; + break; - case en_mutant: - SpawnNewObj (tilex,tiley,&s_mutpath1); - newobj->speed = SPDPATROL; - if (!loadedgame) - gamestate.killtotal++; - break; + case en_mutant: + SpawnNewObj (tilex,tiley,&s_mutpath1); + newobj->speed = SPDPATROL; + if (!loadedgame) + gamestate.killtotal++; + break; - case en_dog: - SpawnNewObj (tilex,tiley,&s_dogpath1); - newobj->speed = SPDDOG; - if (!loadedgame) - gamestate.killtotal++; - break; - } + case en_dog: + SpawnNewObj (tilex,tiley,&s_dogpath1); + newobj->speed = SPDDOG; + if (!loadedgame) + gamestate.killtotal++; + break; + } - newobj->obclass = (classtype)(guardobj+which); - newobj->dir = (dirtype)(dir*2); - newobj->hitpoints = starthitpoints[gamestate.difficulty][which]; - newobj->distance = TILEGLOBAL; - newobj->flags |= FL_SHOOTABLE; - newobj->active = ac_yes; + newobj->obclass = (classtype)(guardobj+which); + newobj->dir = (dirtype)(dir*2); + newobj->hitpoints = starthitpoints[gamestate.difficulty][which]; + newobj->distance = TILEGLOBAL; + newobj->flags |= FL_SHOOTABLE; + newobj->active = ac_yes; - actorat[newobj->tilex][newobj->tiley] = NULL; // don't use original spot + actorat[newobj->tilex][newobj->tiley] = NULL; // don't use original spot - switch (dir) - { - case 0: - newobj->tilex++; - break; - case 1: - newobj->tiley--; - break; - case 2: - newobj->tilex--; - break; - case 3: - newobj->tiley++; - break; - } + switch (dir) + { + case 0: + newobj->tilex++; + break; + case 1: + newobj->tiley--; + break; + case 2: + newobj->tilex--; + break; + case 3: + newobj->tiley++; + break; + } - actorat[newobj->tilex][newobj->tiley] = newobj; + actorat[newobj->tilex][newobj->tiley] = newobj; } - /* ================== = @@ -1067,41 +1062,41 @@ void A_DeathScream (objtype *ob) { #ifndef UPLOAD #ifndef SPEAR - if (mapon==9 && !US_RndT()) + if (mapon==9 && !US_RndT()) #else - if ((mapon==18 || mapon==19) && !US_RndT()) + if ((mapon==18 || mapon==19) && !US_RndT()) #endif - { - switch(ob->obclass) - { + { + switch(ob->obclass) + { case mutantobj: case guardobj: case officerobj: case ssobj: case dogobj: - PlaySoundLocActor(DEATHSCREAM6SND,ob); - return; - } - } + PlaySoundLocActor(DEATHSCREAM6SND,ob); + return; + } + } #endif - switch (ob->obclass) - { - case mutantobj: - PlaySoundLocActor(AHHHGSND,ob); - break; + switch (ob->obclass) + { + case mutantobj: + PlaySoundLocActor(AHHHGSND,ob); + break; - case guardobj: - { + case guardobj: + { int sounds[9]={ DEATHSCREAM1SND, - DEATHSCREAM2SND, - DEATHSCREAM3SND, + DEATHSCREAM2SND, + DEATHSCREAM3SND, #ifndef APOGEE_1_0 - DEATHSCREAM4SND, - DEATHSCREAM5SND, - DEATHSCREAM7SND, - DEATHSCREAM8SND, - DEATHSCREAM9SND + DEATHSCREAM4SND, + DEATHSCREAM5SND, + DEATHSCREAM7SND, + DEATHSCREAM8SND, + DEATHSCREAM9SND #endif }; @@ -1111,64 +1106,64 @@ void A_DeathScream (objtype *ob) PlaySoundLocActor(sounds[US_RndT()%2],ob); #endif break; - } - case officerobj: - PlaySoundLocActor(NEINSOVASSND,ob); - break; - case ssobj: - PlaySoundLocActor(LEBENSND,ob); // JAB - break; - case dogobj: - PlaySoundLocActor(DOGDEATHSND,ob); // JAB - break; + } + case officerobj: + PlaySoundLocActor(NEINSOVASSND,ob); + break; + case ssobj: + PlaySoundLocActor(LEBENSND,ob); // JAB + break; + case dogobj: + PlaySoundLocActor(DOGDEATHSND,ob); // JAB + break; #ifndef SPEAR - case bossobj: - SD_PlaySound(MUTTISND); // JAB - break; - case schabbobj: - SD_PlaySound(MEINGOTTSND); - break; - case fakeobj: - SD_PlaySound(HITLERHASND); - break; - case mechahitlerobj: - SD_PlaySound(SCHEISTSND); - break; - case realhitlerobj: - SD_PlaySound(EVASND); - break; + case bossobj: + SD_PlaySound(MUTTISND); // JAB + break; + case schabbobj: + SD_PlaySound(MEINGOTTSND); + break; + case fakeobj: + SD_PlaySound(HITLERHASND); + break; + case mechahitlerobj: + SD_PlaySound(SCHEISTSND); + break; + case realhitlerobj: + SD_PlaySound(EVASND); + break; #ifndef APOGEE_1_0 - case gretelobj: - SD_PlaySound(MEINSND); - break; - case giftobj: - SD_PlaySound(DONNERSND); - break; - case fatobj: - SD_PlaySound(ROSESND); - break; + case gretelobj: + SD_PlaySound(MEINSND); + break; + case giftobj: + SD_PlaySound(DONNERSND); + break; + case fatobj: + SD_PlaySound(ROSESND); + break; #endif #else - case spectreobj: - SD_PlaySound(GHOSTFADESND); - break; - case angelobj: - SD_PlaySound(ANGELDEATHSND); - break; - case transobj: - SD_PlaySound(TRANSDEATHSND); - break; - case uberobj: - SD_PlaySound(UBERDEATHSND); - break; - case willobj: - SD_PlaySound(WILHELMDEATHSND); - break; - case deathobj: - SD_PlaySound(KNIGHTDEATHSND); - break; + case spectreobj: + SD_PlaySound(GHOSTFADESND); + break; + case angelobj: + SD_PlaySound(ANGELDEATHSND); + break; + case transobj: + SD_PlaySound(TRANSDEATHSND); + break; + case uberobj: + SD_PlaySound(UBERDEATHSND); + break; + case willobj: + SD_PlaySound(WILHELMDEATHSND); + break; + case deathobj: + SD_PlaySound(KNIGHTDEATHSND); + break; #endif - } + } } @@ -1189,9 +1184,7 @@ extern statetype s_angelshoot1; extern statetype s_deathshoot1; extern statetype s_spark1; -// // trans -// extern statetype s_transstand; extern statetype s_transchase1; @@ -1254,18 +1247,15 @@ statetype s_transshoot8 = {false,SPR_TRANS_SHOOT1,10,NULL,NULL,&s_transc void SpawnTrans (int tilex, int tiley) { - // word *map; - // word tile; + if (SoundBlasterPresent && DigiMode != sds_Off) + s_transdie01.tictime = 105; - if (SoundBlasterPresent && DigiMode != sds_Off) - s_transdie01.tictime = 105; - - SpawnNewObj (tilex,tiley,&s_transstand); - newobj->obclass = transobj; - newobj->hitpoints = starthitpoints[gamestate.difficulty][en_trans]; - newobj->flags |= FL_SHOOTABLE|FL_AMBUSH; - if (!loadedgame) - gamestate.killtotal++; + SpawnNewObj (tilex,tiley,&s_transstand); + newobj->obclass = transobj; + newobj->hitpoints = starthitpoints[gamestate.difficulty][en_trans]; + newobj->flags |= FL_SHOOTABLE|FL_AMBUSH; + if (!loadedgame) + gamestate.killtotal++; } @@ -1336,15 +1326,15 @@ statetype s_ubershoot7 = {false,SPR_UBER_SHOOT1,12,NULL,NULL,&s_ubercha void SpawnUber (int tilex, int tiley) { - if (SoundBlasterPresent && DigiMode != sds_Off) - s_uberdie01.tictime = 70; + if (SoundBlasterPresent && DigiMode != sds_Off) + s_uberdie01.tictime = 70; - SpawnNewObj (tilex,tiley,&s_uberstand); - newobj->obclass = uberobj; - newobj->hitpoints = starthitpoints[gamestate.difficulty][en_uber]; - newobj->flags |= FL_SHOOTABLE|FL_AMBUSH; - if (!loadedgame) - gamestate.killtotal++; + SpawnNewObj (tilex,tiley,&s_uberstand); + newobj->obclass = uberobj; + newobj->hitpoints = starthitpoints[gamestate.difficulty][en_uber]; + newobj->flags |= FL_SHOOTABLE|FL_AMBUSH; + if (!loadedgame) + gamestate.killtotal++; } @@ -1358,21 +1348,19 @@ void SpawnUber (int tilex, int tiley) void T_UShoot (objtype *ob) { - int dx,dy,dist; + int dx,dy,dist; - T_Shoot (ob); + T_Shoot (ob); - dx = abs(ob->tilex - player->tilex); - dy = abs(ob->tiley - player->tiley); - dist = dx>dy ? dx : dy; - if (dist <= 1) - TakeDamage (10,ob); + dx = abs(ob->tilex - player->tilex); + dy = abs(ob->tiley - player->tiley); + dist = dx>dy ? dx : dy; + if (dist <= 1) + TakeDamage (10,ob); } -// // will -// extern statetype s_willstand; extern statetype s_willchase1; @@ -1433,15 +1421,15 @@ statetype s_willshoot6 = {false,SPR_WILL_SHOOT4,10,NULL,(statefunc)T_Sh void SpawnWill (int tilex, int tiley) { - if (SoundBlasterPresent && DigiMode != sds_Off) - s_willdie2.tictime = 70; + if (SoundBlasterPresent && DigiMode != sds_Off) + s_willdie2.tictime = 70; - SpawnNewObj (tilex,tiley,&s_willstand); - newobj->obclass = willobj; - newobj->hitpoints = starthitpoints[gamestate.difficulty][en_will]; - newobj->flags |= FL_SHOOTABLE|FL_AMBUSH; - if (!loadedgame) - gamestate.killtotal++; + SpawnNewObj (tilex,tiley,&s_willstand); + newobj->obclass = willobj; + newobj->hitpoints = starthitpoints[gamestate.difficulty][en_will]; + newobj->flags |= FL_SHOOTABLE|FL_AMBUSH; + if (!loadedgame) + gamestate.killtotal++; } @@ -1455,97 +1443,86 @@ void SpawnWill (int tilex, int tiley) void T_Will (objtype *ob) { - int32_t move; - int dx,dy,dist; - boolean dodge; + int32_t move; + int dx,dy,dist; + boolean dodge; - dodge = false; - dx = abs(ob->tilex - player->tilex); - dy = abs(ob->tiley - player->tiley); - dist = dx>dy ? dx : dy; + dodge = false; + dx = abs(ob->tilex - player->tilex); + dy = abs(ob->tiley - player->tiley); + dist = dx>dy ? dx : dy; - if (CheckLine(ob)) // got a shot at player? - { - ob->hidden = false; - if ( (unsigned) US_RndT() < (tics<<3) && objfreelist) - { - // - // go into attack frame - // - if (ob->obclass == willobj) - NewState (ob,&s_willshoot1); - else if (ob->obclass == angelobj) - NewState (ob,&s_angelshoot1); - else - NewState (ob,&s_deathshoot1); + if (CheckLine(ob)) // got a shot at player? + { + ob->hidden = false; + if ( (unsigned) US_RndT() < (tics<<3) && objfreelist) + { + // go into attack frame + if (ob->obclass == willobj) + NewState (ob,&s_willshoot1); + else if (ob->obclass == angelobj) + NewState (ob,&s_angelshoot1); + else + NewState (ob,&s_deathshoot1); + return; + } + dodge = true; + } + else + ob->hidden = true; + + if (ob->dir == nodir) + { + if (dodge) + SelectDodgeDir (ob); + else + SelectChaseDir (ob); + if (ob->dir == nodir) + return; // object is blocked in + } + + move = ob->speed*tics; + + while (move) + { + if (ob->distance < 0) + { + // waiting for a door to open + OpenDoor (-ob->distance-1); + if (doorobjlist[-ob->distance-1].action != dr_open) return; - } - dodge = true; - } - else - ob->hidden = true; + ob->distance = TILEGLOBAL; // go ahead, the door is now open + TryWalk(ob); + } - if (ob->dir == nodir) - { - if (dodge) - SelectDodgeDir (ob); - else - SelectChaseDir (ob); - if (ob->dir == nodir) - return; // object is blocked in - } + if (move < ob->distance) + { + MoveObj (ob,move); + break; + } - move = ob->speed*tics; + // reached goal tile, so select another one - while (move) - { - if (ob->distance < 0) - { - // - // waiting for a door to open - // - OpenDoor (-ob->distance-1); - if (doorobjlist[-ob->distance-1].action != dr_open) - return; - ob->distance = TILEGLOBAL; // go ahead, the door is now open - TryWalk(ob); - } + // fix position to account for round off during moving + ob->x = ((int32_t)ob->tilex<y = ((int32_t)ob->tiley<distance) - { - MoveObj (ob,move); - break; - } + move -= ob->distance; - // - // reached goal tile, so select another one - // + if (dist <4) + SelectRunDir (ob); + else if (dodge) + SelectDodgeDir (ob); + else + SelectChaseDir (ob); - // - // fix position to account for round off during moving - // - ob->x = ((int32_t)ob->tilex<y = ((int32_t)ob->tiley<distance; - - if (dist <4) - SelectRunDir (ob); - else if (dodge) - SelectDodgeDir (ob); - else - SelectChaseDir (ob); - - if (ob->dir == nodir) - return; // object is blocked in - } + if (ob->dir == nodir) + return; // object is blocked in + } } - -// // death -// extern statetype s_deathstand; extern statetype s_deathchase1; @@ -1610,15 +1587,15 @@ statetype s_deathshoot5 = {false,SPR_DEATH_SHOOT4,10,NULL,(statefunc)T_S void SpawnDeath (int tilex, int tiley) { - if (SoundBlasterPresent && DigiMode != sds_Off) - s_deathdie2.tictime = 105; + if (SoundBlasterPresent && DigiMode != sds_Off) + s_deathdie2.tictime = 105; - SpawnNewObj (tilex,tiley,&s_deathstand); - newobj->obclass = deathobj; - newobj->hitpoints = starthitpoints[gamestate.difficulty][en_death]; - newobj->flags |= FL_SHOOTABLE|FL_AMBUSH; - if (!loadedgame) - gamestate.killtotal++; + SpawnNewObj (tilex,tiley,&s_deathstand); + newobj->obclass = deathobj; + newobj->hitpoints = starthitpoints[gamestate.difficulty][en_death]; + newobj->flags |= FL_SHOOTABLE|FL_AMBUSH; + if (!loadedgame) + gamestate.killtotal++; } /* @@ -1631,70 +1608,67 @@ void SpawnDeath (int tilex, int tiley) void T_Launch (objtype *ob) { - int32_t deltax,deltay; - float angle; - int iangle; + int32_t deltax,deltay; + float angle; + int iangle; - deltax = player->x - ob->x; - deltay = ob->y - player->y; - angle = (float) atan2 ((float) deltay, (float) deltax); - if (angle<0) - angle = (float) (M_PI*2+angle); - iangle = (int) (angle/(M_PI*2)*ANGLES); - if (ob->obclass == deathobj) - { - T_Shoot (ob); - if (ob->state == &s_deathshoot2) - { - iangle-=4; - if (iangle<0) - iangle+=ANGLES; - } - else - { - iangle+=4; - if (iangle>=ANGLES) - iangle-=ANGLES; - } - } + deltax = player->x - ob->x; + deltay = ob->y - player->y; + angle = (float) atan2 ((float) deltay, (float) deltax); + if (angle<0) + angle = (float) (M_PI*2+angle); + iangle = (int) (angle/(M_PI*2)*ANGLES); + if (ob->obclass == deathobj) + { + T_Shoot (ob); + if (ob->state == &s_deathshoot2) + { + iangle-=4; + if (iangle<0) + iangle+=ANGLES; + } + else + { + iangle+=4; + if (iangle>=ANGLES) + iangle-=ANGLES; + } + } - GetNewActor (); - newobj->state = &s_rocket; - newobj->ticcount = 1; + GetNewActor (); + newobj->state = &s_rocket; + newobj->ticcount = 1; - newobj->tilex = ob->tilex; - newobj->tiley = ob->tiley; - newobj->x = ob->x; - newobj->y = ob->y; - newobj->obclass = rocketobj; - switch(ob->obclass) - { - case deathobj: - newobj->state = &s_hrocket; - newobj->obclass = hrocketobj; - PlaySoundLocActor (KNIGHTMISSILESND,newobj); - break; - case angelobj: - newobj->state = &s_spark1; - newobj->obclass = sparkobj; - PlaySoundLocActor (ANGELFIRESND,newobj); - break; - default: - PlaySoundLocActor (MISSILEFIRESND,newobj); - } + newobj->tilex = ob->tilex; + newobj->tiley = ob->tiley; + newobj->x = ob->x; + newobj->y = ob->y; + newobj->obclass = rocketobj; + switch(ob->obclass) + { + case deathobj: + newobj->state = &s_hrocket; + newobj->obclass = hrocketobj; + PlaySoundLocActor (KNIGHTMISSILESND,newobj); + break; + case angelobj: + newobj->state = &s_spark1; + newobj->obclass = sparkobj; + PlaySoundLocActor (ANGELFIRESND,newobj); + break; + default: + PlaySoundLocActor (MISSILEFIRESND,newobj); + } - newobj->dir = nodir; - newobj->angle = iangle; - newobj->speed = 0x2000l; - newobj->flags = FL_NEVERMARK; - newobj->active = ac_yes; + newobj->dir = nodir; + newobj->angle = iangle; + newobj->speed = 0x2000l; + newobj->flags = FL_NEVERMARK; + newobj->active = ac_yes; } - -// // angel -// void A_Relaunch (objtype *ob); void A_Victory (objtype *ob); void A_StartAttack (objtype *ob); @@ -1781,12 +1755,12 @@ statetype s_spark4 = {false,SPR_SPARK4,6,(statefunc)T_Projectile,NU void A_Slurpie (objtype *) { - SD_PlaySound(SLURPIESND); + SD_PlaySound(SLURPIESND); } void A_Breathing (objtype *) { - SD_PlaySound(ANGELTIREDSND); + SD_PlaySound(ANGELTIREDSND); } /* @@ -1799,15 +1773,15 @@ void A_Breathing (objtype *) void SpawnAngel (int tilex, int tiley) { - if (SoundBlasterPresent && DigiMode != sds_Off) - s_angeldie11.tictime = 105; + if (SoundBlasterPresent && DigiMode != sds_Off) + s_angeldie11.tictime = 105; - SpawnNewObj (tilex,tiley,&s_angelstand); - newobj->obclass = angelobj; - newobj->hitpoints = starthitpoints[gamestate.difficulty][en_angel]; - newobj->flags |= FL_SHOOTABLE|FL_AMBUSH; - if (!loadedgame) - gamestate.killtotal++; + SpawnNewObj (tilex,tiley,&s_angelstand); + newobj->obclass = angelobj; + newobj->hitpoints = starthitpoints[gamestate.difficulty][en_angel]; + newobj->flags |= FL_SHOOTABLE|FL_AMBUSH; + if (!loadedgame) + gamestate.killtotal++; } @@ -1821,7 +1795,7 @@ void SpawnAngel (int tilex, int tiley) void A_Victory (objtype *) { - playstate = ex_victorious; + playstate = ex_victorious; } @@ -1835,7 +1809,7 @@ void A_Victory (objtype *) void A_StartAttack (objtype *ob) { - ob->temp1 = 0; + ob->temp1 = 0; } @@ -1849,17 +1823,17 @@ void A_StartAttack (objtype *ob) void A_Relaunch (objtype *ob) { - if (++ob->temp1 == 3) - { - NewState (ob,&s_angeltired); - return; - } + if (++ob->temp1 == 3) + { + NewState (ob,&s_angeltired); + return; + } - if (US_RndT()&1) - { - NewState (ob,&s_angelchase1); - return; - } + if (US_RndT()&1) + { + NewState (ob,&s_angelchase1); + return; + } } @@ -1914,12 +1888,12 @@ statetype s_spectrewake = {false,SPR_SPECTRE_F4,10,NULL,(statefunc)A_Dor void SpawnSpectre (int tilex, int tiley) { - SpawnNewObj (tilex,tiley,&s_spectrewait1); - newobj->obclass = spectreobj; - newobj->hitpoints = starthitpoints[gamestate.difficulty][en_spectre]; - newobj->flags |= FL_SHOOTABLE|FL_AMBUSH|FL_BONUS; // |FL_NEVERMARK|FL_NONMARK; - if (!loadedgame) - gamestate.killtotal++; + SpawnNewObj (tilex,tiley,&s_spectrewait1); + newobj->obclass = spectreobj; + newobj->hitpoints = starthitpoints[gamestate.difficulty][en_spectre]; + newobj->flags |= FL_SHOOTABLE|FL_AMBUSH|FL_BONUS; // |FL_NEVERMARK|FL_NONMARK; + if (!loadedgame) + gamestate.killtotal++; } @@ -1933,43 +1907,43 @@ void SpawnSpectre (int tilex, int tiley) void A_Dormant (objtype *ob) { - int32_t deltax,deltay; - int xl,xh,yl,yh; - int x,y; - uintptr_t tile; + int32_t deltax,deltay; + int xl,xh,yl,yh; + int x,y; + uintptr_t tile; - deltax = ob->x - player->x; - if (deltax < -MINACTORDIST || deltax > MINACTORDIST) - goto moveok; - deltay = ob->y - player->y; - if (deltay < -MINACTORDIST || deltay > MINACTORDIST) - goto moveok; + deltax = ob->x - player->x; + if (deltax < -MINACTORDIST || deltax > MINACTORDIST) + goto moveok; + deltay = ob->y - player->y; + if (deltay < -MINACTORDIST || deltay > MINACTORDIST) + goto moveok; - return; + return; moveok: - xl = (ob->x-MINDIST) >> TILESHIFT; - xh = (ob->x+MINDIST) >> TILESHIFT; - yl = (ob->y-MINDIST) >> TILESHIFT; - yh = (ob->y+MINDIST) >> TILESHIFT; + xl = (ob->x-MINDIST) >> TILESHIFT; + xh = (ob->x+MINDIST) >> TILESHIFT; + yl = (ob->y-MINDIST) >> TILESHIFT; + yh = (ob->y+MINDIST) >> TILESHIFT; - for (y=yl ; y<=yh ; y++) - for (x=xl ; x<=xh ; x++) - { - tile = (uintptr_t)actorat[x][y]; - if (!tile) - continue; - if (!ISPOINTER(tile)) - return; - if (((objtype *)tile)->flags&FL_SHOOTABLE) - return; - } + for (y=yl ; y<=yh ; y++) + for (x=xl ; x<=xh ; x++) + { + tile = (uintptr_t)actorat[x][y]; + if (!tile) + continue; + if (!ISPOINTER(tile)) + return; + if (((objtype *)tile)->flags&FL_SHOOTABLE) + return; + } - ob->flags |= FL_AMBUSH | FL_SHOOTABLE; - ob->flags &= ~FL_ATTACKMODE; - ob->flags &= ~FL_NONMARK; // stuck bugfix 1 - ob->dir = nodir; - NewState (ob,&s_spectrewait1); + ob->flags |= FL_AMBUSH | FL_SHOOTABLE; + ob->flags &= ~FL_ATTACKMODE; + ob->flags &= ~FL_NONMARK; // stuck bugfix 1 + ob->dir = nodir; + NewState (ob,&s_spectrewait1); } @@ -1994,32 +1968,32 @@ moveok: void SpawnGhosts (int which, int tilex, int tiley) { - switch(which) - { - case en_blinky: - SpawnNewObj (tilex,tiley,&s_blinkychase1); - break; - case en_clyde: - SpawnNewObj (tilex,tiley,&s_clydechase1); - break; - case en_pinky: - SpawnNewObj (tilex,tiley,&s_pinkychase1); - break; - case en_inky: - SpawnNewObj (tilex,tiley,&s_inkychase1); - break; - } + switch(which) + { + case en_blinky: + SpawnNewObj (tilex,tiley,&s_blinkychase1); + break; + case en_clyde: + SpawnNewObj (tilex,tiley,&s_clydechase1); + break; + case en_pinky: + SpawnNewObj (tilex,tiley,&s_pinkychase1); + break; + case en_inky: + SpawnNewObj (tilex,tiley,&s_inkychase1); + break; + } - newobj->obclass = ghostobj; - newobj->speed = SPDDOG; + newobj->obclass = ghostobj; + newobj->speed = SPDDOG; - newobj->dir = east; - newobj->flags |= FL_AMBUSH; - if (!loadedgame) - { - gamestate.killtotal++; - gamestate.killcount++; - } + newobj->dir = east; + newobj->flags |= FL_AMBUSH; + if (!loadedgame) + { + gamestate.killtotal++; + gamestate.killcount++; + } } @@ -2213,20 +2187,20 @@ statetype s_fatshoot6 = {false,SPR_FAT_SHOOT4,10,NULL,(statefunc)T_Sho void SpawnSchabbs (int tilex, int tiley) { - if (DigiMode != sds_Off) - s_schabbdie2.tictime = 140; - else - s_schabbdie2.tictime = 5; + if (DigiMode != sds_Off) + s_schabbdie2.tictime = 140; + else + s_schabbdie2.tictime = 5; - SpawnNewObj (tilex,tiley,&s_schabbstand); - newobj->speed = SPDPATROL; + SpawnNewObj (tilex,tiley,&s_schabbstand); + newobj->speed = SPDPATROL; - newobj->obclass = schabbobj; - newobj->hitpoints = starthitpoints[gamestate.difficulty][en_schabbs]; - newobj->dir = nodir; - newobj->flags |= FL_SHOOTABLE|FL_AMBUSH; - if (!loadedgame) - gamestate.killtotal++; + newobj->obclass = schabbobj; + newobj->hitpoints = starthitpoints[gamestate.difficulty][en_schabbs]; + newobj->dir = nodir; + newobj->flags |= FL_SHOOTABLE|FL_AMBUSH; + if (!loadedgame) + gamestate.killtotal++; } @@ -2240,20 +2214,20 @@ void SpawnSchabbs (int tilex, int tiley) void SpawnGift (int tilex, int tiley) { - if (DigiMode != sds_Off) - s_giftdie2.tictime = 140; - else - s_giftdie2.tictime = 5; + if (DigiMode != sds_Off) + s_giftdie2.tictime = 140; + else + s_giftdie2.tictime = 5; - SpawnNewObj (tilex,tiley,&s_giftstand); - newobj->speed = SPDPATROL; + SpawnNewObj (tilex,tiley,&s_giftstand); + newobj->speed = SPDPATROL; - newobj->obclass = giftobj; - newobj->hitpoints = starthitpoints[gamestate.difficulty][en_gift]; - newobj->dir = nodir; - newobj->flags |= FL_SHOOTABLE|FL_AMBUSH; - if (!loadedgame) - gamestate.killtotal++; + newobj->obclass = giftobj; + newobj->hitpoints = starthitpoints[gamestate.difficulty][en_gift]; + newobj->dir = nodir; + newobj->flags |= FL_SHOOTABLE|FL_AMBUSH; + if (!loadedgame) + gamestate.killtotal++; } @@ -2267,20 +2241,20 @@ void SpawnGift (int tilex, int tiley) void SpawnFat (int tilex, int tiley) { - if (DigiMode != sds_Off) - s_fatdie2.tictime = 140; - else - s_fatdie2.tictime = 5; + if (DigiMode != sds_Off) + s_fatdie2.tictime = 140; + else + s_fatdie2.tictime = 5; - SpawnNewObj (tilex,tiley,&s_fatstand); - newobj->speed = SPDPATROL; + SpawnNewObj (tilex,tiley,&s_fatstand); + newobj->speed = SPDPATROL; - newobj->obclass = fatobj; - newobj->hitpoints = starthitpoints[gamestate.difficulty][en_fat]; - newobj->dir = nodir; - newobj->flags |= FL_SHOOTABLE|FL_AMBUSH; - if (!loadedgame) - gamestate.killtotal++; + newobj->obclass = fatobj; + newobj->hitpoints = starthitpoints[gamestate.difficulty][en_fat]; + newobj->dir = nodir; + newobj->flags |= FL_SHOOTABLE|FL_AMBUSH; + if (!loadedgame) + gamestate.killtotal++; } @@ -2294,34 +2268,34 @@ void SpawnFat (int tilex, int tiley) void T_SchabbThrow (objtype *ob) { - int32_t deltax,deltay; - float angle; - int iangle; + int32_t deltax,deltay; + float angle; + int iangle; - deltax = player->x - ob->x; - deltay = ob->y - player->y; - angle = (float) atan2((float) deltay, (float) deltax); - if (angle<0) - angle = (float) (M_PI*2+angle); - iangle = (int) (angle/(M_PI*2)*ANGLES); + deltax = player->x - ob->x; + deltay = ob->y - player->y; + angle = (float) atan2((float) deltay, (float) deltax); + if (angle<0) + angle = (float) (M_PI*2+angle); + iangle = (int) (angle/(M_PI*2)*ANGLES); - GetNewActor (); - newobj->state = &s_needle1; - newobj->ticcount = 1; + GetNewActor (); + newobj->state = &s_needle1; + newobj->ticcount = 1; - newobj->tilex = ob->tilex; - newobj->tiley = ob->tiley; - newobj->x = ob->x; - newobj->y = ob->y; - newobj->obclass = needleobj; - newobj->dir = nodir; - newobj->angle = iangle; - newobj->speed = 0x2000l; + newobj->tilex = ob->tilex; + newobj->tiley = ob->tiley; + newobj->x = ob->x; + newobj->y = ob->y; + newobj->obclass = needleobj; + newobj->dir = nodir; + newobj->angle = iangle; + newobj->speed = 0x2000l; - newobj->flags = FL_NEVERMARK; - newobj->active = ac_yes; + newobj->flags = FL_NEVERMARK; + newobj->active = ac_yes; - PlaySoundLocActor (SCHABBSTHROWSND,newobj); + PlaySoundLocActor (SCHABBSTHROWSND,newobj); } /* @@ -2334,34 +2308,34 @@ void T_SchabbThrow (objtype *ob) void T_GiftThrow (objtype *ob) { - int32_t deltax,deltay; - float angle; - int iangle; + int32_t deltax,deltay; + float angle; + int iangle; - deltax = player->x - ob->x; - deltay = ob->y - player->y; - angle = (float) atan2((float) deltay, (float) deltax); - if (angle<0) - angle = (float) (M_PI*2+angle); - iangle = (int) (angle/(M_PI*2)*ANGLES); + deltax = player->x - ob->x; + deltay = ob->y - player->y; + angle = (float) atan2((float) deltay, (float) deltax); + if (angle<0) + angle = (float) (M_PI*2+angle); + iangle = (int) (angle/(M_PI*2)*ANGLES); - GetNewActor (); - newobj->state = &s_rocket; - newobj->ticcount = 1; + GetNewActor (); + newobj->state = &s_rocket; + newobj->ticcount = 1; - newobj->tilex = ob->tilex; - newobj->tiley = ob->tiley; - newobj->x = ob->x; - newobj->y = ob->y; - newobj->obclass = rocketobj; - newobj->dir = nodir; - newobj->angle = iangle; - newobj->speed = 0x2000l; - newobj->flags = FL_NEVERMARK; - newobj->active = ac_yes; + newobj->tilex = ob->tilex; + newobj->tiley = ob->tiley; + newobj->x = ob->x; + newobj->y = ob->y; + newobj->obclass = rocketobj; + newobj->dir = nodir; + newobj->angle = iangle; + newobj->speed = 0x2000l; + newobj->flags = FL_NEVERMARK; + newobj->active = ac_yes; #ifndef APOGEE_1_0 // T_GiftThrow will never be called in shareware v1.0 - PlaySoundLocActor (MISSILEFIRESND,newobj); + PlaySoundLocActor (MISSILEFIRESND,newobj); #endif } @@ -2376,85 +2350,77 @@ void T_GiftThrow (objtype *ob) void T_Schabb (objtype *ob) { - int32_t move; - int dx,dy,dist; - boolean dodge; + int32_t move; + int dx,dy,dist; + boolean dodge; - dodge = false; - dx = abs(ob->tilex - player->tilex); - dy = abs(ob->tiley - player->tiley); - dist = dx>dy ? dx : dy; + dodge = false; + dx = abs(ob->tilex - player->tilex); + dy = abs(ob->tiley - player->tiley); + dist = dx>dy ? dx : dy; - if (CheckLine(ob)) // got a shot at player? - { - ob->hidden = false; - if ( (unsigned) US_RndT() < (tics<<3) && objfreelist) - { - // - // go into attack frame - // - NewState (ob,&s_schabbshoot1); + if (CheckLine(ob)) // got a shot at player? + { + ob->hidden = false; + if ( (unsigned) US_RndT() < (tics<<3) && objfreelist) + { + // go into attack frame + NewState (ob,&s_schabbshoot1); + return; + } + dodge = true; + } + else + ob->hidden = true; + + if (ob->dir == nodir) + { + if (dodge) + SelectDodgeDir (ob); + else + SelectChaseDir (ob); + if (ob->dir == nodir) + return; // object is blocked in + } + + move = ob->speed*tics; + + while (move) + { + if (ob->distance < 0) + { + // waiting for a door to open + OpenDoor (-ob->distance-1); + if (doorobjlist[-ob->distance-1].action != dr_open) return; - } - dodge = true; - } - else - ob->hidden = true; + ob->distance = TILEGLOBAL; // go ahead, the door is now open + TryWalk(ob); + } - if (ob->dir == nodir) - { - if (dodge) - SelectDodgeDir (ob); - else - SelectChaseDir (ob); - if (ob->dir == nodir) - return; // object is blocked in - } + if (move < ob->distance) + { + MoveObj (ob,move); + break; + } - move = ob->speed*tics; + // reached goal tile, so select another one - while (move) - { - if (ob->distance < 0) - { - // - // waiting for a door to open - // - OpenDoor (-ob->distance-1); - if (doorobjlist[-ob->distance-1].action != dr_open) - return; - ob->distance = TILEGLOBAL; // go ahead, the door is now open - TryWalk(ob); - } + // fix position to account for round off during moving + ob->x = ((int32_t)ob->tilex<y = ((int32_t)ob->tiley<distance) - { - MoveObj (ob,move); - break; - } + move -= ob->distance; - // - // reached goal tile, so select another one - // + if (dist <4) + SelectRunDir (ob); + else if (dodge) + SelectDodgeDir (ob); + else + SelectChaseDir (ob); - // - // fix position to account for round off during moving - // - ob->x = ((int32_t)ob->tilex<y = ((int32_t)ob->tiley<distance; - - if (dist <4) - SelectRunDir (ob); - else if (dodge) - SelectDodgeDir (ob); - else - SelectChaseDir (ob); - - if (ob->dir == nodir) - return; // object is blocked in - } + if (ob->dir == nodir) + return; // object is blocked in + } } @@ -2468,85 +2434,77 @@ void T_Schabb (objtype *ob) void T_Gift (objtype *ob) { - int32_t move; - int dx,dy,dist; - boolean dodge; + int32_t move; + int dx,dy,dist; + boolean dodge; - dodge = false; - dx = abs(ob->tilex - player->tilex); - dy = abs(ob->tiley - player->tiley); - dist = dx>dy ? dx : dy; + dodge = false; + dx = abs(ob->tilex - player->tilex); + dy = abs(ob->tiley - player->tiley); + dist = dx>dy ? dx : dy; - if (CheckLine(ob)) // got a shot at player? - { - ob->hidden = false; - if ( (unsigned) US_RndT() < (tics<<3) && objfreelist) - { - // - // go into attack frame - // - NewState (ob,&s_giftshoot1); + if (CheckLine(ob)) // got a shot at player? + { + ob->hidden = false; + if ( (unsigned) US_RndT() < (tics<<3) && objfreelist) + { + // go into attack frame + NewState (ob,&s_giftshoot1); + return; + } + dodge = true; + } + else + ob->hidden = true; + + if (ob->dir == nodir) + { + if (dodge) + SelectDodgeDir (ob); + else + SelectChaseDir (ob); + if (ob->dir == nodir) + return; // object is blocked in + } + + move = ob->speed*tics; + + while (move) + { + if (ob->distance < 0) + { + // waiting for a door to open + OpenDoor (-ob->distance-1); + if (doorobjlist[-ob->distance-1].action != dr_open) return; - } - dodge = true; - } - else - ob->hidden = true; + ob->distance = TILEGLOBAL; // go ahead, the door is now open + TryWalk(ob); + } - if (ob->dir == nodir) - { - if (dodge) - SelectDodgeDir (ob); - else - SelectChaseDir (ob); - if (ob->dir == nodir) - return; // object is blocked in - } + if (move < ob->distance) + { + MoveObj (ob,move); + break; + } - move = ob->speed*tics; + // reached goal tile, so select another one - while (move) - { - if (ob->distance < 0) - { - // - // waiting for a door to open - // - OpenDoor (-ob->distance-1); - if (doorobjlist[-ob->distance-1].action != dr_open) - return; - ob->distance = TILEGLOBAL; // go ahead, the door is now open - TryWalk(ob); - } + // fix position to account for round off during moving + ob->x = ((int32_t)ob->tilex<y = ((int32_t)ob->tiley<distance) - { - MoveObj (ob,move); - break; - } + move -= ob->distance; - // - // reached goal tile, so select another one - // + if (dist <4) + SelectRunDir (ob); + else if (dodge) + SelectDodgeDir (ob); + else + SelectChaseDir (ob); - // - // fix position to account for round off during moving - // - ob->x = ((int32_t)ob->tilex<y = ((int32_t)ob->tiley<distance; - - if (dist <4) - SelectRunDir (ob); - else if (dodge) - SelectDodgeDir (ob); - else - SelectChaseDir (ob); - - if (ob->dir == nodir) - return; // object is blocked in - } + if (ob->dir == nodir) + return; // object is blocked in + } } @@ -2560,85 +2518,77 @@ void T_Gift (objtype *ob) void T_Fat (objtype *ob) { - int32_t move; - int dx,dy,dist; - boolean dodge; + int32_t move; + int dx,dy,dist; + boolean dodge; - dodge = false; - dx = abs(ob->tilex - player->tilex); - dy = abs(ob->tiley - player->tiley); - dist = dx>dy ? dx : dy; + dodge = false; + dx = abs(ob->tilex - player->tilex); + dy = abs(ob->tiley - player->tiley); + dist = dx>dy ? dx : dy; - if (CheckLine(ob)) // got a shot at player? - { - ob->hidden = false; - if ( (unsigned) US_RndT() < (tics<<3) && objfreelist) - { - // - // go into attack frame - // - NewState (ob,&s_fatshoot1); + if (CheckLine(ob)) // got a shot at player? + { + ob->hidden = false; + if ( (unsigned) US_RndT() < (tics<<3) && objfreelist) + { + // go into attack frame + NewState (ob,&s_fatshoot1); + return; + } + dodge = true; + } + else + ob->hidden = true; + + if (ob->dir == nodir) + { + if (dodge) + SelectDodgeDir (ob); + else + SelectChaseDir (ob); + if (ob->dir == nodir) + return; // object is blocked in + } + + move = ob->speed*tics; + + while (move) + { + if (ob->distance < 0) + { + // waiting for a door to open + OpenDoor (-ob->distance-1); + if (doorobjlist[-ob->distance-1].action != dr_open) return; - } - dodge = true; - } - else - ob->hidden = true; + ob->distance = TILEGLOBAL; // go ahead, the door is now open + TryWalk(ob); + } - if (ob->dir == nodir) - { - if (dodge) - SelectDodgeDir (ob); - else - SelectChaseDir (ob); - if (ob->dir == nodir) - return; // object is blocked in - } + if (move < ob->distance) + { + MoveObj (ob,move); + break; + } - move = ob->speed*tics; + // reached goal tile, so select another one - while (move) - { - if (ob->distance < 0) - { - // - // waiting for a door to open - // - OpenDoor (-ob->distance-1); - if (doorobjlist[-ob->distance-1].action != dr_open) - return; - ob->distance = TILEGLOBAL; // go ahead, the door is now open - TryWalk(ob); - } + // fix position to account for round off during moving + ob->x = ((int32_t)ob->tilex<y = ((int32_t)ob->tiley<distance) - { - MoveObj (ob,move); - break; - } + move -= ob->distance; - // - // reached goal tile, so select another one - // + if (dist <4) + SelectRunDir (ob); + else if (dodge) + SelectDodgeDir (ob); + else + SelectChaseDir (ob); - // - // fix position to account for round off during moving - // - ob->x = ((int32_t)ob->tilex<y = ((int32_t)ob->tiley<distance; - - if (dist <4) - SelectRunDir (ob); - else if (dodge) - SelectDodgeDir (ob); - else - SelectChaseDir (ob); - - if (ob->dir == nodir) - return; // object is blocked in - } + if (ob->dir == nodir) + return; // object is blocked in + } } @@ -2823,23 +2773,22 @@ statetype s_hitlershoot6 = {false,SPR_HITLER_SHOOT2,10,NULL,(statefunc)T_ void SpawnFakeHitler (int tilex, int tiley) { - if (DigiMode != sds_Off) - s_hitlerdie2.tictime = 140; - else - s_hitlerdie2.tictime = 5; + if (DigiMode != sds_Off) + s_hitlerdie2.tictime = 140; + else + s_hitlerdie2.tictime = 5; - SpawnNewObj (tilex,tiley,&s_fakestand); - newobj->speed = SPDPATROL; + SpawnNewObj (tilex,tiley,&s_fakestand); + newobj->speed = SPDPATROL; - newobj->obclass = fakeobj; - newobj->hitpoints = starthitpoints[gamestate.difficulty][en_fake]; - newobj->dir = nodir; - newobj->flags |= FL_SHOOTABLE|FL_AMBUSH; - if (!loadedgame) - gamestate.killtotal++; + newobj->obclass = fakeobj; + newobj->hitpoints = starthitpoints[gamestate.difficulty][en_fake]; + newobj->dir = nodir; + newobj->flags |= FL_SHOOTABLE|FL_AMBUSH; + if (!loadedgame) + gamestate.killtotal++; } - /* =============== = @@ -2850,21 +2799,21 @@ void SpawnFakeHitler (int tilex, int tiley) void SpawnHitler (int tilex, int tiley) { - if (DigiMode != sds_Off) - s_hitlerdie2.tictime = 140; - else - s_hitlerdie2.tictime = 5; + if (DigiMode != sds_Off) + s_hitlerdie2.tictime = 140; + else + s_hitlerdie2.tictime = 5; - SpawnNewObj (tilex,tiley,&s_mechastand); - newobj->speed = SPDPATROL; + SpawnNewObj (tilex,tiley,&s_mechastand); + newobj->speed = SPDPATROL; - newobj->obclass = mechahitlerobj; - newobj->hitpoints = starthitpoints[gamestate.difficulty][en_hitler]; - newobj->dir = nodir; - newobj->flags |= FL_SHOOTABLE|FL_AMBUSH; - if (!loadedgame) - gamestate.killtotal++; + newobj->obclass = mechahitlerobj; + newobj->hitpoints = starthitpoints[gamestate.difficulty][en_hitler]; + newobj->dir = nodir; + newobj->flags |= FL_SHOOTABLE|FL_AMBUSH; + if (!loadedgame) + gamestate.killtotal++; } @@ -2878,21 +2827,21 @@ void SpawnHitler (int tilex, int tiley) void A_HitlerMorph (objtype *ob) { - short hitpoints[4]={500,700,800,900}; + short hitpoints[4]={500,700,800,900}; - SpawnNewObj (ob->tilex,ob->tiley,&s_hitlerchase1); - newobj->speed = SPDPATROL*5; + SpawnNewObj (ob->tilex,ob->tiley,&s_hitlerchase1); + newobj->speed = SPDPATROL*5; - newobj->x = ob->x; - newobj->y = ob->y; + newobj->x = ob->x; + newobj->y = ob->y; - newobj->distance = ob->distance; - newobj->dir = ob->dir; - newobj->flags = ob->flags | FL_SHOOTABLE; - newobj->flags &= ~FL_NONMARK; // hitler stuck with nodir fix + newobj->distance = ob->distance; + newobj->dir = ob->dir; + newobj->flags = ob->flags | FL_SHOOTABLE; + newobj->flags &= ~FL_NONMARK; // hitler stuck with nodir fix - newobj->obclass = realhitlerobj; - newobj->hitpoints = hitpoints[gamestate.difficulty]; + newobj->obclass = realhitlerobj; + newobj->hitpoints = hitpoints[gamestate.difficulty]; } @@ -2904,13 +2853,13 @@ void A_HitlerMorph (objtype *ob) //////////////////////////////////////////////////////// void A_MechaSound (objtype *ob) { - if (areabyplayer[ob->areanumber]) - PlaySoundLocActor (MECHSTEPSND,ob); + if (areabyplayer[ob->areanumber]) + PlaySoundLocActor (MECHSTEPSND,ob); } void A_Slurpie (objtype *ob) { - SD_PlaySound(SLURPIESND); + SD_PlaySound(SLURPIESND); } /* @@ -2923,43 +2872,42 @@ void A_Slurpie (objtype *ob) void T_FakeFire (objtype *ob) { - int32_t deltax,deltay; - float angle; - int iangle; + int32_t deltax,deltay; + float angle; + int iangle; - if (!objfreelist) // stop shooting if over MAXACTORS - { - NewState (ob,&s_fakechase1); - return; - } + if (!objfreelist) // stop shooting if over MAXACTORS + { + NewState (ob,&s_fakechase1); + return; + } - deltax = player->x - ob->x; - deltay = ob->y - player->y; - angle = (float) atan2((float) deltay, (float) deltax); - if (angle<0) - angle = (float)(M_PI*2+angle); - iangle = (int) (angle/(M_PI*2)*ANGLES); + deltax = player->x - ob->x; + deltay = ob->y - player->y; + angle = (float) atan2((float) deltay, (float) deltax); + if (angle<0) + angle = (float)(M_PI*2+angle); + iangle = (int) (angle/(M_PI*2)*ANGLES); - GetNewActor (); - newobj->state = &s_fire1; - newobj->ticcount = 1; + GetNewActor (); + newobj->state = &s_fire1; + newobj->ticcount = 1; - newobj->tilex = ob->tilex; - newobj->tiley = ob->tiley; - newobj->x = ob->x; - newobj->y = ob->y; - newobj->dir = nodir; - newobj->angle = iangle; - newobj->obclass = fireobj; - newobj->speed = 0x1200l; - newobj->flags = FL_NEVERMARK; - newobj->active = ac_yes; + newobj->tilex = ob->tilex; + newobj->tiley = ob->tiley; + newobj->x = ob->x; + newobj->y = ob->y; + newobj->dir = nodir; + newobj->angle = iangle; + newobj->obclass = fireobj; + newobj->speed = 0x1200l; + newobj->flags = FL_NEVERMARK; + newobj->active = ac_yes; - PlaySoundLocActor (FLAMETHROWERSND,newobj); + PlaySoundLocActor (FLAMETHROWERSND,newobj); } - /* ================= = @@ -2970,57 +2918,53 @@ void T_FakeFire (objtype *ob) void T_Fake (objtype *ob) { - int32_t move; + int32_t move; - if (CheckLine(ob)) // got a shot at player? - { - ob->hidden = false; - if ( (unsigned) US_RndT() < (tics<<1) && objfreelist) - { - // - // go into attack frame - // - NewState (ob,&s_fakeshoot1); - return; - } - } - else - ob->hidden = true; + if (CheckLine(ob)) // got a shot at player? + { + ob->hidden = false; + if ( (unsigned) US_RndT() < (tics<<1) && objfreelist) + { + // + // go into attack frame + // + NewState (ob,&s_fakeshoot1); + return; + } + } + else + ob->hidden = true; - if (ob->dir == nodir) - { - SelectDodgeDir (ob); - if (ob->dir == nodir) - return; // object is blocked in - } + if (ob->dir == nodir) + { + SelectDodgeDir (ob); + if (ob->dir == nodir) + return; // object is blocked in + } - move = ob->speed*tics; + move = ob->speed*tics; - while (move) - { - if (move < ob->distance) - { - MoveObj (ob,move); - break; - } + while (move) + { + if (move < ob->distance) + { + MoveObj (ob,move); + break; + } - // - // reached goal tile, so select another one - // + // reached goal tile, so select another one - // - // fix position to account for round off during moving - // - ob->x = ((int32_t)ob->tilex<y = ((int32_t)ob->tiley<x = ((int32_t)ob->tilex<y = ((int32_t)ob->tiley<distance; + move -= ob->distance; - SelectDodgeDir (ob); + SelectDodgeDir (ob); - if (ob->dir == nodir) - return; // object is blocked in - } + if (ob->dir == nodir) + return; // object is blocked in + } } #endif @@ -3110,9 +3054,7 @@ void T_Chase (objtype *ob) if ( US_RndT()obclass) { case guardobj: @@ -3181,9 +3123,7 @@ void T_Chase (objtype *ob) { if (ob->distance < 0) { - // // waiting for a door to open - // OpenDoor (-ob->distance-1); if (doorobjlist[-ob->distance-1].action != dr_open) return; @@ -3200,13 +3140,9 @@ void T_Chase (objtype *ob) break; } - // // reached goal tile, so select another one - // - // // fix position to account for round off during moving - // ob->x = ((int32_t)ob->tilex<y = ((int32_t)ob->tiley<dir == nodir) - { - SelectChaseDir (ob); - if (ob->dir == nodir) - return; // object is blocked in - } + if (ob->dir == nodir) + { + SelectChaseDir (ob); + if (ob->dir == nodir) + return; // object is blocked in + } - move = ob->speed*tics; + move = ob->speed*tics; - while (move) - { - if (move < ob->distance) - { - MoveObj (ob,move); - break; - } + while (move) + { + if (move < ob->distance) + { + MoveObj (ob,move); + break; + } - // - // reached goal tile, so select another one - // + // reached goal tile, so select another one - // - // fix position to account for round off during moving - // - ob->x = ((int32_t)ob->tilex<y = ((int32_t)ob->tiley<x = ((int32_t)ob->tilex<y = ((int32_t)ob->tiley<distance; + move -= ob->distance; - SelectChaseDir (ob); + SelectChaseDir (ob); - if (ob->dir == nodir) - return; // object is blocked in - } + if (ob->dir == nodir) + return; // object is blocked in + } } /* @@ -3281,64 +3213,62 @@ void T_Ghosts (objtype *ob) void T_DogChase (objtype *ob) { - int32_t move; - int32_t dx,dy; + int32_t move; + int32_t dx,dy; - if (ob->dir == nodir) - { - SelectDodgeDir (ob); - if (ob->dir == nodir) - return; // object is blocked in - } + if (ob->dir == nodir) + { + SelectDodgeDir (ob); + if (ob->dir == nodir) + return; // object is blocked in + } - move = ob->speed*tics; + move = ob->speed*tics; - while (move) - { - // - // check for byte range - // - dx = player->x - ob->x; - if (dx<0) - dx = -dx; - dx -= move; - if (dx <= MINACTORDIST) - { - dy = player->y - ob->y; - if (dy<0) - dy = -dy; - dy -= move; - if (dy <= MINACTORDIST) - { - NewState (ob,&s_dogjump1); - return; - } - } + while (move) + { + // check for byte range + dx = player->x - ob->x; + if (dx<0) + dx = -dx; + dx -= move; + if (dx <= MINACTORDIST) + { + dy = player->y - ob->y; + if (dy<0) + dy = -dy; + dy -= move; + if (dy <= MINACTORDIST) + { + NewState (ob,&s_dogjump1); + return; + } + } - if (move < ob->distance) - { - MoveObj (ob,move); - break; - } + if (move < ob->distance) + { + MoveObj (ob,move); + break; + } - // - // reached goal tile, so select another one - // + // + // reached goal tile, so select another one + // - // - // fix position to account for round off during moving - // - ob->x = ((int32_t)ob->tilex<y = ((int32_t)ob->tiley<x = ((int32_t)ob->tilex<y = ((int32_t)ob->tiley<distance; + move -= ob->distance; - SelectDodgeDir (ob); + SelectDodgeDir (ob); - if (ob->dir == nodir) - return; // object is blocked in - } + if (ob->dir == nodir) + return; // object is blocked in + } } @@ -3362,20 +3292,20 @@ void T_DogChase (objtype *ob) void SelectPathDir (objtype *ob) { - unsigned spot; + unsigned spot; - spot = MAPSPOT(ob->tilex,ob->tiley,1)-ICONARROWS; + spot = MAPSPOT(ob->tilex,ob->tiley,1)-ICONARROWS; - if (spot<8) - { - // new direction - ob->dir = (dirtype)(spot); - } + if (spot<8) + { + // new direction + ob->dir = (dirtype)(spot); + } - ob->distance = TILEGLOBAL; + ob->distance = TILEGLOBAL; - if (!TryWalk (ob)) - ob->dir = nodir; + if (!TryWalk (ob)) + ob->dir = nodir; } @@ -3389,60 +3319,58 @@ void SelectPathDir (objtype *ob) void T_Path (objtype *ob) { - int32_t move; + int32_t move; - if (SightPlayer (ob)) - return; + if (SightPlayer (ob)) + return; - if (ob->dir == nodir) - { - SelectPathDir (ob); - if (ob->dir == nodir) - return; // all movement is blocked - } + if (ob->dir == nodir) + { + SelectPathDir (ob); + if (ob->dir == nodir) + return; // all movement is blocked + } - move = ob->speed*tics; + move = ob->speed*tics; - while (move) - { - if (ob->distance < 0) - { - // - // waiting for a door to open - // - OpenDoor (-ob->distance-1); - if (doorobjlist[-ob->distance-1].action != dr_open) - return; - ob->distance = TILEGLOBAL; // go ahead, the door is now open - DEMOIF_SDL - { - TryWalk(ob); - } - } + while (move) + { + if (ob->distance < 0) + { + // waiting for a door to open + OpenDoor (-ob->distance-1); + if (doorobjlist[-ob->distance-1].action != dr_open) + return; + ob->distance = TILEGLOBAL; // go ahead, the door is now open + DEMOIF_SDL + { + TryWalk(ob); + } + } - if (move < ob->distance) - { - MoveObj (ob,move); - break; - } + if (move < ob->distance) + { + MoveObj (ob,move); + break; + } - if (ob->tilex>MAPSIZE || ob->tiley>MAPSIZE) - { - sprintf (str, "T_Path hit a wall at %u,%u, dir %u", - ob->tilex,ob->tiley,ob->dir); - Quit (str); - } + if (ob->tilex>MAPSIZE || ob->tiley>MAPSIZE) + { + sprintf (str, "T_Path hit a wall at %u,%u, dir %u", + ob->tilex,ob->tiley,ob->dir); + Quit (str); + } - ob->x = ((int32_t)ob->tilex<y = ((int32_t)ob->tiley<distance; + ob->x = ((int32_t)ob->tilex<y = ((int32_t)ob->tiley<distance; - SelectPathDir (ob); + SelectPathDir (ob); - if (ob->dir == nodir) - return; // all movement is blocked - } + if (ob->dir == nodir) + return; // all movement is blocked + } } @@ -3467,80 +3395,80 @@ void T_Path (objtype *ob) void T_Shoot (objtype *ob) { - int dx,dy,dist; - int hitchance,damage; + int dx,dy,dist; + int hitchance,damage; - hitchance = 128; + hitchance = 128; - if (!areabyplayer[ob->areanumber]) - return; + if (!areabyplayer[ob->areanumber]) + return; - if (CheckLine (ob)) // player is not behind a wall - { - dx = abs(ob->tilex - player->tilex); - dy = abs(ob->tiley - player->tiley); - dist = dx>dy ? dx:dy; + if (CheckLine (ob)) // player is not behind a wall + { + dx = abs(ob->tilex - player->tilex); + dy = abs(ob->tiley - player->tiley); + dist = dx>dy ? dx:dy; - if (ob->obclass == ssobj || ob->obclass == bossobj) - dist = dist*2/3; // ss are better shots + if (ob->obclass == ssobj || ob->obclass == bossobj) + dist = dist*2/3; // ss are better shots - if (thrustspeed >= RUNSPEED) - { - if (ob->flags&FL_VISABLE) - hitchance = 160-dist*16; // player can see to dodge - else - hitchance = 160-dist*8; - } - else - { - if (ob->flags&FL_VISABLE) - hitchance = 256-dist*16; // player can see to dodge - else - hitchance = 256-dist*8; - } + if (thrustspeed >= RUNSPEED) + { + if (ob->flags&FL_VISABLE) + hitchance = 160-dist*16; // player can see to dodge + else + hitchance = 160-dist*8; + } + else + { + if (ob->flags&FL_VISABLE) + hitchance = 256-dist*16; // player can see to dodge + else + hitchance = 256-dist*8; + } - // see if the shot was a hit + // see if the shot was a hit - if (US_RndT()>2; - else if (dist<4) - damage = US_RndT()>>3; - else - damage = US_RndT()>>4; + if (US_RndT()>2; + else if (dist<4) + damage = US_RndT()>>3; + else + damage = US_RndT()>>4; - TakeDamage (damage,ob); - } - } + TakeDamage (damage,ob); + } + } - switch(ob->obclass) - { - case ssobj: - PlaySoundLocActor(SSFIRESND,ob); - break; + switch(ob->obclass) + { + case ssobj: + PlaySoundLocActor(SSFIRESND,ob); + break; #ifndef SPEAR #ifndef APOGEE_1_0 - case giftobj: - case fatobj: - PlaySoundLocActor(MISSILEFIRESND,ob); - break; + case giftobj: + case fatobj: + PlaySoundLocActor(MISSILEFIRESND,ob); + break; #endif - case mechahitlerobj: - case realhitlerobj: - case bossobj: - PlaySoundLocActor(BOSSFIRESND,ob); - break; - case schabbobj: - PlaySoundLocActor(SCHABBSTHROWSND,ob); - break; - case fakeobj: - PlaySoundLocActor(FLAMETHROWERSND,ob); - break; + case mechahitlerobj: + case realhitlerobj: + case bossobj: + PlaySoundLocActor(BOSSFIRESND,ob); + break; + case schabbobj: + PlaySoundLocActor(SCHABBSTHROWSND,ob); + break; + case fakeobj: + PlaySoundLocActor(FLAMETHROWERSND,ob); + break; #endif - default: - PlaySoundLocActor(NAZIFIRESND,ob); - } + default: + PlaySoundLocActor(NAZIFIRESND,ob); + } } @@ -3554,29 +3482,29 @@ void T_Shoot (objtype *ob) void T_Bite (objtype *ob) { - int32_t dx,dy; + int32_t dx,dy; - PlaySoundLocActor(DOGATTACKSND,ob); // JAB + PlaySoundLocActor(DOGATTACKSND,ob); // JAB - dx = player->x - ob->x; - if (dx<0) - dx = -dx; - dx -= TILEGLOBAL; - if (dx <= MINACTORDIST) - { - dy = player->y - ob->y; - if (dy<0) - dy = -dy; - dy -= TILEGLOBAL; - if (dy <= MINACTORDIST) - { - if (US_RndT()<180) - { - TakeDamage (US_RndT()>>4,ob); - return; - } - } - } + dx = player->x - ob->x; + if (dx<0) + dx = -dx; + dx -= TILEGLOBAL; + if (dx <= MINACTORDIST) + { + dy = player->y - ob->y; + if (dy<0) + dy = -dy; + dy -= TILEGLOBAL; + if (dy <= MINACTORDIST) + { + if (US_RndT()<180) + { + TakeDamage (US_RndT()>>4,ob); + return; + } + } + } } @@ -3757,9 +3685,7 @@ boolean CheckPosition (objtype *ob) xh = (ob->x+PLAYERSIZE) >> TILESHIFT; yh = (ob->y+PLAYERSIZE) >> TILESHIFT; - // // check for solid walls - // for (y=yl;y<=yh;y++) { for (x=xl;x<=xh;x++) @@ -3784,115 +3710,111 @@ boolean CheckPosition (objtype *ob) void A_StartDeathCam (objtype *ob) { - int32_t dx,dy; - float fangle; - int32_t xmove,ymove; - int32_t dist; + int32_t dx,dy; + float fangle; + int32_t xmove,ymove; + int32_t dist; - FinishPaletteShifts (); + FinishPaletteShifts (); - VW_WaitVBL (100); + VW_WaitVBL (100); - if (gamestate.victoryflag) - { - playstate = ex_victorious; // exit castle tile - return; - } + if (gamestate.victoryflag) + { + playstate = ex_victorious; // exit castle tile + return; + } - if(usedoublebuffering) VH_UpdateScreen(); + if(usedoublebuffering) VH_UpdateScreen(); - gamestate.victoryflag = true; - unsigned fadeheight = viewsize != 21 ? screenHeight-scaleFactor*STATUSLINES : screenHeight; - VL_BarScaledCoord (0, 0, screenWidth, fadeheight, bordercol); - FizzleFade(screenBuffer, 0, 0, screenWidth, fadeheight, 70, false); + gamestate.victoryflag = true; + unsigned fadeheight = viewsize != 21 ? screenHeight-scaleFactor*STATUSLINES : screenHeight; + VL_BarScaledCoord (0, 0, screenWidth, fadeheight, bordercol); + FizzleFade(screenBuffer, 0, 0, screenWidth, fadeheight, 70, false); - if (bordercol != VIEWCOLOR) - { - CA_CacheGrChunk (STARTFONT+1); - fontnumber = 1; - SETFONTCOLOR(15,bordercol); - PrintX = 68; PrintY = 45; - US_Print (STR_SEEAGAIN); - UNCACHEGRCHUNK(STARTFONT+1); - } - else - { - CacheLump(LEVELEND_LUMP_START,LEVELEND_LUMP_END); + if (bordercol != VIEWCOLOR) + { + CA_CacheGrChunk (STARTFONT+1); + fontnumber = 1; + SETFONTCOLOR(15,bordercol); + PrintX = 68; PrintY = 45; + US_Print (STR_SEEAGAIN); + UNCACHEGRCHUNK(STARTFONT+1); + } + else + { + CacheLump(LEVELEND_LUMP_START,LEVELEND_LUMP_END); #ifdef JAPAN #ifndef JAPDEMO - CA_CacheScreen(C_LETSSEEPIC); + CA_CacheScreen(C_LETSSEEPIC); #endif #else - Write(0,7,STR_SEEAGAIN); + Write(0,7,STR_SEEAGAIN); #endif - } + } - VW_UpdateScreen (); - if(usedoublebuffering) VH_UpdateScreen(); + VW_UpdateScreen (); + if(usedoublebuffering) VH_UpdateScreen(); - IN_UserInput(300); + IN_UserInput(300); - // - // line angle up exactly - // - NewState (player,&s_deathcam); + // line angle up exactly + NewState (player,&s_deathcam); - player->x = gamestate.killx; - player->y = gamestate.killy; + player->x = gamestate.killx; + player->y = gamestate.killy; - dx = ob->x - player->x; - dy = player->y - ob->y; + dx = ob->x - player->x; + dy = player->y - ob->y; - fangle = (float) atan2((float) dy, (float) dx); // returns -pi to pi - if (fangle<0) - fangle = (float) (M_PI*2+fangle); + fangle = (float) atan2((float) dy, (float) dx); // returns -pi to pi + if (fangle<0) + fangle = (float) (M_PI*2+fangle); - player->angle = (short) (fangle/(M_PI*2)*ANGLES); + player->angle = (short) (fangle/(M_PI*2)*ANGLES); - // - // try to position as close as possible without being in a wall - // - dist = 0x14000l; - do - { - xmove = FixedMul(dist,costable[player->angle]); - ymove = -FixedMul(dist,sintable[player->angle]); + // try to position as close as possible without being in a wall + dist = 0x14000l; + do + { + xmove = FixedMul(dist,costable[player->angle]); + ymove = -FixedMul(dist,sintable[player->angle]); - player->x = ob->x - xmove; - player->y = ob->y - ymove; - dist += 0x1000; + player->x = ob->x - xmove; + player->y = ob->y - ymove; + dist += 0x1000; - } while (!CheckPosition (player)); - plux = (word)(player->x >> UNSIGNEDSHIFT); // scale to fit in unsigned - pluy = (word)(player->y >> UNSIGNEDSHIFT); - player->tilex = (word)(player->x >> TILESHIFT); // scale to tile values - player->tiley = (word)(player->y >> TILESHIFT); + } while (!CheckPosition (player)); + plux = (word)(player->x >> UNSIGNEDSHIFT); // scale to fit in unsigned + pluy = (word)(player->y >> UNSIGNEDSHIFT); + player->tilex = (word)(player->x >> TILESHIFT); // scale to tile values + player->tiley = (word)(player->y >> TILESHIFT); - // - // go back to the game - // + // + // go back to the game + // - DrawPlayBorder (); + DrawPlayBorder (); - fizzlein = true; + fizzlein = true; - switch (ob->obclass) - { + switch (ob->obclass) + { #ifndef SPEAR - case schabbobj: - NewState (ob,&s_schabbdeathcam); - break; - case realhitlerobj: - NewState (ob,&s_hitlerdeathcam); - break; - case giftobj: - NewState (ob,&s_giftdeathcam); - break; - case fatobj: - NewState (ob,&s_fatdeathcam); - break; + case schabbobj: + NewState (ob,&s_schabbdeathcam); + break; + case realhitlerobj: + NewState (ob,&s_hitlerdeathcam); + break; + case giftobj: + NewState (ob,&s_giftdeathcam); + break; + case fatobj: + NewState (ob,&s_fatdeathcam); + break; #endif - } + } } #endif diff --git a/wl_agent.c b/wl_agent.c index fc59d6e..26edd2f 100644 --- a/wl_agent.c +++ b/wl_agent.c @@ -101,39 +101,39 @@ void ClipMove (objtype *ob, int32_t xmove, int32_t ymove); void CheckWeaponChange (void) { - int newWeapon = -1; + int newWeapon = -1; - if (!gamestate.ammo) // must use knife with no ammo - return; + if (!gamestate.ammo) // must use knife with no ammo + return; - if(buttonstate[bt_nextweapon] && !buttonheld[bt_nextweapon]) - { - newWeapon = gamestate.weapon + 1; - if(newWeapon > gamestate.bestweapon) newWeapon = 0; - } - else if(buttonstate[bt_prevweapon] && !buttonheld[bt_prevweapon]) - { - newWeapon = gamestate.weapon - 1; - if(newWeapon < 0) newWeapon = gamestate.bestweapon; - } - else - { - unsigned i; - for(i = wp_knife; i <= gamestate.bestweapon; i++) - { - if (buttonstate[bt_readyknife + i - wp_knife]) - { - newWeapon = i; - break; - } - } - } + if(buttonstate[bt_nextweapon] && !buttonheld[bt_nextweapon]) + { + newWeapon = gamestate.weapon + 1; + if(newWeapon > gamestate.bestweapon) newWeapon = 0; + } + else if(buttonstate[bt_prevweapon] && !buttonheld[bt_prevweapon]) + { + newWeapon = gamestate.weapon - 1; + if(newWeapon < 0) newWeapon = gamestate.bestweapon; + } + else + { + unsigned i; + for(i = wp_knife; i <= gamestate.bestweapon; i++) + { + if (buttonstate[bt_readyknife + i - wp_knife]) + { + newWeapon = i; + break; + } + } + } - if(newWeapon != -1) - { - gamestate.weapon = gamestate.chosenweapon = (weapontype) newWeapon; - DrawWeapon(); - } + if(newWeapon != -1) + { + gamestate.weapon = gamestate.chosenweapon = (weapontype) newWeapon; + DrawWeapon(); + } } @@ -154,95 +154,86 @@ void CheckWeaponChange (void) void ControlMovement (objtype *ob) { - int32_t oldx,oldy; - int angle; - int angleunits; + int32_t oldx,oldy; + int angle; + int angleunits; - thrustspeed = 0; + thrustspeed = 0; - oldx = player->x; - oldy = player->y; + oldx = player->x; + oldy = player->y; - if(buttonstate[bt_strafeleft]) - { - angle = ob->angle + ANGLES/4; - if(angle >= ANGLES) - angle -= ANGLES; - if(buttonstate[bt_run]) - Thrust(angle, RUNMOVE * MOVESCALE * tics); - else - Thrust(angle, BASEMOVE * MOVESCALE * tics); - } + if(buttonstate[bt_strafeleft]) + { + angle = ob->angle + ANGLES/4; + if(angle >= ANGLES) + angle -= ANGLES; + if(buttonstate[bt_run]) + Thrust(angle, RUNMOVE * MOVESCALE * tics); + else + Thrust(angle, BASEMOVE * MOVESCALE * tics); + } - if(buttonstate[bt_straferight]) - { - angle = ob->angle - ANGLES/4; - if(angle < 0) + if(buttonstate[bt_straferight]) + { + angle = ob->angle - ANGLES/4; + if(angle < 0) + angle += ANGLES; + if(buttonstate[bt_run]) + Thrust(angle, RUNMOVE * MOVESCALE * tics ); + else + Thrust(angle, BASEMOVE * MOVESCALE * tics); + } + + // side to side move + if (buttonstate[bt_strafe]) + { + // strafing + if (controlx > 0) + { + angle = ob->angle - ANGLES/4; + if (angle < 0) angle += ANGLES; - if(buttonstate[bt_run]) - Thrust(angle, RUNMOVE * MOVESCALE * tics ); - else - Thrust(angle, BASEMOVE * MOVESCALE * tics); - } - - // - // side to side move - // - if (buttonstate[bt_strafe]) - { - // - // strafing - // - // - if (controlx > 0) - { - angle = ob->angle - ANGLES/4; - if (angle < 0) - angle += ANGLES; - Thrust (angle,controlx*MOVESCALE); // move to left - } - else if (controlx < 0) - { - angle = ob->angle + ANGLES/4; - if (angle >= ANGLES) - angle -= ANGLES; - Thrust (angle,-controlx*MOVESCALE); // move to right - } - } - else - { - // - // not strafing - // - anglefrac += controlx; - angleunits = anglefrac/ANGLESCALE; - anglefrac -= angleunits*ANGLESCALE; - ob->angle -= angleunits; - - if (ob->angle >= ANGLES) - ob->angle -= ANGLES; - if (ob->angle < 0) - ob->angle += ANGLES; - - } - - // - // forward/backwards move - // - if (controly < 0) - { - Thrust (ob->angle,-controly*MOVESCALE); // move forwards - } - else if (controly > 0) - { - angle = ob->angle + ANGLES/2; - if (angle >= ANGLES) + Thrust (angle,controlx*MOVESCALE); // move to left + } + else if (controlx < 0) + { + angle = ob->angle + ANGLES/4; + if (angle >= ANGLES) angle -= ANGLES; - Thrust (angle,controly*BACKMOVESCALE); // move backwards - } + Thrust (angle,-controlx*MOVESCALE); // move to right + } + } + else + { + // not strafing + anglefrac += controlx; + angleunits = anglefrac/ANGLESCALE; + anglefrac -= angleunits*ANGLESCALE; + ob->angle -= angleunits; - if (gamestate.victoryflag) // watching the BJ actor - return; + if (ob->angle >= ANGLES) + ob->angle -= ANGLES; + if (ob->angle < 0) + ob->angle += ANGLES; + + } + + // forward/backwards move + if (controly < 0) + { + Thrust (ob->angle,-controly*MOVESCALE); // move forwards + } + else if (controly > 0) + { + angle = ob->angle + ANGLES/2; + if (angle >= ANGLES) + angle -= ANGLES; + Thrust (angle,controly*BACKMOVESCALE); // move backwards + } + + if (gamestate.victoryflag) // watching the BJ actor + return; } /* @@ -264,14 +255,13 @@ void ControlMovement (objtype *ob) void StatusDrawPic (unsigned x, unsigned y, unsigned picnum) { - LatchDrawPicScaledCoord ((screenWidth-scaleFactor*320)/16 + scaleFactor*x, - screenHeight-scaleFactor*(STATUSLINES-y),picnum); + LatchDrawPicScaledCoord ((screenWidth-scaleFactor*320)/16 + scaleFactor*x, + screenHeight-scaleFactor*(STATUSLINES-y),picnum); } void StatusDrawFace(unsigned picnum) { - StatusDrawPic(17, 4, picnum); - + StatusDrawPic(17, 4, picnum); } @@ -285,27 +275,29 @@ void StatusDrawFace(unsigned picnum) void DrawFace (void) { - if(viewsize == 21 && ingame) return; - if (SD_SoundPlaying() == GETGATLINGSND) - StatusDrawFace(GOTGATLINGPIC); - else if (gamestate.health) - { + if(viewsize == 21 && ingame) + return; + + if (SD_SoundPlaying() == GETGATLINGSND) + StatusDrawFace(GOTGATLINGPIC); + else if (gamestate.health) + { #ifdef SPEAR - if (godmode) - StatusDrawFace(GODMODEFACE1PIC+gamestate.faceframe); - else + if (godmode) + StatusDrawFace(GODMODEFACE1PIC+gamestate.faceframe); + else #endif - StatusDrawFace(FACE1APIC+3*((100-gamestate.health)/16)+gamestate.faceframe); - } - else - { + StatusDrawFace(FACE1APIC+3*((100-gamestate.health)/16)+gamestate.faceframe); + } + else + { #ifndef SPEAR - if (LastAttacker && LastAttacker->obclass == needleobj) - StatusDrawFace(MUTANTBJPIC); - else + if (LastAttacker && LastAttacker->obclass == needleobj) + StatusDrawFace(MUTANTBJPIC); + else #endif - StatusDrawFace(FACE8APIC); - } + StatusDrawFace(FACE8APIC); + } } /* @@ -323,28 +315,28 @@ int facetimes = 0; void UpdateFace (void) { - // don't make demo depend on sound playback - if(demoplayback || demorecord) - { - if(facetimes > 0) - { - facetimes--; - return; - } - } - else if(SD_SoundPlaying() == GETGATLINGSND) - return; + // don't make demo depend on sound playback + if(demoplayback || demorecord) + { + if(facetimes > 0) + { + facetimes--; + return; + } + } + else if(SD_SoundPlaying() == GETGATLINGSND) + return; - facecount += tics; - if (facecount > US_RndT()) - { - gamestate.faceframe = (US_RndT()>>6); - if (gamestate.faceframe==3) - gamestate.faceframe = 1; + facecount += tics; + if (facecount > US_RndT()) + { + gamestate.faceframe = (US_RndT()>>6); + if (gamestate.faceframe==3) + gamestate.faceframe = 1; - facecount = 0; - DrawFace (); - } + facecount = 0; + DrawFace (); + } } @@ -361,28 +353,28 @@ void UpdateFace (void) static void LatchNumber (int x, int y, unsigned width, int32_t number) { - unsigned length,c; - char str[20]; + unsigned length,c; + char str[20]; - ltoa (number,str,10); + ltoa (number,str,10); - length = (unsigned) strlen (str); + length = (unsigned) strlen (str); - while (length>=2; + if (gamestate.victoryflag) + return; + if (gamestate.difficulty==gd_baby) + points>>=2; - if (!godmode) - gamestate.health -= points; + if (!godmode) + gamestate.health -= points; - if (gamestate.health<=0) - { - gamestate.health = 0; - playstate = ex_died; - killerobj = attacker; - } + if (gamestate.health<=0) + { + gamestate.health = 0; + playstate = ex_died; + killerobj = attacker; + } - if (godmode != 2) - StartDamageFlash (points); + if (godmode != 2) + StartDamageFlash (points); - DrawHealth (); - DrawFace (); + DrawHealth (); + DrawFace (); - // - // MAKE BJ'S EYES BUG IF MAJOR DAMAGE! - // + // MAKE BJ'S EYES BUG IF MAJOR DAMAGE! #ifdef SPEAR - if (points > 30 && gamestate.health!=0 && !godmode && viewsize != 21) - { - StatusDrawFace(BJOUCHPIC); - facecount = 0; - } + if (points > 30 && gamestate.health!=0 && !godmode && viewsize != 21) + { + StatusDrawFace(BJOUCHPIC); + facecount = 0; + } #endif } @@ -456,12 +447,12 @@ void TakeDamage (int points,objtype *attacker) void HealSelf (int points) { - gamestate.health += points; - if (gamestate.health>100) - gamestate.health = 100; + gamestate.health += points; + if (gamestate.health>100) + gamestate.health = 100; - DrawHealth (); - DrawFace (); + DrawHealth (); + DrawFace (); } @@ -478,13 +469,14 @@ void HealSelf (int points) void DrawLevel (void) { - if(viewsize == 21 && ingame) return; + if(viewsize == 21 && ingame) + return; #ifdef SPEAR - if (gamestate.mapon == 20) - LatchNumber (2,16,2,18); - else + if (gamestate.mapon == 20) + LatchNumber (2,16,2,18); + else #endif - LatchNumber (2,16,2,gamestate.mapon+1); + LatchNumber (2,16,2,gamestate.mapon+1); } //=========================================================================== @@ -500,8 +492,9 @@ void DrawLevel (void) void DrawLives (void) { - if(viewsize == 21 && ingame) return; - LatchNumber (14,16,1,gamestate.lives); + if(viewsize == 21 && ingame) + return; + LatchNumber (14,16,1,gamestate.lives); } @@ -515,10 +508,10 @@ void DrawLives (void) void GiveExtraMan (void) { - if (gamestate.lives<9) - gamestate.lives++; - DrawLives (); - SD_PlaySound (BONUS1UPSND); + if (gamestate.lives<9) + gamestate.lives++; + DrawLives (); + SD_PlaySound (BONUS1UPSND); } //=========================================================================== @@ -533,8 +526,9 @@ void GiveExtraMan (void) void DrawScore (void) { - if(viewsize == 21 && ingame) return; - LatchNumber (6,16,6,gamestate.score); + if(viewsize == 21 && ingame) + return; + LatchNumber (6,16,6,gamestate.score); } /* @@ -568,8 +562,9 @@ void GivePoints (int32_t points) void DrawWeapon (void) { - if(viewsize == 21 && ingame) return; - StatusDrawPic (32,8,KNIFEPIC+gamestate.weapon); + if(viewsize == 21 && ingame) + return; + StatusDrawPic (32,8,KNIFEPIC+gamestate.weapon); } @@ -583,16 +578,17 @@ void DrawWeapon (void) void DrawKeys (void) { - if(viewsize == 21 && ingame) return; - if (gamestate.keys & 1) - StatusDrawPic (30,4,GOLDKEYPIC); - else - StatusDrawPic (30,4,NOKEYPIC); + if(viewsize == 21 && ingame) + return; + if (gamestate.keys & 1) + StatusDrawPic (30,4,GOLDKEYPIC); + else + StatusDrawPic (30,4,NOKEYPIC); - if (gamestate.keys & 2) - StatusDrawPic (30,20,SILVERKEYPIC); - else - StatusDrawPic (30,20,NOKEYPIC); + if (gamestate.keys & 2) + StatusDrawPic (30,20,SILVERKEYPIC); + else + StatusDrawPic (30,20,NOKEYPIC); } /* @@ -605,13 +601,13 @@ void DrawKeys (void) void GiveWeapon (int weapon) { - GiveAmmo (6); + GiveAmmo (6); - if (gamestate.bestweaponitemnumber) - { - case bo_firstaid: - if (gamestate.health == 100) - return; + switch (check->itemnumber) + { + case bo_firstaid: + if (gamestate.health == 100) + return; - SD_PlaySound (HEALTH2SND); - HealSelf (25); - break; + SD_PlaySound (HEALTH2SND); + HealSelf (25); + break; - case bo_key1: - case bo_key2: - case bo_key3: - case bo_key4: - GiveKey (check->itemnumber - bo_key1); - SD_PlaySound (GETKEYSND); - break; + case bo_key1: + case bo_key2: + case bo_key3: + case bo_key4: + GiveKey (check->itemnumber - bo_key1); + SD_PlaySound (GETKEYSND); + break; - case bo_cross: - SD_PlaySound (BONUS1SND); - GivePoints (100); - gamestate.treasurecount++; - break; - case bo_chalice: - SD_PlaySound (BONUS2SND); - GivePoints (500); - gamestate.treasurecount++; - break; - case bo_bible: - SD_PlaySound (BONUS3SND); - GivePoints (1000); - gamestate.treasurecount++; - break; - case bo_crown: - SD_PlaySound (BONUS4SND); - GivePoints (5000); - gamestate.treasurecount++; - break; + case bo_cross: + SD_PlaySound (BONUS1SND); + GivePoints (100); + gamestate.treasurecount++; + break; + case bo_chalice: + SD_PlaySound (BONUS2SND); + GivePoints (500); + gamestate.treasurecount++; + break; + case bo_bible: + SD_PlaySound (BONUS3SND); + GivePoints (1000); + gamestate.treasurecount++; + break; + case bo_crown: + SD_PlaySound (BONUS4SND); + GivePoints (5000); + gamestate.treasurecount++; + break; - case bo_clip: - if (gamestate.ammo == 99) - return; + case bo_clip: + if (gamestate.ammo == 99) + return; - SD_PlaySound (GETAMMOSND); - GiveAmmo (8); - break; - case bo_clip2: - if (gamestate.ammo == 99) - return; + SD_PlaySound (GETAMMOSND); + GiveAmmo (8); + break; + case bo_clip2: + if (gamestate.ammo == 99) + return; - SD_PlaySound (GETAMMOSND); - GiveAmmo (4); - break; + SD_PlaySound (GETAMMOSND); + GiveAmmo (4); + break; #ifdef SPEAR - case bo_25clip: - if (gamestate.ammo == 99) - return; + case bo_25clip: + if (gamestate.ammo == 99) + return; - SD_PlaySound (GETAMMOBOXSND); - GiveAmmo (25); - break; + SD_PlaySound (GETAMMOBOXSND); + GiveAmmo (25); + break; #endif - case bo_machinegun: - SD_PlaySound (GETMACHINESND); - GiveWeapon (wp_machinegun); - break; - case bo_chaingun: - SD_PlaySound (GETGATLINGSND); - facetimes = 38; - GiveWeapon (wp_chaingun); + case bo_machinegun: + SD_PlaySound (GETMACHINESND); + GiveWeapon (wp_machinegun); + break; + case bo_chaingun: + SD_PlaySound (GETGATLINGSND); + facetimes = 38; + GiveWeapon (wp_chaingun); - if(viewsize != 21) - StatusDrawFace (GOTGATLINGPIC); - facecount = 0; - break; + if(viewsize != 21) + StatusDrawFace (GOTGATLINGPIC); + facecount = 0; + break; - case bo_fullheal: - SD_PlaySound (BONUS1UPSND); - HealSelf (99); - GiveAmmo (25); - GiveExtraMan (); - gamestate.treasurecount++; - break; + case bo_fullheal: + SD_PlaySound (BONUS1UPSND); + HealSelf (99); + GiveAmmo (25); + GiveExtraMan (); + gamestate.treasurecount++; + break; - case bo_food: - if (gamestate.health == 100) - return; + case bo_food: + if (gamestate.health == 100) + return; - SD_PlaySound (HEALTH1SND); - HealSelf (10); - break; + SD_PlaySound (HEALTH1SND); + HealSelf (10); + break; - case bo_alpo: - if (gamestate.health == 100) - return; + case bo_alpo: + if (gamestate.health == 100) + return; - SD_PlaySound (HEALTH1SND); - HealSelf (4); - break; + SD_PlaySound (HEALTH1SND); + HealSelf (4); + break; - case bo_gibs: - if (gamestate.health >10) - return; + case bo_gibs: + if (gamestate.health >10) + return; - SD_PlaySound (SLURPIESND); - HealSelf (1); - break; + SD_PlaySound (SLURPIESND); + HealSelf (1); + break; #ifdef SPEAR - case bo_spear: - spearflag = true; - spearx = player->x; - speary = player->y; - spearangle = player->angle; - playstate = ex_completed; + case bo_spear: + spearflag = true; + spearx = player->x; + speary = player->y; + spearangle = player->angle; + playstate = ex_completed; #endif - } + } - StartBonusFlash (); - check->shapenum = -1; // remove from list + StartBonusFlash (); + check->shapenum = -1; // remove from list } /* @@ -826,87 +822,87 @@ void GetBonus (statobj_t *check) boolean TryMove (objtype *ob) { - int xl,yl,xh,yh,x,y; - objtype *check; - int32_t deltax,deltay; + int xl,yl,xh,yh,x,y; + objtype *check; + int32_t deltax,deltay; - xl = (ob->x-PLAYERSIZE) >>TILESHIFT; - yl = (ob->y-PLAYERSIZE) >>TILESHIFT; + xl = (ob->x-PLAYERSIZE) >>TILESHIFT; + yl = (ob->y-PLAYERSIZE) >>TILESHIFT; - xh = (ob->x+PLAYERSIZE) >>TILESHIFT; - yh = (ob->y+PLAYERSIZE) >>TILESHIFT; + xh = (ob->x+PLAYERSIZE) >>TILESHIFT; + yh = (ob->y+PLAYERSIZE) >>TILESHIFT; #define PUSHWALLMINDIST PLAYERSIZE - // - // check for solid walls - // - for (y=yl;y<=yh;y++) - { - for (x=xl;x<=xh;x++) - { - check = actorat[x][y]; - if (check && !ISPOINTER(check)) + // + // check for solid walls + // + for (y=yl;y<=yh;y++) + { + for (x=xl;x<=xh;x++) + { + check = actorat[x][y]; + if (check && !ISPOINTER(check)) + { + if(tilemap[x][y]==64 && x==pwallx && y==pwally) // back of moving pushwall? { - if(tilemap[x][y]==64 && x==pwallx && y==pwally) // back of moving pushwall? - { - switch(pwalldir) - { - case di_north: - if(ob->y-PUSHWALLMINDIST<=(pwally<x-PUSHWALLMINDIST<=(pwallx<x+PUSHWALLMINDIST>=(pwallx<y+PUSHWALLMINDIST>=(pwally<y-PUSHWALLMINDIST<=(pwally<x-PUSHWALLMINDIST<=(pwallx<x+PUSHWALLMINDIST>=(pwallx<y+PUSHWALLMINDIST>=(pwally<0) - yl--; - if (yh0) - xl--; - if (xh0) + yl--; + if (yh0) + xl--; + if (xhflags & FL_SHOOTABLE) ) - { - deltax = ob->x - check->x; - if (deltax < -MINACTORDIST || deltax > MINACTORDIST) - continue; - deltay = ob->y - check->y; - if (deltay < -MINACTORDIST || deltay > MINACTORDIST) - continue; + for (y=yl;y<=yh;y++) + { + for (x=xl;x<=xh;x++) + { + check = actorat[x][y]; + if (ISPOINTER(check) && check != player && (check->flags & FL_SHOOTABLE) ) + { + deltax = ob->x - check->x; + if (deltax < -MINACTORDIST || deltax > MINACTORDIST) + continue; + deltay = ob->y - check->y; + if (deltay < -MINACTORDIST || deltay > MINACTORDIST) + continue; - return false; - } - } - } + return false; + } + } + } - return true; + return true; } @@ -920,38 +916,38 @@ boolean TryMove (objtype *ob) void ClipMove (objtype *ob, int32_t xmove, int32_t ymove) { - int32_t basex,basey; + int32_t basex,basey; - basex = ob->x; - basey = ob->y; + basex = ob->x; + basey = ob->y; - ob->x = basex+xmove; - ob->y = basey+ymove; - if (TryMove (ob)) - return; + ob->x = basex+xmove; + ob->y = basey+ymove; + if (TryMove (ob)) + return; #if 0 - if (noclip && ob->x > 2*TILEGLOBAL && ob->y > 2*TILEGLOBAL - && ob->x < (((int32_t)(mapwidth-1))<y < (((int32_t)(mapheight-1))<x > 2*TILEGLOBAL && ob->y > 2*TILEGLOBAL + && ob->x < (((int32_t)(mapwidth-1))<y < (((int32_t)(mapheight-1))<x = basex+xmove; - ob->y = basey; - if (TryMove (ob)) - return; + ob->x = basex+xmove; + ob->y = basey; + if (TryMove (ob)) + return; - ob->x = basex; - ob->y = basey+ymove; - if (TryMove (ob)) - return; + ob->x = basex; + ob->y = basey+ymove; + if (TryMove (ob)) + return; - ob->x = basex; - ob->y = basey; + ob->x = basex; + ob->y = basey; } //========================================================================== @@ -984,64 +980,62 @@ void VictoryTile (void) // For player movement in demos exactly as in the original Wolf3D v1.4 source code static fixed FixedByFracOrig(fixed a, fixed b) { - int sign = 0; - if(b == 65536) - b = 65535; - else - if(b == -65536) b = 65535, sign = 1; - else - if(b < 0) b = (-b), sign = 1; + int sign = 0; + if(b == 65536) + b = 65535; + else + if(b == -65536) b = 65535, sign = 1; + else + if(b < 0) b = (-b), sign = 1; - if(a < 0) - { - a = -a; - sign = !sign; - } - fixed res = (fixed)(((int64_t) a * b) >> 16); - - if(sign) - res = -res; - return res; + if(a < 0) + { + a = -a; + sign = !sign; + } + fixed res = (fixed)(((int64_t) a * b) >> 16); + + if(sign) + res = -res; + return res; } void Thrust (int angle, int32_t speed) { - int32_t xmove,ymove; - unsigned offset; + int32_t xmove,ymove; + unsigned offset; - // - // ZERO FUNNY COUNTER IF MOVED! - // + // ZERO FUNNY COUNTER IF MOVED! #ifdef SPEAR - if (speed) - funnyticount = 0; + if (speed) + funnyticount = 0; #endif - thrustspeed += speed; - // - // moving bounds speed - // - if (speed >= MINDIST*2) - speed = MINDIST*2-1; + thrustspeed += speed; + // + // moving bounds speed + // + if (speed >= MINDIST*2) + speed = MINDIST*2-1; - xmove = DEMOCHOOSE_ORIG_SDL( - FixedByFracOrig(speed, costable[angle]), - FixedMul(speed,costable[angle])); - ymove = DEMOCHOOSE_ORIG_SDL( - -FixedByFracOrig(speed, sintable[angle]), - -FixedMul(speed,sintable[angle])); + xmove = DEMOCHOOSE_ORIG_SDL( + FixedByFracOrig(speed, costable[angle]), + FixedMul(speed,costable[angle])); + ymove = DEMOCHOOSE_ORIG_SDL( + -FixedByFracOrig(speed, sintable[angle]), + -FixedMul(speed,sintable[angle])); - ClipMove(player,xmove,ymove); + ClipMove(player,xmove,ymove); - player->tilex = (short)(player->x >> TILESHIFT); // scale to tile values - player->tiley = (short)(player->y >> TILESHIFT); + player->tilex = (short)(player->x >> TILESHIFT); // scale to tile values + player->tiley = (short)(player->y >> TILESHIFT); - offset = (player->tiley<tilex; - player->areanumber = *(mapsegs[0] + offset) -AREATILE; + offset = (player->tiley<tilex; + player->areanumber = *(mapsegs[0] + offset) -AREATILE; - if (*(mapsegs[1] + offset) == EXITTILE) - VictoryTile (); + if (*(mapsegs[1] + offset) == EXITTILE) + VictoryTile (); } @@ -1064,17 +1058,17 @@ void Thrust (int angle, int32_t speed) void Cmd_Fire (void) { - buttonheld[bt_attack] = true; + buttonheld[bt_attack] = true; - gamestate.weaponframe = 0; + gamestate.weaponframe = 0; - player->state = &s_attack; + player->state = &s_attack; - gamestate.attackframe = 0; - gamestate.attackcount = - attackinfo[gamestate.weapon][gamestate.attackframe].tics; - gamestate.weaponframe = - attackinfo[gamestate.weapon][gamestate.attackframe].frame; + gamestate.attackframe = 0; + gamestate.attackcount = + attackinfo[gamestate.weapon][gamestate.attackframe].tics; + gamestate.weaponframe = + attackinfo[gamestate.weapon][gamestate.attackframe].frame; } //=========================================================================== @@ -1089,73 +1083,71 @@ void Cmd_Fire (void) void Cmd_Use (void) { - int checkx,checky,doornum,dir; - boolean elevatorok; + int checkx,checky,doornum,dir; + boolean elevatorok; - // - // find which cardinal direction the player is facing - // - if (player->angle < ANGLES/8 || player->angle > 7*ANGLES/8) - { - checkx = player->tilex + 1; - checky = player->tiley; - dir = di_east; - elevatorok = true; - } - else if (player->angle < 3*ANGLES/8) - { - checkx = player->tilex; - checky = player->tiley-1; - dir = di_north; - elevatorok = false; - } - else if (player->angle < 5*ANGLES/8) - { - checkx = player->tilex - 1; - checky = player->tiley; - dir = di_west; - elevatorok = true; - } - else - { - checkx = player->tilex; - checky = player->tiley + 1; - dir = di_south; - elevatorok = false; - } + // find which cardinal direction the player is facing + if (player->angle < ANGLES/8 || player->angle > 7*ANGLES/8) + { + checkx = player->tilex + 1; + checky = player->tiley; + dir = di_east; + elevatorok = true; + } + else if (player->angle < 3*ANGLES/8) + { + checkx = player->tilex; + checky = player->tiley-1; + dir = di_north; + elevatorok = false; + } + else if (player->angle < 5*ANGLES/8) + { + checkx = player->tilex - 1; + checky = player->tiley; + dir = di_west; + elevatorok = true; + } + else + { + checkx = player->tilex; + checky = player->tiley + 1; + dir = di_south; + elevatorok = false; + } - doornum = tilemap[checkx][checky]; - if (*(mapsegs[1]+(checky<tiley<tilex) == ALTELEVATORTILE) - playstate = ex_secretlevel; - else - playstate = ex_completed; - SD_PlaySound (LEVELDONESND); - SD_WaitSoundDone(); - } - else if (!buttonheld[bt_use] && doornum & 0x80) - { - buttonheld[bt_use] = true; - OperateDoor (doornum & ~0x80); - } - else - SD_PlaySound (DONOTHINGSND); + tilemap[checkx][checky]++; // flip switch + if (*(mapsegs[0]+(player->tiley<tilex) == ALTELEVATORTILE) + playstate = ex_secretlevel; + else + playstate = ex_completed; + SD_PlaySound (LEVELDONESND); + SD_WaitSoundDone(); + } + else if (!buttonheld[bt_use] && doornum & 0x80) + { + buttonheld[bt_use] = true; + OperateDoor (doornum & ~0x80); + } + else + SD_PlaySound (DONOTHINGSND); } /* @@ -1178,21 +1170,21 @@ void Cmd_Use (void) void SpawnPlayer (int tilex, int tiley, int dir) { - player->obclass = playerobj; - player->active = ac_yes; - player->tilex = tilex; - player->tiley = tiley; - player->areanumber = (byte) *(mapsegs[0]+(player->tiley<tilex); - player->x = ((int32_t)tilex<y = ((int32_t)tiley<state = &s_player; - player->angle = (1-dir)*90; - if (player->angle<0) - player->angle += ANGLES; - player->flags = FL_NEVERMARK; - Thrust (0,0); // set some variables + player->obclass = playerobj; + player->active = ac_yes; + player->tilex = tilex; + player->tiley = tiley; + player->areanumber = (byte) *(mapsegs[0]+(player->tiley<tilex); + player->x = ((int32_t)tilex<y = ((int32_t)tiley<state = &s_player; + player->angle = (1-dir)*90; + if (player->angle<0) + player->angle += ANGLES; + player->flags = FL_NEVERMARK; + Thrust (0,0); // set some variables - InitAreas (); + InitAreas (); } @@ -1210,110 +1202,105 @@ void SpawnPlayer (int tilex, int tiley, int dir) void KnifeAttack (objtype *ob) { - objtype *check,*closest; - int32_t dist; + objtype *check,*closest; + int32_t dist; - SD_PlaySound (ATKKNIFESND); - // actually fire - dist = 0x7fffffff; - closest = NULL; - for (check=ob->next; check; check=check->next) - { - if ( (check->flags & FL_SHOOTABLE) && (check->flags & FL_VISABLE) + SD_PlaySound (ATKKNIFESND); + // actually fire + dist = 0x7fffffff; + closest = NULL; + for (check=ob->next; check; check=check->next) + { + if ( (check->flags & FL_SHOOTABLE) && (check->flags & FL_VISABLE) && abs(check->viewx-centerx) < shootdelta) - { - if (check->transx < dist) - { - dist = check->transx; - closest = check; - } - } - } + { + if (check->transx < dist) + { + dist = check->transx; + closest = check; + } + } + } - if (!closest || dist > 0x18000l) - { - // missed - return; - } + if (!closest || dist > 0x18000l) // missed + return; - // hit something - DamageActor (closest,US_RndT() >> 4); + // hit something + DamageActor (closest,US_RndT() >> 4); } - - void GunAttack (objtype *ob) { - objtype *check,*closest,*oldclosest; - int damage; - int dx,dy,dist; - int32_t viewdist; + objtype *check,*closest,*oldclosest; + int damage; + int dx,dy,dist; + int32_t viewdist; - switch (gamestate.weapon) - { - case wp_pistol: - SD_PlaySound (ATKPISTOLSND); - break; - case wp_machinegun: - SD_PlaySound (ATKMACHINEGUNSND); - break; - case wp_chaingun: - SD_PlaySound (ATKGATLINGSND); - break; - } + switch (gamestate.weapon) + { + case wp_pistol: + SD_PlaySound (ATKPISTOLSND); + break; + case wp_machinegun: + SD_PlaySound (ATKMACHINEGUNSND); + break; + case wp_chaingun: + SD_PlaySound (ATKGATLINGSND); + break; + } - madenoise = true; + madenoise = true; - // - // find potential targets - // - viewdist = 0x7fffffffl; - closest = NULL; + // + // find potential targets + // + viewdist = 0x7fffffffl; + closest = NULL; - while (1) - { - oldclosest = closest; + while (1) + { + oldclosest = closest; - for (check=ob->next ; check ; check=check->next) - { - if ((check->flags & FL_SHOOTABLE) && (check->flags & FL_VISABLE) - && abs(check->viewx-centerx) < shootdelta) + for (check=ob->next ; check ; check=check->next) + { + if ((check->flags & FL_SHOOTABLE) && (check->flags & FL_VISABLE) + && abs(check->viewx-centerx) < shootdelta) + { + if (check->transx < viewdist) { - if (check->transx < viewdist) - { - viewdist = check->transx; - closest = check; - } + viewdist = check->transx; + closest = check; } - } + } + } - if (closest == oldclosest) - return; // no more targets, all missed + if (closest == oldclosest) + return; // no more targets, all missed - // - // trace a line from player to enemey - // - if (CheckLine(closest)) - break; - } + // + // trace a line from player to enemey + // + if (CheckLine(closest)) + break; + } - // - // hit something - // - dx = ABS(closest->tilex - player->tilex); - dy = ABS(closest->tiley - player->tiley); - dist = dx>dy ? dx:dy; - if (dist<2) - damage = US_RndT() / 4; - else if (dist<4) - damage = US_RndT() / 6; - else - { - if ( (US_RndT() / 12) < dist) // missed - return; - damage = US_RndT() / 6; - } - DamageActor (closest,damage); + // + // hit something + // + dx = ABS(closest->tilex - player->tilex); + dy = ABS(closest->tiley - player->tiley); + dist = dx>dy ? dx:dy; + if (dist<2) + damage = US_RndT() / 4; + else if (dist<4) + damage = US_RndT() / 6; + else + { + if ( (US_RndT() / 12) < dist) // missed + return; + damage = US_RndT() / 6; + } + DamageActor (closest,damage); } //=========================================================================== @@ -1328,29 +1315,29 @@ void GunAttack (objtype *ob) void VictorySpin (void) { - int32_t desty; + int32_t desty; - if (player->angle > 270) - { - player->angle -= (short)(tics * 3); - if (player->angle < 270) - player->angle = 270; - } - else if (player->angle < 270) - { - player->angle += (short)(tics * 3); - if (player->angle > 270) - player->angle = 270; - } + if (player->angle > 270) + { + player->angle -= (short)(tics * 3); + if (player->angle < 270) + player->angle = 270; + } + else if (player->angle < 270) + { + player->angle += (short)(tics * 3); + if (player->angle > 270) + player->angle = 270; + } - desty = (((int32_t)player->tiley-5)<tiley-5)<y > desty) - { - player->y -= tics*4096; - if (player->y < desty) - player->y = desty; - } + if (player->y > desty) + { + player->y -= tics*4096; + if (player->y < desty) + player->y = desty; + } } @@ -1366,90 +1353,90 @@ void VictorySpin (void) void T_Attack (objtype *ob) { - struct atkinf *cur; + struct atkinf *cur; - UpdateFace (); + UpdateFace (); - if (gamestate.victoryflag) // watching the BJ actor - { - VictorySpin (); - return; - } + if (gamestate.victoryflag) // watching the BJ actor + { + VictorySpin (); + return; + } - if ( buttonstate[bt_use] && !buttonheld[bt_use] ) - buttonstate[bt_use] = false; + if ( buttonstate[bt_use] && !buttonheld[bt_use] ) + buttonstate[bt_use] = false; - if ( buttonstate[bt_attack] && !buttonheld[bt_attack]) - buttonstate[bt_attack] = false; + if ( buttonstate[bt_attack] && !buttonheld[bt_attack]) + buttonstate[bt_attack] = false; - ControlMovement (ob); - if (gamestate.victoryflag) // watching the BJ actor - return; + ControlMovement (ob); + if (gamestate.victoryflag) // watching the BJ actor + return; - plux = (word) (player->x >> UNSIGNEDSHIFT); // scale to fit in unsigned - pluy = (word) (player->y >> UNSIGNEDSHIFT); - player->tilex = (short)(player->x >> TILESHIFT); // scale to tile values - player->tiley = (short)(player->y >> TILESHIFT); + plux = (word) (player->x >> UNSIGNEDSHIFT); // scale to fit in unsigned + pluy = (word) (player->y >> UNSIGNEDSHIFT); + player->tilex = (short)(player->x >> TILESHIFT); // scale to tile values + player->tiley = (short)(player->y >> TILESHIFT); - // - // change frame and fire - // - gamestate.attackcount -= (short) tics; - while (gamestate.attackcount <= 0) - { - cur = &attackinfo[gamestate.weapon][gamestate.attackframe]; - switch (cur->attack) - { - case -1: - ob->state = &s_player; - if (!gamestate.ammo) - { - gamestate.weapon = wp_knife; - DrawWeapon (); - } - else - { - if (gamestate.weapon != gamestate.chosenweapon) - { - gamestate.weapon = gamestate.chosenweapon; - DrawWeapon (); - } - } - gamestate.attackframe = gamestate.weaponframe = 0; - return; + // + // change frame and fire + // + gamestate.attackcount -= (short) tics; + while (gamestate.attackcount <= 0) + { + cur = &attackinfo[gamestate.weapon][gamestate.attackframe]; + switch (cur->attack) + { + case -1: + ob->state = &s_player; + if (!gamestate.ammo) + { + gamestate.weapon = wp_knife; + DrawWeapon (); + } + else + { + if (gamestate.weapon != gamestate.chosenweapon) + { + gamestate.weapon = gamestate.chosenweapon; + DrawWeapon (); + } + } + gamestate.attackframe = gamestate.weaponframe = 0; + return; - case 4: - if (!gamestate.ammo) - break; - if (buttonstate[bt_attack]) - gamestate.attackframe -= 2; - case 1: - if (!gamestate.ammo) - { // can only happen with chain gun - gamestate.attackframe++; - break; - } - GunAttack (ob); - if (!ammocheat) - gamestate.ammo--; - DrawAmmo (); - break; + case 4: + if (!gamestate.ammo) + break; + if (buttonstate[bt_attack]) + gamestate.attackframe -= 2; + case 1: + if (!gamestate.ammo) + { // can only happen with chain gun + gamestate.attackframe++; + break; + } + GunAttack (ob); + if (!ammocheat) + gamestate.ammo--; + DrawAmmo (); + break; - case 2: - KnifeAttack (ob); - break; + case 2: + KnifeAttack (ob); + break; - case 3: - if (gamestate.ammo && buttonstate[bt_attack]) - gamestate.attackframe -= 2; - break; - } + case 3: + if (gamestate.ammo && buttonstate[bt_attack]) + gamestate.attackframe -= 2; + break; + } - gamestate.attackcount += cur->tics; - gamestate.attackframe++; - gamestate.weaponframe = - attackinfo[gamestate.weapon][gamestate.attackframe].frame; - } + gamestate.attackcount += cur->tics; + gamestate.attackframe++; + gamestate.weaponframe = + attackinfo[gamestate.weapon][gamestate.attackframe].frame; + } } @@ -1466,27 +1453,27 @@ void T_Attack (objtype *ob) void T_Player (objtype *ob) { - if (gamestate.victoryflag) // watching the BJ actor - { - VictorySpin (); - return; - } + if (gamestate.victoryflag) // watching the BJ actor + { + VictorySpin (); + return; + } - UpdateFace (); - CheckWeaponChange (); + UpdateFace (); + CheckWeaponChange (); - if ( buttonstate[bt_use] ) - Cmd_Use (); + if ( buttonstate[bt_use] ) + Cmd_Use (); - if ( buttonstate[bt_attack] && !buttonheld[bt_attack]) - Cmd_Fire (); + if ( buttonstate[bt_attack] && !buttonheld[bt_attack]) + Cmd_Fire (); - ControlMovement (ob); - if (gamestate.victoryflag) // watching the BJ actor - return; + ControlMovement (ob); + if (gamestate.victoryflag) // watching the BJ actor + return; - plux = (word) (player->x >> UNSIGNEDSHIFT); // scale to fit in unsigned - pluy = (word) (player->y >> UNSIGNEDSHIFT); - player->tilex = (short)(player->x >> TILESHIFT); // scale to tile values - player->tiley = (short)(player->y >> TILESHIFT); + plux = (word) (player->x >> UNSIGNEDSHIFT); // scale to fit in unsigned + pluy = (word) (player->y >> UNSIGNEDSHIFT); + player->tilex = (short)(player->x >> TILESHIFT); // scale to tile values + player->tiley = (short)(player->y >> TILESHIFT); }