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
|
#include "StdAfx.h"
#include ".\npc.h"
#include "Utils.h"
CNPC::CNPC(void)
{
}
CNPC::~CNPC(void)
{
}
#define BEGIN_READ( a ) \
for(vector<string>::iterator i = a.begin(); i != a.end(); i++) {
#define FUNC \
gUtils.Explode( (*i), "=" ).at( 0 )
#define PARAM_0 \
gUtils.Explode( (*i), "=" ).at( 1 )
#define END_READ }
CNPC *CNPC::GetInstance( void )
{
static CNPC m_pInstance;
return &m_pInstance;
}
bool CNPC::InterceptMessages( HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam )
{
return false;
}
void ReadInstructions( vector<string>vIns, NPC *npc )
{
if( npc == NULL || vIns.size() < 1 )
return;
// BEGIN READING SCRIPT HERE
BEGIN_READ( vIns )
if ( FUNC == "ID" ) {
npc->sID = PARAM_0;
} else if ( FUNC == "NOM" ) {
npc->sName = PARAM_0;
}
[color=red]// ICI je dois fair en sorte de lire vendre et acheter et parler pour ajouter chaque entree dans un vecteur separe[/color]
END_READ
}
NPC CNPC::LoadNPCData( string & sFile )
{
NPC newNPC;
ifstream baseFile( sFile.c_str() );
vector<string>vInstructions = gUtils.FileToVector( baseFile );
ReadInstructions( vInstructions, &newNPC );
return newNPC;
}
void CNPC::LoadNPCs( const string &sFile )
{
vector<NPC>vNPCs;
string npcFile;
ifstream baseFile( sFile.c_str() );
while( getline(baseFile, npcFile) )
{
NPC newNPC = LoadNPCData( npcFile );
vNPCs.push_back(newNPC);
}
m_vNPC = vNPCs;
}
void CNPC::NewNPC( void )
{
NPC newNPC;
newNPC.sCreature = "Un Monstre";
newNPC.sName = "New NPC";
newNPC.vScript.clear();
newNPC.vBuy.clear();
newNPC.vLearn.clear();
newNPC.vSell.clear();
newNPC.vTrain.clear();
m_vNPC.push_back(newNPC);
// TODO: Show new NPC dialog & update the list of npcs
}
bool CNPC::DeleteNPC( NPC *npc )
{
bool bDone = false;
for( vector<NPC>::iterator i = m_vNPC.begin(); i != m_vNPC.end(); ++i )
{
if((*i).sName == npc->sName)
{
m_vNPC.erase(i);
bDone = true;
}
}
return bDone;
} |
Partager