Exemple #1
0
void object_auto_walk_object(obj_type *obj)
{
	float			ang_y;
	bool			cwise;
	obj_type		*seek_obj;
	
		// get object
		
	seek_obj=object_find_uid(obj->auto_walk.obj_uid);
	if (seek_obj==NULL) {
		obj->auto_walk.mode=aw_none;
		return;
	}
	
		// turn towards object on y
		
	ang_y=angle_find(obj->pnt.x,obj->pnt.z,seek_obj->pnt.x,seek_obj->pnt.z);
	angle_dif(ang_y,obj->ang.y,&cwise);
	
	obj->turn.ang_to.y=ang_y;
	
	if (cwise) {
		obj->turn.ang_add.y=-object_get_turn_speed(obj);
	}
	else {
		obj->turn.ang_add.y=object_get_turn_speed(obj);
	}
	
		// if flying, put in a seek angle
		
	object_auto_walk_set_vertical_move(obj,(seek_obj->pnt.y-(seek_obj->size.y>>1)),seek_obj->pnt.z);
}
Exemple #2
0
void object_player_turn(obj_type *obj)
{
	float			turn_add,turn_restrict;
	weapon_type		*weap;
	
		// can it turn?
		
	if ((obj->turn.only_when_moving) && (!obj->forward_move.moving)) {
		obj->turn.ang_add.y=0;
		return;
	}
	
		// get turn speed
	
	obj->turn.fix_ang_add.y=0;
	
	turn_add=obj->turn.ang_add.y;
    if (turn_add==0) return;
	
		// zoom factors

	if (camera.mode==cv_fpp) {
		weap=weapon_find_current(obj);
		if (weap!=NULL) {
			if ((weap->zoom.on) && (weap->zoom.mode!=zoom_mode_off)) {
				if (obj->duck.mode!=dm_duck) {
					turn_add*=weap->zoom.turn_factor;
				}
				else {
					turn_add*=weap->zoom.crawl_turn_factor;
				}
			}
		}
	}
	
		// restriction

	if (obj->turn.restrict_player_turning) {
		turn_restrict=object_get_turn_speed(obj);
		
		if (turn_add<-turn_restrict) turn_add=-turn_restrict;
		if (turn_add>turn_restrict) turn_add=turn_restrict;
	}

		// turning
		
    obj->ang.y=angle_add(obj->ang.y,turn_add);
	obj->turn.fix_ang_add.y=turn_add;

		// turn any standing objects

	object_rotate_with_standing_object(obj,turn_add);
}
Exemple #3
0
void object_auto_walk_position(obj_type *obj)
{
	float			ang_y;
	bool			cwise;

		// turn towards position on y
		
	ang_y=angle_find(obj->pnt.x,obj->pnt.z,obj->auto_walk.pnt.x,obj->auto_walk.pnt.z);
	angle_dif(ang_y,obj->ang.y,&cwise);
	
	obj->turn.ang_to.y=ang_y;
	
	if (cwise) {
		obj->turn.ang_add.y=-object_get_turn_speed(obj);
	}
	else {
		obj->turn.ang_add.y=object_get_turn_speed(obj);
	}
	
		// if flying, put in a seek angle
		
	object_auto_walk_set_vertical_move(obj,obj->auto_walk.pnt.y,obj->auto_walk.pnt.z);
}
Exemple #4
0
JSValueRef js_obj_motion_angle_turn_to_angle_func(JSContextRef cx,JSObjectRef func,JSObjectRef j_obj,size_t argc,const JSValueRef argv[],JSValueRef *exception)
{
	float			turn_speed;
	bool			cwise;
	obj_type		*obj;
	
	if (!script_check_param_count(cx,func,argc,2,exception)) return(script_null_to_value(cx));
	
	obj=object_get_attach(j_obj);
	
	obj->turn.ang_to.y=script_value_to_float(cx,argv[0]);
	if (obj->turn.ang_to.y<0.0f) obj->turn.ang_to.y=360.0f+obj->turn.ang_to.y;
	if (obj->turn.ang_to.y>=360.0f) obj->turn.ang_to.y=obj->turn.ang_to.y-360.0f;

	turn_speed=object_get_turn_speed(obj);

	switch (script_value_to_int(cx,argv[1])) {
	
		case -1:
			obj->turn.ang_add.y=-turn_speed;
			break;
		case 1:
			obj->turn.ang_add.y=turn_speed;
			break;
		default:
			angle_dif(obj->turn.ang_to.y,obj->ang.y,&cwise);
			if (cwise) {
				obj->turn.ang_add.y=-turn_speed;
			}
			else {
				obj->turn.ang_add.y=turn_speed;
			}
			break;
	
	}

	return(script_null_to_value(cx));
}
Exemple #5
0
void object_auto_walk_node(obj_type *obj)
{
	int				dist,chk_dist,seek_idx,dest_idx;
	float			ang_y,dif_y;
	bool			cwise;
	node_type		*node;
	
		// get nodes
		
	seek_idx=obj->auto_walk.node_seek_idx;
	dest_idx=obj->auto_walk.node_dest_idx;
	
		// turn towards node
		
	node=&map.nodes[seek_idx];
	
	ang_y=angle_find(obj->pnt.x,obj->pnt.z,node->pnt.x,node->pnt.z);
	dif_y=angle_dif(ang_y,obj->ang.y,&cwise);
	
	obj->turn.ang_to.y=ang_y;

	if (cwise) {
		obj->turn.ang_add.y=-object_get_turn_speed(obj);
	}
	else {
		obj->turn.ang_add.y=object_get_turn_speed(obj);
	}
	
		// stop walking if turn is too hard
		
	object_auto_walk_set_motion(obj);
	
		// if flying, put in a seek angle
		
	object_auto_walk_set_vertical_move(obj,node->pnt.y,node->pnt.z);
	
		// get node slop
		
	if (obj->forward_move.running) {
		chk_dist=(int)(obj->forward_move.max_run_speed*node_slop_speed_factor);
	}
	else {
		chk_dist=(int)(obj->forward_move.max_walk_speed*node_slop_speed_factor);
	}
	
		// near node?
		
	dist=distance_get(node->pnt.x,node->pnt.y,node->pnt.z,obj->pnt.x,obj->pnt.y,obj->pnt.z);
	if (dist>chk_dist) return;
	
		// move on to next node
		
	if (seek_idx!=dest_idx) {
		obj->auto_walk.node_last_seek_idx=obj->auto_walk.node_seek_idx;
		obj->auto_walk.node_seek_idx=map_find_next_node_in_path(&map,seek_idx,dest_idx);
		scripts_post_event_console(&obj->attach,sd_event_path,sd_event_path_node,node->event_id);
		return;
	}
	
		// at last node, send event
		
	obj->auto_walk.mode=aw_none;
	obj->auto_walk.node_seek_idx=-1;
	obj->auto_walk.node_dest_idx=-1;
	
	scripts_post_event_console(&obj->attach,sd_event_path,sd_event_path_done,obj->auto_walk.node_event_id);
}