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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
|
/*
Weapon Fire Object Creation
Functions:
int WepCreate(
long weapon_type,
long owner,
double birth_x,
double birth_y,
birth_heading,
double power,
double range,
double freq
)
---
Various weapon fire creation functions. Creating a weapon
fire object (such as a torpedo) and sending it off on its way.
movement.c takes care of the impact and lifespan management
for these objects.
EventHandleWeaponFire() is the front end function that should
be called. Does all permission checking on object_num.
Returns number of objects created.
*/
#include "swserv.h"
int WepCreate(
int ocs_code, /* Object create script code. */
long owner, /* MUST BE VALID!!! */
int emission_type,
double birth_x,
double birth_y,
double birth_heading,
double power,
double range, /* Needed for stream style weapons. */
double freq
)
{
int objects_created;
long object_num;
xsw_object_struct *obj_ptr;
xsw_object_struct *owner_obj_ptr;
ocs_struct *ocs_ptr;
xsw_object_struct *opm_ptr;
int ocs_num;
int opm_num;
double work_angle;
double tmp_x, tmp_y, tmp_z;
double tmp_h, tmp_p, tmp_b;
/* Cease fire impose? */
if(sysparm.cease_fire)
return(0);
/* ocs_code must be valid. */
if(ocs_code <= OCS_TYPE_GARBAGE)
return(-1);
/* emission_type must be valid. */
if(emission_type < 0)
{
fprintf(stderr,
"WepCreate(): Error: Emission type %i is invalid.\n",
emission_type
);
return(-1);
}
/* Owner must be valid. */
if(DBIsObjectGarbage(owner))
{
fprintf(stderr,
"WepCreate(): Error: Owner object #%ld is invalid.\n",
owner
);
return(-1);
}
else
{
owner_obj_ptr = xsw_object[owner];
}
/* Sanitize birth_heading. */
birth_heading = SANITIZERADIANS(birth_heading);
/* Sanitize power. */
if(power < 0)
power = 0;
/* Sanitize range. */
if(range < 0)
range = 0;
/* Sanitize frequency. */
if(freq < SWR_FREQ_MIN)
freq = SWR_FREQ_MIN;
if(freq > SWR_FREQ_MAX)
freq = SWR_FREQ_MAX;
/* ********************************************************** */
/* Get Object Create Ccript number by Type. */
ocs_num = OCSGetByCode(ocs_code);
if(OCSIsGarbage(ocs_num))
{
fprintf(stderr,
"WepCreate(): Error: %s requested invalid OCS type %i.\n",
DBGetFormalNameStr(owner),
ocs_code
);
return(-1);
}
else
{
/* Get ocs pointer. */
ocs_ptr = ocs[ocs_num];
}
/* coppies must be 1 or greater. */
if(ocs_ptr->coppies < 1)
{
/* Do not create anything. */
return(0);
}
/* Get work_angle. */
work_angle = SANITIZERADIANS(ocs_ptr->heading);
/* *********************************************************** */
/* Get OPM number by OPM name referanced in the OCS. */
opm_num = OPMGetByName(ocs[ocs_num]->opm_name, -1);
if(OPMIsGarbage(opm_num))
{
fprintf(stderr,
"WepCreate(): Error: %s: No such OPM.\n",
ocs_ptr->opm_name
);
return(-1);
}
else
{
/* Get object parmameter macro. */
opm_ptr = opm[opm_num];
}
/* Sanitize number of coppies. */
if((int)ocs_ptr->coppies > MAX_OCS_COPPIES)
ocs_ptr->coppies = MAX_OCS_COPPIES;
/* *********************************************************** */
/* Begin creating weapons fire objects. */
objects_created = 0;
while(objects_created < (int)ocs_ptr->coppies)
{
/* Create an object. */
object_num = DBCreateObject(
opm_ptr->imageset,
opm_ptr->type,
owner,
birth_x, birth_y, 0, /* x, y, z. */
birth_heading, 0, 0 /* heading, pitch, bank. */
);
if(DBIsObjectGarbage(object_num))
{
/* Failed to create object, stop creating. */
fprintf(stderr,
"WepCreate(): DBCreateObject(): Could not create object.\n"
);
break;
}
else
{
/* Increment number of objects created. */
objects_created++;
}
/* Must reget owner and object pointers!! */
owner_obj_ptr = xsw_object[owner];
obj_ptr = xsw_object[object_num];
/* Record tempory positions and attitudes. */
tmp_x = birth_x;
tmp_y = birth_y;
tmp_z = 0;
tmp_h = birth_heading;
tmp_p = 0;
tmp_b = 0;
/* Adjust relative position. */
tmp_x +=
MuPolarRotX(
birth_heading + work_angle,
ocs_ptr->radius
);
tmp_y +=
MuPolarRotY(
birth_heading + work_angle,
ocs_ptr->radius
);
/* **************************************************** */
/* Set parameters on new object from OPM. */
if(OPMModelObject(object_num, opm_num))
{
/* What do we do if we can't model if successfully? */
fprintf(stderr,
"WepCreate(): Error using OPM #%i for new object #%ld.\n",
opm_num, object_num
);
}
/* Set positions. */
obj_ptr->x = tmp_x;
obj_ptr->y = tmp_y;
obj_ptr->z = tmp_z;
obj_ptr->heading = tmp_h;
obj_ptr->pitch = tmp_p;
obj_ptr->bank = tmp_b;
/* Set sector of owner. */
obj_ptr->sect_x = owner_obj_ptr->sect_x;
obj_ptr->sect_y = owner_obj_ptr->sect_y;
obj_ptr->sect_z = owner_obj_ptr->sect_z;
/* Set owner. */
obj_ptr->owner = owner;
/* Set empire. */
strncpy(obj_ptr->empire,
owner_obj_ptr->empire,
XSW_OBJ_EMPIRE_MAX
);
obj_ptr->empire[XSW_OBJ_EMPIRE_MAX - 1] = '\0';
/* Set emission type dependant values. */
switch(emission_type)
{
/* Stream weapons have size given as range.
* They will intercept locked object of owner.
*/
case WEPEMISSION_STREAM:
obj_ptr->size = range;
if(DBIsObjectGarbage(owner_obj_ptr->locked_on))
{
obj_ptr->intercepting_object = -1;
obj_ptr->locked_on = -1;
}
else
{
obj_ptr->intercepting_object = owner_obj_ptr->locked_on;
obj_ptr->locked_on = owner_obj_ptr->locked_on;
}
break;
/* Projectiles have size of OPM and intercept
* locked object of owner.
*/
case WEPEMISSION_PROJECTILE:
/* Already set by modelling.
obj_ptr->size = opm_ptr->size;
*/
if(DBIsObjectGarbage(owner_obj_ptr->locked_on))
{
obj_ptr->intercepting_object = -1;
obj_ptr->locked_on = -1;
}
else
{
obj_ptr->intercepting_object = owner_obj_ptr->locked_on;
obj_ptr->locked_on = owner_obj_ptr->locked_on;
}
break;
/* Default to pulse. They have size of OPM and do NOT
* intercept locked object of owner.
*/
default:
/* Already set by modelling.
obj_ptr->size = opm_ptr->size;
*/
obj_ptr->intercepting_object = -1;
break;
}
/* Set velocites. */
/*
if(owner_obj_ptr->velocity < 0.0008)
{
obj_ptr->velocity_heading =
owner_obj_ptr->heading;
}
else
{
obj_ptr->velocity_heading = owner_obj_ptr->velocity_heading;
obj_ptr->velocity = owner_obj_ptr->velocity;
}
*/
obj_ptr->velocity_heading = owner_obj_ptr->velocity_heading;
obj_ptr->velocity = owner_obj_ptr->velocity;
/* Set thrust as owner's thrust. */
obj_ptr->thrust = owner_obj_ptr->thrust;
/* Set power from given function input. */
obj_ptr->power = power;
obj_ptr->power_max = power;
/* Set frequency. */
obj_ptr->shield_frequency = freq;
/* Mark the time this object was created. */
obj_ptr->birth_time = cur_millitime;
/* ***************************************************** */
/* Send create object request to all connections. */
NetSendCreateObject(-1, object_num);
/* Modify work_angle depending on emission_type. */
if((emission_type == WEPEMISSION_PROJECTILE) ||
(emission_type == WEPEMISSION_PULSE)
)
{
/* Flip work_angle to negative? */
if(work_angle > 0)
{
work_angle *= -1;
}
/* Flip angle to positive, then decrease angle. */
else
{
work_angle *= -1;
work_angle = work_angle *
(double)(1 / (double)(ocs_ptr->coppies));
}
}
}
/* Return the number of objects created. */
return(objects_created);
}
|