?? stunner.java
字號(hào):
/*
Netwar
Copyright (C) 2002 Daniel Grund, Kyle Kakligian, Jason Komutrattananon, & Brian Hibler.
This file is part of Netwar.
Netwar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Netwar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Netwar; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package netwar.game.unit;
import netwar.game.*;
import netwar.utils.*;
import netwar.utils.vectorgraphics.*;
import netwar.game.projectile.Paralyzer;
import java.awt.*;
/** Experimental paralyzer unit.
* @author Group N2 - Project Netwar
* @author Daniel Grund
*/
public class Stunner extends Unit {
ZOrderedList zol;
CoherentPointSet cps;
CoherentPointSet orb;
private static Color orbColor = new Color(96, 96, 255, 50);
/** Constuctor. This Unit has no special parameters. */
public Stunner(){
}
protected int framesToMove(){
return 10; //return the number of frames needed to move one hex.
}
protected int framesToRotate(){
return 6; //return the number of frames needed to rotate one hex-side.
}
protected int framesToMake(){
return 50;
}
protected int framesToDie(){
return 10;
}
protected void createVectors()
{
int i = f * 60 + 30;
vr = new Point3D[1];
vr[0] = Hex.getMapPoint(x,y);
zol = new ZOrderedList(netwar.gui.HexViewer.getHexViewer().getTransform());
cps = new CoherentPointSet(36);
orb = new CoherentPointSet(6);
Color darker = myPlayer.getColor().darker();
//SIGMA
cps.add(new SelfConvertingPoint(3.75f,1,0.25f));//0
cps.add(new SelfConvertingPoint(3.75f,-1,0.25f));//1
cps.add(new SelfConvertingPoint(3.5f,0,0.5f));//2
cps.add(new SelfConvertingPoint(3.25f,-1,0.75f));//3
cps.add(new SelfConvertingPoint(3.25f,1,0.75f));//4
//Outer edges
cps.add(new SelfConvertingPoint(4, -3, 0)); //5
cps.add(new SelfConvertingPoint(3, 4, 0)); //6
cps.add(new SelfConvertingPoint(-4, 3, 0)); //7
cps.add(new SelfConvertingPoint(-3, -4, 0)); //8
cps.add(new SelfConvertingPoint(3, -4, 0)); //9
cps.add(new SelfConvertingPoint(4, 3, 0)); //10
cps.add(new SelfConvertingPoint(-3, 4, 0)); //11
cps.add(new SelfConvertingPoint(-4, -3, 0)); //12
//Bottom corners
cps.add(new SelfConvertingPoint(3, -3, 0)); //13
cps.add(new SelfConvertingPoint(3, 3, 0)); //14
cps.add(new SelfConvertingPoint(-3, 3, 0)); //15
cps.add(new SelfConvertingPoint(-3, -3, 0)); //16
//Upper corners
cps.add(new SelfConvertingPoint(3, -3, 1)); //17
cps.add(new SelfConvertingPoint(3, 3, 1)); //18
cps.add(new SelfConvertingPoint(-3, 3, 1)); //19
cps.add(new SelfConvertingPoint(-3, -3, 1)); //20
//Support bottoms
cps.add(new SelfConvertingPoint(3, -2, 1)); //21
cps.add(new SelfConvertingPoint(2, 3, 1)); //22
cps.add(new SelfConvertingPoint(-3, 2, 1)); //23
cps.add(new SelfConvertingPoint(-2, -3, 1)); //24
cps.add(new SelfConvertingPoint(2, -3, 1)); //25
cps.add(new SelfConvertingPoint(3, 2, 1)); //26
cps.add(new SelfConvertingPoint(-2, 3, 1)); //27
cps.add(new SelfConvertingPoint(-3, -2, 1)); //28
//Orb (Animate make adjusts these)
orb.add(new SelfConvertingPoint(0, 0, 1)); //0: bottom
cps.add(orb.getPoint(0)); //29
orb.add(new SelfConvertingPoint(0, 0, 1)); //1
cps.add(orb.getPoint(1)); //30
orb.add(new SelfConvertingPoint(0, 0, 1)); //2
cps.add(orb.getPoint(2)); //31
orb.add(new SelfConvertingPoint(0, 0, 1)); //3
cps.add(orb.getPoint(3)); //32
orb.add(new SelfConvertingPoint(0, 0, 1)); //4
cps.add(orb.getPoint(4)); //33
orb.add(new SelfConvertingPoint(0, 0, 1)); //5: top
cps.add(orb.getPoint(5)); //34
cps.add(new SelfConvertingPoint(0, 0, 1)); //35
//SIGMA panel
OrderedGraphicSet ogs = new OrderedGraphicSet(
new GraphicParallelogram(cps.getPoint(5), cps.getPoint(10), cps.getPoint(18), cps.getPoint(17), myPlayer.getColor()), 5);
ogs.add(new GraphicLine(cps.getPoint(0), cps.getPoint(1), darker), false);
ogs.add(new GraphicLine(cps.getPoint(1), cps.getPoint(2), darker), false);
ogs.add(new GraphicLine(cps.getPoint(2), cps.getPoint(3), darker), false);
ogs.add(new GraphicLine(cps.getPoint(3), cps.getPoint(4), darker), false);
//Panels
zol.add(ogs);
zol.add(new GraphicParallelogram(cps.getPoint(6), cps.getPoint(11), cps.getPoint(19), cps.getPoint(18), myPlayer.getColor()));
zol.add(new GraphicParallelogram(cps.getPoint(7), cps.getPoint(12), cps.getPoint(20), cps.getPoint(19), myPlayer.getColor()));
zol.add(new GraphicParallelogram(cps.getPoint(8), cps.getPoint(9), cps.getPoint(17), cps.getPoint(20), myPlayer.getColor()));
//Corners
zol.add(new GraphicTriangle(cps.getPoint(5), cps.getPoint(13), cps.getPoint(17), darker));
zol.add(new GraphicTriangle(cps.getPoint(6), cps.getPoint(14), cps.getPoint(18), darker));
zol.add(new GraphicTriangle(cps.getPoint(7), cps.getPoint(15), cps.getPoint(19), darker));
zol.add(new GraphicTriangle(cps.getPoint(8), cps.getPoint(16), cps.getPoint(20), darker));
zol.add(new GraphicTriangle(cps.getPoint(9), cps.getPoint(13), cps.getPoint(17), darker));
zol.add(new GraphicTriangle(cps.getPoint(10), cps.getPoint(14), cps.getPoint(18), darker));
zol.add(new GraphicTriangle(cps.getPoint(11), cps.getPoint(15), cps.getPoint(19), darker));
zol.add(new GraphicTriangle(cps.getPoint(12), cps.getPoint(16), cps.getPoint(20), darker));
//Main surface
zol.add(new GraphicParallelogram(cps.getPoint(17), cps.getPoint(18), cps.getPoint(19), cps.getPoint(20), darker));
//Supports
zol.add(new GraphicTriangle(cps.getPoint(21), cps.getPoint(25), cps.getPoint(29), Color.black));
zol.add(new GraphicTriangle(cps.getPoint(22), cps.getPoint(26), cps.getPoint(29), Color.black));
zol.add(new GraphicTriangle(cps.getPoint(23), cps.getPoint(27), cps.getPoint(29), Color.black));
zol.add(new GraphicTriangle(cps.getPoint(24), cps.getPoint(28), cps.getPoint(29), Color.black));
//Orb
zol.add(new GraphicTriangle(orb.getPoint(0), orb.getPoint(1), orb.getPoint(2), orbColor));
zol.add(new GraphicTriangle(orb.getPoint(0), orb.getPoint(2), orb.getPoint(3), orbColor));
zol.add(new GraphicTriangle(orb.getPoint(0), orb.getPoint(3), orb.getPoint(4), orbColor));
zol.add(new GraphicTriangle(orb.getPoint(0), orb.getPoint(4), orb.getPoint(1), orbColor));
zol.add(new GraphicTriangle(orb.getPoint(5), orb.getPoint(1), orb.getPoint(2), orbColor));
zol.add(new GraphicTriangle(orb.getPoint(5), orb.getPoint(2), orb.getPoint(3), orbColor));
zol.add(new GraphicTriangle(orb.getPoint(5), orb.getPoint(3), orb.getPoint(4), orbColor));
zol.add(new GraphicTriangle(orb.getPoint(5), orb.getPoint(4), orb.getPoint(1), orbColor));
cps.translate(vr[0]);
cps.rotate(vr[0], Point3D.unitUp, i);
ZListNode zln;
int n=0;
for(zln = zol.zNode; zln != null; zln = zln.getNext()) {
n++;
}
ZListNode zlna[] = new ZListNode[n];
n=0;
for(zln = zol.zNode; zln != null; zln = zln.getNext()) {
zlna[n++] = zln;
}
for(n=0;n<zlna.length;n++) {
zlna[n].getThing().update();
}
zol.update();
}
public void draw(GameViewer v) {
zol.draw(v);
}
public void addTo(GameViewer v) {
v.add(zol);
}
public void killGraphics() {
zol.kill();
}
protected void update() {
if(health > 0 && action != 4) {
orb.rotate(orb.getPoint(0), Point3D.unitUp, 7);
}
super.update();
}
protected void animateMove(){
//Update the necessary vectors to move forward during one frame.
int i = Trig.normalize(f * 60 + 30);
Point3D pt = new Point3D(Trig.cos(i) * 2, Trig.sin(i) * 2,0);
vr[0].doSum(pt);
cps.translate(pt);
}
protected void animateRotateLeft(){
cps.rotate(vr[0], Point3D.unitUp, 10);
ZListNode zln;
int n=0;
for(zln = zol.zNode; zln != null; zln = zln.getNext()) {
n++;
}
ZListNode zlna[] = new ZListNode[n];
n=0;
for(zln = zol.zNode; zln != null; zln = zln.getNext()) {
zlna[n++] = zln;
}
for(n=0;n<zlna.length;n++) {
zlna[n].getThing().update();
}
zol.update();
}
protected void animateRotateRight(){
cps.rotate(vr[0], Point3D.unitUp, 350);
ZListNode zln;
int n=0;
for(zln = zol.zNode; zln != null; zln = zln.getNext()) {
n++;
}
ZListNode zlna[] = new ZListNode[n];
n=0;
for(zln = zol.zNode; zln != null; zln = zln.getNext()) {
zlna[n++] = zln;
}
for(n=0;n<zlna.length;n++) {
zlna[n].getThing().update();
}
zol.update();
}
protected void animateMake() {
orb.translate(Point3D.unitUp.getProduct(0.1f));
orb.translate(Point3D.unitUp.getProduct(0.1f));
orb.getPoint(0).doSum(Point3D.unitDown.getProduct(0.1f));
orb.getPoint(1).doSum(Point3D.unitEast.getProduct(0.1f));
orb.getPoint(2).doSum(Point3D.unitNorth.getProduct(0.1f));
orb.getPoint(3).doSum(Point3D.unitWest.getProduct(0.1f));
orb.getPoint(4).doSum(Point3D.unitSouth.getProduct(0.1f));
orb.getPoint(5).doSum(Point3D.unitUp.getProduct(0.1f));
}
protected void animateDie() {
if(frame == framesToDie())
zol.explode((new Point3D(0,0,-5)).doSum(vr[0]));
frame--;
if(frame == 0)
{
zol.kill();
remove();
Hex.getHex(x,y).leave(this);
Hex.getHex(resX,resY).unreserve();
}
}
public float getHeight() {
return orb.getPoint(5).z;
}
public float getWidth() {
return 4.0f;
}
public float weaponRangeSquared(){
return 14400.0f;
}
public int followRange(){
return 5;
}
public int weaponDelay(){
return 19;
}
protected boolean fire() {
Point3D pt = new Point3D(targetSSMDS.getVector(this));
pt.Normalize();
pt.doProduct(5);
pt.z = (target.getHeight() / 2f - cps.getPoint(35).z) * 5f / (float)Math.sqrt(targetSSMDS.getDistanceSquared());
Projectile.newProjectile(new Paralyzer(Color.yellow), cps.getPoint(35), pt, 40, 25, 50, this, target);
return true;
}
/** Unit default2 has a maximum of 120 health.
* @return 120
*/
protected int maxHealth() {
return 75;
}
/** Unit default2 has an armor rating of 3
* @return 3
*/
protected int armor() {
return 6;
}
/** Returns the cost to build this object.
* Non-buildable objects have a cost of zero.
* @return The cost of the object.
*/
public int cost() {
return 250;
}
/** Target validation. If a target meets this criteria it can be acquired by scan().
* This version is for a stunning unit.
*/
protected boolean validTarget(GameObject go) {
return (go.getPlayer() != null && go.getPlayer() != myPlayer && go.paralyzable());
}
protected boolean aim(){
if(target == null) return false;
if(target.getPlayer() == myPlayer)
return false; //Don't shoot at own units, just follow them.
if(!target.paralyzable()) {
target = null;
targetSSMDS = null;
if(mode == 2)
mode = 0;
return false;
}
return true;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -