@@ -14,15 +14,66 @@ public class SpawnData {
};
public List<SpawnData> SpawnDat;

public List<GameObject> SpawnPoints;

[System.Serializable]
public class SpawnPoint {
public Transform FirstPoint;
public UnitSpawn_Hlpr CurSpwn;

public bool IsOpen, LastDes;
}
public List<SpawnPoint> SpawnPoints;

public int getSpawnPointI(byte sdi) {
int ret = -1;
int start = Random.Range(0, SpawnPoints.Count);
for(int i = 0; i < SpawnPoints.Count; i++ ) {
int cr = (start + i) % SpawnPoints.Count;
if(SpawnPoints[cr].CurSpwn == null) {
ret = cr;
break;
}
}
return ret;
}

float BuildTimer = 0.5f; //initial delay
AnimFeedback Anim_FB;

public float MaxSquidCap = 300, SquidGenRate = 3, SquidRefineRate = 10, SquidRefineEff = 0.5f, SquidMineRate = 50;

new void Start() {
base.Start();

Anim_FB = VisDat.GetComponent<AnimFeedback>();
}

new void Update() {

base.Update();

for(int i = SpawnPoints.Count; i-- > 0; ) {
var sp = SpawnPoints[i];
if( Anim_FB) {

bool desOpen = sp.CurSpwn != null;
if( desOpen != sp.LastDes ) {
Anim_FB.Ctrl.SetFloat("Spwn" + (i + 1), desOpen ? 1 : -1);
var st = Anim_FB.Ctrl.GetCurrentAnimatorStateInfo(i);

if( st.normalizedTime < 0 )
Anim_FB.Ctrl.Play(st.fullPathHash, i, 0);
else if(st.normalizedTime > 0.3333f )
Anim_FB.Ctrl.Play(st.fullPathHash, i, 1 );

sp.LastDes = desOpen;
}
sp.IsOpen = Anim_FB.getFlag(i);
} else
sp.IsOpen = true;

}

if(Owner == null || ( !Owner.isLocalPlayer && !isServer) ) return;

if(ResFields.Count > 0 && (Owner.UnrefSquids + Owner.Squids < MaxSquidCap+0.001f) ) {
@@ -84,15 +135,14 @@ public class SpawnData {

}
}


public void spawnUnit(int i) {
SpawnData sd = SpawnDat[i];
Owner.Cmd_createFrom((byte)i, gameObject); //more than 256 ?? nah
BuildTimer = sd.ConstructTime; //todo -- verify
Debug.Log("Cmd_createFrom please??");
}

/*
[Command]
void Cmd_createFrom( byte i) {
Debug.Log("Cmd_createFrom");
@@ -103,7 +153,7 @@ public class SpawnData {
//todo -- SpawnPoints.Count >= 256 == err
c.GetComponent<UnitSpawn_Hlpr>().Rpc_init(gameObject, (byte)Random.Range(0, SpawnPoints.Count));
}
} */

List<ResourceField> ResFields = new List<ResourceField>();

@@ -85,12 +85,8 @@ public class Unit : NetBehaviour {

}

public void init(Team t) {

Tm = t;
public void fixColliders() {

if(Tm.IsLocalTeam)
FowTest.get().register(this);
var l = Tm.Layer; if((this as Helio) != null) l += Team.TeamC;
// Debug.Log("helio? " + l );
foreach(var c in GetComponentsInChildren<Collider2D>()) {
@@ -102,6 +98,15 @@ public class Unit : NetBehaviour {
foreach(var c in GetComponentsInChildren<Collider>()) {
c.gameObject.layer = l;
}
}
public void init(Team t) {

Tm = t;

if(Tm.IsLocalTeam && FowTest.get() != null )
FowTest.get().register(this);

fixColliders();
foreach(var c in GetComponents<SpeedBoost>()) { //todo base class
c.enabled = true;
}
@@ -34,86 +34,120 @@ public class UnitSpawn_Hlpr : NetBehaviour {
foreach(Collider2D c2 in GetComponentsInChildren<Collider2D>()) {
c2.enabled = true;
}
U.fixColliders();

U.initSyncO();

var j = gameObject.AddComponent<DistanceJoint2D>(); //disble inter collision by magic
j.connectedBody = Car.Body;
j.maxDistanceOnly = true;
j.distance = 99999.0f;


j = U.SyncO.gameObject.AddComponent<DistanceJoint2D>(); //disble inter collision by magic
j.connectedBody = Car.SyncO.Body;
j.maxDistanceOnly = true;
j.distance = 99999.0f;
}

float Timer = 0;


Carrier Car;
Carrier.SpawnPoint SP;
[ClientRpc]
public void Rpc_init(GameObject co, byte spI) {

var c = co.GetComponent<Carrier>();
if(c == null || (uint)spI >= (uint)c.SpawnPoints.Count) { //note: in network functions we are unduly careful
Car = co.GetComponent<Carrier>();
if(Car == null || (uint)spI >= (uint)Car.SpawnPoints.Count) { //note: in network functions we are unduly careful
Destroy(gameObject);
Debug.LogError("Error in UnitSpawn_Hlpr::init " + c + " ---- " + (int)spI);
Debug.LogError("Error in UnitSpawn_Hlpr::init " + Car + " ---- " + (int)spI);
return;
}

Player o = c.Owner;
Player o = Car.Owner;

if(o.isLocalPlayer && !isServer) {
o.Squids -= (float) U.SquidCost;
o.Pop += U.PopCost;
}
activate();

U.init(o);

var sp = c.SpawnPoints[spI];
Prev = sp.transform;
SP = Car.SpawnPoints[spI];
SP.CurSpwn = this;
Prev = SP.FirstPoint;

if(Prev.childCount > 0) Next = Prev.GetChild(0);
// U.Trnsfrm.parent = c.Trnsfrm;
U.Trnsfrm.position = Prev.position;
U.Trnsfrm.rotation = Prev.rotation;


Timer = 1;
//enabled = true;
// gameObject.SetActive(true);


var j = gameObject.AddComponent<DistanceJoint2D>(); //disble inter collision by magic
j.connectedBody = c.Body;
j.maxDistanceOnly = true;
j.distance = 99999.0f;
}




}
bool Spawning = false;
void Update() {

if(Timer <= 0) { //created but not init-ed
if((Timer -= Time.deltaTime) < -3) {
Destroy( gameObject);
if(!Spawning) {
if(Timer <= 0) { //created but not init-ed
if((Timer -= Time.deltaTime) < -3) {
Destroy(gameObject);
}
return;
}
return;
}

if( Next != null) {
float spd = U.MaxSpeed / 2;
float dis = (Next.position - Prev.position).magnitude;

D += spd * Time.deltaTime / dis;
if(D > 1.0f) {
Prev = Next;
if(Prev.childCount > 0) {
Next = Prev.GetChild(0);
D -= 1;
} else {
Next = null;
U.Trnsfrm.position = Prev.position;
}
}
}
if(Next != null) {
var p = Vector3.Lerp(Prev.position, Next.position, D);
U.Body.MovePosition(p);
U.Body.MoveRotation( Quaternion.Lerp(Prev.rotation, Next.rotation, D).eulerAngles.z );
} else { // our carrier == kaboom-boom or just done..
U.enabled = true;
Destroy(GetComponent<DistanceJoint2D>());
Destroy(this);
return;
}
if(Prev == null) { //carrier died??

Destroy(gameObject);
return;
}

U.Trnsfrm.position = Prev.position;
U.Trnsfrm.rotation = Prev.rotation;

if(SP.IsOpen) {
activate();
Spawning = true;
}

} else {
if(Next != null) {
float spd = U.MaxSpeed / 2;
float dis = (Next.position - Prev.position).magnitude;

D += spd * Time.deltaTime / dis;
if(D > 1.0f) {
Prev = Next;
if(Prev.childCount > 0) {
Next = Prev.GetChild(0);
D -= 1;
} else {
Next = null;
U.Trnsfrm.position = Prev.position;
}
}
}
if(Next != null) {
var p = Vector3.Lerp(Prev.position, Next.position, D);
U.Trnsfrm.position = p;
U.Body.MovePosition(U.SyncO.Body.position);
U.SyncO.Body.MovePosition(p);
var r = Quaternion.Lerp(Prev.rotation, Next.rotation, D).eulerAngles.z;
U.Body.MoveRotation(U.SyncO.Body.rotation);
U.SyncO.Body.MoveRotation(r);
} else { // our carrier == kaboom-boom or just done..
U.enabled = true;
Destroy(this);
Destroy(GetComponent<DistanceJoint2D>());
Destroy(U.SyncO.gameObject.GetComponent<DistanceJoint2D>());
return;
}
}
}


@@ -230,30 +230,34 @@ struct Buff {
public void Rpc_init(GameObject oo) {
// if(isServer) return; //better way..
init(oo.GetComponent<Player>());
}

new protected void OnEnable() {
base.OnEnable();
SmoothPath = new List<Vector2>();
SmoothPath.Add(TargetP = Trnsfrm.position);
}

public void initSyncO() {

var go = new GameObject();
go.name = name + " syncO";
SyncO = go.AddComponent<Unit_SyncHelper>();
SyncO.Body = go.AddComponent<Rigidbody2D>(Body);
for( int i = 0; i < Trnsfrm.childCount; i++ ) {
for(int i = 0; i < Trnsfrm.childCount; i++) {
var t = Trnsfrm.GetChild(i);
if(t.GetComponentInChildren<Collider2D>() == null) continue;
var go2 = Instantiate(t.gameObject);
go2.transform.parent =SyncO.Trnsfrm;
go2.transform.parent = SyncO.Trnsfrm;
}

var l = 31; if((this as Helio) != null) l--;
foreach(Transform t in SyncO.GetComponentInChildren<Transform>()) {
t.gameObject.layer = l;
}
}
new protected void OnEnable() {
base.OnEnable();
SmoothPath = new List<Vector2>();
SmoothPath.Add(TargetP = Trnsfrm.position);

if(SyncO == null) initSyncO();
}

new protected void OnDisable() {
base.OnDisable();
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.