1 /*-------------------------------------------------------------------------------
2
3 BARONY
4 File: actcampfire.cpp
5 Desc: behavior function for campfires
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 "stat.hpp"
15 #include "items.hpp"
16 #include "sound.hpp"
17 #include "net.hpp"
18 #include "player.hpp"
19
20 /*-------------------------------------------------------------------------------
21
22 act*
23
24 The following function describes an entity behavior. The function
25 takes a pointer to the entity that uses it as an argument.
26
27 -------------------------------------------------------------------------------*/
28
29 #define CAMPFIRE_LIGHTING my->skill[0]
30 #define CAMPFIRE_FLICKER my->skill[1]
31 #define CAMPFIRE_HEALTH my->skill[3]
32 #define CAMPFIRE_INIT my->skill[4]
33 #define CAMPFIRE_SOUNDTIME my->skill[5]
34
actCampfire(Entity * my)35 void actCampfire(Entity* my)
36 {
37 Entity* entity;
38 int i;
39
40 // init
41 if ( !CAMPFIRE_INIT )
42 {
43 CAMPFIRE_INIT = 1;
44 CAMPFIRE_HEALTH = MAXPLAYERS;
45 }
46
47 // crackling sounds
48 if ( CAMPFIRE_HEALTH > 0 )
49 {
50 CAMPFIRE_SOUNDTIME--;
51 if ( CAMPFIRE_SOUNDTIME <= 0 )
52 {
53 CAMPFIRE_SOUNDTIME = 480;
54 playSoundEntityLocal( my, 133, 128 );
55 }
56
57 // spew flame particles
58 for ( i = 0; i < 3; i++ )
59 {
60 entity = spawnFlame(my, SPRITE_FLAME);
61 entity->x += ((rand() % 30) - 10) / 10.f;
62 entity->y += ((rand() % 30) - 10) / 10.f;
63 entity->z -= 1;
64 }
65 entity = spawnFlame(my, SPRITE_FLAME);
66 entity->z -= 2;
67
68 // light environment
69 if ( !CAMPFIRE_LIGHTING )
70 {
71 my->light = lightSphereShadow(my->x / 16, my->y / 16, 6, 160);
72 CAMPFIRE_LIGHTING = 1;
73 }
74 if ( flickerLights )
75 {
76 //Campfires will never flicker if this setting is disabled.
77 CAMPFIRE_FLICKER--;
78 }
79 if (CAMPFIRE_FLICKER <= 0)
80 {
81 CAMPFIRE_LIGHTING = (CAMPFIRE_LIGHTING == 1) + 1;
82
83 if (CAMPFIRE_LIGHTING == 1)
84 {
85 my->removeLightField();
86 my->light = lightSphereShadow(my->x / 16, my->y / 16, 6, 160);
87 }
88 else
89 {
90 my->removeLightField();
91 my->light = lightSphereShadow(my->x / 16, my->y / 16, 6, 152);
92 }
93 CAMPFIRE_FLICKER = 2 + rand() % 7;
94 }
95 }
96 else
97 {
98 my->removeLightField();
99 my->light = NULL;
100 my->flags[BRIGHT] = false;
101 }
102
103 if ( multiplayer != CLIENT )
104 {
105 // using campfire
106 for (i = 0; i < MAXPLAYERS; i++)
107 {
108 if ( (i == 0 && selectedEntity == my) || (client_selected[i] == my) )
109 {
110 if (inrange[i])
111 {
112 if ( CAMPFIRE_HEALTH > 0 )
113 {
114 messagePlayer(i, language[457]);
115 CAMPFIRE_HEALTH--;
116 if ( CAMPFIRE_HEALTH <= 0 )
117 {
118 serverUpdateEntitySkill(my, 3); // extinguish for all clients
119 messagePlayer(i, language[458]);
120 my->removeLightField();
121 my->light = NULL;
122 }
123 Item* item = newItem(TOOL_TORCH, WORN, 0, 1, 0, true, NULL);
124 itemPickup(i, item);
125 free(item);
126 }
127 else
128 {
129 messagePlayer(i, language[458]);
130 }
131 }
132 }
133 }
134 }
135 }
136