mirror of
https://github.com/vcmi/vcmi.git
synced 2025-09-16 09:26:28 +02:00
w miarę działający CMusicHandler pozwalający na granie niektórych dźwięków trochę łatwiej (choć i tak do dziecinnie proste ;]). Odgłos kliknięcia wywołujemy wywołując funkcję playClick(). Pozwoliłem sobie dorobić częściową obsługę tego w PreGame'ie.
This commit is contained in:
24
CMT.cpp
24
CMT.cpp
@@ -9,6 +9,7 @@
|
||||
#include <cmath>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <assert.h>
|
||||
#include <vector>
|
||||
#include "zlib.h"
|
||||
@@ -22,6 +23,7 @@
|
||||
#include "CBuildingHandler.h"
|
||||
#include "CObjectHandler.h"
|
||||
#include "CGameInfo.h"
|
||||
#include "CMusicHandler.h"
|
||||
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
|
||||
# include <fcntl.h>
|
||||
# include <io.h>
|
||||
@@ -221,28 +223,18 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
GEOR13 = TTF_OpenFont("Fonts\\georgia.ttf",13);
|
||||
|
||||
//initializing audio
|
||||
if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048)==-1)
|
||||
{
|
||||
printf("Mix_OpenAudio: %s\n", Mix_GetError());
|
||||
exit(2);
|
||||
}
|
||||
atexit(Mix_CloseAudio);
|
||||
CMusicHandler * mush = new CMusicHandler;
|
||||
mush->initMusics();
|
||||
//audio initialized
|
||||
|
||||
Mix_Music *music;
|
||||
music = Mix_LoadMUS("MP3\\MainMenuWoG.mp3");
|
||||
if(!music)
|
||||
{
|
||||
printf("Mix_LoadMUS(\"MainMenuWoG.mp3\"): %s\n", Mix_GetError());
|
||||
// this might be a critical error...
|
||||
}
|
||||
|
||||
if(Mix_PlayMusic(music, -1)==-1) //uncomment this fragment to have music
|
||||
if(Mix_PlayMusic(mush->mainMenuWoG, -1)==-1) //uncomment this fragment to have music
|
||||
{
|
||||
printf("Mix_PlayMusic: %s\n", Mix_GetError());
|
||||
// well, there's no music, but most games don't break without music...
|
||||
}
|
||||
|
||||
mush->playClick();
|
||||
|
||||
screen = SDL_SetVideoMode(800,600,24,SDL_HWSURFACE|SDL_DOUBLEBUF/*|SDL_FULLSCREEN*/);
|
||||
ekran = screen;
|
||||
//FILE * zr = fopen("mal.txt","r");
|
||||
@@ -263,6 +255,7 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
//}
|
||||
SDL_WM_SetCaption(NAME,""); //set window title
|
||||
CPreGame * cpg = new CPreGame();
|
||||
cpg->mush = mush;
|
||||
cpg->runLoop();
|
||||
THC timeHandler tmh;
|
||||
CGameInfo * cgi = new CGameInfo;
|
||||
@@ -289,6 +282,7 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
objh->loadObjects();
|
||||
cgi->objh = objh;
|
||||
CAmbarCendamo * ac = new CAmbarCendamo("Arrogance"); //4gryf
|
||||
CMapHeader * mmhh = new CMapHeader(ac->bufor); //czytanie nag��wka
|
||||
cgi->ac = ac;
|
||||
THC std::cout<<"Wczytywanie pliku: "<<tmh.getDif()<<std::endl;
|
||||
ac->deh3m();
|
||||
|
67
CMusicHandler.cpp
Normal file
67
CMusicHandler.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
#include "CMusicHandler.h"
|
||||
|
||||
void CMusicHandler::initMusics()
|
||||
{
|
||||
if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048)==-1)
|
||||
{
|
||||
printf("Mix_OpenAudio: %s\n", Mix_GetError());
|
||||
exit(2);
|
||||
}
|
||||
atexit(Mix_CloseAudio);
|
||||
|
||||
AITheme0 = Mix_LoadMUS("MP3\\AITheme0.mp3");
|
||||
AITheme1 = Mix_LoadMUS("MP3\\AITHEME1.mp3");
|
||||
AITheme2 = Mix_LoadMUS("MP3\\AITHEME2.mp3");
|
||||
buildTown = Mix_LoadWAV("MP3\\BUILDTWN.wav");
|
||||
combat1 = Mix_LoadMUS("MP3\\COMBAT01.mp3");
|
||||
combat2 = Mix_LoadMUS("MP3\\COMBAT02.mp3");
|
||||
combat3 = Mix_LoadMUS("MP3\\COMBAT03.mp3");
|
||||
combat4 = Mix_LoadMUS("MP3\\COMBAT04.mp3");
|
||||
castleTown = Mix_LoadMUS("MP3\\CstleTown.mp3");
|
||||
defendCastle = Mix_LoadMUS("MP3\\Defend Castle.mp3");
|
||||
dirt = Mix_LoadMUS("MP3\\DIRT.mp3");
|
||||
dungeon = Mix_LoadMUS("MP3\\DUNGEON.mp3");
|
||||
elemTown = Mix_LoadMUS("MP3\\ElemTown.mp3");
|
||||
evilTheme = Mix_LoadMUS("MP3\\EvilTheme.mp3");
|
||||
fortressTown = Mix_LoadMUS("MP3\\FortressTown.mp3");
|
||||
goodTheme = Mix_LoadMUS("MP3\\GoodTheme.mp3");
|
||||
grass = Mix_LoadMUS("MP3\\GRASS.mp3");
|
||||
infernoTown = Mix_LoadMUS("MP3\\InfernoTown.mp3");
|
||||
lava = Mix_LoadMUS("MP3\\LAVA.mp3");
|
||||
loopLepr = Mix_LoadMUS("MP3\\LoopLepr.mp3");
|
||||
loseCampain = Mix_LoadMUS("MP3\\Lose Campain.mp3");
|
||||
loseCastle = Mix_LoadMUS("MP3\\LoseCastle.mp3");
|
||||
loseCombat = Mix_LoadMUS("MP3\\LoseCombat.mp3");
|
||||
mainMenu = Mix_LoadMUS("MP3\\MAINMENU.mp3");
|
||||
mainMenuWoG = Mix_LoadMUS("MP3\\MainMenuWoG.mp3");
|
||||
necroTown = Mix_LoadMUS("MP3\\necroTown.mp3");
|
||||
neutralTheme = Mix_LoadMUS("MP3\\NeutralTheme.mp3");
|
||||
rampart = Mix_LoadMUS("MP3\\RAMPART.mp3");
|
||||
retreatBattle = Mix_LoadMUS("MP3\\Retreat Battle.mp3");
|
||||
rough = Mix_LoadMUS("MP3\\ROUGH.mp3");
|
||||
sand = Mix_LoadMUS("MP3\\SAND.mp3");
|
||||
secretTheme = Mix_LoadMUS("MP3\\SecretTheme.mp3");
|
||||
snow = Mix_LoadMUS("MP3\\SNOW.mp3");
|
||||
stronghold = Mix_LoadMUS("MP3\\StrongHold.mp3");
|
||||
surrenderBattle = Mix_LoadMUS("MP3\\Surrender Battle.mp3");
|
||||
swamp = Mix_LoadMUS("MP3\\SWAMP.mp3");
|
||||
towerTown = Mix_LoadMUS("MP3\\TowerTown.mp3");
|
||||
ultimateLose = Mix_LoadMUS("MP3\\UltimateLose.mp3");
|
||||
underground = Mix_LoadMUS("MP3\\Underground.mp3");
|
||||
water = Mix_LoadMUS("MP3\\WATER.mp3");
|
||||
winBattle = Mix_LoadMUS("MP3\\Win Battle.mp3");
|
||||
winScenario = Mix_LoadMUS("MP3\\Win Scenario.mp3");
|
||||
|
||||
click = Mix_LoadWAV("MP3\\snd1.wav");
|
||||
click->volume = 30;
|
||||
}
|
||||
|
||||
void CMusicHandler::playClick()
|
||||
{
|
||||
int channel;
|
||||
channel = Mix_PlayChannel(-1, click, 0);
|
||||
if(channel == -1)
|
||||
{
|
||||
fprintf(stderr, "Unable to play WAV file: %s\n", Mix_GetError());
|
||||
}
|
||||
}
|
16
CMusicHandler.h
Normal file
16
CMusicHandler.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef CMUSICHANDLER_H
|
||||
#define CMUSICHANDLER_H
|
||||
|
||||
#include "SDL_mixer.h"
|
||||
|
||||
class CMusicHandler
|
||||
{
|
||||
public:
|
||||
Mix_Music *AITheme0, *AITheme1, *AITheme2, *combat1, *combat2, *combat3, *combat4, *castleTown, *defendCastle, *dirt, *dungeon, *elemTown, *evilTheme, *fortressTown, *goodTheme, *grass, *infernoTown, *lava, *loopLepr, *loseCampain, *loseCastle, *loseCombat, *mainMenu, *mainMenuWoG, *necroTown, *neutralTheme, *rampart, *retreatBattle, *rough, *sand, *secretTheme, *snow, *stronghold, *surrenderBattle, *swamp, *towerTown, *ultimateLose, *underground, *water, *winScenario, *winBattle;
|
||||
Mix_Chunk * buildTown, *click;
|
||||
void initMusics();
|
||||
void playClick(); //plays click music ;]
|
||||
};
|
||||
|
||||
|
||||
#endif //CMUSICHANDLER_H
|
@@ -559,6 +559,7 @@ void CPreGame::runLoop()
|
||||
}
|
||||
else if ((sEvent.type==SDL_MOUSEBUTTONDOWN) && (sEvent.button.button == SDL_BUTTON_LEFT))
|
||||
{
|
||||
mush->playClick();
|
||||
for (int i=0;i<btns.size(); i++)
|
||||
{
|
||||
if (isItIn(&btns[i]->pos,sEvent.motion.x,sEvent.motion.y))
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#include "CPreGameTextHandler.h"
|
||||
#include "CMessage.h"
|
||||
#include "map.h"
|
||||
#include "CMusicHandler.h"
|
||||
class CPreGame;
|
||||
extern CPreGame * CPG;
|
||||
class ScenSel
|
||||
@@ -22,6 +23,7 @@ public:
|
||||
class CPreGame
|
||||
{
|
||||
public:
|
||||
CMusicHandler * mush;
|
||||
CSemiLodHandler * slh ;
|
||||
std::vector<Button<> *> btns;
|
||||
CPreGameTextHandler * preth ;
|
||||
|
232
map.cpp
Normal file
232
map.cpp
Normal file
@@ -0,0 +1,232 @@
|
||||
#include "map.h"
|
||||
|
||||
int readNormalNr (unsigned char * bufor, int pos, int bytCon = 4)
|
||||
{
|
||||
int ret=0;
|
||||
int amp=1;
|
||||
for (int i=0; i<bytCon; i++)
|
||||
{
|
||||
ret+=bufor[pos+i]*amp;
|
||||
amp*=256;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
CMapHeader::CMapHeader(unsigned char *map)
|
||||
{
|
||||
this->version = (Eformat)map[0]; //wersja mapy
|
||||
this->areAnyPLayers = map[4];
|
||||
this->height = this->width = map[5]; // wymiary mapy
|
||||
this->twoLevel = map[9]; //czy sa lochy
|
||||
|
||||
int length = map[10]; //name length
|
||||
int i=14, pom;
|
||||
while (i-14<length) //read name
|
||||
this->name+=map[i++];
|
||||
length = map[i] + map[i+1]*256; //description length
|
||||
i+=4;
|
||||
for (pom=0;pom<length;pom++)
|
||||
this->description+=map[i++];
|
||||
this->difficulty = map[i++]; // reading map difficulty
|
||||
this->levelLimit = map[i++]; // hero level limit
|
||||
for (pom=0;pom<8;pom++)
|
||||
{
|
||||
this->players[pom].canHumanPlay = map[i++];
|
||||
this->players[pom].canComputerPlay = map[i++];
|
||||
if ((!(this->players[pom].canHumanPlay || this->players[pom].canComputerPlay)) || (!this->areAnyPLayers))
|
||||
{
|
||||
i+=13;
|
||||
continue;
|
||||
}
|
||||
|
||||
this->players[pom].AITactic = map[i++];
|
||||
if (map[i++])
|
||||
{
|
||||
this->players[pom].allowedFactions = 0;
|
||||
this->players[pom].allowedFactions += map[i++];
|
||||
this->players[pom].allowedFactions += (map[i++])*256;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->players[pom].allowedFactions = 511;
|
||||
i+=2;
|
||||
}
|
||||
this->players[pom].isFactionRandom = map[i++];
|
||||
this->players[pom].hasMainTown = map[i++];
|
||||
if (this->players[pom].hasMainTown)
|
||||
{
|
||||
this->players[pom].generateHeroAtMainTown = map[i++];
|
||||
i++; //unknown byte
|
||||
this->players[pom].posOfMainTown.x = map[i++];
|
||||
this->players[pom].posOfMainTown.y = map[i++];
|
||||
this->players[pom].posOfMainTown.z = map[i++];
|
||||
}
|
||||
i++; //unknown byte
|
||||
int unknown = map[i++];
|
||||
if (unknown == 255)
|
||||
{
|
||||
this->players[pom].mainHeroPortrait = 255;
|
||||
i+=5;
|
||||
continue;
|
||||
}
|
||||
this->players[pom].mainHeroPortrait = map[i++];
|
||||
int nameLength = map[i++];
|
||||
i+=3;
|
||||
for (int pp=0;pp<nameLength;pp++)
|
||||
this->players[pom].mainHeroName+=map[i++];
|
||||
i++; ////unknown byte
|
||||
int heroCount = map[i++];
|
||||
i+=3;
|
||||
for (int pp=0;pp<heroCount;pp++)
|
||||
{
|
||||
SheroName vv;
|
||||
vv.heroID=map[i++];
|
||||
int hnl = map[i++];
|
||||
i+=3;
|
||||
for (int zz=0;zz<hnl;zz++)
|
||||
{
|
||||
vv.heroName+=map[i++];
|
||||
}
|
||||
this->players[pom].heroesNames.push_back(vv);
|
||||
}
|
||||
}
|
||||
this->victoryCondition = (EvictoryConditions)map[i++];
|
||||
if (this->victoryCondition != winStandard) //specific victory conditions
|
||||
{
|
||||
int nr;
|
||||
switch (this->victoryCondition) //read victory conditions
|
||||
{
|
||||
case artifact:
|
||||
{
|
||||
this->vicConDetails = new VicCon0();
|
||||
((VicCon0*)this->vicConDetails)->ArtifactID = map[i+2];
|
||||
nr=2;
|
||||
break;
|
||||
}
|
||||
case gatherTroop:
|
||||
{
|
||||
this->vicConDetails = new VicCon1();
|
||||
int temp1 = map[i+2];
|
||||
int temp2 = map[i+3];
|
||||
((VicCon1*)this->vicConDetails)->monsterID = map[i+2];
|
||||
((VicCon1*)this->vicConDetails)->neededQuantity=readNormalNr(map, i+4);
|
||||
nr=6;
|
||||
break;
|
||||
}
|
||||
case gatherResource:
|
||||
{
|
||||
this->vicConDetails = new VicCon2();
|
||||
((VicCon2*)this->vicConDetails)->resourceID = map[i+2];
|
||||
((VicCon2*)this->vicConDetails)->neededQuantity=readNormalNr(map, i+3);
|
||||
nr=5;
|
||||
break;
|
||||
}
|
||||
case buildCity:
|
||||
{
|
||||
this->vicConDetails = new VicCon3();
|
||||
((VicCon3*)this->vicConDetails)->posOfCity.x = map[i+2];
|
||||
((VicCon3*)this->vicConDetails)->posOfCity.y = map[i+3];
|
||||
((VicCon3*)this->vicConDetails)->posOfCity.z = map[i+4];
|
||||
((VicCon3*)this->vicConDetails)->councilNeededLevel = map[i+5];
|
||||
((VicCon3*)this->vicConDetails)->fortNeededLevel = map[i+6];
|
||||
nr=5;
|
||||
break;
|
||||
}
|
||||
case buildGrail:
|
||||
{
|
||||
this->vicConDetails = new VicCon4();
|
||||
if (map[i+4]>2)
|
||||
((VicCon4*)this->vicConDetails)->anyLocation = true;
|
||||
else
|
||||
{
|
||||
((VicCon4*)this->vicConDetails)->whereBuildGrail.x = map[i+2];
|
||||
((VicCon4*)this->vicConDetails)->whereBuildGrail.y = map[i+3];
|
||||
((VicCon4*)this->vicConDetails)->whereBuildGrail.z = map[i+4];
|
||||
}
|
||||
nr=3;
|
||||
break;
|
||||
}
|
||||
case beatHero:
|
||||
{
|
||||
this->vicConDetails = new VicCon5();
|
||||
((VicCon5*)this->vicConDetails)->locationOfHero.x = map[i+2];
|
||||
((VicCon5*)this->vicConDetails)->locationOfHero.y = map[i+3];
|
||||
((VicCon5*)this->vicConDetails)->locationOfHero.z = map[i+4];
|
||||
nr=3;
|
||||
break;
|
||||
}
|
||||
case captureCity:
|
||||
{
|
||||
this->vicConDetails = new VicCon6();
|
||||
((VicCon6*)this->vicConDetails)->locationOfTown.x = map[i+2];
|
||||
((VicCon6*)this->vicConDetails)->locationOfTown.y = map[i+3];
|
||||
((VicCon6*)this->vicConDetails)->locationOfTown.z = map[i+4];
|
||||
nr=3;
|
||||
break;
|
||||
}
|
||||
case beatMonster:
|
||||
{
|
||||
this->vicConDetails = new VicCon7();
|
||||
((VicCon7*)this->vicConDetails)->locationOfMonster.x = map[i+2];
|
||||
((VicCon7*)this->vicConDetails)->locationOfMonster.y = map[i+3];
|
||||
((VicCon7*)this->vicConDetails)->locationOfMonster.z = map[i+4];
|
||||
nr=3;
|
||||
break;
|
||||
}
|
||||
case takeDwellings:
|
||||
{
|
||||
this->vicConDetails = new CspecificVictoryConidtions();
|
||||
nr=3;
|
||||
break;
|
||||
}
|
||||
case takeMines:
|
||||
{
|
||||
this->vicConDetails = new CspecificVictoryConidtions();
|
||||
nr=3;
|
||||
break;
|
||||
}
|
||||
case transportItem:
|
||||
{
|
||||
this->vicConDetails = new VicCona();
|
||||
((VicCona*)this->vicConDetails)->artifactID = map[i+2];
|
||||
((VicCona*)this->vicConDetails)->destinationPlace.x = map[i+3];
|
||||
((VicCona*)this->vicConDetails)->destinationPlace.y = map[i+4];
|
||||
((VicCona*)this->vicConDetails)->destinationPlace.z = map[i+5];
|
||||
nr=3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this->vicConDetails->allowNormalVictory = map[i++];
|
||||
this->vicConDetails->appliesToAI = map[i++];
|
||||
i+=nr;
|
||||
}
|
||||
this->lossCondition.typeOfLossCon = (ElossCon)map[i++];
|
||||
switch (this->lossCondition.typeOfLossCon) //read loss conditions
|
||||
{
|
||||
case lossCastle:
|
||||
{
|
||||
this->lossCondition.castlePos.x=map[i++];
|
||||
this->lossCondition.castlePos.y=map[i++];
|
||||
this->lossCondition.castlePos.z=map[i++];
|
||||
}
|
||||
case lossHero:
|
||||
{
|
||||
this->lossCondition.heroPos.x=map[i++];
|
||||
this->lossCondition.heroPos.y=map[i++];
|
||||
this->lossCondition.heroPos.z=map[i++];
|
||||
}
|
||||
case timeExpires:
|
||||
{
|
||||
this->lossCondition.timeLimit = readNormalNr(map, i++,2);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
this->howManyTeams=map[i++]; //read number of teams
|
||||
if(this->howManyTeams>0) //read team numbers
|
||||
{
|
||||
for(int rr=0; rr<8; ++rr)
|
||||
{
|
||||
this->players[rr].team=map[i++];
|
||||
}
|
||||
}
|
||||
}
|
23
map.h
23
map.h
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "global.h"
|
||||
|
||||
struct Sresource
|
||||
{
|
||||
@@ -175,7 +176,7 @@ struct Mapa
|
||||
std::vector<Rumor> rumors;
|
||||
std::vector<DefInfo> defy; // list of .def files
|
||||
PlayerInfo players[8]; // info about players
|
||||
std::vector<int> teams; // teams[i] = team of player nr i
|
||||
std::vector<int> teams; // teams[i] = team of player no i
|
||||
LossCondition lossCondition;
|
||||
EvictoryConditions victoryCondition; //victory conditions
|
||||
CspecificVictoryConidtions * vicConDetails; // used only if vistory conditions aren't standard
|
||||
@@ -183,5 +184,25 @@ struct Mapa
|
||||
std::vector<CMapEvent> events;
|
||||
};
|
||||
|
||||
class CMapHeader
|
||||
{
|
||||
public:
|
||||
Eformat version; // version of map Eformat
|
||||
bool areAnyPLayers; // if there are any playable players on map
|
||||
int height, width;
|
||||
bool twoLevel; // if map has underground level
|
||||
std::string name; //name of map
|
||||
std::string description; //and description
|
||||
int difficulty; // 0 easy - 4 impossible
|
||||
int levelLimit;
|
||||
LossCondition lossCondition;
|
||||
EvictoryConditions victoryCondition; //victory conditions
|
||||
CspecificVictoryConidtions * vicConDetails; // used only if vistory conditions aren't standard
|
||||
PlayerInfo players[8]; // info about players
|
||||
std::vector<int> teams; // teams[i] = team of player no i
|
||||
int howManyTeams;
|
||||
CMapHeader(unsigned char *map); //an argument is a reference to string described a map (unpacked)
|
||||
};
|
||||
|
||||
|
||||
#endif //MAPD
|
Reference in New Issue
Block a user