Select Page

Now that I have that new, fancy method of doing constructor junk, I built an NPC dock class, using an FSM (Finite State Machine). Here’s the starting code:

function NPCShips_Dock_Class(owner) constructor {
	Ship_Object = owner;
	state = "idle";
	check_distance = 4200;
	
	set_state = function(ds) {
		state = ds;
	}
		
	controller = function() {
		switch(state) {
			case "idle":
				Ship_Object.is_landing = false;
			break;
			case "dock_check":
				check();
			break;
			case "stop_ship":
				stop_ship();
			break;
			case "turn_ship":
				turn_ship();
			break;
			case "move_to_target":
				move_to_target();
			break;
			case "landing":
				landing();
			break;
			case "launch":
				launch();
			break;
		}
	}
// ...and so on

It basically jumps from one state to the next until it’s all done. Haven’t put in the launch code yet, but that’ll come soon enough. For now, the ships just act like mama’s called them all home for dinner…and it’s pot roast night!

Progress

  • Got the NPCs flying spawning, finding the closest planet, and making a mad dash to land on whichever one is closest.