File: netobjpose.c

package info (click to toggle)
xshipwars 1.32-5
  • links: PTS
  • area: main
  • in suites: potato
  • size: 17,176 kB
  • ctags: 6,357
  • sloc: ansic: 157,152; makefile: 226; sh: 75
file content (171 lines) | stat: -rw-r--r-- 3,664 bytes parent folder | download
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
#include "swserv.h"
  
 
 
int NetHandleObjectPose(int condescriptor, char *arg)
{
        static long object_num;
        
        static int type;
        static int isref_num;
        static long size;
        
        static double x, y, z;
        static double heading, pitch, bank;
        
        static double velocity;
        
        static double velocity_heading;
        static double velocity_pitch;
        static double velocity_bank;

        static int current_frame;
        static xsw_object_struct *obj_ptr;


        /*
         *	CS_CODE_POSEOBJ format:
         *
         *      object_num,
         *      type, isref_num, size,
         *      x, y, z,
         *      heading, pitch,
         *      velocity, velocity_heading,
         *      throttle, frame
         */
        sscanf(arg,
"%ld\
 %i %i %ld\
 %lf %lf %lf\
 %lf %lf %lf\
 %lf\
 %lf %lf %lf\
 %i",
 
                &object_num,
            
                &type,
                &isref_num,
                &size,
        
                &x, 
                &y,
                &z,
        
                &heading,
                &pitch,
                &bank,
        
                &velocity,
         
                &velocity_heading,
                &velocity_pitch,
                &velocity_bank,
         
                &current_frame 
        );

	/* Connection must own object. */         
        if(connection[condescriptor]->object_num != object_num)
            return(-3);
 

	if(DBIsObjectGarbage(object_num))
	    return(-1);
	else
	    obj_ptr = xsw_object[object_num];


        /* Set object_num's location and apperance. */
        /* Don't set type, imageset, or size. */
/*
        obj_ptr->type = type;
        obj_ptr->imageset = isref_num;
        obj_ptr->size = size;
*/


        /* Set these only if object has enough antimatter. */
        if(obj_ptr->antimatter > 0)
        {
            obj_ptr->x = x;
            obj_ptr->y = y;
            obj_ptr->z = z;
            obj_ptr->velocity = velocity;
            obj_ptr->velocity_heading = velocity_heading;
        }

        obj_ptr->heading = heading;
        obj_ptr->pitch = pitch;

/*
        obj_ptr->animation.current_frame = current_frame;
*/

        return(0);
}


int NetSendObjectPose(int condescriptor, long object_num)
{
        static char sndbuf[CS_DATA_MAX_LEN];
        static xsw_object_struct *obj_ptr;  


        if(DBIsObjectGarbage(object_num))
            return(-1);
        else
            obj_ptr = xsw_object[object_num];


        /*
         *	CS_CODE_POSEOBJ format:
         *
         *      object_num,
         *      type, isref_num, size,
         *      x, y, z,
         *      heading, pitch, bank,
         *      velocity,
         *      velocity_heading, velocity_pitch, velocity_bank,
         *      current_frame
         */
        sprintf(sndbuf,
"%i %ld\
 %i %i %ld\
 %.4lf %.4lf %.4lf\
 %.4lf %.4lf %.4lf\
 %.4lf\
 %.4lf %.4lf %.4lf\
 %i\n",
   
                CS_CODE_POSEOBJ,
                object_num,
        
                obj_ptr->type,
                obj_ptr->imageset,
                obj_ptr->size,

                obj_ptr->x,
                obj_ptr->y,
                obj_ptr->z,

                obj_ptr->heading,
                obj_ptr->pitch,
                obj_ptr->bank,
         
                obj_ptr->velocity,

                obj_ptr->velocity_heading,
                0.0000, 
                0.0000,

                obj_ptr->animation.current_frame
        );


        /* Send data to all or single connection. */
        NetDoSend(condescriptor, sndbuf);


        return(0); 
}