DieHard Wolfers Forum Index DieHard Wolfers
A Wolfenstein 3d Fan Community


  Hosted by: MCS & Areyep.com - Designed by: BrotherTank

Original Yahoo Forum - Die Hard Archives

AReyeP HomepageAreyep Homepage DieHard Wolfenstein BunkerDieHard Wolfenstein Bunker Log inLog in RegisterRegister Banlist FAQFAQ Search ForumsSearch

  Username:    Password:      Remember me       

[Tutorial] Switches for electricity, etc.
Page 1 of 1
DieHard Wolfers Forum Index -> Code Tutorials View Previous TopicRefresh this PageAdd Topic to your Browser FavoritesSearch ForumsPrint this TopicE-mail TopicGoto Page BottomView Next Topic
Post new topicReply to topic
Author Message
Kuki
Can I Play Daddy
Can I Play Daddy


Joined: 16 Mar 2003
Last Visit: 18 Jan 2010

Topics: 6
Posts: 43
Location: Torun/Olsztyn, Poland
poland.gif

PostPosted: Thu Jul 29, 2004 2:34 am
   Subject: [Tutorial] Switches for electricity, etc.
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Next PostGoto Bottom of Posts

I remember someone requesting this, so here's a simple tutorial for making a switch that turns something on/off. Let's say we'll turn Blinky (red ghost) into a lamp and then turn him on off.

1. Open WL_DEF.H
2. Add the red line:
::: CODE :::

#define NUMAREAS      37
#define ELEVATORTILE   21
#define AMBUSHTILE      106
#define   ALTELEVATORTILE   107
#define SWITCHTILE   1

1 is the number of wall you want to use for switch - position one. This will be Gray Stone #1, but you should adjust it, of course.
3. Still in WL_DEF.H add boolean electricity; to the gamestate.structure:
::: CODE :::

   long      TimeCount;
   long      killx,killy;
   boolean      victoryflag;      // set during victory animations
   boolean      electricity;

4. Open WL_AGENT.C and in void Cmd_Use (void) add:
::: CODE :::

   if (!buttonheld[bt_use] && doornum == ELEVATORTILE && elevatorok)
   {
   //
   // use elevator
   //
      buttonheld[bt_use] = true;

      tilemap[checkx][checky]++;      // flip switch
      if (*(mapsegs[0]+farmapylookup[player->tiley]+player->tilex) == ALTELEVATORTILE)
         playstate = ex_secretlevel;
      else
         playstate = ex_completed;
      SD_PlaySound (LEVELDONESND);
      SD_WaitSoundDone();
   }
   else if (!buttonheld[bt_use] && (doornum == SWITCHTILE || doornum == SWITCHTILE+1) && elevatorok) // if you want the switch to be on both sides of the wall, remove the "&& elevatorok" part
   {
   //
   // use switch
   //
      buttonheld[bt_use] = true;

      if (doornum==SWITCHTILE)
      {
      tilemap[checkx][checky]++;      // flip switch
//      gamestate.electricity=true;      // you can use this
      }
      else
      {
      tilemap[checkx][checky]--;      // flip switch
//      gamestate.electricity=true;      // and this
      }
      gamestate.electricity=1-gamestate.electricity;   // instead of using this. This one changes from the actual state to the second one, the others change to on, when switch is in position A, off when in position B
      SD_PlaySound (LEVELDONESND);
      SD_WaitSoundDone();
   }


   else if (!buttonheld[bt_use] && doornum & 0x80)
   {
      buttonheld[bt_use] = true;
      OperateDoor (doornum & ~0x80);
   }
   else
      SD_PlaySound (DONOTHINGSND);

5. Open WL_ACT2.C and add the red line:
::: CODE :::

void   T_FakeFire (objtype *ob);
void   T_Ghosts (objtype *ob);
void   T_Blinky (objtype *ob);

void A_Slurpie (objtype *ob);

6. Change the following lines to look like these:
::: CODE :::

statetype s_blinkychase1    = {false,SPR_BLINKY_W1,10,T_Ghosts,NULL,&s_blinkychase2};
statetype s_blinkychase2    = {false,SPR_BLINKY_W2,10,T_Ghosts,NULL,&s_blinkychase1};

::: CODE :::

statetype s_blinkychase1    = {false,SPR_BLINKY_W1,0,T_Blinky,NULL,&s_blinkychase1};
statetype s_blinkychase2    = {false,SPR_BLINKY_W2,0,T_Blinky,NULL,&s_blinkychase2};

7. In void SpawnGhosts(int, int, int):
::: CODE :::

    case en_inky:
      SpawnNewObj (tilex,tiley,&s_inkychase1);
      break;
   }

   if (which!=en_blinky)
   {
   new->obclass = ghostobj;
   new->speed = SPDDOG;

   new->dir = east;
   new->flags |= FL_AMBUSH;
   if (!loadedgame)
     gamestate.killtotal++;
   }
   else
   new->obclass = ghostobj;

}

8. Add this somewhere in WL_ACT2.C, say before void T_Ghosts (objtype):
::: CODE :::


/*
=================
=
= T_Blinky
=
=================
*/

void T_Blinky (objtype *ob)
{
if (ob->state==&s_blinkychase1 && gamestate.electricity==true)
ob->state=&s_blinkychase2;
else if (ob->state==&s_blinkychase2 && gamestate.electricity==false)
ob->state=&s_blinkychase1;
return;
}


9. In WL_GAME.C in void Died (void):
::: CODE :::

      gamestate.keys = 0;
      gamestate.attackframe = gamestate.attackcount =
      gamestate.weaponframe = 0;
      gamestate.electricity = false;      // set to false after death

10. Same file, in void GameLoop (void):
::: CODE :::

switch (playstate)
      {
      case ex_completed:
      case ex_secretlevel:
         gamestate.electricity = false; // set to false at end of level, so it is false at the beginning of next one
         gamestate.keys = 0;

11. In WL_MAIN.C in void NewGame (int, int):
::: CODE :::

   gamestate.ammo = STARTAMMO;
   gamestate.lives = 3;
   gamestate.nextextra = EXTRAPOINTS;
   gamestate.episode=episode;
   gamestate.electricity=false; // set to false at the beginning of game

I think that's all. Source can be modified to switch other things than poor Blinky, that's just an example. You can turn light shading on/off, change shading colors, turn snow on/off, turn day into night (done that, it's cool Cool), activate mechanical guards etc. I believe it's also a good idea to have one wall that represents the switch in two positions (one in E/W picture, one in N/S picture) instead of two walls, as it is done in this tutorial, so that you'd use up 2 pictures instead of 4. But this is another story...

Well, enjoy and report any bugs here or to kukimik@poczta.onet.pl.

Kuki
wolf3dbreaker
I am Death Incarnate
I am Death Incarnate


Joined: 09 Jun 2003
Last Visit: 29 Sep 2009

Topics: 31
Posts: 196
Location: Philippines
philippines.gif

PostPosted: Thu Jul 29, 2004 3:34 am
   Subject: Re: [Tutorial] Switches for electricity, etc.
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Hey cool! I've always wanted to have this feature!

_________________
Gone from the community for a while. Will be back on July
WSJ
DieHard Officer
DieHard Officer


Joined: 17 Apr 2004
Last Visit: 08 May 2017

Topics: 24
Posts: 521

blank.gif

PostPosted: Thu Jul 29, 2004 9:45 pm
   Subject: Re: [Tutorial] Switches for electricity, etc.
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Nice work, Kuki. Smile This might give some of the less-experienced coders some ideas of what they can do with the code.
Raistlin
DieHard Guard
DieHard Guard


Joined: 22 Apr 2003
Last Visit: 18 Oct 2006

Topics: 24
Posts: 246

blank.gif

PostPosted: Fri Jul 30, 2004 12:20 am
   Subject: Re: [Tutorial] Switches for electricity, etc.
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Hey, nice work, dude!!!

Now how do I make the switch
unlock loked doors?

_________________
As I watched him on T.v, somehow it really bothered me...
Kuki
Can I Play Daddy
Can I Play Daddy


Joined: 16 Mar 2003
Last Visit: 18 Jan 2010

Topics: 6
Posts: 43
Location: Torun/Olsztyn, Poland
poland.gif

PostPosted: Fri Jul 30, 2004 4:47 am
   Subject: Re: [Tutorial] Switches for electricity, etc.
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Raistlin wrote:
Now how do I make the switch
unlock loked doors?


Check the OperateDoor function in WL_ACT1.C and add "&& gamestate.electricity" or a similiar condition to the first if.
::: CODE :::
... && lock <= dr_lock4 && gamestate.electricity)

This will lock/unlock all locked doors after the switch is used, still keeping them openable with a key.

Should work, haven't tried, though Smile

Kuki
KyleRTCW
DieHard Officer
DieHard Officer


Joined: 30 Jul 2003
Last Visit: 11 Jan 2018

Topics: 45
Posts: 510
Location: Ohio
usa.gif

PostPosted: Fri Jul 30, 2004 10:29 am
   Subject: Re: [Tutorial] Switches for electricity, etc.
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

AWESOME Shocked
I always wanted this feature for a "security lasers"!
Too bad I'm not interested in my TC anymore. Sad

_________________
Steam: http://steamcommunity.com/id/stormx312
WLHack
DieHard Wolfer
DieHard Wolfer


Joined: 10 Jul 2005
Last Visit: 14 Jan 2018

Topics: 66
Posts: 1240
Location: Loppi - Finland
finland.gif

PostPosted: Thu Dec 01, 2005 7:12 am
   Subject: Re: [Tutorial] Switches for electricity, etc.
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

I am not a much of a coder, so can anyone tell me how to I make
a object that would be blockable when switch is OFF and be
a passable when the switch is ON?
thellt
Bring 'em On
Bring 'em On


Joined: 21 Jan 2008
Last Visit: 12 May 2009

Topics: 11
Posts: 85
Location: bloodgulch
usa.gif

PostPosted: Wed Feb 06, 2008 9:50 am
   Subject: Re: [Tutorial] Switches for electricity, etc.
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Bottom of Posts

i would like to make a wall switch that turns on a torture electricity table or something like a fire torture devise or maybe a trap that involves guards (fried guards Laughing !) Thumbs Up Very Happy
Display posts from previous:   
Post new topicReply to topic Time synchronized with the forum server time
DieHard Wolfers Forum Index -> Code Tutorials View Previous TopicRefresh this PageAdd Topic to your Browser FavoritesSearch ForumsPrint this TopicE-mail TopicGoto Page TopView Next Topic
Page 1 of 1
Jump to:  

Related topics
 Topics   Replies   Views   Last Post 
No new posts [Code] Different Door Sides - Ripper
Author: Ripper
1 1764 Tue Apr 19, 2011 7:00 pm
gerolf View latest post
No new posts [Code] Add Text to Screen at Skill Level select - Chris
Author: Chris
3 2473 Tue Sep 28, 2010 6:59 pm
Tricob View latest post
No new posts [Code] Blood Splatz Tutorial - Blood Splatters
Author: Dugtrio17
45 11373 Tue Mar 11, 2008 12:02 am
AlumiuN View latest post
No new posts [Code] Display Different Ammo Types on Statusbar-BrotherTank
Author: BrotherTank
1 2410 Fri Feb 11, 2005 9:18 pm
Zombie_Plan View latest post
No new posts [Code] Adding a Frames per Second Counter - Darkone
Author: BrotherTank
0 1733 Sat Mar 13, 2004 2:07 pm
BrotherTank View latest post
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
   You cannot delete your posts in this forum
You cannot vote in polls in this forum


Copyright ©2003-2008 DieHard Wolfers
A Modified subBunker Theme by BrotherTank
Powered by phpBB © 2001, 2005 phpBB Group