Jump to content



Photo

A Class to Control Saucer Behaviour?


  • Please log in to reply
4 replies to this topic

#1 nath2099

nath2099

    Neophyte

  • Members
  • Pip
  • 9 posts

  • Flag: Australia

  • Favorite Pinball: GNR

Posted 31 July 2014 - 07:53 AM

Hi,

 

I'm trying to create a class to handle when a ball lands in a saucer. Looking through the supplied table code I'm thinking I need to do something like the following:

 

Create the class:


public class TW : BxSolenoid {
SetLamp(70,true);
float timer = 300f;
void Update(){ timer -= Time.deltaTime; if (timer <= 0) { SetLamp(70,false); } } } 

In the table manager class, find the object on the FP table, and make it an object of the TW class: (What do I replace the "Toys/Toy1" with to find the kicker?

GameObject.Find ("Toys/Toy1").AddComponent<TW>();

Am I heading in the correct direction?

 

 

Here is the code I'm working with atm:

using UnityEngine;
using System.Collections;





public class Script{
    public void Init(){
        GameObject table = GameObject.Find("TABLE");
        test_TableManager behaviour = table.AddComponent<test_TableManager>();
		behaviour.PreInit();		// Call pre-initialization steps
		behaviour.Init();			// Script initialization
		behaviour.PostInit();		// Call poste-initialization steps
    }
}

public class test_TableManager : BxTableManager{
	bool m_autokick = true;
	public override void Init (){
		base.Init();					// Call BxVPMTableManager Start (Display version and default controller options
		InitArrays(255,255,10,255);		// 89 Lamps, 65 Solenoids/Flashers (10 by default for GIs) and 255 Switches...)
		//SetDMDObject("DMD","BxVPMDMD");	// Link the Vpm driven Dmd Update Component to the object "DMD"
		InitSubwaySystem();				// Initialize Subway System
		PrepareElements();
				
		AddSwitchCallBack(70, KLKickout);
		AddSwitchCallBack(71, TWKickout);	
		
		Global.Physics.g_GeneralForceMultiplier 			= 1;
        Global.Physics.g_PlungerForceMultiplier 			= 15f;
        Global.Physics.g_AutoPlungerForceMultiplier 		= 45f;
        Global.Physics.g_FlipperForceMultiplier 			= 350f;
        Global.Physics.g_FlipperSpeedTargetMultiplier 		= 10000f;
        Global.Physics.g_VerticalKickerForceMultiplier 		= 300;
        Global.Physics.g_OrientedKickerForceMultiplier 		= 400f;
        Global.Physics.g_BumperKickForceMultiplier 			= 500f;
        Global.Physics.g_SlingshotForceMultiplier 			= 180f;
        Global.Physics.g_SlingshotThresholdForce 			= 20;
        Global.Physics.g_NudgeForceMultiplierX 				= 0.6f;
        Global.Physics.g_NudgeForceMultiplierY 				= 0.3F;
		Global.Physics.g_DiverterForceMultiplier 			= 1500;
        Global.Physics.g_DebugShotForceMultiplier 			= 200;
        Global.Physics.g_CoilMagnetForceMultiplier 			= 5.5f;
        Global.Physics.SetBallDiameter(26.987f);    // Set the balls diameter
        Global.Physics.g_AirBall = false;
		//BxBumperKick.s_AutoKickBumperMode = false;		// Bumpers automatically kick
		//GameObject ball=GameObject.Find("Shop/ball");
		//ball.renderer.material.mainTexture=Resources.Load("BITMAP/amigaball") as Texture;////affect amigaball
		//ball.renderer.material.color=Color.white;   //// so that amigaball can be seen
		

	}
	void PrepareElements(){
		/*
		for (int l = 0; l < 200; l++) {
            try {
                GameObject.Find("Playfield/Lamps").transform.GetChild(l).FindChild("decal").Translate(new Vector3(0f, 0f, -0.09f));
                Material mat = GameObject.Find("Playfield/Lamps").transform.GetChild(l).FindChild("decal").renderer.material;///find decal object
                mat.shader = Shader.Find("PU3D/Managed/TexBackTrans");	///// change its shader to textured backlit transparent
                mat.color = new Color(mat.color.r / 3f, mat.color.r / 3f, mat.color.b / 3f, 0.9f); //// lowering its color by 3(texture used is really bright)
                mat.SetFloat("_BackLightingStrength", 9f); ///// setting its backlighting strength(you need to test)
                mat.color = new Color(mat.color.r, mat.color.r, mat.color.r, 0.9f);
            }
            catch { }
        }
		*/
		/*
		GameObject.Find("Playfield/Lamps/Light1").transform.FindChild("decal").Translate(new Vector3(0f, 0f, -0.09f));
		Material mat = GameObject.Find("Playfield/Lamps/Light1").transform.FindChild("decal").renderer.material;///find decal object
        mat.shader = Shader.Find("PU3D/Managed/TexBackTrans");	///// change its shader to textured backlit transparent
        mat.color = new Color(mat.color.r / 30f, mat.color.r / 30f, mat.color.b / 30f, 0.9f); //// lowering its color by 3(texture used is really bright)
        mat.SetFloat("_BackLightingStrength", 0f); ///// setting its backlighting strength(you need to test)
        mat.color = new Color(mat.color.r, mat.color.r, mat.color.r, 0.9f);
		*/
		//GameObject.Find("Playfield/Lamps/bulbInLaneBottomLeft").transform.FindChild("decal").Translate(new Vector3(0f, 0f, -0.09f));;
		//GameObject.Find("Playfield/Lamps/Light55");
		//GameObject.Find("Playfield/Lamps/bulbInLaneBottomLeft/decal").renderer.material.SetFloat("_BackLightingStrength",30f); ///// setting its backlighting strength
	}

		
		
	//! Initialize table driver
	/*
	public override void InitDriver(){
		m_driver = new BxDriver_wpc();
	}	
	*/
	public override void LateUpdate (){
		base.LateUpdate();
		if(Input.GetKeyDown(KeyCode.K)){
			SetSolenoid(4, true); // todo => switch off (will not work when not using changedSolenoidsCallback)
		}		
		if(Input.GetKeyDown(KeyCode.L)){
			//SetSolenoid(69, true);
			launchBall(true);
		}
	}
	
	//! Initialize Subway System (redefinition)
	public override void InitSubwaySystem(){
		base.InitSubwaySystem();
		GameObject subway = GameObject.Find ("TABLE/SUBWAY");
		if(subway==null){
			Debug.LogError("Unable to find SUBWAY object");
			return;
		}
		BxSwManager subManager = (BxSwManager)subway.GetComponent("BxSwManager");
		if(subManager==null) subManager = (BxSwManager)subway.GetComponent("BxSwVisualManager");
		if(subManager==null){
			Debug.LogError("Unable to find the Subway manager component in SUBWAY object");
			return;
		}
		float swL = Global.Physics.g_BallDiameter;					// length of switches in mm
		BxSwNode drain = subManager.AddEntrance("Drain",5);		// Main drain node used as subway entrance		
		BxSwNode pkick = subManager.AddExit("PlungerKicker",4);	// Exit GoT_ kicker Node
		pkick.m_swicthSlot = 52;								// Node switch number
		BxSwEdge mainThrough = subManager.LinkNodes(drain,pkick,1.5f);			// main Through edge link (1.5 seconds for a ball to cross it)
		mainThrough.AddSwitch(50, mainThrough.m_length-swL*1.5f, swL*0.9f);		// First switch on the edge
		mainThrough.AddSwitch(51, mainThrough.m_length-swL*0.5f , swL*0.9f);	// Second switch on the edge (making 3 in total with the pkick node switch)
		
		BxSwNode KLSaucer  =  subManager.AddEntrance("KLSaucerKicker",70, false); // switch #70, kill ball = false	
		KLSaucer =  subManager.AddExit("KLSaucerKicker",70, 10f);		// solenoid #70
	
		BxSwNode TWSaucer  =  subManager.AddEntrance("TWSaucerKicker",71, false); // switch #71, kill ball = false	
		TWSaucer =  subManager.AddExit("TWSaucerKicker",71, 10f);		// solenoid #71

		
		
		subManager.Build();
		for(int i=0;i<10;i++){
			BxSwVirtualBall b = new BxSwVirtualBall();
			drain.InsertBall(b);
			subManager.ReportNewBall(b);
			subManager.DoStep();
		}


		//BxSwNode thingSaucer		=  subManager.AddEntrance("Kicker1",87,false);				// Intput kicker with switch 87 NOT destroying the ball (Saucer)
		//thingSaucer					=  subManager.AddExit("Kicker1",26,0f);	// Output kicker driven by solenoid 26 (SHOULD be the same as above because of the same name) => No animation for kicking (releaseTime=0)
		
		
	}

	
	//! Link lamp array to Unity objects (called by InitArrays)
	public override void InitLampsObjects(){
		base.InitLampsObjects(); // call ancestor's function
		AddLamp("bulbInLaneBottomLeft",2);
		SetLamp (2,true);
		AddLamp("bulbInLaneTopLeft",3);
		AddLamp("KLLamp",70);
		AddLamp("TWLamp",71);
		//SetLamp (3,true);
	}
	
	//! Link solenoid array to Unity objects (called by InitArrays)
	public override void InitSolenoidsObjects(){
		base.InitSolenoidsObjects(); // call ancestor's function
			
		AddSolenoid("Bumper1"						, 61	, "BxBumperKick");
		AddSolenoid("Bumper1/cap"					, 62	, "BxBasicLamp");
		BxBasicLamp BumperLight1=GameObject.Find("Bumper1/cap").GetComponentInChildren<BxBasicLamp>();
		BumperLight1.m_onTime=0f;
		BumperLight1.m_offTime=0.5f;
		
		AddSolenoid("Bumper2"						, 63	, "BxBumperKick");
		AddSolenoid("Bumper2/cap"					, 64	, "BxBasicLamp");
		BxBasicLamp BumperLight2=GameObject.Find("Bumper2/cap").GetComponentInChildren<BxBasicLamp>();
		BumperLight2.m_onTime=0f;
		BumperLight2.m_offTime=0.5f;
		
		AddSolenoid("Bumper3"						, 65	, "BxBumperKick");
		AddSolenoid("Bumper3/cap"					, 66	, "BxBasicLamp");
		BxBasicLamp BumperLight3=GameObject.Find("Bumper3/cap").GetComponentInChildren<BxBasicLamp>();
		BumperLight3.m_onTime=0f;
		BumperLight3.m_offTime=0.5f;
		
		AddSolenoid("LeftSlingshotRubber"			, 67	, "BxSlingshotKick");
		AddSolenoid("RightSlingshotRubber"			, 68	, "BxSlingshotKick");
		AddSolenoid("Flippers/RightFlipper"			, 69	, "BxBasicFlip");	// Right Flipper
		// #70 KLSaucerKicker set in InitSubwaySystem
		// #71 TWSaucerKicker set in InitSubwaySystem
		AddSolenoid("Flippers/LeftFlipper"			, 72	, "BxBasicFlip");	// Left Flipper
		AddSolenoid("Flippers/UpperRightFlipper"	, 73	, "BxBasicFlip");	// URight Flipper
		AddSolenoid("rightAutoPlunger"				, 74	, "BxAutoPlunger");	// 

		
	}
	

	public override void InitSwitchesObjects(){
		base.InitSwitchesObjects(); // call ancestor's function		
		AddSwitch("Bumper1"					, 61);
		AddSwitch("Bumper2"					, 63);
		AddSwitch("Bumper3"					, 65);	
		AddSwitch("LeftSlingshotRubber"		, 67	,"BxSlingshotSwitch");
		AddSwitch("RightSlingshotRubber"	, 68	,"BxSlingshotSwitch");
		// #70 KLSaucerKicker set in InitSubwaySystem
		// #71 TWSaucerKicker set in InitSubwaySystem
		AddSwitch("rightLaunchTrigger"		, 74	,"BxTriggerSwitch");

	}

				

	
	public override void SetSwitch (int slot, bool state){
		base.SetSwitch (slot, state);
		switch(slot){
			case 61:
				SetSolenoid(61,state);
				SetSolenoid(62,state);
				break;
			case 63:
				SetSolenoid(63,state);
				SetSolenoid(64,state);
				break;
			case 65:
				SetSolenoid(65,state);
				SetSolenoid(66,state);
				break;
			case 67:
			case 68:	
				if(state) {
					SetSolenoid(slot,state); 
				}
				break;			
		}
	}
	
		
	void KLKickout(int slot, bool state){
        SetSolenoid(70, true);

    }


	void TWKickout(int slot, bool state){
        SetSolenoid(71, true);
		
    }
	
	public void launchBall(bool state){
		//SetSolenoid(69, state);
		SetSolenoid(74, state); 

	}	
}

Edited by nath2099, 31 July 2014 - 07:56 AM.


#2 chepas

chepas

    t.me/horsepin

  • Members
  • PipPipPipPip
  • 1,966 posts

  • Flag: ---------

  • Favorite Pinball: BSD, Tr0n, SW:Stern

Posted 31 July 2014 - 10:55 AM

 

What do I replace the "Toys/Toy1" with to find the kicker?

 

If you go into the table explorer in editor and find the kickers on the left , you'll see more or less same structure as the toys.

 

Not sure what you want to do here. You're trying to add methods to run when the kicker is hit? Like enabling a mode when kicker is hit?

 

I think the general idea is to use the subway for any kicker and just callbacks. It will be easier once the the api is done but really I would like to see them add pyprocgame in for all of the rules and just link to callbacks through pinproc.

 

You'd kill like 300 birds with one stone if we could use pyprocgame. DMD, Modes , just everything.


Bump maps are the new auto-tune :BDH:
VPX - RSS Updates ---- blog.flippingflips.xyz/en/ -- Visual Pinball No.1 (2021) . Est.2000


#3 nath2099

nath2099

    Neophyte

  • Members
  • Pip
  • 9 posts

  • Flag: Australia

  • Favorite Pinball: GNR

Posted 31 July 2014 - 11:48 AM

 

 

You're trying to add methods to run when the kicker is hit? Like enabling a mode when kicker is hit?

That is exactly what I'm trying to do!

 

 

 

You'd kill like 300 birds with one stone if we could use pyprocgame. DMD, Modes , just everything.

Agree 100%, would be nice.

 

Maybe I'm looking at Unit3d a bit too early for running custom games, I guess the ROMS do most of the work currently. Might have to wait till the API is done and documented.


 

 

If you go into the table explorer in editor and find the kickers on the left , you'll see more or less same structure as the toys.

In the FP table editor, or the U3DP editor?? Can't seem to find Table Explorer in FP...



#4 chepas

chepas

    t.me/horsepin

  • Members
  • PipPipPipPip
  • 1,966 posts

  • Flag: ---------

  • Favorite Pinball: BSD, Tr0n, SW:Stern

Posted 31 July 2014 - 02:24 PM

 

In the FP table editor, or the U3DP editor?? Can't seem to find Table Explorer in FP...

Load up Unit3D with the bat. When inside push escape for options and then table explorer and find the kickers in list. It will be something like "Table/Kickers/Kicker1".

"Unit3D Pinball.exe"  /editor /verbose 5

 

Maybe I'm looking at Unit3d a bit too early for running custom games, I guess the ROMS do most of the work currently. Might have to wait till the API is done and documented.

 

 

I wouldn't worry about doing too much scripting in this for now. Just get your kickers kicking. Unit3D is good to test accurate shots vs FP. Gives you a better view vs VP for design.

 

Workflow for me to get ready for coding pyprocgame is FP, Unit3D then convert to VP.


Edited by chepas, 02 August 2014 - 09:16 AM.

Bump maps are the new auto-tune :BDH:
VPX - RSS Updates ---- blog.flippingflips.xyz/en/ -- Visual Pinball No.1 (2021) . Est.2000


#5 BilboX

BilboX

    Enthusiast

  • Unit3D Pinball Team
  • 433 posts
  • Location:French Polynesia

  • Flag: France

  • Favorite Pinball: Metallica, Addams Familly, Scared Stiff, White Water

Posted 06 August 2014 - 07:15 PM

So you are making an origibal table? No ROM driven?

 

The next update will include mostly anything needed for original tables.

 

There is a big problem with your "class": no constructor and your functions are called outside a correct context.

For what you wnat, you'll need to use callbacks. Again, in the the next release (we hope before september), you'll also have examples with an "original" script driven table: Abra Ca Dabra port of FP...

 

More infos then.

 

Cheers!


UP2