Page 1 of 1

HOWTO: Changing laser color for Player depending on weapon

Posted: Wed Sep 10, 2014 4:53 pm
by dertien
This is probably not rocket science, but for those of you who compile their own game and would like to have different laser colors depending on Laser installed, I would like to share this with you:

Download the source and open PlayerEntity.m in notepad ++

at line 5321 you will find this code block

Code: Select all

switch (currentWeapon)
	{
		case WEAPON_PLASMA_CANNON:
			weapon_energy_use =		6.0f;
			weapon_reload_time =	0.25f;
			break;
			
		case WEAPON_PULSE_LASER:
			weapon_energy_use =		0.8f;
			weapon_reload_time =	0.5f;
			break;
			
		case WEAPON_BEAM_LASER:
			weapon_energy_use =		1.0f;
			weapon_reload_time =	0.1f;
			break;
			
		case WEAPON_MINING_LASER:
			weapon_energy_use =		1.4f;
			weapon_reload_time =	2.5f;
			break;
			
		case WEAPON_THARGOID_LASER:
		case WEAPON_MILITARY_LASER:
			weapon_energy_use =		1.2f;
			weapon_reload_time =	0.1f;
			break;
			
		case WEAPON_NONE:
		case WEAPON_UNDEFINED:
			weapon_energy_use =		0.0f;
			weapon_reload_time =	0.1f;
			break;
	}
Replace it with this:

Code: Select all

switch (currentWeapon)
	{
		case WEAPON_PLASMA_CANNON:
			weapon_energy_use =		6.0f;
			weapon_reload_time =	0.25f;
			break;
			
		case WEAPON_PULSE_LASER:
			weapon_energy_use =		0.8f;
			weapon_reload_time =	0.5f;
			[self setLaserColor:[OOColor redColor]];
			break;
			
		case WEAPON_BEAM_LASER:
			weapon_energy_use =		1.0f;
			weapon_reload_time =	0.1f;
			[self setLaserColor:[OOColor orangeColor]];
			break;
			
		case WEAPON_MINING_LASER:
			weapon_energy_use =		1.4f;
			weapon_reload_time =	2.5f;
			[self setLaserColor:[OOColor yellowColor]];
			break;
			
		case WEAPON_THARGOID_LASER:
		case WEAPON_MILITARY_LASER:
			weapon_energy_use =		1.2f;
			weapon_reload_time =	0.1f;
			[self setLaserColor:[OOColor cyanColor]];
			break;
			
		case WEAPON_NONE:
		case WEAPON_UNDEFINED:
			weapon_energy_use =		0.0f;
			weapon_reload_time =	0.1f;
			break;
	}
Compile it and tadaaaa !!! you have your different colored lasers.

Change the color of the lasers to your liking.

Have fun.

Windows users who wish to compile could find this post useful: https://bb.oolite.space/viewtopic.php?f=8&t=15279

Since there is a way to set different background colors for galaxies, I can't really see why this should not be implemented in a core game, since this has nothing to do with how the laser behaves gameplay wise. It would be nice to have a way to change the laser color either in the options screen, having default (red for all) or different laser colors could be set, also for people who are color blind this would be a very good asset to have.

This workaround might not be the ideal place to put the extra code, but it works.

For those who cannot compile or do not wish to do so I have put online two Oolite versions (1.81) with different laser colors.

Being:

Pulse laser color: Red
Beam laser color: Orange
Mining laser color: Yellow
Military laser color: Blue

OOlite ver 1.81 - Bluespace (dark blue space): https://app.box.com/s/bjrsdwsxthgkwdeozkbg

Oolite ver 1.81 - Vanilla (black space): https://app.box.com/s/ptu0rudfiyj4j8aevzoc

No other things were changed.

Enjoy

Re: HOWTO: Changing laser color for Player depending on weap

Posted: Wed Sep 10, 2014 5:26 pm
by cim
dertien wrote:
Since there is a way to set different background colors for galaxies, I can't really see why this should not be implemented in a core game
It is there already - sort of - as a hidden compile-time setting. If you compile with the OBJCFLAGS="-DDEBUG_LASER_TYPES" option, then pulse lasers will always be red, beam lasers will be yellow, and military lasers will be purple - look at the setWeaponDataFromType function in ShipEntity.m

I put it in so I could see at a glance what weapons the new populator was equipping ships with while writing that bit of 1.79. It's not advertised because, as I implemented it there, it overrides custom laser colours for particular ships (including making the thargon drone laser red), and that's not the right way round. If we ever figure out a sensible way to make lasers OXP-definable, then laser colour will be part of that, of course.

Re: HOWTO: Changing laser color for Player depending on weap

Posted: Wed Sep 10, 2014 5:38 pm
by dertien
Would you reckon Cim; that this would cause framerate or other issues, when done this way ?

Or would you be safe to assume that although it is not in any way elegant it should not pose any significant issues?

Re: HOWTO: Changing laser color for Player depending on weap

Posted: Wed Sep 10, 2014 5:41 pm
by cim
Doing it the way you did it should be entirely fine. The only disadvantage is needing to recompile the game if you decide you don't like those player laser colours.

Re: HOWTO: Changing laser color for Player depending on weap

Posted: Wed Sep 10, 2014 5:48 pm
by dertien
Ok thanks Cim,