doom

a minimalistic implementation of doom
git clone git://ssnf.xyz/doom
Log | Files | Refs

p_switch.c (8617B)


      1 #include "i_system.h"
      2 #include "doomdef.h"
      3 #include "p_local.h"
      4 #include "g_game.h"
      5 #include "s_sound.h"
      6 #include "sounds.h"
      7 #include "doomstat.h"
      8 #include "r_state.h"
      9 
     10 int      switchlist[MAXSWITCHES * 2];
     11 int      numswitches;
     12 button_t buttonlist[MAXBUTTONS];
     13 
     14 switchlist_t alphSwitchList[] = {
     15 	{"SW1BRCOM",	"SW2BRCOM",	1},
     16 	{"SW1BRN1",	"SW2BRN1",	1},
     17 	{"SW1BRN2",	"SW2BRN2",	1},
     18 	{"SW1BRNGN",	"SW2BRNGN",	1},
     19 	{"SW1BROWN",	"SW2BROWN",	1},
     20 	{"SW1COMM",	"SW2COMM",	1},
     21 	{"SW1COMP",	"SW2COMP",	1},
     22 	{"SW1DIRT",	"SW2DIRT",	1},
     23 	{"SW1EXIT",	"SW2EXIT",	1},
     24 	{"SW1GRAY",	"SW2GRAY",	1},
     25 	{"SW1GRAY1",	"SW2GRAY1",	1},
     26 	{"SW1METAL",	"SW2METAL",	1},
     27 	{"SW1PIPE",	"SW2PIPE",	1},
     28 	{"SW1SLAD",	"SW2SLAD",	1},
     29 	{"SW1STARG",	"SW2STARG",	1},
     30 	{"SW1STON1",	"SW2STON1",	1},
     31 	{"SW1STON2",	"SW2STON2",	1},
     32 	{"SW1STONE",	"SW2STONE",	1},
     33 	{"SW1STRTN",	"SW2STRTN",	1},
     34 	{"SW1BLUE",	"SW2BLUE",	2},
     35 	{"SW1CMT",		"SW2CMT",	2},
     36 	{"SW1GARG",	"SW2GARG",	2},
     37 	{"SW1GSTON",	"SW2GSTON",	2},
     38 	{"SW1HOT",		"SW2HOT",	2},
     39 	{"SW1LION",	"SW2LION",	2},
     40 	{"SW1SATYR",	"SW2SATYR",	2},
     41 	{"SW1SKIN",	"SW2SKIN",	2},
     42 	{"SW1VINE",	"SW2VINE",	2},
     43 	{"SW1WOOD",	"SW2WOOD",	2},
     44 	{"SW1PANEL",	"SW2PANEL",	3},
     45 	{"SW1ROCK",	"SW2ROCK",	3},
     46 	{"SW1MET2",	"SW2MET2",	3},
     47 	{"SW1WDMET",	"SW2WDMET",	3},
     48 	{"SW1BRIK",	"SW2BRIK",	3},
     49 	{"SW1MOD1",	"SW2MOD1",	3},
     50 	{"SW1ZIM",		"SW2ZIM",	3},
     51 	{"SW1STON6",	"SW2STON6",	3},
     52 	{"SW1TEK",		"SW2TEK",	3},
     53 	{"SW1MARB",	"SW2MARB",	3},
     54 	{"SW1SKULL",	"SW2SKULL",	3},
     55 	{"\0",		"\0",		0}
     56 };
     57 
     58 void
     59 P_InitSwitchList(void)
     60 {
     61 	int		i, j, episode;
     62 
     63 	episode = 1;
     64 	for (i = 0, j = 0; i < MAXSWITCHES; ++i) {
     65 		if (!alphSwitchList[i].episode) {
     66 			numswitches = j/2;
     67 			switchlist[j] = -1;
     68 			break;
     69 		}
     70 		if (alphSwitchList[i].episode <= episode) {
     71 			switchlist[j++] = R_TextureNumForName(alphSwitchList[i].name1);
     72 			switchlist[j++] = R_TextureNumForName(alphSwitchList[i].name2);
     73 		}
     74 	}
     75 }
     76 
     77 void
     78 P_StartButton(line_t* line, bwhere_e w, int texture, int time)
     79 {
     80 	int i;
     81 
     82 	for (i = 0; i < MAXBUTTONS; ++i) {
     83 			if (buttonlist[i].btimer && buttonlist[i].line == line)
     84 				return;
     85 		for (i = 0; i < MAXBUTTONS; ++i) {
     86 			if (!buttonlist[i].btimer) {
     87 				buttonlist[i].line = line;
     88 				buttonlist[i].where = w;
     89 				buttonlist[i].btexture = texture;
     90 				buttonlist[i].btimer = time;
     91 				buttonlist[i].soundorg = (mobj_t *)&line->frontsector->soundorg;
     92 				return;
     93 			}
     94 		}
     95 		I_Error("P_StartButton: no button slots left!");
     96 	}
     97 }
     98 
     99 void
    100 P_ChangeSwitchTexture(line_t* line, int useAgain)
    101 {
    102 	int texTop, texMid, texBot, i, sound;
    103 
    104 	if (!useAgain) line->special = 0;
    105 	texTop = sides[line->sidenum[0]].toptexture;
    106 	texMid = sides[line->sidenum[0]].midtexture;
    107 	texBot = sides[line->sidenum[0]].bottomtexture;
    108 	sound = sfx_swtchn;
    109 	if (line->special == 11) sound = sfx_swtchx;
    110 	for (i = 0; i < numswitches * 2; ++i) {
    111 		if (switchlist[i] == texTop) {
    112 			S_StartSound(buttonlist->soundorg,sound);
    113 			sides[line->sidenum[0]].toptexture = switchlist[i^1];
    114 			if (useAgain) P_StartButton(line,top,switchlist[i],BUTTONTIME);
    115 			return;
    116 		} else {
    117 			if (switchlist[i] == texMid) {
    118 				S_StartSound(buttonlist->soundorg,sound);
    119 				sides[line->sidenum[0]].midtexture = switchlist[i^1];
    120 				if (useAgain) P_StartButton(line, middle,switchlist[i],BUTTONTIME);
    121 				return;
    122 			} else {
    123 				if (switchlist[i] == texBot) {
    124 					S_StartSound(buttonlist->soundorg,sound);
    125 					sides[line->sidenum[0]].bottomtexture = switchlist[i^1];
    126 					if (useAgain) P_StartButton(line, bottom,switchlist[i],BUTTONTIME);
    127 					return;
    128 				}
    129 			}
    130 		}
    131 	}
    132 }
    133 
    134 boolean
    135 P_UseSpecialLine(mobj_t* thing, line_t* line, int side)
    136 {
    137 	if (side && line->special != 124) return false;
    138 	if (!thing->player) {
    139 		if (line->flags & ML_SECRET) return false;
    140 		switch (line->special) {
    141 			case 1:
    142 			case 32:
    143 			case 33:
    144 			case 34:
    145 				break;
    146 			default:
    147 				return false;
    148 		}
    149 	}
    150 	switch (line->special) {
    151 		case 1:
    152 		case 26:
    153 		case 27:
    154 		case 28:
    155 		case 31:
    156 		case 32:
    157 		case 33:
    158 		case 34:
    159 		case 117:
    160 		case 118:
    161 			EV_VerticalDoor(line, thing);
    162 			break;
    163 		case 7:
    164 			if (EV_BuildStairs(line,build8))
    165 				P_ChangeSwitchTexture(line,0);
    166 			break;
    167 		case 9:
    168 			if (EV_DoDonut(line))
    169 				P_ChangeSwitchTexture(line,0);
    170 			break;
    171 		case 11:
    172 			P_ChangeSwitchTexture(line,0);
    173 			G_ExitLevel();
    174 			break;
    175 		case 14:
    176 			if(EV_DoPlat(line,raiseAndChange,32))
    177 				P_ChangeSwitchTexture(line,0);
    178 			break;
    179 		case 15:
    180 			if (EV_DoPlat(line,raiseAndChange,24))
    181 				P_ChangeSwitchTexture(line,0);
    182 			break;
    183 		case 18:
    184 			if (EV_DoFloor(line, raiseFloorToNearest))
    185 				P_ChangeSwitchTexture(line,0);
    186 			break;
    187 		case 20:
    188 			if (EV_DoPlat(line,raiseToNearestAndChange,0))
    189 				P_ChangeSwitchTexture(line,0);
    190 			break;
    191 		case 21:
    192 			if (EV_DoPlat(line,downWaitUpStay,0))
    193 				P_ChangeSwitchTexture(line,0);
    194 			break;
    195 		case 23:
    196 			if (EV_DoFloor(line,lowerFloorToLowest))
    197 				P_ChangeSwitchTexture(line,0);
    198 			break;
    199 		case 29:
    200 			if (EV_DoDoor(line,normal))
    201 				P_ChangeSwitchTexture(line,0);
    202 			break;
    203 		case 41:
    204 			if (EV_DoCeiling(line,lowerToFloor))
    205 				P_ChangeSwitchTexture(line,0);
    206 			break;
    207 		case 71:
    208 			if (EV_DoFloor(line,turboLower))
    209 				P_ChangeSwitchTexture(line,0);
    210 			break;
    211 		case 49:
    212 			if (EV_DoCeiling(line,crushAndRaise))
    213 				P_ChangeSwitchTexture(line,0);
    214 			break;
    215 		case 50:
    216 			if (EV_DoDoor(line,close))
    217 				P_ChangeSwitchTexture(line,0);
    218 			break;
    219 		case 51:
    220 			P_ChangeSwitchTexture(line,0);
    221 			G_SecretExitLevel();
    222 			break;
    223 		case 55:
    224 			if (EV_DoFloor(line,raiseFloorCrush))
    225 				P_ChangeSwitchTexture(line,0);
    226 			break;
    227 		case 101:
    228 			if (EV_DoFloor(line,raiseFloor))
    229 				P_ChangeSwitchTexture(line,0);
    230 			break;
    231 		case 102:
    232 			if (EV_DoFloor(line,lowerFloor))
    233 				P_ChangeSwitchTexture(line,0);
    234 			break;
    235 		case 103:
    236 			if (EV_DoDoor(line,open))
    237 				P_ChangeSwitchTexture(line,0);
    238 			break;
    239 		case 111:
    240 			if (EV_DoDoor (line,blazeRaise))
    241 				P_ChangeSwitchTexture(line,0);
    242 			break;
    243 		case 112:
    244 			if (EV_DoDoor (line,blazeOpen))
    245 				P_ChangeSwitchTexture(line,0);
    246 			break;
    247 		case 113:
    248 			if (EV_DoDoor (line,blazeClose))
    249 				P_ChangeSwitchTexture(line,0);
    250 			break;
    251 		case 122:
    252 			if (EV_DoPlat(line,blazeDWUS,0))
    253 				P_ChangeSwitchTexture(line,0);
    254 			break;
    255 		case 127:
    256 			if (EV_BuildStairs(line,turbo16))
    257 				P_ChangeSwitchTexture(line,0);
    258 			break;
    259 		case 131:
    260 			if (EV_DoFloor(line,raiseFloorTurbo))
    261 				P_ChangeSwitchTexture(line,0);
    262 			break;
    263 		case 133:
    264 		case 135:
    265 		case 137:
    266 			if (EV_DoLockedDoor(line,blazeOpen,thing))
    267 				P_ChangeSwitchTexture(line,0);
    268 			break;
    269 		case 140:
    270 			if (EV_DoFloor(line,raiseFloor512))
    271 				P_ChangeSwitchTexture(line,0);
    272 			break;
    273 		case 42:
    274 			if (EV_DoDoor(line,close))
    275 				P_ChangeSwitchTexture(line,1);
    276 			break;
    277 		case 43:
    278 			if (EV_DoCeiling(line,lowerToFloor))
    279 				P_ChangeSwitchTexture(line,1);
    280 			break;
    281 		case 45:
    282 			if (EV_DoFloor(line,lowerFloor))
    283 				P_ChangeSwitchTexture(line,1);
    284 			break;
    285 		case 60:
    286 			if (EV_DoFloor(line,lowerFloorToLowest))
    287 				P_ChangeSwitchTexture(line,1);
    288 			break;
    289 		case 61:
    290 			if (EV_DoDoor(line,open))
    291 				P_ChangeSwitchTexture(line,1);
    292 			break;
    293 		case 62:
    294 			if (EV_DoPlat(line,downWaitUpStay,1))
    295 				P_ChangeSwitchTexture(line,1);
    296 			break;
    297 		case 63:
    298 			if (EV_DoDoor(line,normal))
    299 				P_ChangeSwitchTexture(line,1);
    300 			break;
    301 		case 64:
    302 			if (EV_DoFloor(line,raiseFloor))
    303 				P_ChangeSwitchTexture(line,1);
    304 			break;
    305 		case 66:
    306 			if (EV_DoPlat(line,raiseAndChange,24))
    307 				P_ChangeSwitchTexture(line,1);
    308 			break;
    309 		case 67:
    310 			if (EV_DoPlat(line,raiseAndChange,32))
    311 				P_ChangeSwitchTexture(line,1);
    312 			break;
    313 		case 65:
    314 			if (EV_DoFloor(line,raiseFloorCrush))
    315 				P_ChangeSwitchTexture(line,1);
    316 			break;
    317 		case 68:
    318 			if (EV_DoPlat(line,raiseToNearestAndChange,0))
    319 				P_ChangeSwitchTexture(line,1);
    320 			break;
    321 		case 69:
    322 			if (EV_DoFloor(line, raiseFloorToNearest))
    323 				P_ChangeSwitchTexture(line,1);
    324 			break;
    325 		case 70:
    326 			if (EV_DoFloor(line,turboLower))
    327 				P_ChangeSwitchTexture(line,1);
    328 			break;
    329 		case 114:
    330 			if (EV_DoDoor(line,blazeRaise))
    331 				P_ChangeSwitchTexture(line,1);
    332 			break;
    333 		case 115:
    334 			if (EV_DoDoor(line,blazeOpen))
    335 				P_ChangeSwitchTexture(line,1);
    336 			break;
    337 		case 116:
    338 			if (EV_DoDoor(line,blazeClose))
    339 				P_ChangeSwitchTexture(line,1);
    340 			break;
    341 		case 123:
    342 			if (EV_DoPlat(line,blazeDWUS,0))
    343 				P_ChangeSwitchTexture(line,1);
    344 			break;
    345 		case 132:
    346 			if (EV_DoFloor(line,raiseFloorTurbo))
    347 				P_ChangeSwitchTexture(line,1);
    348 			break;
    349 		case 99:
    350 		case 134:
    351 		case 136:
    352 			if (EV_DoLockedDoor (line,blazeOpen,thing))
    353 				P_ChangeSwitchTexture(line,1);
    354 			break;
    355 		case 138:
    356 			EV_LightTurnOn(line,255);
    357 			P_ChangeSwitchTexture(line,1);
    358 			break;
    359 		case 139:
    360 			EV_LightTurnOn(line,35);
    361 			P_ChangeSwitchTexture(line,1);
    362 			break;
    363 	}
    364 	return true;
    365 }
    366