Package transientlibs.bindedobjects.gamecontent

Source Code of transientlibs.bindedobjects.gamecontent.Tech

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package transientlibs.bindedobjects.gamecontent;

import transientlibs.tex.ActList;
import transientlibs.tex.ReqList;
import transientlibs.tex.StringAnalyst;
import transientlibs.objects.misc.ResearchBranch;
import transientlibs.processors.misc.Detonator;
import transientlibs.objects.general.Node;
import transientlibs.objects.primitives.TBoolean;
import transientlibs.objects.general.TechProgress;
import transientlibs.preui.objects.gui.elements.ButtonGroup;
import java.util.ArrayList;
import java.util.Iterator;
import transientlibs.slick2d.util.Log;
import transientlibs.bindedobjects.core.Activator;
import transientlibs.bindedobjects.core.datasets.BindedValue;
import transientlibs.bindedobjects.core.Binding;
import transientlibs.bindedobjects.core.Req;
import transientlibs.objects.primitives.Int;

/**
*
* @author kibertoad
*/
public class Tech extends BindedValue {





public static ArrayList<Tech> techs = new ArrayList<Tech>();

    public static Tech lastTech;
    public String group;

    public boolean isResearched = false;
    public Int pointCost = new Int (1);
    public Int progress = new Int (0);

    public static final int typeStage = 1;
    public static final int valueStage = 2;
    public static int currentStage = 1;






public static void loadTech (){

      if (StringAnalyst.isFileExist("techs.dat")) {

        StringAnalyst reader = new StringAnalyst();



        reader.openFile("techs.dat");

        while (!reader.eof) {


        reader.readRow();
        analyzeStringForTechs (reader);
        }

        reader.closeFile();
      }
    }

          public static void analyzeStringForTechs (StringAnalyst analyst) {
        analyzeStringForTechs ("-NO-", analyst);
    }

public static void analyzeStringForTechs (String getString, StringAnalyst analyst) {

   if (!"-NO-".equals(getString)) {analyst.fullStr = getString;}

   analyst.checkForAliases();

        analyst.getNextString();
        String nowStr = analyst.lastStr;

        boolean withResult = false;


        if (nowStr.equals("type")) {

            currentStage = typeStage;

            ResearchBranch.researchbranches.add(new ResearchBranch());
            ResearchBranch.lastResearchBranch = ResearchBranch.researchbranches.get(ResearchBranch.researchbranches.size() - 1);
            ResearchBranch.lastResearchBranch.ID = analyst.getBinding(Binding.researchBranchBinding);
            ResearchBranch.lastResearchBranch.LName.value = analyst.lastStr;

            withResult = true;
        }

        if (nowStr.equals("group")) {
            lastTech.group = analyst.restOfRow();
            withResult = true;
        }

        if (nowStr.equals("tech")) {

            currentStage = valueStage;

            techs.add (new Tech ());
            lastTech = techs.get(techs.size()-1);
            lastTech.ID = analyst.getBinding (Binding.techBinding);

            ReqList.lastReqList = lastTech.reqs;
            ActList.lastActList = lastTech.acts;

            //ReqList.lastReqList = lastTech.trainReqs;

            withResult = true;

        }

    if (nowStr.equals("name")) {

        if (currentStage == typeStage) {ResearchBranch.lastResearchBranch.LName.value = analyst.restOfRow();} else

        {lastTech.LName.value = analyst.restOfRow();}


            withResult = true;
        }

    if (nowStr.equals("points")) {
            lastTech.pointCost.value = analyst.getNextNumber();
            withResult = true;
        }


        if (nowStr.equals("desc")) {

            if (currentStage == typeStage) {ResearchBranch.lastResearchBranch.desc = analyst.restOfRow();}
            else
        {lastTech.desc = analyst.restOfRow();}

           withResult = true;
        }

        if (withResult == false) {withResult = Req.analyzeStringForReqs(analyst.fullStr, analyst);}
        if (withResult == false) {withResult = Activator.analyzeStringForActs(analyst.fullStr, analyst);}


        if ((withResult == false) && (nowStr.length()>2) && (!nowStr.startsWith("//"))) {
            Log.error("Unknown string: "+nowStr);        }

}

  @Override
    public String name (){
        return LName.value;
    }

 


    public static void fillTechList(ButtonGroup infoTable) {

        infoTable.restartFilling();

        Iterator<Tech> i = techs.iterator();

        Tech nowTech;

        while (i.hasNext()) {
            nowTech = i.next();

            //if ((nowTech.reqs.isFulfilled()) && (Detonator.instance.techResearched.get(nowTech.ID).value==false)) {infoTable.addNodeOption(nowTech.LName+" ("+nowTech.ID+")", nowTech);}
            if ((nowTech.reqs.isFulfilled()) && (Detonator.INSTANCE.techResearched.get(nowTech.ID).value==false)) {infoTable.addNodeOption(nowTech.LName.value, nowTech);}
        }

        infoTable.complete();

    }

    public void researchCompleted (ArrayList<TBoolean> resultList, TechProgress techProgress){
    if (resultList != null) {
        resultList.get(ID).value = true;
    }

        techProgress.currentResearch = null;
        techProgress.researchProgress.setup(0, 0);
    }

    public void startResearch (TechProgress techProgress){
        techProgress.currentResearch = this;
        techProgress.researchProgress.setup(0, pointCost.value);
    }

    @Override
    public void bindValues (){

      Detonator.INSTANCE.activeTech = this;

      Detonator.INSTANCE.setBindedValue("techprogress", progress);
      Detonator.INSTANCE.setBindedValue("techprogressneeded", pointCost);

    }


        public static Tech getTechByID (int byID) {
        return techs.get(byID);
    }

    public static Tech getTechByCode (String byCode) {
        return techs.get(Binding.readBinding(Binding.techBinding, byCode.toLowerCase()));
    }


}
TOP

Related Classes of transientlibs.bindedobjects.gamecontent.Tech

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.