lol
Spoiler:
Chameleon found out this one weird trick of dumping whole magazine under 1 second...


TOpenSpadongs.15 View.as:
Spoiler:
Code: Select all
/*
Copyright (c) 2013 yvt
This file is part of OpenSpades.
OpenSpades 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 3 of the License, or
(at your option) any later version.
OpenSpades 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 OpenSpades. If not, see <http://www.gnu.org/licenses/>.
*/
namespace spades {
class ViewSMGSkin:
IToolSkin, IViewToolSkin, IWeaponSkin,
BasicViewWeapon {
private AudioDevice@ audioDevice;
private Model@ gunModel;
private Model@ magazineModel;
private Model@ sightModel1;
private Model@ sightModel2;
private Model@ sightModel3;
private Model@ movemodel;
private AudioChunk@ fireSound;
private AudioChunk@ reloadSound;
float ReadyState;
ViewSMGSkin(Renderer@ r, AudioDevice@ dev){
super(r);
@audioDevice = dev;
@gunModel = renderer.RegisterModel
("Models/Weapons/SMG/WeaponNoMagazine.kv6");
@magazineModel = renderer.RegisterModel
("Models/Weapons/SMG/Magazine.kv6");
@sightModel1 = renderer.RegisterModel
("Models/Weapons/SMG/Sight1.kv6");
@sightModel2 = renderer.RegisterModel
("Models/Weapons/SMG/Sight2.kv6");
@sightModel3 = renderer.RegisterModel
("Models/Weapons/SMG/Sight3.kv6");
@movemodel = renderer.RegisterModel
("Models/Weapons/SMG/WeaponMove.kv6");
@fireSound = dev.RegisterSound
("Sounds/Weapons/SMG/Fire.wav");
@reloadSound = dev.RegisterSound
("Sounds/Weapons/SMG/Reload.wav");
}
void Update(float dt) {
BasicViewWeapon::Update(dt);
}
void WeaponFired(){
BasicViewWeapon::WeaponFired(); //NOTE i might be able to do firing animation by linking a function here
if(!IsMuted){
Vector3 origin = Vector3(0.f, -0.3f, 0.5f);
AudioParam param;
param.volume = 0.3f;
audioDevice.PlayLocal(fireSound, origin, param);
}
}
void ReloadingWeapon() {
if(!IsMuted){
Vector3 origin = Vector3(0.f, -0.3f, 0.5f);
AudioParam param;
param.volume = 0.2f;
audioDevice.PlayLocal(reloadSound, origin, param);
}
}
float GetZPos() {
return 0.2f - AimDownSightStateSmooth * 0.038f;
}
// rotates gun matrix to ensure the sight is in
// the center of screen (0, ?, 0).
Matrix4 AdjustToAlignSight(Matrix4 mat, Vector3 sightPos, float fade) {
Vector3 p = mat * sightPos;
mat = CreateRotateMatrix(Vector3(0.f, 0.f, 1.f), atan(p.x / p.y) * fade) * mat;
mat = CreateRotateMatrix(Vector3(-1.f, 0.f, 0.f), atan(p.z / p.y) * fade) * mat;
return mat;
}
void Draw2D() {
BasicViewWeapon::Draw2D();
}
void AddToScene() {
Matrix4 mat = CreateScaleMatrix(0.033f); //DEFAULT 0.033
mat = GetViewWeaponMatrix() * mat;
bool reloading = IsReloading;
float reload = ReloadProgress;
Vector3 leftHand, rightHand;
leftHand = mat * Vector3(1.f, 8.f, -0.85f); //(x,y,z) (x+left/-right, y+further/-closer, z+down/-up)
rightHand = mat * Vector3(0.75f, 2.25f, -1.f); //(x,y,z) (x+left/-right, y+further/-closer, z+down/-up)
Vector3 leftHand2 = mat * Vector3(5.f, -10.f, 4.f); //release magazine
Vector3 leftHand3 = mat * Vector3(1.5f, 4.f, -5.f); //move hand from player, center of screen
Vector3 leftHand4 = mat * Vector3(4.0f, -5.f, -3.f); //move hand to player, to left-down corner
if(AimDownSightStateSmooth > 0.8f){
mat = AdjustToAlignSight(mat, Vector3(0.f, 5.f, -4.9f), (AimDownSightStateSmooth - 0.8f) / 0.2f);
}
ModelRenderParam param;
Matrix4 weapMatrix = eyeMatrix * mat;
param.matrix = weapMatrix * CreateScaleMatrix(0.5f) *
CreateTranslateMatrix(-0.5f, 0.f, 0.f);
param.depthHack = true;
renderer.AddModel(gunModel, param);
// draw sights
Matrix4 sightMat = weapMatrix;
sightMat *= CreateTranslateMatrix(0.05f, 5.f, -4.85f);
sightMat *= CreateScaleMatrix(0.0f);
param.matrix = sightMat;
renderer.AddModel(sightModel1, param); // front-NOT.USED
sightMat = weapMatrix;
sightMat *= CreateTranslateMatrix(0.025f, 11.f, -4.85f);
sightMat *= CreateScaleMatrix(0.05f);
param.matrix = sightMat;
renderer.AddModel(sightModel3, param); // front pin
sightMat = weapMatrix;
sightMat *= CreateTranslateMatrix(0.025f, -5.f, -4.9f);
sightMat *= CreateScaleMatrix(0.1f);
param.matrix = sightMat;
renderer.AddModel(sightModel2, param); // rear
// magazine/reload action
mat *= CreateTranslateMatrix(0.f, 3.f, 1.f);
reload *= 2.5f;
if(reloading)
{
if(reload < 0.7f)
{
// magazine release
float per = reload / 0.7f;
mat *= CreateTranslateMatrix(0.f, 0.f, per*per*50.f);
leftHand = Mix(leftHand, leftHand2, SmoothStep(per));
}
else if(reload < 1.5f) //1.4
{
// insert magazine
float per = (1.5f - reload) / 0.5f; //1.4; 0.7
if(per < 0.3f)
{
// non-smooth insertion
per *= 4.f; per -= 0.4f;
per = Clamp(per, 0.0f, 0.3f);
}
mat *= CreateTranslateMatrix(0.f, 0.f, per*per*10.f);
leftHand = mat * Vector3(0.f, 0.f, 4.f);
}
else if(reload < 2.f)
{
// move the left hand to the original position
// and start doing something with the "right" hand-INCORRECT
float per = (reload - 1.5f) / 0.5f; //1.4
leftHand = mat * Vector3(0.f, 0.f, 4.f);
leftHand = Mix(leftHand, leftHand3, SmoothStep(per));
}
else if(reload < 2.2f)
{
float per = (reload - 2.f) / 0.3f;
leftHand = Mix(leftHand3, leftHand4, SmoothStep(per));
}
else
{
float per = (reload - 2.2f) / 0.3f;
leftHand = Mix(leftHand4, leftHand, SmoothStep(per)); //bring back to original position
}
}
param.matrix = eyeMatrix * mat; //* CreateScaleMatrix(0.5f);
renderer.AddModel(magazineModel, param);
LeftHandPosition = leftHand;
RightHandPosition = rightHand;
//NEW ANIMATION--------------------------------------------------------#-#-#-#-#
//IGNORE LINES LIKE THIS - they are just comments
//sightMat = weapMatrix;
//sightMat *= CreateTranslateMatrix(1.f, 1.f, 1.f) * CreateScaleMatrix(0.5f);
param.matrix = weapMatrix * CreateTranslateMatrix(-0.25f, 0.f, 0.f) * CreateScaleMatrix(0.5f);
param.depthHack = true;
if(reloading)
{
if(reload < 0.7f)
{
//magazine release - this actually does nothing,
//but i'm afraid that removing this might break something :D
float per = reload / 0.7f;
//sightMat *= CreateTranslateMatrix(0.f, 0.f, 0.f);
}
else if(reload < 1.4f) //1.4
{
// insert magazine - does nothing
float per = (1.4f - reload) / 0.7f; //1.4; 0.7
//sightMat *= CreateTranslateMatrix(0.f, 0.f, 0.f);
}
else if(reload < 1.9f)
{
// does nothing
float per = (reload - 1.4f) / 0.5f; //1.4
//sightMat *= CreateTranslateMatrix(0.f, 0.f, 0.f);
}
else if(reload < 2.2f)
{
float per = (reload - 2.f) / 0.3f;
param.matrix *= CreateTranslateMatrix(0.f, per*-8.f, 0.f);
//finally starts moving my WeaponMove.kv6 model
//moves it closer to eye.
}
else
{
param.matrix *= CreateTranslateMatrix(0.f, -8.f, 0.f);
//somehow the model resets while executing every else { },
//so i make the game return the model to needed place
//(with first line)
//and THEN tell game to return it slowly to the default place
//(with the last line).
float per = (reload - 2.2f) / 0.3f;
param.matrix *= CreateTranslateMatrix(0.f, per*8.f, 0.f);
}
}
if (ReadyState < 1.f)
{
if (ReadyState < 0.5f)
{
float per = (0.5f - ReadyState) / 0.5f;
param.matrix *= CreateTranslateMatrix(0.f, per*-8.f, 0.f);
}
if (ReadyState < 1.0f)
{
param.matrix *= CreateTranslateMatrix(0.f, -8.f, 0.f);
float per = (1.0f - ReadyState) / 0.5f;
param.matrix *= CreateTranslateMatrix(0.f, per*8.f, 0.f);
}
}
//param.matrix = eyeMatrix * sightMat;
renderer.AddModel(movemodel, param);
}
}
IWeaponSkin@ CreateViewSMGSkin(Renderer@ r, AudioDevice@ dev) {
return ViewSMGSkin(r, dev);
}
}Spoiler:
Code: Select all
/*
Copyright (c) 2013 yvt
This file is part of OpenSpades.
OpenSpades 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 3 of the License, or
(at your option) any later version.
OpenSpades 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 OpenSpades. If not, see <http://www.gnu.org/licenses/>.
*/
namespace spades {
class ViewSMGSkin:
IToolSkin, IViewToolSkin, IWeaponSkin,
BasicViewWeapon {
private AudioDevice@ audioDevice;
private Model@ gunModel;
private Model@ magazineModel;
private Model@ sightModel1;
private Model@ sightModel2;
private Model@ sightModel3;
private Model@ movemodel;
private AudioChunk@[] fireSounds(4);
private AudioChunk@ fireFarSound;
private AudioChunk@ fireStereoSound;
private AudioChunk@ reloadSound;
ViewSMGSkin(Renderer@ r, AudioDevice@ dev){
super(r);
@audioDevice = dev;
@gunModel = renderer.RegisterModel
("Models/Weapons/SMG/WeaponNoMagazine.kv6");
@magazineModel = renderer.RegisterModel
("Models/Weapons/SMG/Magazine.kv6");
@sightModel1 = renderer.RegisterModel
("Models/Weapons/SMG/Sight1.kv6");
@sightModel2 = renderer.RegisterModel
("Models/Weapons/SMG/Sight2.kv6");
@sightModel3 = renderer.RegisterModel
("Models/Weapons/SMG/Sight3.kv6");
@movemodel = renderer.RegisterModel
("Models/Weapons/SMG/WeaponMove.kv6");
@fireSounds[0] = dev.RegisterSound
("Sounds/Weapons/SMG/FireLocal1.wav");
@fireSounds[1] = dev.RegisterSound
("Sounds/Weapons/SMG/FireLocal2.wav");
@fireSounds[2] = dev.RegisterSound
("Sounds/Weapons/SMG/FireLocal3.wav");
@fireSounds[3] = dev.RegisterSound
("Sounds/Weapons/SMG/FireLocal4.wav");
@fireFarSound = dev.RegisterSound
("Sounds/Weapons/SMG/FireFar.wav");
@fireStereoSound = dev.RegisterSound
("Sounds/Weapons/SMG/FireStereo.wav");
@reloadSound = dev.RegisterSound
("Sounds/Weapons/SMG/ReloadLocal.wav");
}
void Update(float dt) {
BasicViewWeapon::Update(dt);
}
void WeaponFired(){
BasicViewWeapon::WeaponFired();
if(!IsMuted){
Vector3 origin = Vector3(0.4f, -0.3f, 0.5f);
AudioParam param;
param.volume = 8.f;
audioDevice.PlayLocal(fireSounds[GetRandom(fireSounds.length)], origin, param);
param.volume = 4.f;
audioDevice.PlayLocal(fireFarSound, origin, param);
param.volume = 1.f;
audioDevice.PlayLocal(fireStereoSound, origin, param);
}
}
void ReloadingWeapon() {
if(!IsMuted){
Vector3 origin = Vector3(0.4f, -0.3f, 0.5f);
AudioParam param;
param.volume = 0.2f;
audioDevice.PlayLocal(reloadSound, origin, param);
}
}
float GetZPos() {
return 0.2f - AimDownSightStateSmooth * 0.038f;
}
// rotates gun matrix to ensure the sight is in
// the center of screen (0, ?, 0).
Matrix4 AdjustToAlignSight(Matrix4 mat, Vector3 sightPos, float fade) {
Vector3 p = mat * sightPos;
mat = CreateRotateMatrix(Vector3(0.f, 0.f, 1.f), atan(p.x / p.y) * fade) * mat;
mat = CreateRotateMatrix(Vector3(-1.f, 0.f, 0.f), atan(p.z / p.y) * fade) * mat;
return mat;
}
void Draw2D() {
if(AimDownSightState > 0.8)
return;
BasicViewWeapon::Draw2D();
}
void AddToScene() {
Matrix4 mat = CreateScaleMatrix(0.033f);
mat = GetViewWeaponMatrix() * mat;
bool reloading = IsReloading;
float reload = ReloadProgress;
Vector3 leftHand, rightHand;
leftHand = mat * Vector3(1.f, 8.f, -0.85f);
rightHand = mat * Vector3(0.75f, 2.25f, -1.f);
//leftHand = mat * Vector3(1.f, 6.f, 1.f);
//rightHand = mat * Vector3(0.f, -8.f, 2.f);
Vector3 leftHand2 = mat * Vector3(5.f, -10.f, 4.f);
Vector3 leftHand3 = mat * Vector3(1.5f, 4.f, -5.f);
Vector3 leftHand4 = mat * Vector3(4.0f, -5.f, -3.f);
//Vector3 leftHand2 = mat * Vector3(5.f, -10.f, 4.f);
//Vector3 leftHand3 = mat * Vector3(1.f, 6.f, -4.f);
//Vector3 leftHand4 = mat * Vector3(1.f, 9.f, -6.f);
if(AimDownSightStateSmooth > 0.8f){
mat = AdjustToAlignSight(mat, Vector3(0.f, 5.f, -4.9f), (AimDownSightStateSmooth - 0.8f) / 0.2f);
}
ModelRenderParam param;
Matrix4 weapMatrix = eyeMatrix * mat;
param.matrix = weapMatrix * CreateScaleMatrix(0.5f) *
CreateTranslateMatrix(-0.5f, 0.f, 0.f);
param.depthHack = true;
renderer.AddModel(gunModel, param);
/*Comment begin
ModelRenderParam param;
Matrix4 weapMatrix = eyeMatrix * mat;
param.matrix = weapMatrix;
param.depthHack = true;
renderer.AddModel(gunModel, param);
Comment end*/
// draw sights
Matrix4 sightMat = weapMatrix;
sightMat *= CreateTranslateMatrix(0.05f, 5.f, -4.85f);
sightMat *= CreateScaleMatrix(0.0f);
//sightMat *= CreateScaleMatrix(0.1f);
param.matrix = sightMat;
renderer.AddModel(sightModel1, param); // front
sightMat = weapMatrix;
sightMat *= CreateTranslateMatrix(0.025f, 11.f, -4.85f);
sightMat *= CreateScaleMatrix(0.05f);
param.matrix = sightMat;
renderer.AddModel(sightModel3, param); // front pin
sightMat = weapMatrix;
sightMat *= CreateTranslateMatrix(0.025f, -5.f, -4.9f);
sightMat *= CreateScaleMatrix(0.1f);
param.matrix = sightMat;
renderer.AddModel(sightModel2, param); // rear
/*Comment begin
sightMat = weapMatrix;
sightMat *= CreateTranslateMatrix(0.025f, 5.f, -4.85f);
sightMat *= CreateScaleMatrix(0.05f);
param.matrix = sightMat;
renderer.AddModel(sightModel3, param); // front pin
sightMat = weapMatrix;
sightMat *= CreateTranslateMatrix(0.04f, -9.f, -4.9f);
sightMat *= CreateScaleMatrix(0.08f);
param.matrix = sightMat;
renderer.AddModel(sightModel2, param); // rear
Comment end*/
// magazine/reload action
mat *= CreateTranslateMatrix(0.f, 3.f, 1.f);
reload *= 2.5f;
if(reloading)
{
if(reload < 0.7f)
{
// magazine release
float per = reload / 0.7f;
mat *= CreateTranslateMatrix(0.f, 0.f, per*per*50.f);
leftHand = Mix(leftHand, leftHand2, SmoothStep(per));
}
else if(reload < 1.5f)
{
// insert magazine
float per = (1.5f - reload) / 0.5f;
if(per < 0.3f)
{
// non-smooth insertion
per *= 4.f; per -= 0.4f;
per = Clamp(per, 0.0f, 0.3f);
}
mat *= CreateTranslateMatrix(0.f, 0.f, per*per*10.f);
leftHand = mat * Vector3(0.f, 0.f, 4.f);
}
else if(reload < 2.f)
{
// move the left hand to the original position
// and start doing something with the right hand
float per = (reload - 1.5f) / 0.5f;
leftHand = mat * Vector3(0.f, 0.f, 4.f);
leftHand = Mix(leftHand, leftHand3, SmoothStep(per));
}
else if(reload < 2.2f)
{
float per = (reload - 2.0f) / 0.3f;
leftHand = Mix(leftHand3, leftHand4, SmoothStep(per));
}
else
{
float per = (reload - 2.2f) / 0.3f;
leftHand = Mix(leftHand4, leftHand, SmoothStep(per));
}
}
param.matrix = eyeMatrix * mat;
renderer.AddModel(magazineModel, param);
LeftHandPosition = leftHand;
RightHandPosition = rightHand;
//NEW ANIMATION--------------------------------------------------------#-#-#-#-#
//IGNORE LINES LIKE THIS - they are just comments
//sightMat = weapMatrix;
//sightMat *= CreateTranslateMatrix(1.f, 1.f, 1.f) * CreateScaleMatrix(0.5f);
//RELOAD ANIMATION--------------------------------------------------------#-#-#-#-#
param.matrix = weapMatrix * CreateTranslateMatrix(-0.25f, 0.f, 0.f) * CreateScaleMatrix(0.5f);
param.depthHack = true;
if(reloading)
{
if(reload < 0.7f)
{
//magazine release - this actually does nothing,
//but i'm afraid that removing this might break something :D
float per = reload / 0.7f;
//sightMat *= CreateTranslateMatrix(0.f, 0.f, 0.f);
}
else if(reload < 1.4f) //1.4
{
// insert magazine - does nothing
float per = (1.4f - reload) / 0.7f; //1.4; 0.7
//sightMat *= CreateTranslateMatrix(0.f, 0.f, 0.f);
}
else if(reload < 1.9f)
{
// does nothing
float per = (reload - 1.4f) / 0.5f; //1.4
//sightMat *= CreateTranslateMatrix(0.f, 0.f, 0.f);
}
else if(reload < 2.2f)
{
float per = (reload - 2.f) / 0.3f;
param.matrix *= CreateTranslateMatrix(0.f, per*-8.f, 0.f);
//finally starts moving my WeaponMove.kv6 model
//moves it closer to eye.
}
else
{
param.matrix *= CreateTranslateMatrix(0.f, -8.f, 0.f);
//somehow the model resets while executing every else { },
//so i make the game return the model to needed place
//(with first line)
//and THEN tell game to return it slowly to the default place
//(with the last line).
float per = (reload - 2.2f) / 0.3f;
param.matrix *= CreateTranslateMatrix(0.f, per*8.f, 0.f);
}
}
//SHOOT ANIMATION--------------------------------------------------------#-#-#-#-#
if (ReadyState < 1.f)
{
if (ReadyState < 0.5f)
{
float per = (0.5f - ReadyState) / 0.5f;
param.matrix *= CreateTranslateMatrix(0.f, per*-8.f, 0.f);
}
if (ReadyState < 1.0f)
{
param.matrix *= CreateTranslateMatrix(0.f, -8.f, 0.f);
float per = (1.0f - ReadyState) / 0.5f;
param.matrix *= CreateTranslateMatrix(0.f, per*8.f, 0.f);
}
}
//param.matrix = eyeMatrix * sightMat;
renderer.AddModel(movemodel, param);
}
}
IWeaponSkin@ CreateViewSMGSkin(Renderer@ r, AudioDevice@ dev)
{
return ViewSMGSkin(r, dev);
}
}
https://www.dropbox.com/s/79z2druqjly85ut/Thomspon.zip
https://www.mediafire.com/?8pc7opetfx8767p