1 /*-------------------------------------------------------------------------------
2 
3 	BARONY
4 	File: actflame.cpp
5 	Desc: behavior function for flame particles
6 
7 	Copyright 2013-2016 (c) Turning Wheel LLC, all rights reserved.
8 	See LICENSE for details.
9 
10 -------------------------------------------------------------------------------*/
11 
12 #include "main.hpp"
13 #include "game.hpp"
14 #include "collision.hpp"
15 #include "entity.hpp"
16 
17 /*-------------------------------------------------------------------------------
18 
19 	act*
20 
21 	The following function describes an entity behavior. The function
22 	takes a pointer to the entity that uses it as an argument.
23 
24 -------------------------------------------------------------------------------*/
25 
26 #define FLAME_LIFE my->skill[0]
27 #define FLAME_VELX my->vel_x
28 #define FLAME_VELY my->vel_y
29 #define FLAME_VELZ my->vel_z
30 
actFlame(Entity * my)31 void actFlame(Entity* my)
32 {
33 	if ( FLAME_LIFE <= 0 )
34 	{
35 		list_RemoveNode(my->mynode);
36 		return;
37 	}
38 	my->x += FLAME_VELX;
39 	my->y += FLAME_VELY;
40 	my->z += FLAME_VELZ;
41 	FLAME_LIFE--;
42 }
43 
44 /*-------------------------------------------------------------------------------
45 
46 	spawnFlame
47 
48 	Spawns a flame particle for the entity supplied as an argument
49 
50 -------------------------------------------------------------------------------*/
51 
spawnFlame(Entity * parentent,Sint32 sprite)52 Entity* spawnFlame(Entity* parentent, Sint32 sprite )
53 {
54 	Entity* entity;
55 	double vel;
56 
57 	entity = newEntity(sprite, 1, map.entities, nullptr); // flame particle
58 	if ( intro )
59 	{
60 		entity->setUID(0);
61 	}
62 	entity->x = parentent->x;
63 	entity->y = parentent->y;
64 	entity->z = parentent->z;
65 	entity->sizex = 6;
66 	entity->sizey = 6;
67 	entity->yaw = (rand() % 360) * PI / 180.0;
68 	entity->pitch = (rand() % 360) * PI / 180.0;
69 	entity->roll = (rand() % 360) * PI / 180.0;
70 	vel = (rand() % 10) / 10.0;
71 	entity->vel_x = vel * cos(entity->yaw) * .1;
72 	entity->vel_y = vel * sin(entity->yaw) * .1;
73 	entity->vel_z = -.25;
74 	entity->skill[0] = 5;
75 	entity->flags[NOUPDATE] = true;
76 	entity->flags[PASSABLE] = true;
77 	entity->flags[SPRITE] = true;
78 	entity->flags[BRIGHT] = true;
79 	entity->flags[UNCLICKABLE] = true;
80 	entity->behavior = &actFlame;
81 	if ( multiplayer != CLIENT )
82 	{
83 		entity_uids--;
84 	}
85 	entity->setUID(-3);
86 
87 	return entity;
88 }
89