
#include "obpc.h"

#ifndef PandaWave_RESOURCES
#include "RevengeResources.h"
#endif

#include "RevengeApp.h"
#include <XMessages.h>
#include "tagpick.h"
#include <assert.h>
#include <XPopup.h>
#include <XWindow.h>


// ==============================  BYTE SWAPPING DATA  ========================================
static byte_swap_code observer_physics_constants_byte_swapping_data[]=
{
	_begin_bs_array, 1,
	
	// struct observer_physics_constant	parallel_velocity, orthogonal_velocity;
	_4byte, _4byte, _4byte, _4byte, _4byte, _4byte,
	_4byte, _4byte, _4byte, _4byte, _4byte, _4byte,
	
	// struct observer_physics_constant yaw_velocity, orbit_velocity;
	_4byte, _4byte, _4byte, _4byte, _4byte, _4byte,
	_4byte, _4byte, _4byte, _4byte, _4byte, _4byte,
	
	// struct observer_physics_constant vertical_velocity;
	_4byte, _4byte, _4byte, _4byte, _4byte, _4byte,

	// struct observer_physics_constant pitch_velocity;
	_4byte, _4byte, _4byte, _4byte, _4byte, _4byte,

	// struct observer_physics_constant zoom_velocity;
	_4byte, _4byte, _4byte, _4byte, _4byte, _4byte,

	// short unused[44];
	44*sizeof(short),
	
	_end_bs_array
};

observer_physics_constants default_obpc =
{
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};


// ==============================  EDIT WINDOW  ========================================
void edit_obpc( tag_entry* e )
{
	TobpcEditForm* form = new TobpcEditForm( e );
	form->AttachWindow( 1017 );
}

void defaultnew_obpc( tag_entry *e )
{
	observer_physics_constants def;
	byte_swap_move_be( "obpc", &def, &default_obpc, sizeof(observer_physics_constants), 1, observer_physics_constants_byte_swapping_data );
	set_entry_data( e, &def, sizeof(def), false );
}

void dependency_obpc( tag_entry *e )
{
#if 0 // no dependencies
	observer_physics_constants def;
	read_observer_physics_constants( &def, e );
#endif
}


// ==============================  READ TAG DATA  ========================================
bool read_observer_physics_constants( observer_physics_constants* def, tag_entry* e )
{
	return load_tag_data_into_struct( "obpc", e, def, SIZEOF_STRUCT_OBSERVER_PHYSICS_CONSTANTS, 1, observer_physics_constants_byte_swapping_data);
}


// ==============================  SAVE TAG DATA  ========================================
bool save_observer_physics_constants( observer_physics_constants* def, tag_entry* e )
{
	return save_tag_data_from_struct( "obpc", e, def, SIZEOF_STRUCT_OBSERVER_PHYSICS_CONSTANTS, 1, observer_physics_constants_byte_swapping_data);
}


// ==============================  READ TAG DATA (WITH ID) ========================================
bool read_observer_physics_constants( observer_physics_constants* def, tag id )
{
	tag_entry* e;
	
	assert( def );
	
	e = get_entry( 'obpc', id );
	if( 0 == e ) {
		return FALSE;
	}
	
	return read_observer_physics_constants( def, e );	
}


// ==============================  SAVE TAG DATA (WITH ID) ========================================
bool save_observer_physics_constants( observer_physics_constants* def, tag id )
{
	tag_entry* e;
	
	assert( def );
	
	e = get_entry( 'obpc', id );
	if( 0 == e ) {
		return FALSE;
	}

	return save_observer_physics_constants( def, e );
}


// ==============================  DISPATCH  ========================================
BEGINDISPATCH(TobpcEditForm,TTagEditForm)
	DISPATCHTABLE(KXGControlClick,TobpcEditForm::DoControlClick)
ENDDISPATCH


TobpcEditForm::TobpcEditForm( struct tag_entry *e ) : TTagEditForm( e )
{
}

// ==============================  INITIALIZE FORM =======================================
void TobpcEditForm::DoFormInitialize()
{
	TTagEditForm::DoFormInitialize();

}


// ==============================  INPUT HANDLING  ========================================
long TobpcEditForm::DoControlClick( long arg, void *ptr )
{
#ifdef __MWERKS__
	#pragma unused(ptr)
#endif
	return -1;
}

		
// ========================================  SAVE TO TAG  ==================================================
void TobpcEditForm::CommitToTag()
{
	GetValues();
	save_observer_physics_constants( &def, fEntry );
}


// ========================================  RELOAD TAG  ==================================================
void TobpcEditForm::ReloadTag()
{
	read_observer_physics_constants( &def, fEntry );
	SetValues();
}


// ========================================  TAG NEEDS UPDATING  ==================================================
bool TobpcEditForm::NeedCommit()
{
	GetValues();
	return tag_data_needs_update( "obpc", fEntry, &def, SIZEOF_STRUCT_OBSERVER_PHYSICS_CONSTANTS, 1, observer_physics_constants_byte_swapping_data);
}

		
// ========================================  SET INTERFACE VALUES  ==================================================
void TobpcEditForm::SetValues()
{

	SetFixed( 11701, def.parallel_velocity.negative.maximum_velocity );
	SetFixed( 11702, def.orthogonal_velocity.negative.maximum_velocity );
	SetFixed( 11703, def.vertical_velocity.negative.maximum_velocity );
	SetFixed( 11704, def.yaw_velocity.negative.maximum_velocity );
	SetFixed( 11705, def.pitch_velocity.negative.maximum_velocity );
	SetFixed( 11706, def.orbit_velocity.negative.maximum_velocity );
	SetFixed( 11707, def.zoom_velocity.negative.maximum_velocity );

	SetFixed( 11708, def.parallel_velocity.negative.acceleration );
	SetFixed( 11709, def.orthogonal_velocity.negative.acceleration );
	SetFixed( 11710, def.vertical_velocity.negative.acceleration );
	SetFixed( 11711, def.yaw_velocity.negative.acceleration );
	SetFixed( 11712, def.pitch_velocity.negative.acceleration );
	SetFixed( 11713, def.orbit_velocity.negative.acceleration );
	SetFixed( 11714, def.zoom_velocity.negative.acceleration );

	SetFixed( 11715, def.parallel_velocity.negative.deceleration );
	SetFixed( 11716, def.orthogonal_velocity.negative.deceleration );
	SetFixed( 11717, def.vertical_velocity.negative.deceleration );
	SetFixed( 11718, def.yaw_velocity.negative.deceleration );
	SetFixed( 11719, def.pitch_velocity.negative.deceleration );
	SetFixed( 11720, def.orbit_velocity.negative.deceleration );
	SetFixed( 11721, def.zoom_velocity.negative.deceleration );

	SetFixed( 11722, def.parallel_velocity.positive.maximum_velocity );
	SetFixed( 11723, def.orthogonal_velocity.positive.maximum_velocity );
	SetFixed( 11724, def.vertical_velocity.positive.maximum_velocity );
	SetFixed( 11725, def.yaw_velocity.positive.maximum_velocity );
	SetFixed( 11726, def.pitch_velocity.positive.maximum_velocity );
	SetFixed( 11727, def.orbit_velocity.positive.maximum_velocity );
	SetFixed( 11728, def.zoom_velocity.positive.maximum_velocity );

	SetFixed( 11729, def.parallel_velocity.positive.acceleration );
	SetFixed( 11730, def.orthogonal_velocity.positive.acceleration );
	SetFixed( 11731, def.vertical_velocity.positive.acceleration );
	SetFixed( 11732, def.yaw_velocity.positive.acceleration );
	SetFixed( 11733, def.pitch_velocity.positive.acceleration );
	SetFixed( 11734, def.orbit_velocity.positive.acceleration );
	SetFixed( 11735, def.zoom_velocity.positive.acceleration );
	
	SetFixed( 11736, def.parallel_velocity.positive.deceleration );
	SetFixed( 11737, def.orthogonal_velocity.positive.deceleration );
	SetFixed( 11738, def.vertical_velocity.positive.deceleration );
	SetFixed( 11739, def.yaw_velocity.positive.deceleration );
	SetFixed( 11740, def.pitch_velocity.positive.deceleration );
	SetFixed( 11741, def.orbit_velocity.positive.deceleration );
	SetFixed( 11742, def.zoom_velocity.positive.deceleration );
}


// ========================================  GET INTERFACE VALUES  ==================================================
void TobpcEditForm::GetValues()
{
	def.parallel_velocity.negative.maximum_velocity = GetFixed( 11701 );
	def.orthogonal_velocity.negative.maximum_velocity = GetFixed( 11702 );
	def.vertical_velocity.negative.maximum_velocity = GetFixed( 11703 );
	def.yaw_velocity.negative.maximum_velocity = GetFixed( 11704 );
	def.pitch_velocity.negative.maximum_velocity = GetFixed( 11705 );
	def.orbit_velocity.negative.maximum_velocity = GetFixed( 11706 );
	def.zoom_velocity.negative.maximum_velocity = GetFixed( 11707 );

	def.parallel_velocity.negative.acceleration = GetFixed( 11708 );
	def.orthogonal_velocity.negative.acceleration = GetFixed( 11709 );
	def.vertical_velocity.negative.acceleration = GetFixed( 11710 );
	def.yaw_velocity.negative.acceleration = GetFixed( 11711 );
	def.pitch_velocity.negative.acceleration = GetFixed( 11712 );
	def.orbit_velocity.negative.acceleration = GetFixed( 11713 );
	def.zoom_velocity.negative.acceleration = GetFixed( 11714 );

	def.parallel_velocity.negative.deceleration = GetFixed( 11715 );
	def.orthogonal_velocity.negative.deceleration = GetFixed( 11716 );
	def.vertical_velocity.negative.deceleration = GetFixed( 11717 );
	def.yaw_velocity.negative.deceleration = GetFixed( 11718 );
	def.pitch_velocity.negative.deceleration = GetFixed( 11719 );
	def.orbit_velocity.negative.deceleration = GetFixed( 11720 );
	def.zoom_velocity.negative.deceleration = GetFixed( 11721 );

	def.parallel_velocity.positive.maximum_velocity = GetFixed( 11722 );
	def.orthogonal_velocity.positive.maximum_velocity = GetFixed( 11723 );
	def.vertical_velocity.positive.maximum_velocity = GetFixed( 11724 );
	def.yaw_velocity.positive.maximum_velocity = GetFixed( 11725 );
	def.pitch_velocity.positive.maximum_velocity = GetFixed( 11726 );
	def.orbit_velocity.positive.maximum_velocity = GetFixed( 11727 );
	def.zoom_velocity.positive.maximum_velocity = GetFixed( 11728 );

	def.parallel_velocity.positive.acceleration = GetFixed( 11729 );
	def.orthogonal_velocity.positive.acceleration = GetFixed( 11730 );
	def.vertical_velocity.positive.acceleration = GetFixed( 11731 );
	def.yaw_velocity.positive.acceleration = GetFixed( 11732 );
	def.pitch_velocity.positive.acceleration = GetFixed( 11733 );
	def.orbit_velocity.positive.acceleration = GetFixed( 11734 );
	def.zoom_velocity.positive.acceleration = GetFixed( 11735 );
	
	def.parallel_velocity.positive.deceleration = GetFixed( 11736 );
	def.orthogonal_velocity.positive.deceleration = GetFixed( 11737 );
	def.vertical_velocity.positive.deceleration = GetFixed( 11738 );
	def.yaw_velocity.positive.deceleration = GetFixed( 11739 );
	def.pitch_velocity.positive.deceleration = GetFixed( 11740 );
	def.orbit_velocity.positive.deceleration = GetFixed( 11741 );
	def.zoom_velocity.positive.deceleration = GetFixed( 11742 );
}

