File: cmdsmoke.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 (140 lines) | stat: -rw-r--r-- 2,876 bytes parent folder | download | duplicates (6)
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
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>

#include "../include/string.h"
#include "../include/strexp.h"

#include "gw.h"
#include "messages.h"
#include "cmd.h"
#include "smoke.h"
#include "sar.h"
#include "scenesound.h"
#include "config.h"


void SARCmdSmoke(SAR_CMD_PROTOTYPE);


#define ATOI(s)         (((s) != NULL) ? atoi(s) : 0)
#define ATOL(s)         (((s) != NULL) ? atol(s) : 0)
#define ATOF(s)         (((s) != NULL) ? (float)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) ? ((int)strlen(s)) : 0)

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

#define STR_IS_YES(s)	(StringIsYes(s))

#define NOTIFY(s)			\
{ if(SAR_CMD_IS_VERBOSE(flags) &&	\
     (scene != NULL) && ((s) != NULL)	\
  ) { SARMessageAdd(scene, (s)); }	\
}


/*
 *	Smoke creation
 */
void SARCmdSmoke(SAR_CMD_PROTOTYPE)
{
	char **strv;
	int strc, obj_num = -1;
	Boolean got_match = False;
	sar_core_struct *core_ptr = SAR_CORE(data);
	sar_scene_struct *scene = core_ptr->scene;
/*	sar_option_struct *opt = &core_ptr->option; */

	/* No argument? */
	if(*arg == '\0')
	{
	    NOTIFY(
		"Usage: smoke <x> <y> <z> <type> <size>"
	    );
	    return;
	}

	/* Parse argument */
	strv = strexp(arg, &strc);
	if(strc == 5)
	{
	    const char *tex_name;
	    float size = (float)MAX(ATOF(strv[4]), 1.0);
	    sar_position_struct pos;

	    pos.x = ATOF(strv[0]);
	    pos.y = ATOF(strv[1]);
	    pos.z = ATOF(strv[2]);

	    /* Type */
	    switch(ATOI(strv[3]))
	    {
	      case 0:	/* Light */
		tex_name = SAR_STD_TEXNAME_SMOKE_LIGHT;
		break;
	      case 1:	/* Medium */
		tex_name = SAR_STD_TEXNAME_SMOKE_MEDIUM;
		break;
	      case 2:	/* Dark */
		tex_name = SAR_STD_TEXNAME_SMOKE_DARK;
		break;
	      default:	/* Light */
		tex_name = SAR_STD_TEXNAME_SMOKE_LIGHT;
		break;
	    }

	    obj_num = SmokeCreate(
		scene,
		&core_ptr->object, &core_ptr->total_objects,
		SAR_SMOKE_TYPE_SMOKE,
		&pos,		/* Position */
		NULL,		/* Respawn offset */
		size / 4.0f,	/* Size start */
		size,		/* Size max */
		-1.0f,		/* Size increase rate */
		1,		/* Hide at max? */
		5,		/* Units */
		1000,		/* Respawn interval */
		tex_name,	/* Texture name */
		-1,		/* Reference object */
		0		/* Life span */
	    );

	    got_match = True;
	}

	if(got_match)
	{
	    char *s = (char *)malloc(
		(80 + STRLEN(arg)) * sizeof(char)
	    );
	    sprintf(
		s,
"Created smoke object #%i.",
		obj_num
	    );
	    NOTIFY(s);
	    free(s);
	}
	else
	{
	    char *s = (char *)malloc(
		(80 + STRLEN(arg)) * sizeof(char)
	    );
	    sprintf(
		s,
"%s: Invalid value.",
		arg
	    );
	    NOTIFY(s);
	    free(s);
	}

	strlistfree(strv, strc);
}