Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 46dba6eac76ff97e8dade3170dc8274846b87e86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936

/*
   base/ship.cc
   This file is part of the Osirion project and is distributed under
   the terms and conditions of the GNU General Public License version 2
*/

#include <cmath>
#include <iostream>

#include "auxiliary/functions.h"
#include "math/functions.h"

#include "core/gameserver.h"
#include "core/entity.h"
#include "core/entityprojectile.h"

#include "base/game.h"
#include "base/ship.h"

#include "base/spacemine.h"

using math::degrees360f;
using math::degrees180f;

namespace game
{

const float 		MIN_DELTA = 0.000001f;

Ship::Ship(core::Player *owner, const ShipModel *shipmodel) : core::EntityControlable()
{
	assert(shipmodel);
	
	entity_moduletypeid = ship_enttype;
	set_radius(0);
	
	ship_shipmodel = shipmodel;
	
	ship_impulsedrive_timer = 0;
	ship_jumpdrive_timer = 0;
	ship_jumpdepart = 0;
	
	ship_dock = 0;
	ship_spawn = 0;
	
	ship_maxarmor = 100.0f;
	ship_armor = 0.0f;
	
	ship_maxshield = 0.0f;
	ship_shield = 0.0f;
	
	current_impulse = false;
	
	// apply ship type settings
	ship_shipmodel->apply(this);

	// radius fallback values
	if (!radius()) {
		if (model()) {
			set_radius(model()->radius());
		}
	}	
	if (!radius()) {
		set_radius(0.5f);
	}
	
	// mass fallback value
	if (!mass()) {
		set_mass(radius() * 100.0f);
	}
		
	if (owner) {
		// this ship is owned by a player,
		// player colors override template colors
		set_owner(owner);
		get_color().assign(owner->color());
		get_color_second().assign(owner->color_second());
		std::string str(aux::text_strip(owner->name()));
		aux::to_label(str);
		set_label(str);
		
		// add an inventory
		add_inventory();
		inventory()->set_capacity(ship_shipmodel->maxcargo());
	}
	
	if (model()) {
		add_slots();
		slots()->load(model());
/*		
		for (core::Slots::iterator it = slots()->begin(); it != slots()->end(); it++) {
			// default fire rate: 1 projectile / second
			(*it)->set_projectile_interval(1000);
			(*it)->set_projectile_lifespan(5000);
			(*it)->set_projectile_speed(5.0f);
			(*it)->set_projectile_damage(10.0f);
			(*it)->set_projectile_modelname("laser1");
		}
*/
	}

	// menus for docked players
	if (ship_shipmodel->dockable()) {
		using core::MenuDescription;
		using core::ButtonDescription;
	
		MenuDescription *menu_main = new MenuDescription();
		menu_main->set_label("main");
		menu_main->set_text("Launch area");
		add_menu(menu_main);

		ButtonDescription *button = new ButtonDescription();
		button->set_text("Launch");
		button->set_command("launch", ButtonDescription::CommandGame);
		button->set_alignment(ButtonDescription::Center);
		menu_main->add_button(button);
		
		set_flag(core::Entity::Dockable);
	}

	ship_armor = maxarmor();
	
	// initialize physics
	// FIXME probably should not be called here
	//reset();	
	//body()->setDamping(ship_shipmodel->linear_damping(), ship_shipmodel->angular_damping());
}

Ship::~Ship()
{
}

void Ship::print() const
{
	core::EntityControlable::print();
	con_print << "  armor ^B" << armor() << "^N/^B" << maxarmor() << std::endl;
}

void Ship::func_impulse()
{

	switch (entity_state) {
		case core::Entity::Impulse:
			entity_state = core::Entity::Normal;
			//target_thrust = 1.0f;
			//entity_thrust = 0.0f;
			set_dirty();
			break;
			
		case core::Entity::ImpulseInitiate:
			entity_state = core::Entity::Normal;
			set_dirty();
			break;
			
		case core::Entity::JumpInitiate:
			entity_state = core::Entity::Normal;
			ship_jumpdrive_timer = 0;
			entity_timer = 0;
			set_dirty();
			break;
			
		case core::Entity::Normal:	
			entity_state = core::Entity::ImpulseInitiate;
			entity_timer = impulse_timer_delay;
			ship_impulsedrive_timer = core::server()->time();
			break;
			
		default:
			break;
	}
	
}

void Ship::initiate_jump(JumpPoint *depart)
{
	ship_jumpdepart = 0;

	if (!depart)
		return;

	if (!depart->target())
		return;

	ship_jumpdepart = depart;
	entity_state = core::Entity::JumpInitiate;
	entity_timer = jump_timer_delay;
	ship_jumpdrive_timer = core::server()->time();
	
	set_dirty();
}

void Ship::func_jump(std::string const &args)
{
	if (entity_state == core::Entity::Docked) {
		return;
	}

	// devel mode provides instant jump access to arbitrary systems
	if (Game::g_devel->value() && (args.size())) {

		core::Zone *jumptargetzone = core::Zone::search(args);

		if (!jumptargetzone) {
			std::string helpstr;
			for (core::Zone::Registry::iterator it = core::Zone::registry().begin(); it != core::Zone::registry().end(); it++) {
				if (helpstr.size())
					helpstr.append("^N|^B");
				helpstr.append((*it).second->label());
			}
			owner()->send("Usage: jump [^B" + helpstr + "^N]");
			return;
		}

		if (jumptargetzone == zone()) {
			owner()->send("Already in the " + jumptargetzone->name());
			return;
		}

		owner()->send("Jumping to the " + jumptargetzone->name());
		set_zone(jumptargetzone);

		//ship_jumpdrive_timer = 0;
		//entity_timer = 0;
		
		// setting the cooldown timer even with cheats on will allow some time for the jump completed sound to play
		ship_jumpdrive_timer = core::server()->time();
		entity_timer = jump_cooldown_delay;
				
		set_state(core::Entity::Jump);
		set_dirty();
		return;

	} else {

		if (!jumpdrive() && !Game::g_devel->value()) {
			owner()->send("This ship is not equiped with a hyperspace drive!");
			return;

		} else 	if (entity_state == core::Entity::Jump) {
			return;

		} else if (entity_state == core::Entity::JumpInitiate) {
			owner()->send("Jump aborted, hyperspace drive deactivated");
			ship_jumpdrive_timer = 0;
			entity_timer = 0;
			entity_state = core::Entity::Normal;
			return;
		}
		initiate_jump(find_closest_jumppoint());
	}
}

JumpPoint * Ship::find_closest_jumppoint()
{
	// find closest jumpgate or jumppoint
	float d = -1;
	JumpPoint *jumppoint = 0;
	for (core::Zone::Content::iterator it = zone()->content().begin(); it != zone()->content().end(); it++) {
		core::Entity *entity = (*it);
		if ((entity->moduletype() == jumppoint_enttype) || (entity->moduletype() == jumpgate_enttype)) {
			JumpPoint *te = static_cast<JumpPoint *>(entity);
			float d1 = math::distance(location(), te->location());
			if ((d < 0) || (d1 < d)) {
				d = d1;
				jumppoint = te;
			}
		}
	}

	if (jumppoint && jumppoint->target()) {
		if (Game::g_jumppointrange->value() < d) {
			owner()->send("Jumppoint out of range!");
			return 0;
		} else {
			owner()->send("Jumping to the " + jumppoint->target()->zone()->name());
			return jumppoint;
		}
	} else {
		owner()->send("No jumppoints found!");
		return 0;
	}

	return 0;
}

void Ship::explode()
{
	set_state(core::Entity::Destroyed);

	target_direction = 0;
	target_pitch = 0;
	target_roll = 0;
	target_strafe = 0.0f;
	target_vstrafe = 0.0f;
	
	target_afterburner = 0.0f;
	target_thrust = 0;

	entity_thrust = 0;
	
	if (owner()) {
		if (owner()->control() == this)
			owner()->set_view(this);
	}
};


void Ship::reset()
{
	current_target_direction = 0.0f;
	current_target_pitch = 0.0f;;
	current_target_roll = 0.0f;
	current_target_strafe = 0.0f;
	current_target_vstrafe = 0.0f;
	current_target_afterburner = 0.0f;
	
	EntityControlable::reset();
	
	if (body()) {
		body()->setDamping(ship_shipmodel->linear_damping(), ship_shipmodel->angular_damping());
	}
}

void Ship::set_zone(core::Zone *zone)
{
	core::EntityControlable::set_zone(zone);

	if (owner() && (owner()->control() == (EntityControlable*) this))
		owner()->set_zone(zone);
}

void Ship::set_dock(core::Entity *dock)
{
	if (!dock) {
		ship_dock = 0;
		return;
	}
	
	get_location().assign(dock->location());
	get_axis().assign(dock->axis());
	ship_dock = dock;
	if (dock->zone() != zone())
	{
		set_zone(dock->zone());
	}
	
	set_state(core::Entity::Docked);
	reset();
	
	// if the dock is not owned by a player. set it as spawn	
	const core::Player *owner = (dock->type() == core::Entity::Controlable ? static_cast<core::EntityControlable *>(dock)->owner() : 0 );
	if (!owner) {
		set_spawn(dock);
	}
}
	
void Ship::launch()
{
	if (!ship_dock)
		return;
	
	get_axis().assign(ship_dock->axis());
	
	if (ship_dock->type() == core::Entity::Globe)
		get_location().assign(ship_dock->location() + (ship_dock->axis().forward() * (planet_safe_distance + this->radius() + ship_dock->radius())));
	else
		get_location().assign(ship_dock->location() + (ship_dock->axis().forward() * (this->radius() + ship_dock->radius())));
	
	ship_dock = 0;
	
	set_state(core::Entity::Normal);
	reset();
}

void Ship::set_spawn(core::Entity *spawn)
{
	ship_spawn = spawn;
}
	
void Ship::action (btScalar seconds)
{
	float engine_force = 0;
	float turn_force = ship_turn_force;
	float roll_force = ship_roll_force;
	
	btTransform t;	
	
	switch (entity_state) {
		case core::Entity::Normal:
			engine_force = ship_thrust_force * entity_thrust;
			break;
			
		case core::Entity::ImpulseInitiate:
			engine_force = ship_thrust_force * entity_thrust;
			break;
			
		case core::Entity::Impulse:
			engine_force = ship_impulse_force;
			turn_force *= .5f;
			roll_force *= .5f;
			break;
			
		case core::Entity::JumpInitiate:
		case core::Entity::Jump:
			engine_force = 0.0f;
			break;
			
		case core::Entity::Docked:
			return;
			break;
			
		default:
			engine_force = 0.0f;
			break;
	}
	
	t.setIdentity();
	entity_motionstate->getWorldTransform(t);	
	get_location().assign(t.getOrigin());
	get_axis().assign(t.getBasis());

	const float torque_scale = 0.001f;

	// apply strafe
	body()->applyCentralImpulse(math::to_btVector3(axis().up() * current_target_vstrafe * ship_strafe_force));	
	body()->applyCentralImpulse(math::to_btVector3(axis().left() * current_target_strafe * ship_strafe_force));

	// apply afterburner
	body()->applyCentralImpulse(math::to_btVector3(axis().forward() * current_target_afterburner * ship_strafe_force));

	// apply main thruster
	// note: negative afterburner puts the ship in reverse and disables the main thruster
	if (current_target_afterburner >= 0) {
		body()->applyCentralImpulse(math::to_btVector3(axis().forward() * engine_force));
	}
	
	// apply direction
	body()->applyTorqueImpulse(math::to_btVector3(axis().up() * current_target_direction * turn_force * torque_scale));
	// apply pitch
	body()->applyTorqueImpulse(math::to_btVector3(axis().left() * -current_target_pitch * turn_force * torque_scale));
	
	// apply roll
	body()->applyTorqueImpulse(math::to_btVector3(axis().forward() * -current_target_roll * roll_force* torque_scale));

	// limit speed
	entity_speed = (float) entity_body->getLinearVelocity().length();
	if (entity_speed > Game::g_impulsespeed->value() * 0.01f) {
		entity_speed = Game::g_impulsespeed->value() * 0.01f;
		body()->setLinearVelocity(math::to_btVector3(axis().forward() * entity_speed));
	}
}

void Ship::hit(core::Entity *other)
{
	if (state() == core::Entity::Destroyed) {
		return;
	}
	
	if (state() == core::Entity::Docked) {
		return;
	}
	
	if (other->moduletype() == spacemine_enttype) {
		
		// hit by a mine
		SpaceMine * spacemine = static_cast<SpaceMine *>(other);
		if (spacemine->state() != core::Entity::Destroyed) {
			ship_armor -= spacemine->damage();
		}
		
		// destroyed
		if (ship_armor <= 0) {
			explode();
			
			if (owner()) {
				ship_armor = 0;
				std::string message("^B");
				message.append(owner()->name());
				
				core::Player *assassin = 0;
				
				if (spacemine->ownerid()) {
					assassin = core::server()->find_player(spacemine->ownerid());
				}
				
				if (assassin) {
					if (assassin == owner()) {
						message.append(" ^Bran into his own mine.");
					} else {
						message.append(" ^Bran into ");
						message.append(assassin->name());
						message.append(" ^B's mine.");
					}
				} else {
					message.append(" ^Bwent boom.");
				}
				core::server()->broadcast(message);
			} else {
				die();
			}
		}
		
	} else if (other->type() == core::Entity::Projectile) {
		
		// hit by projectile
		core::EntityProjectile *projectile = static_cast<core::EntityProjectile *>(other);

		// don't hit self
		if ((projectile->state() != core::Entity::Destroyed) &&
		     (projectile->ownerid() != id())) {
					
			ship_armor -= projectile->damage();
			
			// destroyed
			if (ship_armor <= 0) {
				explode();
				
				if (owner()) {
					ship_armor = 0;
					std::string message("^B");
					message.append(owner()->name());
					
					core::Player *assassin = 0;
					
					if (projectile->ownerid()) {
						assassin = core::server()->find_player(projectile->ownerid());
					}
					
					if (assassin) {
						if (assassin == owner()) {
							message.append(" ^Bate his own bullet.");
						} else {
							message.append(" ^Bwas blown to bits by ");
							message.append(assassin->name());
						}
					} else {
						message.append(" ^Bwas blown to bits.");
					}
					core::server()->broadcast(message);
				} else {
					die();
				}
			}
		}
	}
}

void Ship::collision(core::Entity *other)
{
	if (state() == core::Entity::Destroyed) {
		return;
	}
	
	if (state() == core::Entity::Docked) {
		return;
	}
	
	// do not fly into planets
	if (other->moduletype() == planet_enttype) {
		
		// ran into a planet
		explode();
		
		if (owner()) {
			std::string message("^B");
			message.append(owner()->name());
			message.append(" ^Bran into ");
			message.append(other->name());
			message.append(".");
			core::server()->broadcast(message);
		} else {
			die();
		}		
	} else if (other->moduletype() == star_enttype) {
		
		// flew into a star
		explode();
		
		if (owner()) {
			std::string message("^B");
			message.append(owner()->name());
			message.append(" ^Bflew into a star.");
			core::server()->broadcast(message);
		} else {
			die();
		}	
		
	}
}

void Ship::frame(const unsigned long elapsed)
{
	//const float direction_reaction = 2.0f;		// directional control reaction time
	//const float thrust_reaction = 0.5f;		// thrust control reaction time
	//const float strafe_reaction = 1.5f;		// strafe control reaction time
	//const float afterburner_reaction = 1.0f;	// afterburner control reaction time

	math::Vector3f n;				// normal of a plane	
	math::Axis target_axis(axis());			// target axis

	/* -- update state ----------------------------------------- */

	// speed might be set to 0 on this update
	if (entity_speed != 0.0f) {
		set_dirty();
	}

	if (entity_state == core::Entity::Docked) {

		target_direction = 0;
		target_pitch = 0;
		target_roll = 0;
		target_strafe = 0.0f;
		target_vstrafe = 0.0f;

		target_afterburner = 0.0f;
		target_thrust = 0;

		entity_thrust = 0;
		entity_speed = 0.0f;
		entity_controlflags = 0;
		
	} else if (entity_state == core::Entity::JumpInitiate) {

		if (ship_jumpdrive_timer + 1.0f <= core::server()->time()) {
			entity_timer -= 1.0f;

			if (entity_timer <= 0) {
				if (ship_jumpdepart && ship_jumpdepart->target()) {
					set_state(core::Entity::Jump);
					entity_speed = Game::g_impulsespeed->value() * 0.01f;
					if (ship_jumpdepart->moduletype() == jumpgate_enttype) {
						get_axis().assign(ship_jumpdepart->target()->axis());
						get_location().assign(ship_jumpdepart->target()->location());
						get_location() += axis().forward() * (radius() + ship_jumpdepart->target()->radius());
					} else {
						get_location().assign(ship_jumpdepart->target()->location() + location() - ship_jumpdepart->location());
					}
					
					set_zone(ship_jumpdepart->target()->zone());
					
					if (owner() && owner()->view() && (owner()->view()->zone() != ship_jumpdepart->target()->zone()))
						owner()->set_view(0);
					
					owner()->send("^BJumping to the " + ship_jumpdepart->target()->zone()->name());
				} else {
					set_state(core::Entity::Normal);
				}
				
				ship_jumpdrive_timer = core::server()->time();
				entity_timer = jump_cooldown_delay;

				set_dirty();
				return;
			} else {
				ship_jumpdrive_timer = core::server()->time();
				set_dirty();
			}
		}

		// control is disabled while the jumpdrive is activated
		target_direction = 0;
		target_pitch = 0;
		target_roll = 0;
		target_strafe = 0.0f;
		target_vstrafe = 0.0f;
		
		target_afterburner = 0.0f;
		target_thrust = 0.1f;
		
		entity_controlflags = 0;

	} else if (entity_state == core::Entity::Jump) {

		// control is disabled while the jumpdrive is activated
		target_direction = 0;
		target_pitch = 0;
		target_roll = 0;
		target_strafe = 0.0f;
		target_vstrafe = 0.0f;
		
		target_afterburner = 0.0f;
		target_thrust = 0.0f;
		
		entity_controlflags = 0;

		// apply jump drive cooldown
		if (ship_jumpdrive_timer + 1.0f <= core::server()->time()) {
			entity_timer -= 1.0f;
			
			if (entity_timer <= 0) {
				ship_jumpdrive_timer = 0;
				set_state(core::Entity::Normal);
				set_dirty();
				
				if (owner() && owner()->view() && owner()->control() == (EntityControlable*) this)
					owner()->set_view(0);
				
			} else {
				ship_jumpdrive_timer = core::server()->time();
				set_dirty();
			}
		}
		
		return;
		
	} else if (entity_state == core::Entity::ImpulseInitiate) {

		//  cancel impulse drive if afterburner goes reverse
		if (target_afterburner < 0.0f) {
			set_state(core::Entity::Normal);
			set_dirty();
			entity_timer = 0;
		} else {

			if (ship_impulsedrive_timer + 1.0f <= core::server()->time()) {
				entity_timer -= 1.0f;

				if (entity_timer <= 0) {
					entity_state = core::Entity::Impulse;
					entity_timer = 0;
					set_dirty();
				} else {
					ship_impulsedrive_timer = core::server()->time();
					set_dirty();
				}
			}

			// clamp input values
			//target_thrust = 0.0f;
			//target_afterburner = 0.0f;
			math::clamp(target_pitch, -1.0f, 1.0f);
			math::clamp(target_roll, -1.0f, 1.0f);
			math::clamp(target_direction, -1.0f, 1.0f);
		}

	} else if (entity_state == core::Entity::Impulse) {

		// clamp input values
		math::clamp(target_pitch, -1.0f, 1.0f);
		math::clamp(target_roll, -1.0f, 1.0f);
		math::clamp(target_direction, -1.0f, 1.0f);

		//  cancel impulse drive if afterburner goes reverse
		if (target_afterburner < 0.0f) {
			set_state(core::Entity::Normal);
			set_dirty();
			entity_timer = 0;
			//target_thrust = 1.0f;
			//entity_thrust = 1.0f;
		} else {
			//target_afterburner = 0.0f;
			//target_thrust = 0.0f;
		}

	} else if (entity_state == core::Entity::Normal) {

		// clamp input values
		math::clamp(target_thrust, 0.0f, 1.0f);
		math::clamp(target_pitch, -1.0f, 1.0f);
		math::clamp(target_roll, -1.0f, 1.0f);
		math::clamp(target_direction, -1.0f, 1.0f);
		math::clamp(target_afterburner, -1.0f, 1.0f);
		
		entity_controlflags = target_controlflags;


	} else if (entity_state == core::Entity::Destroyed) {
	
		target_direction = 0;
		target_pitch = 0;
		target_roll = 0;
		target_strafe = 0.0f;
		target_vstrafe = 0.0f;
		
		target_afterburner = 0.0f;
		target_thrust = 0;

		entity_thrust = 0;
		entity_controlflags = 0;
	}
	
	// current health
	entity_health = armor() * 100.0f / maxarmor();

	/* -- SNAPPY ------------------------------------------ */
	
	current_target_afterburner = target_afterburner;
	if (current_target_afterburner < 0.0f) {
		target_thrust = 0;
	}
	entity_thrust = target_thrust;
	
	current_target_strafe = target_strafe;
	current_target_vstrafe = target_vstrafe;
	
	current_target_roll = target_roll;
	current_target_pitch = target_pitch;
	current_target_direction = target_direction;
	
	// clamp values
	math::clamp(entity_thrust, 0.0f, 1.0f);
	
	/* -- NOT SNAPPY -------------------------------------- */
	/*
	// update afterburner control target
	
	if (current_target_afterburner < target_afterburner) {
		current_target_afterburner += afterburner_reaction * seconds;
		if (current_target_afterburner > target_afterburner)
			current_target_afterburner = target_afterburner;

	} else if (current_target_afterburner > target_afterburner) {
		current_target_afterburner -= afterburner_reaction * seconds;
		if (current_target_afterburner < target_afterburner)
			current_target_afterburner = target_afterburner;
	}	
	
	// update thrust control target
	if (current_target_afterburner < 0.0f) {
		target_thrust = 0;
	}

	if (entity_thrust < target_thrust) {
		entity_thrust += thrust_reaction * seconds;
		if (entity_thrust > target_thrust)
			entity_thrust = target_thrust;

	} else if (entity_thrust > target_thrust) {
		entity_thrust -= thrust_reaction * seconds;
		if (entity_thrust < target_thrust)
			entity_thrust = target_thrust;
	}
	math::clamp(entity_thrust, 0.0f, 1.0f);

	// update strafe control target
	if (current_target_strafe < target_strafe) {
		current_target_strafe += strafe_reaction * seconds;
		if (current_target_strafe > target_strafe)
			current_target_strafe = target_strafe;
	} else if (current_target_strafe > target_strafe) {
		current_target_strafe -= strafe_reaction * seconds;
		if (current_target_strafe < target_strafe)
			current_target_strafe = target_strafe;
	}
	
	// update vstrafe control target
	if (current_target_vstrafe < target_vstrafe) {
		current_target_vstrafe += strafe_reaction * seconds;
		if (current_target_vstrafe > target_vstrafe)
			current_target_vstrafe = target_vstrafe;
	} else if (current_target_vstrafe > target_vstrafe) {
		current_target_vstrafe -= strafe_reaction * seconds;
		if (current_target_vstrafe < target_vstrafe)
			current_target_vstrafe = target_vstrafe;
	}

	// update direction control target
	if (current_target_direction < target_direction) {
		current_target_direction += direction_reaction * seconds;
		if (current_target_direction > target_direction) {
			current_target_direction = target_direction;
		}
	} else if (current_target_direction > target_direction) {
		current_target_direction -= direction_reaction * seconds;
		if (current_target_direction < target_direction) {
			current_target_direction = target_direction;
		}
	}

	// update pitch control target
	if (current_target_pitch < target_pitch) {
		current_target_pitch += direction_reaction * seconds;
		if (current_target_pitch > target_pitch)
			current_target_pitch = target_pitch;
	} else if (current_target_pitch > target_pitch) {
		current_target_pitch -= direction_reaction * seconds;
		if (current_target_pitch < target_pitch)
			current_target_pitch = target_pitch;
	}

	// update roll control target
	if (current_target_roll < target_roll) {
		current_target_roll += direction_reaction * seconds;
		if (current_target_roll > target_roll)
			current_target_roll = target_roll;
	} else if (current_target_roll > target_roll) {
		current_target_roll -= direction_reaction * seconds;
		if (current_target_roll < target_roll)
			current_target_roll = target_roll;
	}
	*/
	
	EntityControlable::frame(elapsed);
	
	
	// TODO move to core::
	if (model() && slots() && (state() == core::Entity::Normal) && has_controlflag(core::EntityControlable::ControlFlagFire)) {
		
		const float modelscale = radius() / model()->radius();
		
		for (core::Slots::iterator it = slots()->begin(); it != slots()->end(); it++) {
			core::Slot *slot = (*it);
			
			// create projectiles
			if (slot->has_flag(core::Slot::Mounted) && slot->item() && (slot->item()->info()->type() == Weapon::infotype())) {
				
				const Weapon *weapon = static_cast<const Weapon *>(slot->item()->info());
				if ((weapon->subtype() == Weapon::Cannon) && (weapon->projectile_interval() > 0) && (slot->last_fired() + weapon->projectile_interval() <=  core::server()->timestamp())) {
					slot->set_last_fired(core::server()->timestamp());
					
					core::EntityProjectile *projectile = new core::EntityProjectile();
					
					projectile->set_damage(weapon->damage());
					projectile->set_lifespan(weapon->projectile_lifespan());
					projectile->set_projectile_modelname(weapon->projectile_modelname());
					projectile->set_color(color());
					projectile->set_color_second(color_second());
					projectile->set_zone(zone());
					projectile->set_axis(axis() * slot->axis());
					projectile->set_location(location() + (axis() * slot->location() * modelscale) + projectile->axis().forward() * projectile->radius());
					if (owner()) {
						projectile->set_ownerid(owner()->id());
					}
					projectile->set_speed(weapon->projectile_speed());					
					projectile->reset();
					
				}
			}
		}
	}

}

} // namespace game