home *** CD-ROM | disk | FTP | other *** search
- // ------- bitpart.cpp
-
- #include <stdlib.h>
- #include "shootout.h"
-
- BitPart::BitPart(char *gfxfile) : Player(gfxfile, "sounds.sfx")
- {
- }
-
- BitPart::~BitPart()
- {
- }
-
- void BitPart::initialize_bitpart()
- {
- steps = 0;
- door = 0;
- location = nowhere;
- mode = inactive;
- noactivity = 0;
- clipper.x1 = clipper.x2 = clipper.y1 = clipper.y2 = 0;
- clipper.occupied = 0;
- exitright = 1;
- enterright = 1;
- disappear();
- }
-
- void BitPart::make_entrance()
- {
- int sct = stepct/stepincr;
- if (++steps < sct) {
- if (enterright)
- setx(getx()+stepincr);
- else
- setx(getx()-stepincr);
- }
- else if (steps >= sct && steps < sct + forwardsteps) {
- if (clipper.y1 == 0)
- unclip();
- setinterval(bpwalkinterval);
- sety(gety()+1);
- set_imageno((steps & 1) + 2);
- }
- else if (steps == sct + forwardsteps) {
- noactivity = 0;
- mode = standing;
- setinterval(1);
- steps = 0;
- if (door != 0)
- door->close();
- if (iscitizen() && on_the_street(location) &&
- ((Shootout*)director)->sheriff->isdead())
- set_imageno(8);
- else
- set_imageno(1);
- }
- }
-
- void BitPart::hit_the_mark()
- {
- short int sheriffdead = ((Shootout*)director)->sheriff->isdead();
- short int badguysdead = ((Shootout*)director)->badguys->getnum() == 3;
- short int citizensdead = ((Shootout*)director)->citizens->getnum();
- if (sheriffdead || badguysdead) {
- // -- either the sheriff is dead or all the badguys are dead
- if (iscitizen() && !on_the_street(location))
- // --- send citizens to the street
- noactivity = waitcount;
- else if (!iscitizen())
- // --- badguys leave town
- noactivity = waitcount;
- else {
- if (sheriffdead) {
- if (get_imageno() != 8)
- set_imageno(8);
- }
- else if (!citizensdead)
- // ---- all bad guys are dead and no citizens. applaud
- mode = applauding;
- }
- }
- else {
- if (get_imageno() == 8)
- set_imageno(1);
- ++noactivity;
- }
- if (noactivity == waitcount) {
- mode = exiting;
- setinterval(bpwalkinterval);
- noactivity = 0;
- }
- }
- void BitPart::exit_stage()
- {
- int sct = stepct/stepincr;
- if (steps == 0) {
- clip(clipper.x1, clipper.y1, clipper.x2, clipper.y2);
- if (door != 0)
- door->open();
- }
- if (steps < forwardsteps) {
- sety(gety()-1);
- set_imageno((steps & 1) + 4);
- }
- else if (steps == forwardsteps) {
- exitright = door ? 1 : random(2);
- setinterval(1);
- set_imageno(9-exitright*3);
- }
- else if (steps > forwardsteps && steps < sct+forwardsteps) {
- if (exitright)
- setx(getx()-stepincr);
- else
- setx(getx()+stepincr);
- }
- else if (steps == sct+forwardsteps) {
- mode = inactive;
- if (door != 0)
- door->close();
- disappear();
- ((Shootout*)director)->exitstage(this);
- setinterval(1);
- return;
- }
- steps++;
- }
-
- void BitPart::swan_song()
- {
- set_imageno(7);
- if (getx() > 270)
- setx(270);
- mode = dying;
- }
-
- void BitPart::fall()
- {
- int y = gety();
- if (y < sidewalk)
- sety(y+10);
- else {
- mode = dead;
- play_sound_clip(3);
- ((Shootout*)director)->exitstage(this);
- }
- }
-
- void BitPart::getshot()
- {
- setinterval(1);
- unclip();
- mode = die;
- if (door)
- door->close();
- }
-
- void BitPart::applaud()
- {
- if (((Shootout*)director)->citizens->getnum()) {
- // -- stop clapping and exit if the sheriff kills a citizen
- setinterval(1); // run, don't walk
- mode = exiting;
- }
- else {
- if (((Shootout*)director)->sheriff->isdead())
- mode = standing;
- else {
- // ----- applause seqence
- if (get_imageno() != 10)
- set_imageno(10);
- else
- set_imageno(11);
- if (!sound_clip_is_playing())
- play_sound_clip(5);
- }
- }
- }
-
- void BitPart::update_position()
- {
- switch (mode) {
- case entrance:
- make_entrance();
- break;
- case standing:
- hit_the_mark();
- break;
- case exiting:
- exit_stage();
- break;
- case die:
- swan_song();
- case dying:
- fall();
- break;
- case applauding:
- applaud();
- break;
- default:
- break;
- }
- }
-
- void BitPart::enter(Portal cl, Door *dr, Location loc)
- {
- if (loc == alley2 && clipper.building == jail)
- enterright = 0;
- else if (loc == alley3 && clipper.building == saloon)
- enterright = 0;
- else
- enterright = 1;
- door = dr;
- if (door)
- door->open();
- location = loc;
- clipper = cl;
- mode = entrance;
- noactivity = 0;
- if (enterright)
- setx(clipper.x1-stepct);
- else
- setx(clipper.x2);
- sety(clipper.y1 ? clipper.y1-13 : 104);
- set_imageno(1);
- appear();
- steps = 0;
- }
-
- short int BitPart::zone()
- {
- short int zn = 0;
- if (mode != inactive && mode != dead && mode != dying) {
- zn = location - 5;
- if (zn < 1)
- zn = 1;
- else if (zn > 5)
- zn = 5;
- }
- return zn;
- }
-
-