File: fire.c

package info (click to toggle)
searchandrescue 0.8.2-10
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,656 kB
  • ctags: 6,111
  • sloc: ansic: 89,072; cpp: 7,691; sh: 90; makefile: 80
file content (124 lines) | stat: -rw-r--r-- 2,908 bytes parent folder | download | duplicates (3)
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
#include <stdlib.h>
#include "v3dtex.h"
#include "obj.h"
#include "objutils.h"
#include "fire.h"
#include "sar.h"
#include "config.h"


int FireCreate(
	sar_core_struct *core_ptr, sar_scene_struct *scene,
	sar_object_struct ***ptr, int *total,
	const sar_position_struct *pos,
	float radius, float height,
	int ref_object,
	const char *tex_name, const char *ir_tex_name
);


#define ATOI(s)		(((s) != NULL) ? atoi(s) : 0)
#define ATOL(s)		(((s) != NULL) ? atol(s) : 0)
#define ATOF(s)		(((s) != NULL) ? atof(s) : 0.0f)
#define STRDUP(s)	(((s) != NULL) ? strdup(s) : NULL)

#define MAX(a,b)	(((a) > (b)) ? (a) : (b))
#define MIN(a,b)	(((a) < (b)) ? (a) : (b))
#define CLIP(a,l,h)	(MIN(MAX((a),(l)),(h)))
#define STRLEN(s)	(((s) != NULL) ? strlen(s) : 0)
#define STRISEMPTY(s)	(((s) != NULL) ? (*(s) == '\0') : 1)

#define RADTODEG(r)	((r) * 180.0 / PI)
#define DEGTORAD(d)	((d) * PI / 180.0)


/*
 *	Creates a new Fire.
 */
int FireCreate(
	sar_core_struct *core_ptr, sar_scene_struct *scene,
	sar_object_struct ***ptr, int *total,
	const sar_position_struct *pos,
	float radius, float height,
	int ref_object,				/* Not used */
	const char *tex_name, const char *ir_tex_name
)
{
	int obj_num;
	sar_object_struct *obj_ptr;
	sar_object_fire_struct *fire;
	const sar_option_struct *opt = &core_ptr->option;
	if((scene == NULL) || (pos == NULL))
	    return(-1);

	/* Create fire object */
	obj_num = SARObjNew(
	    scene, ptr, total,
	    SAR_OBJ_TYPE_FIRE
	);
	if(obj_num < 0)
	    return(-1);

	obj_ptr = (*ptr)[obj_num];
	if(obj_ptr == NULL)
	    return(-1);

	fire = SAR_OBJ_GET_FIRE(obj_ptr);
	if(fire == NULL)
	    return(-1);


	/* Begin setting new values */

	/* Position */
	memcpy(
	    &obj_ptr->pos, pos, sizeof(sar_position_struct)
	);

	/* Set visible range based on radius */
	if(radius >= 100.0f)
	    obj_ptr->range = (float)SFMMilesToMeters(16.0);
	else if(radius >= 70.0f)
	    obj_ptr->range = (float)SFMMilesToMeters(14.0);
	else if(radius >= 30.0f)
	    obj_ptr->range = (float)SFMMilesToMeters(12.0);
	else if(radius >= 10.0f)
	    obj_ptr->range = (float)SFMMilesToMeters(10.0);
	else
	    obj_ptr->range = (float)SFMMilesToMeters(7.0);

	/* Temperature */
	obj_ptr->temperature = 1.0f;

	/* Set size of fire */
	fire->radius = radius;
	fire->height = height;

	/* Set frame animation values */
	fire->cur_frame = 0;
/* Use explosion frame increment interval */
	fire->frame_inc_int = opt->explosion_frame_int;
	fire->next_frame_inc = cur_millitime +
	    fire->frame_inc_int;

	fire->cur_frame = 0;
	fire->frame_repeats = 0;
	fire->total_frame_repeats = 1;

	/* Get texture references on the scene*/
	fire->tex_num = SARGetTextureRefNumberByName(
	    scene, tex_name
	);
	fire->ir_tex_num = SARGetTextureRefNumberByName(
	    scene, ir_tex_name
	);

#if 0
	/* Set reference object */
/* Not used */
	fire->ref_object = ref_object;
#endif
	fire->ref_object = -1;

	return(obj_num);
}