HOWTO: Changing laser color for Player depending on weapon

An area for discussing new ideas and additions to Oolite.

Moderators: winston, another_commander

Post Reply
dertien
---- E L I T E ----
---- E L I T E ----
Posts: 471
Joined: Sun Jan 23, 2011 9:27 pm
Location: Belgium, Monarchy, Feudal, Overtaxed system

HOWTO: Changing laser color for Player depending on weapon

Post by dertien » Wed Sep 10, 2014 4:53 pm

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: http://aegidian.org/bb/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
Last edited by dertien on Wed Sep 10, 2014 6:06 pm, edited 2 times in total.
Alpha Backer of Elite Dangerous
With 250 GBP :D

User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4018
Joined: Fri Nov 11, 2011 6:19 pm

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

Post by cim » Wed Sep 10, 2014 5:26 pm

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.

dertien
---- E L I T E ----
---- E L I T E ----
Posts: 471
Joined: Sun Jan 23, 2011 9:27 pm
Location: Belgium, Monarchy, Feudal, Overtaxed system

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

Post by dertien » Wed Sep 10, 2014 5:38 pm

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?
Alpha Backer of Elite Dangerous
With 250 GBP :D

User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4018
Joined: Fri Nov 11, 2011 6:19 pm

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

Post by cim » Wed Sep 10, 2014 5:41 pm

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.

dertien
---- E L I T E ----
---- E L I T E ----
Posts: 471
Joined: Sun Jan 23, 2011 9:27 pm
Location: Belgium, Monarchy, Feudal, Overtaxed system

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

Post by dertien » Wed Sep 10, 2014 5:48 pm

Ok thanks Cim,
Alpha Backer of Elite Dangerous
With 250 GBP :D

Post Reply