<commit_before>/*******************************************************************************
 * This file is part of TERMINAL RECALL
 * Copyright (c) 2012-2014 <NAME>
 * Part of the jTRFP.org project
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     chuck - initial API and implementation
 ******************************************************************************/
package org.jtrfp.trcl;

import java.awt.Color;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;

import javax.media.opengl.GL3;

import org.apache.commons.math3.geometry.euclidean.threed.Rotation;
import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
import org.jtrfp.jfdt.UnrecognizedFormatException;
import org.jtrfp.jtrfp.FileLoadException;
import org.jtrfp.trcl.beh.CubeCollisionBehavior;
import org.jtrfp.trcl.beh.DamageableBehavior;
import org.jtrfp.trcl.beh.DeathBehavior;
import org.jtrfp.trcl.beh.DebrisOnDeathBehavior;
import org.jtrfp.trcl.beh.ExplodesOnDeath;
import org.jtrfp.trcl.beh.phy.RotatingObjectBehavior;
import org.jtrfp.trcl.beh.phy.ShiftingObjectBehavior;
import org.jtrfp.trcl.beh.tun.DestructibleWallBehavior;
import org.jtrfp.trcl.beh.tun.IrisBehavior;
import org.jtrfp.trcl.beh.tun.TunnelEntryListener;
import org.jtrfp.trcl.core.Features;
import org.jtrfp.trcl.core.ResourceManager;
import org.jtrfp.trcl.core.TRFactory;
import org.jtrfp.trcl.core.TRFactory.TR;
import org.jtrfp.trcl.ext.tr.GPUFactory.GPUFeature;
import org.jtrfp.trcl.file.LVLFile;
import org.jtrfp.trcl.file.TDFFile;
import org.jtrfp.trcl.file.TDFFile.ExitMode;
import org.jtrfp.trcl.file.TNLFile;
import org.jtrfp.trcl.file.TNLFile.Segment;
import org.jtrfp.trcl.file.TNLFile.Segment.Obstacle;
import org.jtrfp.trcl.gpu.Model;
import org.jtrfp.trcl.gpu.Texture;
import org.jtrfp.trcl.gui.ReporterFactory.Reporter;
import org.jtrfp.trcl.img.vq.ColorPaletteVectorList;
import org.jtrfp.trcl.miss.LoadingProgressReporter;
import org.jtrfp.trcl.obj.BarrierCube;
import org.jtrfp.trcl.obj.Explosion.ExplosionType;
import org.jtrfp.trcl.obj.ForceField;
import org.jtrfp.trcl.obj.ObjectDirection;
import org.jtrfp.trcl.obj.ObjectSystem;
import org.jtrfp.trcl.obj.TunnelExitObject;
import org.jtrfp.trcl.obj.TunnelSegment;
import org.jtrfp.trcl.obj.WorldObject;
import org.jtrfp.trcl.prop.HorizGradientCubeGen;
import org.jtrfp.trcl.prop.SkyCubeGen;
import org.jtrfp.trcl.shell.GameShellFactory.GameShell;

public class Tunnel extends RenderableSpacePartitioningGrid {
    private LVLFile 	lvl;
    private final TR 	tr;
    private final GL3 	gl;
    final double 	tunnelDia = 150000;
    final double 	wallThickness = 5000;
    private final World world;
    private 	  Color []		   palette;
    private 	  ColorPaletteVectorList   paletteVL;
    private	  ColorPaletteVectorList   ESTuTvPalette;
    private final TDFFile.Tunnel 	   sourceTunnel;
    private final TunnelExitObject 	   exitObject;
    private final LoadingProgressReporter[]reporters;
    private final LoadingProgressReporter  tunnelAssemblyReporter;
    private ObjectSystem		   objectSystem;//DO NOT REMOVE. Strong reference to avoid GC
    private final HashSet<TunnelEntryListener>
    					   tunnelEntryListeners = new HashSet<TunnelEntryListener>();
    public static final SkyCubeGen	   TUNNEL_SKYCUBE_GEN = new HorizGradientCubeGen
		(Color.darkGray,Color.black);
    private String                         debugName;

    public static final Vector3D TUNNEL_START_POS = new Vector3D(0,
	    TRFactory.mapSquareSize * 5, TRFactory.mapSquareSize*15);
    public static final ObjectDirection TUNNEL_START_DIRECTION = new ObjectDirection(
	    new Vector3D(1, 0, 0), new Vector3D(0, 1, 0));
    public static final Vector3D TUNNEL_OBJECT_POS_OFFSET = new Vector3D(0, 0,
	    -2 * TRFactory.mapSquareSize);

    public Tunnel(TR tr, TDFFile.Tunnel sourceTunnel,
	    LoadingProgressReporter rootReporter, String debugName) {
	super();
	this.world	  = tr.getWorld();
	reporters	  = rootReporter.generateSubReporters(2);
	this.sourceTunnel = sourceTunnel;
	this.tr           = tr;
	gl 		  = Features.get(tr, GPUFeature.class).getGl();
	tunnelAssemblyReporter 
	  		  = reporters[0];
	this.debugName    = debugName;
	Vector3D tunnelEnd = null;
	try {
	    lvl = tr.getResourceManager()
		    .getLVL(sourceTunnel.getTunnelLVLFile());
	    final Vector3D entranceVector = TUNNEL_START_DIRECTION.getHeading();
	    palette = tr.getResourceManager().getPalette(lvl.getGlobalPaletteFile());
	    palette[0] = new Color(0,0,0,0);//KLUDGE: Color zero must be transparent.
	    paletteVL = new ColorPaletteVectorList(palette);
	    ESTuTvPalette = new ColorPaletteVectorList(tr.getResourceManager().getLTE("FOG\\"+lvl.getLuminanceMapFile()).toColors(palette));
	    tunnelEnd = buildTunnel(sourceTunnel, entranceVector, false);
	} catch (Exception e) {
	    e.printStackTrace();
	}
	final GameShell gameShell = Features.get(tr, GameShell.class);
	exitObject = new TunnelExitObject(this,"Tunnel."+debugName,gameShell.getGame().getPlayer());
	exitObject.setSkyCubeGen(gameShell.getGame().getCurrentMission().getOverworldSystem().getSkySystem().getBelowCloudsSkyCubeGen());
	exitObject
		.setMirrorTerrain(sourceTunnel.getExitMode() == ExitMode.exitToChamber);
	exitObject.setPosition(tunnelEnd.add(new Vector3D(10000,0,0)).toArray());
	exitObject.setDirection(TUNNEL_START_DIRECTION);
	exitObject.notifyPositionChange();
	add(exitObject);
	// X is tunnel depth, Z is left-right
	try {
	    objectSystem = new ObjectSystem(tr, lvl, null, Vector3D.MINUS_I,
		    TUNNEL_START_POS.add(TUNNEL_OBJECT_POS_OFFSET),
		    reporters[1]);
	} catch (Exception e) {
	    e.printStackTrace();
	}
	nonBlockingAddBranch(objectSystem);
	/*tr.getGameShell().getGame().getCurrentMission().getOverworldSystem().add(
		entranceObject = new TunnelEntranceObject(tr, this));*/
    }// end constructor

    private Vector3D buildTunnel(TDFFile.Tunnel _tun, Vector3D groundVector,
	    boolean entrance) throws IllegalAccessException,
	    UnrecognizedFormatException, FileNotFoundException,
	    FileLoadException, IOException {
	// Entrance uses only a stub. Player is warped to TUNNEL_POS facing
	// TUNNEL_START_DIRECTION
	ResourceManager rm = tr.getResourceManager();
	LVLFile tlvl = rm.getLVL(_tun.getTunnelLVLFile());
	final ColorPaletteVectorList tunnelColorPalette = new ColorPaletteVectorList(tr.getResourceManager().getPalette(lvl.getGlobalPaletteFile()));
	Texture[] tunnelTexturePalette = rm.getTextures(
		tlvl.getLevelTextureListFile(), paletteVL, ESTuTvPalette, true);
	TNLFile tun = tr.getResourceManager().getTNLData(
		tlvl.getHeightMapOrTunnelFile());

	final double segLen = 65536;
	final double bendiness = 18;
	List<Segment> segs = tun.getSegments();
	final LoadingProgressReporter[] reporters = tunnelAssemblyReporter
		.generateSubReporters(segs.size());
	Rotation rotation = entrance ? new Rotation(new Vector3D(0, 0, 1),
		groundVector) : new Rotation(new Vector3D(0, 0, 1),<commit_msg>⎘ObjectSystem init with properties and defualt constructor.<commit_after>/*******************************************************************************
 * This file is part of TERMINAL RECALL
 * Copyright (c) 2012-2014 <NAME>
 * Part of the jTRFP.org project
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     chuck - initial API and implementation
 ******************************************************************************/
package org.jtrfp.trcl;

import java.awt.Color;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;

import javax.media.opengl.GL3;

import org.apache.commons.math3.geometry.euclidean.threed.Rotation;
import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
import org.jtrfp.jfdt.UnrecognizedFormatException;
import org.jtrfp.jtrfp.FileLoadException;
import org.jtrfp.trcl.beh.CubeCollisionBehavior;
import org.jtrfp.trcl.beh.DamageableBehavior;
import org.jtrfp.trcl.beh.DeathBehavior;
import org.jtrfp.trcl.beh.DebrisOnDeathBehavior;
import org.jtrfp.trcl.beh.ExplodesOnDeath;
import org.jtrfp.trcl.beh.phy.RotatingObjectBehavior;
import org.jtrfp.trcl.beh.phy.ShiftingObjectBehavior;
import org.jtrfp.trcl.beh.tun.DestructibleWallBehavior;
import org.jtrfp.trcl.beh.tun.IrisBehavior;
import org.jtrfp.trcl.beh.tun.TunnelEntryListener;
import org.jtrfp.trcl.core.Features;
import org.jtrfp.trcl.core.ResourceManager;
import org.jtrfp.trcl.core.TRFactory;
import org.jtrfp.trcl.core.TRFactory.TR;
import org.jtrfp.trcl.ext.tr.GPUFactory.GPUFeature;
import org.jtrfp.trcl.file.LVLFile;
import org.jtrfp.trcl.file.TDFFile;
import org.jtrfp.trcl.file.TDFFile.ExitMode;
import org.jtrfp.trcl.file.TNLFile;
import org.jtrfp.trcl.file.TNLFile.Segment;
import org.jtrfp.trcl.file.TNLFile.Segment.Obstacle;
import org.jtrfp.trcl.gpu.Model;
import org.jtrfp.trcl.gpu.Texture;
import org.jtrfp.trcl.gui.ReporterFactory.Reporter;
import org.jtrfp.trcl.img.vq.ColorPaletteVectorList;
import org.jtrfp.trcl.miss.LoadingProgressReporter;
import org.jtrfp.trcl.obj.BarrierCube;
import org.jtrfp.trcl.obj.Explosion.ExplosionType;
import org.jtrfp.trcl.obj.ForceField;
import org.jtrfp.trcl.obj.ObjectDirection;
import org.jtrfp.trcl.obj.ObjectSystem;
import org.jtrfp.trcl.obj.TunnelExitObject;
import org.jtrfp.trcl.obj.TunnelSegment;
import org.jtrfp.trcl.obj.WorldObject;
import org.jtrfp.trcl.prop.HorizGradientCubeGen;
import org.jtrfp.trcl.prop.SkyCubeGen;
import org.jtrfp.trcl.shell.GameShellFactory.GameShell;

public class Tunnel extends RenderableSpacePartitioningGrid {
    private LVLFile 	lvl;
    private final TR 	tr;
    private final GL3 	gl;
    final double 	tunnelDia = 150000;
    final double 	wallThickness = 5000;
    private final World world;
    private 	  Color []		   palette;
    private 	  ColorPaletteVectorList   paletteVL;
    private	  ColorPaletteVectorList   ESTuTvPalette;
    private final TDFFile.Tunnel 	   sourceTunnel;
    private final TunnelExitObject 	   exitObject;
    private final LoadingProgressReporter[]reporters;
    private final LoadingProgressReporter  tunnelAssemblyReporter;
    private ObjectSystem		   objectSystem;//DO NOT REMOVE. Strong reference to avoid GC
    private final HashSet<TunnelEntryListener>
    					   tunnelEntryListeners = new HashSet<TunnelEntryListener>();
    public static final SkyCubeGen	   TUNNEL_SKYCUBE_GEN = new HorizGradientCubeGen
		(Color.darkGray,Color.black);
    private String                         debugName;

    public static final Vector3D TUNNEL_START_POS = new Vector3D(0,
	    TRFactory.mapSquareSize * 5, TRFactory.mapSquareSize*15);
    public static final ObjectDirection TUNNEL_START_DIRECTION = new ObjectDirection(
	    new Vector3D(1, 0, 0), new Vector3D(0, 1, 0));
    public static final Vector3D TUNNEL_OBJECT_POS_OFFSET = new Vector3D(0, 0,
	    -2 * TRFactory.mapSquareSize);

    public Tunnel(TR tr, TDFFile.Tunnel sourceTunnel,
	    LoadingProgressReporter rootReporter, String debugName) {
	super();
	this.world	  = tr.getWorld();
	reporters	  = rootReporter.generateSubReporters(2);
	this.sourceTunnel = sourceTunnel;
	this.tr           = tr;
	gl 		  = Features.get(tr, GPUFeature.class).getGl();
	tunnelAssemblyReporter 
	  		  = reporters[0];
	this.debugName    = debugName;
	Vector3D tunnelEnd = null;
	try {
	    lvl = tr.getResourceManager()
		    .getLVL(sourceTunnel.getTunnelLVLFile());
	    final Vector3D entranceVector = TUNNEL_START_DIRECTION.getHeading();
	    palette = tr.getResourceManager().getPalette(lvl.getGlobalPaletteFile());
	    palette[0] = new Color(0,0,0,0);//KLUDGE: Color zero must be transparent.
	    paletteVL = new ColorPaletteVectorList(palette);
	    ESTuTvPalette = new ColorPaletteVectorList(tr.getResourceManager().getLTE("FOG\\"+lvl.getLuminanceMapFile()).toColors(palette));
	    tunnelEnd = buildTunnel(sourceTunnel, entranceVector, false);
	} catch (Exception e) {
	    e.printStackTrace();
	}
	final GameShell gameShell = Features.get(tr, GameShell.class);
	exitObject = new TunnelExitObject(this,"Tunnel."+debugName,gameShell.getGame().getPlayer());
	exitObject.setSkyCubeGen(gameShell.getGame().getCurrentMission().getOverworldSystem().getSkySystem().getBelowCloudsSkyCubeGen());
	exitObject
		.setMirrorTerrain(sourceTunnel.getExitMode() == ExitMode.exitToChamber);
	exitObject.setPosition(tunnelEnd.add(new Vector3D(10000,0,0)).toArray());
	exitObject.setDirection(TUNNEL_START_DIRECTION);
	exitObject.notifyPositionChange();
	add(exitObject);
	// X is tunnel depth, Z is left-right
	try {
	    objectSystem = new ObjectSystem();
	    objectSystem.setTr(tr);
	    //lvl
	    objectSystem.setHeadingOverride(Vector3D.MINUS_J);
	    objectSystem.setPositionOffset(TUNNEL_START_POS.add(TUNNEL_OBJECT_POS_OFFSET));
	    objectSystem.setProgressReporter(reporters[1]);
	    objectSystem.populateFromLVL(lvl);
	} catch (Exception e) {
	    e.printStackTrace();
	}
	nonBlockingAddBranch(objectSystem);
	/*tr.getGameShell().getGame().getCurrentMission().getOverworldSystem().add(
		entranceObject = new TunnelEntranceObject(tr, this));*/
    }// end constructor

    private Vector3D buildTunnel(TDFFile.Tunnel _tun, Vector3D groundVector,
	    boolean entrance) throws IllegalAccessException,
	    UnrecognizedFormatException, FileNotFoundException,
	    FileLoadException, IOException {
	// Entrance uses only a stub. Player is warped to TUNNEL_POS facing
	// TUNNEL_START_DIRECTION
	ResourceManager rm = tr.getResourceManager();
	LVLFile tlvl = rm.getLVL(_tun.getTunnelLVLFile());
	final ColorPaletteVectorList tunnelColorPalette = new ColorPaletteVectorList(tr.getResourceManager().getPalette(lvl.getGlobalPaletteFile()));
	Texture[] tunnelTexturePalette = rm.getTextures(
		tlvl.getLevelTextureListFile(), paletteVL, ESTuTvPalette, true);
	TNLFile tun = tr.getResourceManager().getTNLData(
		tlvl.getHeightMapOrTunnelFile());

	final double segLen = 65536;
	final double bendiness = 18;
	List<Segment> segs = tun.getSegments();
	final LoadingProgressReporter[] reporters = tunnelAssemblyReporter
		.generateSubReporters(segs.size());
	Rotation rotation = entrance ? new Rotation(new Vector3D(0, 0, 1),
		groundVector) : new Rotation(new Vector3D(0, 0, 1),
{'fraction_non_alphanumeric': 0.1209451615106194, 'fraction_numerical': 0.01092672266612033, 'mean_word_length': 5.061258278145695, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '238593', 'n_tokens_mistral': 5094, 'n_tokens_neox': 4841, 'n_words': 898}