Skip to content

Commit

Permalink
replicator IA finished
Browse files Browse the repository at this point in the history
debug enable in .config (hide eln console print)
  • Loading branch information
Dolu1990 committed May 13, 2014
1 parent 009d852 commit 9c2ee20
Show file tree
Hide file tree
Showing 16 changed files with 436 additions and 313 deletions.
34 changes: 24 additions & 10 deletions mods/eln/Eln.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
import net.minecraft.command.ServerCommandManager;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.monster.EntityEnderman;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.EnumArmorMaterial;
Expand All @@ -217,6 +218,7 @@
import net.minecraft.world.WorldSavedData;
import net.minecraft.world.WorldServer;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.biome.SpawnListEntry;
import net.minecraft.world.storage.SaveHandler;
import net.minecraft.world.storage.WorldInfo;
import net.minecraft.block.material.Material;
Expand Down Expand Up @@ -478,6 +480,7 @@ public class Eln {

float xRayScannerRange;
boolean addOtherModOreToXRay;
public static boolean debugEnable = false;

@PreInit
public void preInit(FMLPreInitializationEvent event) {
Expand Down Expand Up @@ -551,6 +554,7 @@ public void preInit(FMLPreInitializationEvent event) {
blocBaseId + 2, "choubakaka").getInt();

modbusEnable = config.get("modbus", "enable", false).getBoolean(false);
debugEnable = config.get("debug", "enable", false).getBoolean(false);

genCooper = config.get("mapGenerate", "cooper", true).getBoolean(true);
genPlumb = config.get("mapGenerate", "plumb", true).getBoolean(true);
Expand Down Expand Up @@ -871,21 +875,21 @@ public void load(FMLInitializationEvent event) {

checkRecipe();

System.out.println("Electrical age init done");
Utils.println("Electrical age init done");
}

void checkRecipe() {
System.out.println("No recipe for ");
Utils.println("No recipe for ");
for (SixNodeDescriptor d : sixNodeItem.subItemList.values()) {
ItemStack stack = d.newItemStack();
if (aRecipeExist(stack) == false) {
System.out.println(" " + d.name);
Utils.println(" " + d.name);
}
}
for (TransparentNodeDescriptor d : transparentNodeItem.subItemList.values()) {
ItemStack stack = d.newItemStack();
if (aRecipeExist(stack) == false) {
System.out.println(" " + d.name);
Utils.println(" " + d.name);
}
}
}
Expand Down Expand Up @@ -947,12 +951,12 @@ public void onServerStarting(FMLServerStartingEvent ev) {
if (firstStart) {
if (addOtherModOreToXRay) {
for (String name : OreDictionary.getOreNames()) {
// System.out.println(name + " " +
// Utils.println(name + " " +
// OreDictionary.getOreID(name));
if (name.startsWith("ore")) {
for (ItemStack stack : OreDictionary.getOres(name)) {
int id = stack.itemID + 4096*stack.getItem().getMetadata(stack.getItemDamage());
// System.out.println(OreDictionary.getOreID(name));
// Utils.println(OreDictionary.getOreID(name));
boolean find = false;
for (OreScannerConfigElement c : oreScannerConfig) {
if (c.blockKey == id) {
Expand All @@ -962,7 +966,7 @@ public void onServerStarting(FMLServerStartingEvent ev) {
}

if (!find) {
System.out.println(id + " added to xRay (other mod)");
Utils.println(id + " added to xRay (other mod)");
oreScannerConfig.add(new OreScannerConfigElement(id, 0.15f));
}
}
Expand Down Expand Up @@ -6317,10 +6321,20 @@ void registerReplicator(){

//Localize mob name
LanguageRegistry.instance().addStringLocalization("entity.EAReplicator.name", "en_US", "Replicator");
/*

//Add mob spawn
EntityRegistry.addSpawn(ReplicatorEntity.class, 2, 1, 2, EnumCreatureType.monster, BiomeGenBase.plains);
EntityRegistry.addSpawn(ReplicatorEntity.class, 5, 1, 2, EnumCreatureType.monster, BiomeGenBase.extremeHills); */
// EntityRegistry.addSpawn(ReplicatorEntity.class, 1, 1, 2, EnumCreatureType.monster, BiomeGenBase.plains);
for(BiomeGenBase biome : BiomeGenBase.biomeList){
if(biome == null) continue;
{
List list = biome.getSpawnableList(EnumCreatureType.monster);
list.add(new SpawnListEntry(ReplicatorEntity.class, 1, 1, 2));
}
{
List list = biome.getSpawnableList(EnumCreatureType.ambient);
list.add(new SpawnListEntry(ReplicatorEntity.class, 2, 1, 2));
}
}
}


Expand Down
6 changes: 3 additions & 3 deletions mods/eln/electricaldatalogger/DataLogs.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ byte read(int idx) {
@Override
public void readFromNBT(NBTTagCompound nbt, String str) {
byte[] cpy = nbt.getByteArray(str + "log");
System.out.println("Datalog readnbt " + cpy.length);
Utils.println("Datalog readnbt " + cpy.length);
for(int idx = 0; idx < cpy.length; idx++) {
write(cpy[cpy.length - 1 - idx]);
}
Expand All @@ -60,7 +60,7 @@ public void readFromNBT(NBTTagCompound nbt, String str) {
maxValue = nbt.getFloat(str + "maxValue");
minValue = nbt.getFloat(str + "minValue");
unitType = nbt.getByte(str + "unitType");
System.out.println("Datalog readnbt done");
Utils.println("Datalog readnbt done");
}

@Override
Expand Down Expand Up @@ -183,7 +183,7 @@ static void draw(byte []value, int size, float samplingPeriod, float maxValue, f
//fontrenderer.drawString("Time", (int)(0.5f / scale), (int)(0.8f / scale), 0);
GL11.glPopMatrix();
//startT = System.nanoTime() - startT;
//System.out.println("startT : " + startT);
//Utils.println("startT : " + startT);
}

public static String getYstring(float factor, float maxValue, float minValue, byte unitType) {
Expand Down
2 changes: 1 addition & 1 deletion mods/eln/electricalsource/ElectricalSourceElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public ThermalLoad getThermalLoad(LRDU lrdu) {

@Override
public int getConnectionMask(LRDU lrdu) {
return NodeBase.maskElectricalAll + (color << NodeBase.maskColorShift) + (colorCare << NodeBase.maskColorCareShift);
return NodeBase.maskElectricalPower + (color << NodeBase.maskColorShift) + (colorCare << NodeBase.maskColorCareShift);
}

@Override
Expand Down
72 changes: 72 additions & 0 deletions mods/eln/entity/ConfigurableAiWander.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package mods.eln.entity;

import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.entity.ai.RandomPositionGenerator;
import net.minecraft.util.Vec3;

public class ConfigurableAiWander extends EntityAIBase
{
private EntityCreature entity;
private double xPosition;
private double yPosition;
private double zPosition;
private double speed;

private int randLimit;

public ConfigurableAiWander(EntityCreature par1EntityCreature, double par2,int randLimit)
{
this.entity = par1EntityCreature;
this.speed = par2;
this.setMutexBits(1);
this.randLimit = randLimit;
}

/**
* Returns whether the EntityAIBase should begin execution.
*/
public boolean shouldExecute()
{
if (this.entity.getAge() >= 100)
{
return false;
}
else if (this.entity.getRNG().nextInt(randLimit) != 0)
{
return false;
}
else
{
Vec3 vec3 = RandomPositionGenerator.findRandomTarget(this.entity, 10, 7);

if (vec3 == null)
{
return false;
}
else
{
this.xPosition = vec3.xCoord;
this.yPosition = vec3.yCoord;
this.zPosition = vec3.zCoord;
return true;
}
}
}

/**
* Returns whether an in-progress EntityAIBase should continue executing
*/
public boolean continueExecuting()
{
return !this.entity.getNavigator().noPath();
}

/**
* Execute a one shot task or start executing a continuous task
*/
public void startExecuting()
{
this.entity.getNavigator().tryMoveToXYZ(this.xPosition, this.yPosition, this.zPosition, this.speed);
}
}
23 changes: 14 additions & 9 deletions mods/eln/entity/ReplicatoCableAI.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,30 @@ public class ReplicatoCableAI extends EntityAIBase implements ITimeRemoverObserv
public ReplicatoCableAI(ReplicatorEntity entity) {
this.entity = entity;
Eln.instance.highVoltageCableDescriptor.applyTo(load, false);
load.setRs(load.getRs()*10);
this.setMutexBits(1);
}

public Coordonate cableCoordonate = null;
Random rand = new Random();
int lookingPerUpdate = 10;
int lookingPerUpdate = 20;

ElectricalLoad load = new ElectricalLoad(),cableLoad;
ElectricalConnection connection;
TimeRemover timeRemover = new TimeRemover(this);
double moveTimeOut;
double moveTimeOutReset = 20;
double resetTimeout;
double resetTimeoutReset = 120;
@Override
public boolean shouldExecute() {
System.out.println("LookingForCableAi");
//System.out.println("LookingForCableAi");
ArrayList<NodeBase> nodes = NodeManager.instance.getNodes();
if(nodes.size() == 0) return false;
for(int idx = 0;idx < lookingPerUpdate;idx++){
NodeBase node = nodes.get(rand.nextInt(nodes.size()));
double distance = node.coordonate.distanceTo(entity);
if(distance > 10) continue;
if(distance > 15) continue;
if(node instanceof SixNode == false) continue;
SixNode sixNode = (SixNode)node;
for(SixNodeElement e : sixNode.sideElementList){
Expand All @@ -57,9 +60,10 @@ public boolean shouldExecute() {
if(path == null/* || path.isFinished() == false*/) continue;
entity.getNavigator().setPath(path, 1);
cableCoordonate = node.coordonate;
System.out.println("LookingForCableAi done");
//System.out.println("LookingForCableAi done");
moveTimeOut = moveTimeOutReset;
load.setRp(1000000000000.0);
resetTimeout = resetTimeoutReset;
return true;
}
}
Expand All @@ -79,6 +83,7 @@ public boolean continueExecuting() {
public void updateTask() {
//System.out.println("update");
moveTimeOut -= 0.05;
resetTimeout -= 0.05;
ElectricalCableElement cable;
if((cable = getCable()) == null){
cableCoordonate = null;
Expand All @@ -93,14 +98,14 @@ public void updateTask() {
if(distance < 2){
//System.out.println("replicator on cable !");
double u = cable.electricalLoad.Uc;

if(load.getRpPower() > 200){
double nextRp = Math.pow(u/Eln.LVU, -0.3)*u*u/(50);
if(load.getRp() < 0.8*nextRp){
entity.attackEntityFrom(DamageSource.magic, 5);
}
else{
entity.eatElectricity(load.getRpPower()*0.05);
}
load.setRp(Math.pow(u/Eln.LVU, -0.3)*u*u/(50));
load.setRp(nextRp);

timeRemover.setTimeout(0.16);
moveTimeOut = moveTimeOutReset;
Expand All @@ -111,7 +116,7 @@ public void updateTask() {
}


if(moveTimeOut < 0){
if(moveTimeOut < 0 || resetTimeout < 0){
cableCoordonate = null;
}

Expand Down Expand Up @@ -145,7 +150,7 @@ ElectricalCableElement getCable(){
@Override
public void startExecuting() {
// TODO Auto-generated method stub
System.out.println("START REPLICATOOOOOR");
//System.out.println("START REPLICATOOOOOR");

//System.out.println(this.entity.getNavigator().tryMoveToXYZ(-2470,56,-50, 1));
}
Expand Down
Loading

0 comments on commit 9c2ee20

Please sign in to comment.