dxx-rebirth/similar/main/effects.cpp

197 lines
4.9 KiB
C++
Raw Normal View History

2006-03-20 17:12:09 +00:00
/*
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
*/
/*
*
* Special effects, such as rotating fans, electrical walls, and
* other cool animations.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "gr.h"
#include "inferno.h"
#include "game.h"
#include "vclip.h"
#include "effects.h"
#include "bm.h"
#include "u_mem.h"
#include "textures.h"
#include "cntrlcen.h"
#include "dxxerror.h"
2006-03-20 17:12:09 +00:00
int Num_effects;
eclip Effects[MAX_EFFECTS];
void init_special_effects()
{
int i;
for (i=0;i<Num_effects;i++)
{
eclip &ec = Effects[i];
ec.time_left = ec.vc.frame_time;
}
2006-03-20 17:12:09 +00:00
}
void reset_special_effects()
{
int i;
for (i=0;i<Num_effects;i++) {
eclip &ec = Effects[i];
ec.segnum = segment_none; //clear any active one-shots
ec.flags &= ~(EF_STOPPED|EF_ONE_SHOT); //restart any stopped effects
2006-03-20 17:12:09 +00:00
//reset bitmap, which could have been changed by a crit_clip
if (ec.changing_wall_texture != -1)
Textures[ec.changing_wall_texture] = ec.vc.frames[ec.frame_count];
2006-03-20 17:12:09 +00:00
if (ec.changing_object_texture != -1)
ObjBitmaps[ec.changing_object_texture] = ec.vc.frames[ec.frame_count];
2006-03-20 17:12:09 +00:00
}
}
void do_special_effects()
{
int i;
for (i=0;i < Num_effects;i++) {
eclip &ec = Effects[i];
2006-03-20 17:12:09 +00:00
if ((ec.changing_wall_texture == -1) && (ec.changing_object_texture==-1) )
2006-03-20 17:12:09 +00:00
continue;
if (ec.flags & EF_STOPPED)
2006-03-20 17:12:09 +00:00
continue;
ec.time_left -= FrameTime;
2006-03-20 17:12:09 +00:00
while (ec.time_left < 0) {
2006-03-20 17:12:09 +00:00
ec.time_left += ec.vc.frame_time;
2006-03-20 17:12:09 +00:00
ec.frame_count++;
if (ec.frame_count >= ec.vc.num_frames) {
if (ec.flags & EF_ONE_SHOT) {
Assert(ec.segnum!=segment_none);
Assert(ec.sidenum>=0 && ec.sidenum<6);
Assert(ec.dest_bm_num!=0 && Segments[ec.segnum].sides[ec.sidenum].tmap_num2!=0);
Segments[ec.segnum].sides[ec.sidenum].tmap_num2 = ec.dest_bm_num | (Segments[ec.segnum].sides[ec.sidenum].tmap_num2&0xc000); //replace with destoyed
ec.flags &= ~EF_ONE_SHOT;
ec.segnum = segment_none; //done with this
2006-03-20 17:12:09 +00:00
}
ec.frame_count = 0;
2006-03-20 17:12:09 +00:00
}
}
if (ec.flags & EF_CRITICAL)
2006-03-20 17:12:09 +00:00
continue;
if (ec.crit_clip!=-1 && Control_center_destroyed) {
int n = ec.crit_clip;
2006-03-20 17:12:09 +00:00
if (ec.changing_wall_texture != -1)
Textures[ec.changing_wall_texture] = Effects[n].vc.frames[Effects[n].frame_count];
2006-03-20 17:12:09 +00:00
if (ec.changing_object_texture != -1)
ObjBitmaps[ec.changing_object_texture] = Effects[n].vc.frames[Effects[n].frame_count];
2006-03-20 17:12:09 +00:00
}
else {
if (ec.changing_wall_texture != -1)
Textures[ec.changing_wall_texture] = ec.vc.frames[ec.frame_count];
2006-03-20 17:12:09 +00:00
if (ec.changing_object_texture != -1)
ObjBitmaps[ec.changing_object_texture] = ec.vc.frames[ec.frame_count];
2006-03-20 17:12:09 +00:00
}
}
}
void restore_effect_bitmap_icons()
{
int i;
for (i=0;i<Num_effects;i++)
{
eclip &ec = Effects[i];
if (! (ec.flags & EF_CRITICAL)) {
if (ec.changing_wall_texture != -1)
Textures[ec.changing_wall_texture] = ec.vc.frames[0];
2006-03-20 17:12:09 +00:00
if (ec.changing_object_texture != -1)
ObjBitmaps[ec.changing_object_texture] = ec.vc.frames[0];
2006-03-20 17:12:09 +00:00
}
}
2006-03-20 17:12:09 +00:00
}
//stop an effect from animating. Show first frame.
void stop_effect(int effect_num)
{
eclip *ec = &Effects[effect_num];
//Assert(ec->bm_ptr != -1);
ec->flags |= EF_STOPPED;
ec->frame_count = 0;
//*ec->bm_ptr = &GameBitmaps[ec->vc.frames[0].index];
if (ec->changing_wall_texture != -1)
Textures[ec->changing_wall_texture] = ec->vc.frames[0];
if (ec->changing_object_texture != -1)
ObjBitmaps[ec->changing_object_texture] = ec->vc.frames[0];
}
//restart a stopped effect
void restart_effect(int effect_num)
{
Effects[effect_num].flags &= ~EF_STOPPED;
//Assert(Effects[effect_num].bm_ptr != -1);
}
/*
* reads n eclip structs from a PHYSFS_file
2006-03-20 17:12:09 +00:00
*/
int eclip_read_n(eclip *ec, int n, PHYSFS_file *fp)
2006-03-20 17:12:09 +00:00
{
int i;
for (i = 0; i < n; i++) {
2014-01-18 18:02:02 +00:00
vclip_read(fp, ec[i].vc);
ec[i].time_left = PHYSFSX_readFix(fp);
ec[i].frame_count = PHYSFSX_readInt(fp);
ec[i].changing_wall_texture = PHYSFSX_readShort(fp);
ec[i].changing_object_texture = PHYSFSX_readShort(fp);
ec[i].flags = PHYSFSX_readInt(fp);
ec[i].crit_clip = PHYSFSX_readInt(fp);
ec[i].dest_bm_num = PHYSFSX_readInt(fp);
ec[i].dest_vclip = PHYSFSX_readInt(fp);
ec[i].dest_eclip = PHYSFSX_readInt(fp);
ec[i].dest_size = PHYSFSX_readFix(fp);
ec[i].sound_num = PHYSFSX_readInt(fp);
ec[i].segnum = PHYSFSX_readInt(fp);
ec[i].sidenum = PHYSFSX_readInt(fp);
2006-03-20 17:12:09 +00:00
}
return i;
}