Example #1
0
int projectile_unserialize(object *obj, serial *ser, int animation_id, game_state *gs) {
    uint8_t har_id = serial_read_int8(ser);

    game_player *player;
    object *o;
    har *h;

    for(int i = 0; i < 2; i++) {
        player = game_state_get_player(gs, i);
        o = game_player_get_har(player);
        h = object_get_userdata(o);
        if (h->af_data->id == har_id) {
            af_move *move = af_get_move(h->af_data, animation_id);
            object_set_animation(obj, &move->ani);
            object_set_userdata(obj, h);
            object_set_stl(obj, object_get_stl(o));
            projectile_create(obj);
            return 0;
        }
    }
    DEBUG("COULD NOT FIND HAR ID %d", har_id);
    // could not find the right HAR...
    return 1;
}
Example #2
0
bool weapon_add_projectile(int tick,obj_type *obj,weapon_type *weap,proj_setup_type *proj_setup,d3pnt *pt,d3ang *ang)
{
	d3pnt					spt,ept,hpt;
	proj_type				*proj;
	ray_trace_contact_type	contact;
	
		// create new projectile
		
	proj=projectile_create(tick,obj,weap,proj_setup);
	if (proj==NULL) return(FALSE);

	projectile_spawn_position(proj,pt,ang,obj);
	
		// call spawn
		
	scripts_post_event_console(&proj->attach,sd_event_spawn,0,0);
	
		// if this object is the player object, then spawn projectile in remotes
		
	if (net_setup.client.joined) {
		if ((obj->uid==server.player_obj_uid) || (obj->bot)) {
			net_client_send_projectile_add(obj->remote.uid,weap->name,proj_setup->name,pt,ang);
		}
	}

		// add in object motion

	proj->force.vct.x=obj->motion.vct.x*proj_setup->inherit_motion_factor;
	proj->force.vct.y=obj->motion.vct.y*proj_setup->inherit_motion_factor;
	proj->force.vct.z=obj->motion.vct.z*proj_setup->inherit_motion_factor;

		// detect weapons being fired into walls
		// if so, destroy projectile

	spt.x=obj->pnt.x;
	spt.y=obj->pnt.y-(obj->size.y>>1);
	spt.z=obj->pnt.z;

	ept.x=proj->pnt.x;
	ept.y=proj->pnt.y;
	ept.z=proj->pnt.z;
	
	contact.obj.on=TRUE;
	contact.proj.on=FALSE;
	contact.obj.ignore_uid=obj->uid;

	contact.hit_mode=poly_ray_trace_hit_mode_all;
	contact.origin=poly_ray_trace_origin_projectile;
	
	if (ray_trace_map_by_point(&spt,&ept,&hpt,&contact)) {

		proj->pnt.x=hpt.x;
		proj->pnt.y=hpt.y;
		proj->pnt.z=hpt.z;

		proj->contact.hit_poly.mesh_idx=contact.poly.mesh_idx;
		proj->contact.hit_poly.poly_idx=contact.poly.poly_idx;
		proj->contact.obj_uid=contact.obj.uid;
		proj->contact.proj_uid=-1;

		projectile_hit(tick,proj,FALSE);
	}

	return(TRUE);
}