aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/Squid.cpp
blob: 7aae36154da39d7668538788090c8f95de4e5428 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include "stdafx.h"
#include "com.mojang.nbt.h"
#include "net.minecraft.world.level.tile.h"
#include "net.minecraft.world.phys.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.item.h"
#include "net.minecraft.world.entity.h"
#include "net.minecraft.world.entity.ai.attributes.h"
#include "net.minecraft.world.entity.monster.h"
#include "SharedConstants.h"
#include "Squid.h"
#include "..\Minecraft.Client\Textures.h"

void Squid::_init()
{
	xBodyRot = xBodyRotO = 0.0f;
	zBodyRot = zBodyRotO = 0.0f;

	tentacleMovement = oldTentacleMovement = 0.0f;
	tentacleAngle = oldTentacleAngle = 0.0f;

	speed = 0.0f;
	tentacleSpeed = 0.0f;
	rotateSpeed = 0.0f;

	tx = ty = tz = 0.0f;
}

Squid::Squid(Level *level) : WaterAnimal( level )
{
	// 4J Stu - This function call had to be moved here from the Entity ctor to ensure that
	// the derived version of the function is called
	this->defineSynchedData();
	registerAttributes();
	setHealth(getMaxHealth());

	_init();
	this->setSize(0.95f, 0.95f);
	tentacleSpeed = 1 / (random->nextFloat() + 1) * 0.2f;
}

void Squid::registerAttributes()
{
	WaterAnimal::registerAttributes();

	getAttribute(SharedMonsterAttributes::MAX_HEALTH)->setBaseValue(10);
}

int Squid::getAmbientSound() 
{
	return -1;
}

int Squid::getHurtSound() 
{
	return -1;
}

int Squid::getDeathSound() 
{
	return -1;
}

float Squid::getSoundVolume() 
{
	return 0.4f;
}

int Squid::getDeathLoot() 
{
	return 0;
}

bool Squid::makeStepSound()
{
	return false;
}

void Squid::dropDeathLoot(bool wasKilledByPlayer, int playerBonusLevel)
{
	int count = random->nextInt(3 + playerBonusLevel) + 1;
	for (int i = 0; i < count; i++) 
	{
		spawnAtLocation(shared_ptr<ItemInstance>( new ItemInstance(Item::dye_powder, 1, DyePowderItem::BLACK) ), 0.0f);
	}
}

bool Squid::isInWater() 
{
	return level->checkAndHandleWater(bb->grow(0, -0.6f, 0), Material::water, shared_from_this() );
}

void Squid::aiStep() 
{
	WaterAnimal::aiStep();

	xBodyRotO = xBodyRot;
	zBodyRotO = zBodyRot;

	oldTentacleMovement = tentacleMovement;
	oldTentacleAngle = tentacleAngle;

	tentacleMovement += tentacleSpeed;
	if (tentacleMovement > (float) PI * 2.0f) 
	{
		tentacleMovement -= (float) PI * 2.0f;
		if (random->nextInt(10) == 0) tentacleSpeed = 1 / (random->nextFloat() + 1) * 0.2f;
	}

	if (isInWater()) 
	{
		if (tentacleMovement < PI) 
		{
			float tentacleScale = tentacleMovement / PI;
			tentacleAngle = Mth::sin(tentacleScale * tentacleScale * PI) * PI * 0.25f;

			if (tentacleScale > .75) 
			{
				speed = 1.0f;
				rotateSpeed = 1.0f;
			} 
			else 
			{
				rotateSpeed = rotateSpeed * 0.8f;
			}
		} 
		else 
		{
			tentacleAngle = 0.0f;
			speed = speed * 0.9f;
			rotateSpeed = rotateSpeed * 0.99f;
		}

		if (!level->isClientSide) 
		{
			xd = tx * speed;
			yd = ty * speed;
			zd = tz * speed;
		}

		double horizontalMovement = sqrt(xd * xd + zd * zd);

		yBodyRot += ((-(float) atan2(xd, zd) * 180 / PI) - yBodyRot) * 0.1f;
		yRot = yBodyRot;
		zBodyRot = zBodyRot + (float) PI * rotateSpeed * 1.5f;
		xBodyRot += ((-(float) atan2(horizontalMovement, yd) * 180 / PI) - xBodyRot) * 0.1f;
	}
	else 
	{
		tentacleAngle = Mth::abs(Mth::sin(tentacleMovement)) * PI * 0.25f;

		if (!level->isClientSide) 
		{
			// unable to move, apply gravity
			xd = 0.0f;
			yd -= 0.08;
			yd *= 0.98f;
			zd = 0.0f;
		}

		// fall over
		xBodyRot += (-90 - xBodyRot) * 0.02f;
	}
}

void Squid::travel(float xa, float ya)
{
	move(xd, yd, zd);
}

void Squid::serverAiStep()
{
	noActionTime++;

	// ridiculous simple movement ai
	if (noActionTime > SharedConstants::TICKS_PER_SECOND * 5)
	{
		tx = ty = tz = 0;
	}
	else if (random->nextInt(50) == 0 || !wasInWater || (tx == 0 && ty == 0 && tz == 0)) 
	{
		float angle = random->nextFloat() * PI * 2.0f;
		tx = Mth::cos(angle) * 0.2f;
		ty = -0.1f + random->nextFloat() * 0.2f;
		tz = Mth::sin(angle) * 0.2f;
	}
	checkDespawn();	// 4J - 1.7.0 fix
}

bool Squid::canSpawn()
{
	return y > 45 && y < level->seaLevel && WaterAnimal::canSpawn();
}