fangflecked-old

old project. ive since repurposed the name
git clone git://moonbender.net/fangflecked-old
Log | Files | Refs | README

main.qc (9719B)


      1 //THIS FILE NEEDS AN OVERHAUL
      2 
      3 void() ToggleMenu =
      4 {
      5 	if(serverkey("constate") != "disconnected")
      6 	{
      7 		if(in_menu == MENU_NONE)
      8 		{
      9 			in_menu = MENU_MAIN;
     10 			time_in_menu = 0;
     11 			local float i;
     12 			for(i = 0; i < BUTTONS_COUNT; i++)
     13 			{
     14 				buttons[i].active = 1;
     15 			}
     16 			setcursormode(TRUE,"menu/cursor");
     17 		}
     18 		else
     19 		{
     20 			in_menu = MENU_NONE;
     21 			setcursormode(FALSE);
     22 		}
     23 	}
     24 	else
     25 	{
     26 		in_menu = MENU_MAIN;
     27 		time_in_menu = 0;
     28 		setcursormode(TRUE,"menu/cursor");
     29 	}
     30 }
     31 
     32 noref void(float apiver, string enginename, float enginever) CSQC_Init =
     33 {
     34 	registercommand("togglemenu");
     35 	registercommand("startwalk");
     36 	registercommand("stopwalk");
     37 	registercommand("promptjoin");
     38 	print("CSQC Started\n");
     39 	dummy = spawn();
     40 	if(serverkey("constate") == "disconnected")
     41 		ToggleMenu();
     42 	//bgpos = 0;
     43 };
     44 
     45 noref void() CSQC_WorldLoaded =
     46 {
     47 	precache_model("models/stalag1.iqm");
     48 	precache_model("models/stalag2.iqm");
     49 	
     50 	particleeffectnum("weapons.bulletimpact");
     51 	
     52 	if(!vmodel)
     53 		vmodel = spawn();
     54 		
     55 	vmodel.renderflags = RF_VIEWMODEL;
     56 	vmodel.origin = '24 0 -18';
     57 	vmodel_targetpos = vmodel_currentpos = vmodel.origin;
     58 	vmodel_velocity = '0 0 0';
     59 	vmodel_muzzleoffset = '48 -1 2';
     60 	setmodel(vmodel,"");
     61 };
     62 
     63 void() Update_Vmodel =
     64 {
     65 	local vector offset;
     66 	local vector dir;
     67 	
     68 	offset_x = 0.6 * sin(time * 1.2);
     69 	offset_y = 0.4 * cos(time * 1.5);
     70 	offset_z = 0.7 * sin(1.1*time + 0.5);
     71 	
     72 	dir = vmodel_targetpos - vmodel_currentpos;
     73 	if(vlen(dir) < (0.15 * 128 * frametime))
     74 		vmodel_currentpos = vmodel_targetpos;
     75 	else
     76 		vmodel_currentpos += (dir * 0.15 * 128) * frametime;
     77 	
     78 	if(vlen(vmodel.angles) < (0.1 * 128 * frametime))
     79 		vmodel.angles = '0 0 0';
     80 	else
     81 		vmodel.angles += (-vmodel.angles * 0.2 * 128) * frametime;
     82 		
     83 	vmodel_currentpos += (vmodel_velocity * 128) * frametime;
     84 	vmodel_velocity *= 1 - frametime * 30;
     85 	
     86 	vmodel.angles += (vmodel_avelocity * 128) * frametime;
     87 	vmodel_avelocity *= 1 - frametime * 30;
     88 	
     89 	vmodel.origin = vmodel_currentpos + offset;
     90 		
     91 	if (vmodel.frame1time >= 1)
     92 	{
     93 		vmodel.frame1time = 0;
     94 		vmodel.frame = 0; //real hacky, it'll work for now
     95 	}
     96 	vmodel.frame1time = vmodel.frame1time + .008;
     97 }
     98 
     99 noref void(float isnew) CSQC_Ent_Update =
    100 {
    101 	if(isnew)
    102 		print(strcat(etos(self),"\n"));
    103 }	
    104 
    105 noref void(float width, float height, float menushown) CSQC_UpdateView =
    106 {
    107 	clearscene();
    108 	g_width = width;
    109 	g_height = height;
    110 
    111 	setviewprop(VF_DRAWENGINESBAR, 0);	
    112 	setviewprop(VF_DRAWCROSSHAIR, 0);
    113 	//setviewprop(VF_ORIGIN, self.origin);
    114 	//setviewprop(VF_ANGLES, input_angles);
    115 			
    116 	addentities(MASK_ENGINE);
    117 	dynamiclight_add('-30 0 80', 200, '1 0.6 0.6');
    118 
    119 	if(vmodel)
    120 	{
    121 		Update_Vmodel();
    122 		addentity(vmodel);
    123 /*		if(mzlflash.alpha > 0.09)
    124 		{
    125 			makevectors(view_angles);
    126 			local vector offset = vmodel.origin + vmodel_muzzleoffset;
    127 			local vector muzzlepos;
    128 			muzzlepos = getviewprop(VF_ORIGIN);
    129 			muzzlepos += v_forward * offset_x;
    130 			muzzlepos -= v_right * offset_y;
    131 			muzzlepos += v_up * (offset_z + 6);
    132 		}
    133 		*/
    134 	}
    135 
    136 	renderscene();
    137 	
    138 	if(in_menu)
    139 	{
    140 		Draw_Menu();
    141 	}
    142 	else
    143 	{
    144 		local float health, ammo;
    145 		health = getstatf(STAT_HEALTH);
    146 		if(weapon == 1)
    147 			ammo = getstatf(51);
    148 		else if(weapon == 2)
    149 			ammo = getstatf(50);
    150 		else
    151 			ammo = -1;
    152 		drawstring([0.01*width, 0.94*height, 0], strcat("+",ftos(health)), [0.03*width, 0.03*width, 0], [1, 1, 1], 1, 1);
    153 		if(ammo != -1)
    154 			drawstring([0.75*width, 0.94*height, 0], strcat("AMMO:",ftos(ammo)), [0.03*width, 0.03*width, 0], [1, 1, 1], 1, 1);
    155 	}
    156 	if(serverkey("constate") != "active" && serverkey("disconnected"))
    157 	{
    158 		drawfill('0 0 0',  [width, height, 0], '0.2 0.4 0.7', 1);
    159 		drawstring([width/2 - 60, height/2, 0], "Loading...", [16,16,0],[1,1,1],1,1);
    160 	}
    161 };
    162 
    163 noref float(string cmd) CSQC_ConsoleCommand =
    164 {
    165 	//self = theplayer;
    166 	//if (!self)
    167 	//	return FALSE;
    168 
    169 	tokenize(cmd);
    170 	switch(argv(0))
    171 	{
    172 		case "togglemenu":
    173 			ToggleMenu();
    174 			return TRUE;
    175 			break;
    176 		case "map":
    177 			return FALSE;
    178 			break;
    179 		case "startwalk":
    180 			walk = TRUE;
    181 			return FALSE;
    182 		case "stopwalk":
    183 			walk = FALSE;
    184 			return FALSE;
    185 		case "promptjoin":
    186 			menu_join();
    187 			return TRUE;
    188 		default:
    189 			return FALSE;
    190 	}
    191 	return FALSE;
    192 };
    193 
    194 noref float(float evtype, float scanx, float chary, float devid) CSQC_InputEvent =
    195 {
    196 	switch(evtype)
    197 	{
    198 	case IE_KEYDOWN:
    199 		if(in_menu != MENU_NONE)
    200 		{
    201 			if(scanx == K_MOUSE1)
    202 			{
    203 				print(strcat(ftos(num_for_edict(world)), ", ", ftos(num_for_edict(self)), "\n"));
    204 				Menu_Click();
    205 				return TRUE;
    206 			}
    207 		}
    208 		return FALSE;
    209 	case IE_KEYUP:
    210 		return FALSE;
    211 	case IE_MOUSEDELTA:
    212 		return FALSE;
    213 	case IE_MOUSEABS:
    214 		//if(devid != 0 && devid != 1)
    215 		//	return FALSE;
    216 		cursor_pos_x = scanx;
    217 		cursor_pos_y = chary;
    218 		return FALSE;
    219 	}
    220 	return FALSE;
    221 };
    222 
    223 noref void() CSQC_Input_Frame =
    224 {
    225 
    226 	if(walk)
    227 	{
    228 		input_movevalues *= 0.5;
    229 	}
    230 	//TODO: this was causing deprecation warnings
    231 	//but I think removing it will disable
    232 	//player movement prediction. Figure
    233 	//out a better place to put it!
    234 	//also: figure out what the rest of the code in
    235 	//this function is doing :V
    236 //	runstandardplayerphysics(self);
    237 }
    238 
    239 //TODO: Put this somewhere else
    240 float() alphafade =
    241 {
    242 	
    243 	self.alpha -= (frametime / 7);
    244 //	self.scale += (frametime * 9);
    245 	if(self.alpha <= 0.05)
    246 		remove(self);
    247 	
    248 	local vector cross1 = 10 * self.scale * normalize(crossproduct( getviewprop(VF_ORIGIN) - self.origin + self.targetpos * self.scale, self.targetpos * self.scale));
    249 	local vector cross2 = 10 * self.scale * normalize(crossproduct( getviewprop(VF_ORIGIN) - self.origin, self.targetpos * self.scale));
    250 	R_BeginPolygon("bloodsplat2");
    251 	
    252 	R_PolygonVertex(self.origin + cross2, '0 1 0', '1 1 1', self.alpha);
    253 	R_PolygonVertex(self.origin - cross2, '0 0 0', '1 1 1', self.alpha);
    254 	R_PolygonVertex(self.origin + (self.targetpos*self.scale*18) - cross1, '1 0 0', '1 1 1', self.alpha);
    255 
    256 	R_PolygonVertex(self.origin + (self.targetpos*self.scale*18) + cross1, '1 1 0', '1 1 1', self.alpha);
    257 	R_PolygonVertex(self.origin + cross2, '0 1 0', '1 1 1', self.alpha);
    258 	R_PolygonVertex(self.origin + (self.targetpos*self.scale*18) - cross1, '1 0 0', '1 1 1', self.alpha);
    259 	
    260 	R_EndPolygon();
    261 	
    262 	return 0;
    263 }
    264 
    265 //TODO: Clean this up, motherfucker!
    266 noref void() CSQC_Parse_Event =
    267 {
    268 	local float first = readbyte();
    269 	if
    270 		(
    271 			first == EVENT_PISTOLFIRE 
    272 			|| first == EVENT_MGFIRE
    273 		) //Event is a gunshot
    274 	{
    275 		local float entnum, traceent;
    276 		local vector pos, norm;
    277 		entnum = readentitynum();
    278 
    279 		pos_x = readcoord();
    280 		pos_y = readcoord();
    281 		pos_z = readcoord();
    282 		norm_x = readcoord();
    283 		norm_y = readcoord();
    284 		norm_z = readcoord();
    285 		
    286 		traceent = readentitynum();
    287 
    288 		//why do I pass which type of
    289 		//gunshot it is, AND check which
    290 		//weapon the player is holding?
    291 		//TODO: CCLEAN THIS UP
    292 
    293 		if(entnum == player_localentnum)
    294 		{
    295 			if(weapon == 1)
    296 			{
    297 				if (vmodel.frame1time > 0)
    298 				{
    299 					vmodel.frame1time = 0;
    300 					vmodel.frame = frameforname(vmodel.modelindex, "fire");
    301 //					local entity casing = spawn();
    302 //					setmodel(casing, "models/shell.iqm");
    303 //					setorigin(casing, vmodel.origin);
    304 //					casing.drawmask = 1;
    305 //					casing.alpha = 1;
    306 //					casing.scale = 1;
    307 //					casing.angles = '0 0 90';
    308 	//				casing.targetpos = norm * 1.5;
    309 //					casing.predraw = alphafade;
    310 //					casing.movetype = MOVETYPE_BOUNCE;
    311 				}
    312 				
    313 			}
    314 			else if(weapon == 2)
    315 			{
    316 			
    317 			}
    318 		}
    319 		//really need to put a ton of this stuff into
    320 		//a separate function, in a different file
    321 		if(traceent == 0)
    322 		{
    323 			local float sparksnum, bulletnum;
    324 			bulletnum = particleeffectnum("weapons.bulletimpact");
    325 			sparksnum = particleeffectnum("weapons.pelletsparks");
    326 			pointparticles(sparksnum, pos);
    327 			pointparticles(bulletnum, pos);
    328 		}
    329 		else
    330 		{
    331 			local vector entorg;
    332 			local float effect;
    333 			entorg = getentity(traceent, GE_ORIGIN);
    334 			norm = (norm * 0.25) + (normalize(pos - (entorg + '0 0 12')) * 0.75);
    335 			effect = particleeffectnum("weapons.bloodspray");
    336 			pointparticles(effect, pos);
    337 			
    338 //			local entity splat = spawn();
    339 //			setmodel(splat, "models/blood.iqm");
    340 //			setorigin(splat, pos + '0 0 0');
    341 //			splat.drawmask = 1;
    342 //			splat.alpha = 1;
    343 //			splat.scale = 0.05;
    344 //			splat.angles = [random()*360, random()*360, random()*360];
    345 //			splat.targetpos = norm * 1.5;
    346 //			splat.predraw = alphafade;
    347 		}
    348 	}
    349 	else if
    350 		(
    351 			first == EVENT_WEAPONCHANGE
    352 		) //Event is a weapon switch
    353 	{
    354 		//weapon to switch to
    355 		//TODO: Do defines for these too
    356 		local float to;
    357 		to = readbyte();
    358 		if(to == 1)
    359 		{
    360 			vmodel.origin = '32 -8 -16';
    361 			vmodel.angles = '-60 0 0';
    362 			vmodel_currentpos = vmodel.origin + '0 0 -24';
    363 			vmodel_targetpos = vmodel.origin;
    364 			vmodel_muzzleoffset = '12 0 1';
    365 			setmodel(vmodel,"models/shotty.iqm");
    366 			vmodel.skin = 0;
    367 			weapon = to;
    368 		}
    369 		else if(to == 2)
    370 		{
    371 			vmodel.origin = '10 -8 -18';
    372 			vmodel.angles = '-70 0 0';
    373 			vmodel_currentpos = vmodel.origin + '0 0 -24';
    374 			vmodel_targetpos = vmodel.origin;
    375 			vmodel_muzzleoffset = '40 0 4';
    376 			setmodel(vmodel,"");
    377 			weapon = to;
    378 		}
    379 	}
    380 	else if
    381 		(
    382 			first == EVENT_PLAYERDEATH
    383 		) //player just died
    384 	{
    385 		setmodel(vmodel,"");
    386 		//yep, this is all that happens when
    387 		//you die atm
    388 	}
    389 	else if
    390 		(
    391 		 	first == EVENT_EMITPARTICLES
    392 		) //just does fire for now
    393 		{
    394 			pos_x = readcoord();
    395 			pos_y = readcoord();
    396 			pos_z = readcoord();
    397 			
    398 			local float effect;
    399 			effect = particleeffectnum("fire.torchflame");
    400 			pointparticles(effect, pos);
    401 		}
    402 }