From: <ma...@us...> - 2011-12-18 23:15:33
|
Revision: 7843 http://planeshift.svn.sourceforge.net/planeshift/?rev=7843&view=rev Author: magodra Date: 2011-12-18 23:15:24 +0000 (Sun, 18 Dec 2011) Log Message: ----------- - Merged r7178:7840 into trunc from planeshift/soc/2011/tribe. - Modified so that new message MSGTYPE where added at end of list. - Removed dublicate function QueueSpawnBuilding - Ignored DB changes that would cause NPC room to be unpopulated. - Added stuff to update_schema.sql for new db changes. - DB version changed. Revision Links: -------------- http://planeshift.svn.sourceforge.net/planeshift/?rev=7178&view=rev Modified Paths: -------------- trunk/data/emotes.xml trunk/data/npcbehave.xml trunk/src/common/net/messages.cpp trunk/src/common/net/messages.h trunk/src/common/net/npcmessages.cpp trunk/src/common/net/npcmessages.h trunk/src/npcclient/command.cpp trunk/src/npcclient/networkmgr.cpp trunk/src/npcclient/networkmgr.h trunk/src/npcclient/npc.cpp trunk/src/npcclient/npc.h trunk/src/npcclient/npcbehave.cpp trunk/src/npcclient/npcbehave.h trunk/src/npcclient/npcclient.cpp trunk/src/npcclient/npcclient.h trunk/src/npcclient/npcoperations.cpp trunk/src/npcclient/npcoperations.h trunk/src/npcclient/perceptions.cpp trunk/src/npcclient/perceptions.h trunk/src/npcclient/tribe.cpp trunk/src/npcclient/tribe.h trunk/src/server/database/mysql/char_skills.sql trunk/src/server/database/mysql/create_all.sql trunk/src/server/database/mysql/item_categories.sql trunk/src/server/database/mysql/item_stats.sql trunk/src/server/database/mysql/natural_resources.sql trunk/src/server/database/mysql/sc_locations.sql trunk/src/server/database/mysql/sc_npc_definitions.sql trunk/src/server/database/mysql/sc_tribe_resources.sql trunk/src/server/database/mysql/server_options.sql trunk/src/server/database/mysql/tribes.sql trunk/src/server/database/mysql/upgrade_schema.sql trunk/src/server/entitymanager.cpp trunk/src/server/entitymanager.h trunk/src/server/gem.cpp trunk/src/server/gem.h trunk/src/server/npcmanager.cpp trunk/src/server/npcmanager.h trunk/src/server/psserver.cpp trunk/src/server/workmanager.cpp Added Paths: ----------- trunk/src/npcclient/recipe.cpp trunk/src/npcclient/recipe.h trunk/src/npcclient/recipetreenode.cpp trunk/src/npcclient/recipetreenode.h trunk/src/server/database/mysql/sc_tribe_assets.sql trunk/src/server/database/mysql/sc_tribe_knowledge.sql trunk/src/server/database/mysql/tribe_recipes.sql Removed Paths: ------------- trunk/src/npcclient/tribeneed.cpp trunk/src/npcclient/tribeneed.h trunk/src/server/database/mysql/tribe_needs.sql Property Changed: ---------------- trunk/ trunk/data/renderlayers/ trunk/data/shader/ trunk/lang/1337/ trunk/lang/englishtemplate/ trunk/lang/french/ trunk/lang/italian/ trunk/src/tools/ccheck/ Property changes on: trunk ___________________________________________________________________ Modified: svn:mergeinfo - /personal/Kayden:2590-3147 /personal/Xordan:1745,1752,1812,1838,1887,1894,2012,2014-2017,2055-2056,2062,2064,2270,2272-2273,2277-2278,2283-2284,2286-2287,2290-2291,2330,2333-2334,2336,2424,2592,2595-2596,2598-2603,2613 /soc/2011/gui:7434,7519-7521,7569 /soc/2011/sound:7354,7363,7366-7367,7369,7373-7374,7376,7380,7382-7384,7386,7390,7392-7393,7396,7398-7399,7403,7410,7412,7415-7418,7420-7421,7425,7428-7430,7439,7442-7443,7445-7447,7457,7464-7465,7468-7469,7474-7475,7477-7482,7485,7487,7489-7491,7493-7494,7496,7498,7506-7507,7523,7525-7526,7528,7534,7538,7544-7546,7553,7556-7557,7574,7587,7590-7592,7594-7598 + /personal/Kayden:2590-3147 /personal/Xordan:1745,1752,1812,1838,1887,1894,2012,2014-2017,2055-2056,2062,2064,2270,2272-2273,2277-2278,2283-2284,2286-2287,2290-2291,2330,2333-2334,2336,2424,2592,2595-2596,2598-2603,2613 /soc/2011/gui:7434,7519-7521,7569 /soc/2011/sound:7354,7363,7366-7367,7369,7373-7374,7376,7380,7382-7384,7386,7390,7392-7393,7396,7398-7399,7403,7410,7412,7415-7418,7420-7421,7425,7428-7430,7439,7442-7443,7445-7447,7457,7464-7465,7468-7469,7474-7475,7477-7482,7485,7487,7489-7491,7493-7494,7496,7498,7506-7507,7523,7525-7526,7528,7534,7538,7544-7546,7553,7556-7557,7574,7587,7590-7592,7594-7598 /soc/2011/tribe:7179-7840 Added: svnmerge-integrated + /trunk:1-7177 Modified: trunk/data/emotes.xml =================================================================== --- trunk/data/emotes.xml 2011-12-18 18:29:42 UTC (rev 7842) +++ trunk/data/emotes.xml 2011-12-18 23:15:24 UTC (rev 7843) @@ -1,5 +1,8 @@ <emotes> <emote command="/greet" general="%s greets everyone." specific="%s greets %s" anim="greet" enabled="0" /> +<emote command="/flee" general="%s flees in panic." specific="%s flees from %s" anim="run" enabled="0" /> +<emote command="/divide" general="%s starts his cell division." specific="%s can't cell-divide together with anyone." anim="idle" enabled="0" /> +<emote command="/work" general="%s starts working." specific="%s invites %s to work." anim="idle" enabled="0" /> </emotes> Modified: trunk/data/npcbehave.xml =================================================================== --- trunk/data/npcbehave.xml 2011-12-18 18:29:42 UTC (rev 7842) +++ trunk/data/npcbehave.xml 2011-12-18 23:15:24 UTC (rev 7843) @@ -388,6 +388,133 @@ </behavior> </npctype> + <npctype name="AbstractTribesman" vel="2.5"> + <behavior name="do nothing" initial="80" resume="yes"> + <wait anim="stand" duration="100" /> + </behavior> + <behavior name="peace_meet" completion_decay="500"> + <locate obj="perception" /> + <rotate type="locatedest" anim="walk" ang_vel="120" /> + <emote cmd="/greet" /> + </behavior> + <behavior name="aggressive_meet" decay="10" completion_decay="150"> + <locate obj="perception" /> + <rotate type="locatedest" anim="walk" ang_vel="120" /> + <melee seek_range="20" melee_range="3" /> + </behavior> + <behavior name="coward_attacked" decay="10"> + <emote cmd="/flee" /> + <locate obj="waypoint" static="no" /> + <navigate anim="walk" /> + <locate obj="waypoint" static="no" random="yes" range="10" /> + <wander anim="walk" /> + </behavior> + <behavior name="normal_attacked" decay="10"> + <locate obj="target" range="20" /> + <rotate type="locatedest" anim="walk" ang_vel="120" /> + <melee seek_range="20" melee_range="3" /> + </behavior> + <behavior name="united_attacked" decay="10"> + <locate obj="enemy" /> + <percept event="tribesman attacked" target="tribe" /> + <melee seek_range="20" melee_range="3" /> + </behavior> + <behavior name="Chase" initial="0" growth="0" decay="1" complection_decay="-1" > + <chase type="target" chase_range="20" anim="run" vel="5" /> + </behavior> + <behavior name="Explore" completion_decay="100" resume="yes" auto_memorize="all"> + <locate obj="waypoint" static="no" /> + <navigate anim="walk" /> + <locate obj="waypoint" static="no" random="yes" range="80" /> + <wander anim="walk" /> + <wait anim="stand" duration="3" /> + <locate obj="tribe:home" static="no" /> + <wander anim="walk" /> + <navigate anim="walk" /> + <share_memories /> + </behavior> + <behavior name="GatherResource" completion_decay="100" resume="yes"> + <locate obj="ownbuffer" /> + <navigate anim="walk" /> + <equip item="Rock Pick" slot="righthand" /> + <dig resource="tribe:wealth" /> + <locate obj="tribe:home"/> + <navigate anim="walk" /> + <transfer item="tribe:wealth" target="tribe" /> + <share_memories /> + </behavior> + <behavior name="MineResource" completion_decay="100" resume="yes"> + <locate obj="waypoint" static="no" /> + <navigate anim="walk" /> + <locate obj="ownbuffer" static="no" /> + <wander anim="walk" /> + <equip item="Rock Pick" slot="righthand" /> + <loop iterations="3"> + <dig resource="tribe:buffer" /> + <wait anim="stand" duration="10" /> + </loop> + <dequip slot="righthand" /> + <locate obj="waypoint" static="no" /> + <navigate anim="walk" /> + <locate obj="tribe:home" static="no" /> + <wander anim="walk" /> + <transfer item="ownbuffer" target="tribe" /> + </behavior> + <behavior name="GoToSleep" resume="yes"> + <locate obj="waypoint" static="no" /> + <navigate anim="walk" /> + <locate obj="tribe:home" static="no" /> + <wander anim="walk" /> + <wait anim="sit" duration="180" /> + </behavior> + <behavior name="Breed" resume="yes" completion_decay="100"> + <locate obj="waypoint" static="no" /> + <navigate anim="walk" /> + <locate obj="tribe:home" static="no" /> + <wander anim="walk" /> + <navigate anim="walk" /> + <emote cmd="/divide" /> + <wait duration="30" anim="stand" /> + <locate obj="self" static="no" /> + <reproduce /> + </behavior> + <behavior name="Resurrect" when_dead="yes" completion_decay="200"> + <resurrect /> + </behavior> + <behavior name="GoToWork" completion_decay="100"> + <locate obj="waypoint" static="no" /> + <navigate anim="walk" /> + <locate obj="tribe:memory:work" static="no" /> + <wander anim="walk" /> + <locate obj="waypoint" static="no" /> + <navigate anim="walk" /> + <emote cmd="/work" /> + <wait duration="buffer" anim="stand" /> + <locate obj="tribe:home" static="no" /> + <wander anim="walk" /> + </behavior> + + <behavior name="Guard" resume="yes"> + <locate obj="ownbuffer" /> + <navigate anim="walk" /> + <circle anim="walk" radius="2" /> + </behavior> + <behavior name="turn" completion_decay="500"> + <rotate type="random" min="0" max="360" anim="walk" /> + <move anim="walk" duration="3" /> + </behavior> + + <react event="collision" behavior="turn" delta="500" /> + <react event="tribe:work" behavior="GoToWork" delta="100" /> + <react event="tribe:resurrect" behavior="Resurrect" delta="200" when_dead="yes" /> + <react event="tribe:mine" behavior="MineResource" delta="100" /> + <react event="tribe:gather" behavior="GatherResource" delta="100" /> + <react event="tribe:breed" behavior="Breed" delta="100" /> + <react event="tribe:explore" behavior="Explore" delta="100" /> + <react event="target out of range" behavior="Chase" /> + <react event="target out of chase" behavior="Chase" absolute="0" only_interrupt="chase" /> + </npctype> + <npctype name="MineingTribe" vel="2.5"> <behavior name="do nothing" decay="0" growth="0" initial="10"> Property changes on: trunk/data/renderlayers ___________________________________________________________________ Modified: svn:mergeinfo - /soc/2011/gui/data/renderlayers:7434,7519-7521,7569 /soc/2011/sound/data/renderlayers:7354,7363,7366-7367,7369,7373-7374,7376,7380,7382-7384,7386,7390,7392-7393,7396,7398-7399,7403,7410,7412,7415-7418,7420-7421,7425,7428-7430,7439,7442-7443,7445-7447,7457,7464-7465,7468-7469,7474-7475,7477-7482,7485,7487,7489-7491,7493-7494,7496,7498,7506-7507,7523,7525-7526,7528,7534,7538,7544-7546,7553,7556-7557,7574,7587,7590-7592,7594-7598 + /soc/2011/gui/data/renderlayers:7434,7519-7521,7569 /soc/2011/sound/data/renderlayers:7354,7363,7366-7367,7369,7373-7374,7376,7380,7382-7384,7386,7390,7392-7393,7396,7398-7399,7403,7410,7412,7415-7418,7420-7421,7425,7428-7430,7439,7442-7443,7445-7447,7457,7464-7465,7468-7469,7474-7475,7477-7482,7485,7487,7489-7491,7493-7494,7496,7498,7506-7507,7523,7525-7526,7528,7534,7538,7544-7546,7553,7556-7557,7574,7587,7590-7592,7594-7598 /soc/2011/tribe/data/renderlayers:7179-7840 Property changes on: trunk/data/shader ___________________________________________________________________ Modified: svn:mergeinfo - /soc/2011/gui/data/shader:7434,7519-7521,7569 /soc/2011/sound/data/shader:7354,7363,7366-7367,7369,7373-7374,7376,7380,7382-7384,7386,7390,7392-7393,7396,7398-7399,7403,7410,7412,7415-7418,7420-7421,7425,7428-7430,7439,7442-7443,7445-7447,7457,7464-7465,7468-7469,7474-7475,7477-7482,7485,7487,7489-7491,7493-7494,7496,7498,7506-7507,7523,7525-7526,7528,7534,7538,7544-7546,7553,7556-7557,7574,7587,7590-7592,7594-7598 + /soc/2011/gui/data/shader:7434,7519-7521,7569 /soc/2011/sound/data/shader:7354,7363,7366-7367,7369,7373-7374,7376,7380,7382-7384,7386,7390,7392-7393,7396,7398-7399,7403,7410,7412,7415-7418,7420-7421,7425,7428-7430,7439,7442-7443,7445-7447,7457,7464-7465,7468-7469,7474-7475,7477-7482,7485,7487,7489-7491,7493-7494,7496,7498,7506-7507,7523,7525-7526,7528,7534,7538,7544-7546,7553,7556-7557,7574,7587,7590-7592,7594-7598 /soc/2011/tribe/data/shader:7179-7840 Property changes on: trunk/lang/1337 ___________________________________________________________________ Modified: svn:mergeinfo - /soc/2011/gui/lang/1337:7434,7519-7521,7569 /soc/2011/sound/lang/1337:7354,7363,7366-7367,7369,7373-7374,7376,7380,7382-7384,7386,7390,7392-7393,7396,7398-7399,7403,7410,7412,7415-7418,7420-7421,7425,7428-7430,7439,7442-7443,7445-7447,7457,7464-7465,7468-7469,7474-7475,7477-7482,7485,7487,7489-7491,7493-7494,7496,7498,7506-7507,7523,7525-7526,7528,7534,7538,7544-7546,7553,7556-7557,7574,7587,7590-7592,7594-7598 + /soc/2011/gui/lang/1337:7434,7519-7521,7569 /soc/2011/sound/lang/1337:7354,7363,7366-7367,7369,7373-7374,7376,7380,7382-7384,7386,7390,7392-7393,7396,7398-7399,7403,7410,7412,7415-7418,7420-7421,7425,7428-7430,7439,7442-7443,7445-7447,7457,7464-7465,7468-7469,7474-7475,7477-7482,7485,7487,7489-7491,7493-7494,7496,7498,7506-7507,7523,7525-7526,7528,7534,7538,7544-7546,7553,7556-7557,7574,7587,7590-7592,7594-7598 /soc/2011/tribe/lang/1337:7179-7840 Property changes on: trunk/lang/englishtemplate ___________________________________________________________________ Modified: svn:mergeinfo - /personal/Kayden/lang/english:2590-3147 /personal/Xordan/lang/english:1745,1752,1812,1838,1887,1894,2012,2014-2017,2055-2056,2062,2064,2270,2272-2273,2277-2278,2283-2284,2286-2287,2290-2291,2330,2333-2334,2336,2424,2592,2595-2596,2598-2603,2613 /soc/2011/gui/lang/englishtemplate:7434,7519-7521,7569 /soc/2011/sound/lang/englishtemplate:7354,7363,7366-7367,7369,7373-7374,7376,7380,7382-7384,7386,7390,7392-7393,7396,7398-7399,7403,7410,7412,7415-7418,7420-7421,7425,7428-7430,7439,7442-7443,7445-7447,7457,7464-7465,7468-7469,7474-7475,7477-7482,7485,7487,7489-7491,7493-7494,7496,7498,7506-7507,7523,7525-7526,7528,7534,7538,7544-7546,7553,7556-7557,7574,7587,7590-7592,7594-7598 + /personal/Kayden/lang/english:2590-3147 /personal/Xordan/lang/english:1745,1752,1812,1838,1887,1894,2012,2014-2017,2055-2056,2062,2064,2270,2272-2273,2277-2278,2283-2284,2286-2287,2290-2291,2330,2333-2334,2336,2424,2592,2595-2596,2598-2603,2613 /soc/2011/gui/lang/englishtemplate:7434,7519-7521,7569 /soc/2011/sound/lang/englishtemplate:7354,7363,7366-7367,7369,7373-7374,7376,7380,7382-7384,7386,7390,7392-7393,7396,7398-7399,7403,7410,7412,7415-7418,7420-7421,7425,7428-7430,7439,7442-7443,7445-7447,7457,7464-7465,7468-7469,7474-7475,7477-7482,7485,7487,7489-7491,7493-7494,7496,7498,7506-7507,7523,7525-7526,7528,7534,7538,7544-7546,7553,7556-7557,7574,7587,7590-7592,7594-7598 /soc/2011/tribe/lang/englishtemplate:7179-7840 Property changes on: trunk/lang/french ___________________________________________________________________ Modified: svn:mergeinfo - /soc/2011/gui/lang/french:7434,7519-7521,7569 /soc/2011/sound/lang/french:7354,7363,7366-7367,7369,7373-7374,7376,7380,7382-7384,7386,7390,7392-7393,7396,7398-7399,7403,7410,7412,7415-7418,7420-7421,7425,7428-7430,7439,7442-7443,7445-7447,7457,7464-7465,7468-7469,7474-7475,7477-7482,7485,7487,7489-7491,7493-7494,7496,7498,7506-7507,7523,7525-7526,7528,7534,7538,7544-7546,7553,7556-7557,7574,7587,7590-7592,7594-7598 + /soc/2011/gui/lang/french:7434,7519-7521,7569 /soc/2011/sound/lang/french:7354,7363,7366-7367,7369,7373-7374,7376,7380,7382-7384,7386,7390,7392-7393,7396,7398-7399,7403,7410,7412,7415-7418,7420-7421,7425,7428-7430,7439,7442-7443,7445-7447,7457,7464-7465,7468-7469,7474-7475,7477-7482,7485,7487,7489-7491,7493-7494,7496,7498,7506-7507,7523,7525-7526,7528,7534,7538,7544-7546,7553,7556-7557,7574,7587,7590-7592,7594-7598 /soc/2011/tribe/lang/french:7179-7840 Property changes on: trunk/lang/italian ___________________________________________________________________ Modified: svn:mergeinfo - /soc/2011/gui/lang/italian:7434,7519-7521,7569 /soc/2011/sound/lang/italian:7354,7363,7366-7367,7369,7373-7374,7376,7380,7382-7384,7386,7390,7392-7393,7396,7398-7399,7403,7410,7412,7415-7418,7420-7421,7425,7428-7430,7439,7442-7443,7445-7447,7457,7464-7465,7468-7469,7474-7475,7477-7482,7485,7487,7489-7491,7493-7494,7496,7498,7506-7507,7523,7525-7526,7528,7534,7538,7544-7546,7553,7556-7557,7574,7587,7590-7592,7594-7598 + /soc/2011/gui/lang/italian:7434,7519-7521,7569 /soc/2011/sound/lang/italian:7354,7363,7366-7367,7369,7373-7374,7376,7380,7382-7384,7386,7390,7392-7393,7396,7398-7399,7403,7410,7412,7415-7418,7420-7421,7425,7428-7430,7439,7442-7443,7445-7447,7457,7464-7465,7468-7469,7474-7475,7477-7482,7485,7487,7489-7491,7493-7494,7496,7498,7506-7507,7523,7525-7526,7528,7534,7538,7544-7546,7553,7556-7557,7574,7587,7590-7592,7594-7598 /soc/2011/tribe/lang/italian:7179-7840 Modified: trunk/src/common/net/messages.cpp =================================================================== --- trunk/src/common/net/messages.cpp 2011-12-18 18:29:42 UTC (rev 7842) +++ trunk/src/common/net/messages.cpp 2011-12-18 23:15:24 UTC (rev 7843) @@ -5140,7 +5140,8 @@ float yRot, float zRot, uint32_t flags, - csStringSet* msgstrings) + csStringSet* msgstrings, + int tribeID) { msg.AttachNew(new MsgEntry( MAX_MESSAGE_SIZE )); @@ -5148,15 +5149,16 @@ msg->clientnum = clientNum; msg->Add( eid.Unbox() ); - msg->Add( (uint32_t) type ); - msg->Add( name ); - msg->Add( msgstrings->Request(factname).GetHash() ); - msg->Add( msgstrings->Request(matname).GetHash() ); - msg->Add( msgstrings->Request(sector).GetHash() ); - msg->Add( pos ); - msg->Add( xRot ); - msg->Add( yRot ); - msg->Add( zRot ); + msg->Add((uint32_t) type); + msg->Add(name); + msg->Add(msgstrings->Request(factname).GetHash()); + msg->Add(msgstrings->Request(matname).GetHash()); + msg->Add(msgstrings->Request(sector).GetHash()); + msg->Add(pos); + msg->Add(xRot); + msg->Add(yRot); + msg->Add(zRot); + msg->Add(tribeID); if (flags) // No point sending 0, has to be at the end { msg->Add( flags ); @@ -5178,6 +5180,7 @@ xRot = me->GetFloat(); yRot = me->GetFloat(); zRot = me->GetFloat(); + tribeID = me->GetInt16(); if (!me->IsEmpty()) { flags = me->GetUInt32(); @@ -5197,7 +5200,8 @@ msgtext.AppendFmt("Sector: %s ",sector.GetDataSafe()); msgtext.AppendFmt("Pos(%.2f,%.2f,%.2f) ",pos.x,pos.y,pos.z); msgtext.AppendFmt("yrot: %.2f Flags:",yRot); - if (flags & NOPICKUP) msgtext.AppendFmt(" NOPICKUP"); + if(flags & NOPICKUP) msgtext.AppendFmt(" NOPICKUP"); + if(tribeID) msgtext.AppendFmt("Belongs to tribe(id:%d)\n", tribeID); return msgtext; } Modified: trunk/src/common/net/messages.h =================================================================== --- trunk/src/common/net/messages.h 2011-12-18 18:29:42 UTC (rev 7842) +++ trunk/src/common/net/messages.h 2011-12-18 23:15:24 UTC (rev 7843) @@ -269,7 +269,9 @@ MSGTYPE_MUSICAL_SHEET, MSGTYPE_PLAY_SONG, MSGTYPE_STOP_SONG, - MSGTYPE_SIMPLE_RENDER_MESH + + MSGTYPE_SIMPLE_RENDER_MESH, + MSGTYPE_NPC_WORKDONE }; class psMessageCracker; @@ -3287,7 +3289,8 @@ float yRot, float zRot, uint32_t flags, - csStringSet* msgstrings + csStringSet* msgstrings, + int tribeid = 0 ); psPersistItem( MsgEntry* me, NetBase::AccessPointers* accessPointers ); @@ -3310,6 +3313,7 @@ float xRot; float yRot; float zRot; + int tribeID; EID eid; uint32_t type; uint32_t flags; Modified: trunk/src/common/net/npcmessages.cpp =================================================================== --- trunk/src/common/net/npcmessages.cpp 2011-12-18 18:29:42 UTC (rev 7842) +++ trunk/src/common/net/npcmessages.cpp 2011-12-18 23:15:24 UTC (rev 7843) @@ -334,6 +334,28 @@ msgtext.AppendFmt("Spawner: %u Spawned: %d TribeMemberType: %u", spawner_id.Unbox(), spawned_id.Unbox(),tribeMemberType); break; } + case psNPCCommandsMessage::CMD_SPAWN_BUILDING: + { + msgtext.Append("CMD_SPAWN_BUILDING: "); + + //Extract the data + csVector3 pos; + pos[0] = msg->GetFloat(); + pos[1] = msg->GetFloat(); + pos[2] = msg->GetFloat(); + const char* sectorName = msg->GetStr(); + const char* buildingName = msg->GetStr(); + int tribeID = msg->GetInt16(); + + if(msg->overrun) + { + Debug2(LOG_SUPERCLIENT, msg->clientnum, "Received incomplete CMD_SPAWN_BUILDING from NPC client %u.\n", msg->clientnum); + break; + } + + msgtext.AppendFmt("Pos: (%f;%f;%f) in sectorName %s. TribeID: %d. Building: %s", pos[0], pos[1], pos[2], sectorName, tribeID, buildingName); + + } case psNPCCommandsMessage::CMD_TALK: { msgtext.Append("CMD_TALK: "); @@ -883,7 +905,43 @@ return msgtext; } +//--------------------------------------------------------------------------- +PSF_IMPLEMENT_MSG_FACTORY(psNPCWorkDoneMessage,MSGTYPE_NPC_WORKDONE); +psNPCWorkDoneMessage::psNPCWorkDoneMessage(uint32_t clientToken, EID npcId, const char* resource, const char* nick) +{ + int size = sizeof(int); + size += (strlen(resource) + 1)*sizeof(char); + size += (strlen(nick) + 1)*sizeof(char); + msg.AttachNew(new MsgEntry(size)); + + msg->SetType(MSGTYPE_NPC_WORKDONE); + msg->clientnum = clientToken; + msg->Add(npcId.Unbox()); + msg->Add(resource); + msg->Add(nick); +} + +psNPCWorkDoneMessage::psNPCWorkDoneMessage(MsgEntry* message) +{ + if(!message) + return; + npcId = EID(message->GetUInt32()); + resource = message->GetStr(); + nick = message->GetStr(); +} + +csString psNPCWorkDoneMessage::ToString(NetBase::AccessPointers* /*accessPointers*/) +{ + csString msgtext; + + msgtext.AppendFmt("NPC EID: %d", npcId.Unbox()); + msgtext.AppendFmt("Item received: %s", resource); + msgtext.AppendFmt("With nick: %s", nick); + + return msgtext; +} + //--------------------------------------------------------------------------- PSF_IMPLEMENT_MSG_FACTORY(psNewNPCCreatedMessage,MSGTYPE_NEW_NPC); Modified: trunk/src/common/net/npcmessages.h =================================================================== --- trunk/src/common/net/npcmessages.h 2011-12-18 18:29:42 UTC (rev 7842) +++ trunk/src/common/net/npcmessages.h 2011-12-18 23:15:24 UTC (rev 7843) @@ -200,8 +200,9 @@ CMD_TERMINATOR, // cmds go from superclient to server CMD_DRDATA, CMD_ATTACK, - CMD_SIT, + CMD_SIT, CMD_SPAWN, + CMD_SPAWN_BUILDING, // used for superclient to request a new building CMD_TALK, CMD_VISIBILITY, CMD_PICKUP, @@ -305,6 +306,26 @@ }; /** +* The message sent from server to superclient upon a successful +* work done. +*/ +class psNPCWorkDoneMessage : public psMessageCracker +{ +public: + EID npcId; + const char* resource; + const char* nick; + + psNPCWorkDoneMessage(uint32_t clientToken, EID npcId, const char* resource, const char* nick); + + psNPCWorkDoneMessage(MsgEntry *message); + + PSF_DECLARE_MSG_FACTORY(); + + virtual csString ToString(NetBase::AccessPointers* accessPointers); +}; + +/** * The message sent from server to superclient after successful * NPC Creation. */ Modified: trunk/src/npcclient/command.cpp =================================================================== --- trunk/src/npcclient/command.cpp 2011-12-18 18:29:42 UTC (rev 7842) +++ trunk/src/npcclient/command.cpp 2011-12-18 23:15:24 UTC (rev 7843) @@ -104,6 +104,12 @@ return 0; } +int com_triberecipes(char *arg) +{ + npcclient->ListTribeRecipes(arg); + return 0; +} + int com_waypointlist(char *arg) { npcclient->ListWaypoints(arg); @@ -122,7 +128,6 @@ return 0; } - int com_locationtest(char *line) { WordArray words(line,false); @@ -373,8 +378,23 @@ return 0; } -int com_dumpwarpspace(char *) +int com_fireperc(char* arg) { + csStringArray arguments; + arguments.SplitString(arg, " "); + if(npcclient->FirePerception(atoi(arguments.Get(0)), arguments.Get(1))) + { + CPrintf(CON_CMDOUTPUT, "Perception %s fired on NPC %s.\n", arguments.Get(1), arguments.Get(0)); + } + else + { + CPrintf(CON_CMDOUTPUT, "Could not fire perception. NPC ID: %s does not exist.\n", arguments.Get(0)); + } + return 0; +} + +int com_dumpwarpspace(char*) +{ npcclient->GetWorld()->DumpWarpCache(); return 0; } @@ -415,6 +435,7 @@ { "enable", false, com_enable, "Enable a disabled NPC. [all | pattern | EID]"}, { "entlist", false, com_entlist, "List all known entities (entlist [pattern | EID]"}, { "filtermsg", true, com_filtermsg, "Add or remove messages from the LOG_MESSAGE log"}, + { "fireperc", false, com_fireperc, "Fire the given perception on the given npc. (fireperc [npcPID] [perception])"}, { "help", false, com_help, "Show help information" }, { "loclist", false, com_locationlist, "List all known locations (loclist [pattern])"}, { "loctest", false, com_locationtest, "Test a location (loc sector x y z"}, @@ -430,6 +451,7 @@ { "showlogs", false, com_showlogs, "Show server logs" }, { "showtime", false, com_showtime, "Show the current game time"}, { "tribelist", false, com_tribelist, "List all known tribes (tribelist [pattern])"}, + { "triberecipes", false, com_triberecipes, "List all recipes in a tribe. (triberecipes [tribeid])"}, { "waypointlist", false, com_waypointlist, "List all known waypoints (waypointlist [pattern])"}, { "status", false, com_status, "Give some general statistics on the npcclient"}, { 0, 0, 0, 0 } Modified: trunk/src/npcclient/networkmgr.cpp =================================================================== --- trunk/src/npcclient/networkmgr.cpp 2011-12-18 18:29:42 UTC (rev 7842) +++ trunk/src/npcclient/networkmgr.cpp 2011-12-18 23:15:24 UTC (rev 7843) @@ -77,6 +77,7 @@ msghandler->Subscribe(this,MSGTYPE_NEW_NPC); msghandler->Subscribe(this,MSGTYPE_NPC_COMMAND); msghandler->Subscribe(this,MSGTYPE_NPCRACELIST); + msghandler->Subscribe(this,MSGTYPE_NPC_WORKDONE); connection= conn; connection->SetEngine( engine ); @@ -101,6 +102,7 @@ msghandler->Unsubscribe(this,MSGTYPE_MSGSTRINGS); msghandler->Unsubscribe(this,MSGTYPE_NPC_COMMAND); msghandler->Unsubscribe(this,MSGTYPE_NPCRACELIST); + msghandler->Unsubscribe(this,MSGTYPE_NPC_WORKDONE); } delete outbound; @@ -239,6 +241,10 @@ CPrintf(CON_CMDOUTPUT, msg.command.GetData()); break; } + case MSGTYPE_NPC_WORKDONE: + { + HandleNPCWorkDone(message); + } } } @@ -339,7 +345,7 @@ Debug4(LOG_NET, 0, "Got persistItem message, size %zu, eid=%d, name=%s\n", me->GetSize(),mesg.eid.Unbox(),mesg.name.GetDataSafe() ); - if (obj && obj->GetPID().IsValid()) + if(obj && obj->GetPID().IsValid()) { // We have a player/NPC item mismatch. CPrintf(CON_ERROR, "Deleting because we already know gemNPCActor: " @@ -351,7 +357,7 @@ } - if (obj) + if(obj) { // We already know this item so just update the position. CPrintf(CON_ERROR, "Deleting because we already know " @@ -362,9 +368,21 @@ obj = NULL; // Obj isn't valid after remove } - gemNPCItem* item = new gemNPCItem( npcclient, mesg); + if(mesg.tribeID != 0) + { + csVector3 where; + Tribe* tribe = npcclient->GetTribe(mesg.tribeID); + + // Check just to be sure... it should never happen + if(tribe) + { + tribe->AddBuildingAsset(mesg.name, mesg.pos, ASSET_BUILDING); + } + } + + gemNPCItem* item = new gemNPCItem(npcclient, mesg); - npcclient->Add( item ); + npcclient->Add(item); } void NetworkManager::HandleObjectRemoval( MsgEntry* me ) @@ -1003,6 +1021,19 @@ } } +void NetworkManager::HandleNPCWorkDone(MsgEntry *me) +{ + psNPCWorkDoneMessage msg(me); + + NPC* npc = npcclient->FindNPC(msg.npcId); + + // If he just prospected a mine and its a tribe member + if(npc->GetBuffer() == "new mine" && npc->GetTribe()) + { + npc->GetTribe()->ProspectMine(npc,msg.resource,msg.nick); + } +} + void NetworkManager::HandleNewNpc(MsgEntry *me) { psNewNPCCreatedMessage msg(me); @@ -1122,7 +1153,7 @@ if ( outbound->msg->overrun ) { - CS_ASSERT(!"NetworkManager::QueueSpawnCommand put message in overrun state!\n"); + CS_ASSERT(!"NetworkManager::QueueSitCommand put message in overrun state!\n"); } cmd_count++; } @@ -1143,6 +1174,27 @@ cmd_count++; } +void NetworkManager::QueueSpawnBuildingCommand(csVector3 where, const char* sectorName, const char* buildingName, int tribeID) +{ + CheckCommandsOverrun(100); + + outbound->msg->Add((int8_t) psNPCCommandsMessage::CMD_SPAWN_BUILDING); + outbound->msg->Add(where[0]); + outbound->msg->Add(where[1]); + outbound->msg->Add(where[2]); + + outbound->msg->Add(sectorName); + outbound->msg->Add(buildingName); + + outbound->msg->Add(tribeID); + + if(outbound->msg->overrun) + { + CS_ASSERT(!"NetworkManager::QueueSpawnBuildingCommand put message in overrun state!\n"); + } + cmd_count++; +} + void NetworkManager::QueueTalkCommand(gemNPCActor *speaker, gemNPCActor* target, psNPCCommandsMessage::PerceptionTalkType talkType, bool publicTalk, const char* text) { CheckCommandsOverrun(100); Modified: trunk/src/npcclient/networkmgr.h =================================================================== --- trunk/src/npcclient/networkmgr.h 2011-12-18 18:29:42 UTC (rev 7842) +++ trunk/src/npcclient/networkmgr.h 2011-12-18 23:15:24 UTC (rev 7843) @@ -68,6 +68,7 @@ void HandlePerceptions(MsgEntry *msg); void HandleDisconnect(MsgEntry *msg); void HandleTimeUpdate(MsgEntry *msg); + void HandleNPCWorkDone(MsgEntry *msg); void HandleNewNpc(MsgEntry *msg); // void RemoveEntity(psCelPersistMessage& pmsg); @@ -147,6 +148,15 @@ * @param tribeMemberType If part of a tribe set to the need set index to be used for this new entity. */ void QueueSpawnCommand(gemNPCActor *mother, gemNPCActor *father, uint32_t tribeMemberType); + + /** Send a spawn building command to server + * + * @param where Containing the desired location + * @param sectorName The name of the sector in which we want a spawn. + * @param buildingName The name of the building. Or more exactly... of the mesh for it. + * @param tribeID The owner of this building + */ + void QueueSpawnBuildingCommand(csVector3 where, const char* sectorName, const char* buildingName, int tribeID); /** Queue a talk command to the server * @@ -174,6 +184,7 @@ void QueueSequenceCommand(csString name, int cmd, int count); void QueueImperviousCommand(gemNPCActor * entity, bool impervious); void QueueInfoReplyCommand(uint32_t clientNum,const char* reply); + void SendAllCommands(bool final = false); void SendConsoleCommand(const char *cmd); Modified: trunk/src/npcclient/npc.cpp =================================================================== --- trunk/src/npcclient/npc.cpp 2011-12-18 18:29:42 UTC (rev 7842) +++ trunk/src/npcclient/npc.cpp 2011-12-18 23:15:24 UTC (rev 7843) @@ -99,6 +99,7 @@ debugLog.Push(csString("")); } nextDebugLogEntry = 0; + tribeBuffer = " "; } @@ -214,6 +215,28 @@ DumpDebugLog(); CPrintf(CON_CMDOUTPUT,"\n"); + + // Dump it's memory buffer + CPrintf(CON_CMDOUTPUT, "Buffers:\n"); + CPrintf(CON_CMDOUTPUT, "String buffer: %s\n", tribeBuffer.GetData()); + CPrintf(CON_CMDOUTPUT, "Memory buffer:\n"); + if(bufferMemory.sector) + { + CPrintf(CON_CMDOUTPUT, "Name: %s\n", bufferMemory.name.GetData()); + CPrintf(CON_CMDOUTPUT, "Pos: x:%f y:%f z:%f\n", + bufferMemory.pos[0], + bufferMemory.pos[1], + bufferMemory.pos[2]); + CPrintf(CON_CMDOUTPUT, "Has Sector:\n"); + if(bufferMemory.GetSector()) + CPrintf(CON_CMDOUTPUT, "Yes\n"); + else + CPrintf(CON_CMDOUTPUT, "No\n"); + } + else + { + CPrintf(CON_CMDOUTPUT, "Empty\n"); + } } EID NPC::GetEID() @@ -415,11 +438,16 @@ } } - Printf(15,"Got event %s",pcpt->ToString().GetData() ); brain->FirePerception(this, pcpt); } +void NPC::TriggerEvent(const char* pcpt) +{ + Perception perc(pcpt); + TriggerEvent(&perc, -1, NULL, NULL, false); +} + void NPC::SetLastPerception(Perception *pcpt) { if (last_perception) @@ -878,7 +906,6 @@ void NPC::Printf(const char *msg,...) { va_list args; - if(!IsDebugging()) return; @@ -1102,7 +1129,17 @@ return spawnSector; } +void NPC::SetBufferMemory(Tribe::Memory* memory) +{ + // Just copy data + bufferMemory.name = memory->name; + bufferMemory.pos = memory->pos; + bufferMemory.sector = memory->sector; + bufferMemory.sectorName = memory->sectorName; + bufferMemory.radius = memory->radius; +} + //----------------------------------------------------------------------------- void HateList::AddHate(EID entity_id, float delta) Modified: trunk/src/npcclient/npc.h =================================================================== --- trunk/src/npcclient/npc.h 2011-12-18 18:29:42 UTC (rev 7842) +++ trunk/src/npcclient/npc.h 2011-12-18 23:15:24 UTC (rev 7843) @@ -35,6 +35,7 @@ // Local Includes //============================================================================= #include "npcbehave.h" +#include "tribe.h" struct iCollideSystem; @@ -248,6 +249,14 @@ void TriggerEvent(Perception *pcpt, float maxRange=-1.0, csVector3* basePos=NULL, iSector* baseSector=NULL, bool sameSector=false); + + /** Send a perception to this NPC + * + * Uses the above method, but acts as a wrapper. + * Receives only the name of the perception and uses default values + * for the rest of the arguments + */ + void TriggerEvent(const char* pcpt); void SetLastPerception(Perception *pcpt); Perception *GetLastPerception() { return last_perception; } @@ -457,12 +466,21 @@ */ int GetFallCounter() { return fallCounter; } + csString GetBuffer() { return tribeBuffer; } + void SetBuffer(csString buffer) { tribeBuffer = buffer; } + + Tribe::Memory* GetBufferMemory() { return &bufferMemory; } + void SetBufferMemory(Tribe::Memory* memory); + private: psNPCTick* tick; psNPCClient* npcclient; NetworkManager* networkmanager; psWorld* world; iCollideSystem* cdsys; + + csString tribeBuffer; ///< Used to store dynamic data + Tribe::Memory bufferMemory; ///< Used to store location data friend class psNPCTick; Modified: trunk/src/npcclient/npcbehave.cpp =================================================================== --- trunk/src/npcclient/npcbehave.cpp 2011-12-18 18:29:42 UTC (rev 7842) +++ trunk/src/npcclient/npcbehave.cpp 2011-12-18 23:15:24 UTC (rev 7843) @@ -376,6 +376,32 @@ void NPCType::FirePerception(NPC *npc, Perception *pcpt) { + Behavior* behavior = npc->GetCurrentBehavior(); + if(behavior && behavior->IsAMOn() && npc->GetTribe()) + { + csArray<csString>* types = behavior->GetAMTypes(); + csString type = pcpt->GetType(); + + // Special Cases + if(types->Get(0) == "all") + { + npc->GetTribe()->Memorize(npc,pcpt); + } + else if(types->Get(0) == "ownbuffer") + { + if(npc->GetBuffer() == type) + { + npc->GetTribe()->Memorize(npc,pcpt); + } + } + + // Normal case + if(types->Find(type) != csArrayItemNotFound) + { + npc->GetTribe()->Memorize(npc,pcpt); + } + } + for (size_t x=0; x<reactions.GetSize(); x++) { reactions[x]->React(npc,pcpt); @@ -705,6 +731,8 @@ minLimit = 0.0; maxLimitValid = false; maxLimit = 0.0; + auto_memorize.SetSize(0); + AMOn = false; } Behavior::Behavior(const char *n) @@ -752,6 +780,8 @@ minLimit = other.minLimit; maxLimitValid = other.maxLimitValid; maxLimit = other.maxLimit; + auto_memorize = other.auto_memorize; + AMOn = other.AMOn; for (size_t x=0; x<other.sequence.GetSize(); x++) { @@ -797,8 +827,15 @@ { maxLimitValid = false; } - + // Load the locations that the npc should memorize without breaking behavior + csString tmp = node->GetAttributeValue("auto_memorize"); + if(tmp.Length()) + { + auto_memorize = psSplit(tmp,','); + AMOn = true; + } + current_need = init_need; return LoadScript(node,true); @@ -1196,6 +1233,8 @@ } case ScriptOperation::OPERATION_FAILED: { + //TODO -- Remove printf + //printf("ZeeDebug: Operation %s failed\n", sequence[current_step]->GetName()); sequence[current_step]->Failure(npc); current_step = 0; // Restart operation next time DoCompletionDecay(npc); Modified: trunk/src/npcclient/npcbehave.h =================================================================== --- trunk/src/npcclient/npcbehave.h 2011-12-18 18:29:42 UTC (rev 7842) +++ trunk/src/npcclient/npcbehave.h 2011-12-18 23:15:24 UTC (rev 7843) @@ -273,8 +273,11 @@ float minLimit; ///< The minimum value to limit the need if minLimitValid has been set true. bool maxLimitValid; ///< True if a maximum limit for the need for this bahavior has been set float maxLimit; ///< The maximum value to limit the need if maxLimitValid has been set true. - + csArray<csString> auto_memorize; ///< Used to store what types of perceptions to memorize without changing behaviors + bool AMOn; ///< Flag to signal if auto_memorize is on/off + public: + Behavior(); Behavior(const char *n); Behavior(Behavior& other); @@ -336,6 +339,10 @@ * */ bool IsActive(){ return isActive; } + + /** Get Auto Memorize types */ + csArray<csString>* GetAMTypes() { return &auto_memorize; } + bool IsAMOn() { return AMOn; } void SetCurrentStep(int step) { current_step = step; } size_t GetCurrentStep(){ return current_step; } Modified: trunk/src/npcclient/npcclient.cpp =================================================================== --- trunk/src/npcclient/npcclient.cpp 2011-12-18 18:29:42 UTC (rev 7842) +++ trunk/src/npcclient/npcclient.cpp 2011-12-18 23:15:24 UTC (rev 7843) @@ -68,8 +68,8 @@ #include "npc.h" #include "perceptions.h" #include "gem.h" +#include "recipe.h" #include "tribe.h" -#include "tribeneed.h" #include "status.h" bool running; @@ -90,15 +90,16 @@ psNPCClient::psNPCClient () : serverconsole(NULL) { - npcclient = this; // Static pointer to self - world = NULL; + npcclient = this; // Static pointer to self + world = NULL; // PFMaps = NULL; - pathNetwork = NULL; - eventmanager = NULL; - running = true; - database = NULL; - network = NULL; - tick_counter = 0; + pathNetwork = NULL; + eventmanager = NULL; + recipemanager = NULL; + running = true; + database = NULL; + network = NULL; + tick_counter = 0; current_long_range_perception_index = 0; current_long_range_perception_loc_index = 0; } @@ -134,6 +135,10 @@ delete pathNetwork; // delete PFMaps; delete world; + + // TODO -- Make the recipemanager's destructor + // Delete Recipe Manager + delete recipemanager; } bool psNPCClient::Initialize(iObjectRegistry* object_reg,const char *_host, const char *_user, const char *_pass, int _port) @@ -198,6 +203,7 @@ return false; } eventmanager = new EventManager; + recipemanager = new RecipeManager(this, eventmanager); msghandler = eventmanager; psMessageCracker::msghandler = eventmanager; @@ -229,6 +235,12 @@ exit(1); } + if (!recipemanager->LoadRecipes()) + { + CPrintf(CON_ERROR, "Couldn't load the recipes table\n"); + exit(1); + } + if (!LoadTribes()) { CPrintf(CON_ERROR, "Couldn't load the tribes table\n"); @@ -245,7 +257,7 @@ { CPrintf(CON_ERROR, "Couldn't load the sc_location_type table\n"); exit(1); - } + } cdsys = csQueryRegistry<iCollideSystem> (objreg); @@ -402,6 +414,49 @@ return root; } +Tribe* psNPCClient::GetTribe(int id) +{ + for(int i=0;i<tribes.GetSize();i++) + { + if(tribes[i]->GetID() == id) + { + return tribes[i]; + } + } +} + +bool psNPCClient::AddNPCType(csString newType) +{ + csRef<iDocumentSystem> xml = csPtr<iDocumentSystem>(new csTinyDocumentSystem); + csRef<iDocument> doc = xml->CreateDocument(); + const char* error = doc->Parse(newType); + if(error) + { + Error2("Error parsing assembled xml: %s.", error); + return false; + } + + csRef<iDocumentNode> root = doc->GetRoot(); + csRef<iDocumentNode> node = root->GetNode("npctype"); + if(!node) + { + Error1("Error. No root node on xml."); + return false; + } + + NPCType* npctype = new NPCType(this, eventmanager); + if(npctype->Load(node)) + { + npctypes.Put(npctype->GetName(), npctype); + return true; + } + else + { + delete npctype; + return false; + } +} + bool psNPCClient::LoadNPCTypes(iDocumentNode* root) { csRef<iDocumentNode> topNode = root->GetNode("npctypes"); @@ -498,8 +553,22 @@ //success only if the array is empty at this point, else failure. return postponedNPCTypeID.IsEmpty(); } + +bool psNPCClient::FirePerception(int NPCId, const char* perception) +{ + for(int i=0;i<npcs.GetSize();i++) + { + + if((int)npcs[i]->GetPID().Unbox() == NPCId) + { + npcs[i]->TriggerEvent(perception); + return true; + } + + } + return false; +} - void psNPCClient::Add( gemNPCObject* object ) { EID eid = object->GetEID(); @@ -678,8 +747,17 @@ if (!CheckAttachTribes(npc)) { - return false; + return false; } + + else if(npc->GetTribe()) + { + // Overwrite brain with tribe brain + int id = npc->GetTribe()->GetID(); + csString typeName = "tribe_"; + typeName.Append(id); + npc->SetBrain(npctypes.Get(typeName.GetData(), NULL), eventmanager); + } } else { @@ -759,29 +837,13 @@ } for (int i=0; i<(int)rs.Count(); i++) { - Tribe *tribe = new Tribe; + Tribe *tribe = new Tribe(eventmanager); + tribe->SetRecipeManager(recipemanager); + if (tribe->Load(rs[i])) { tribes.Push(tribe); - { // Start Load Needs scope - Result rs2(db->Select("select * from tribe_needs where tribe_id=%d",tribe->GetID())); - if (!rs2.IsValid()) - { - Error2("Could not load tribe needs from db: %s",db->GetLastError() ); - return false; - } - for (int j=0; j<(int)rs2.Count(); j++) - { - if (!tribe->LoadNeed(rs2[j])) - { - Error2("Failed to load needs for tribe from db: %s",db->GetLastError()); - return false; - } - - } - } // End Load Needs scope - { // Start Load Members scope Result rs2(db->Select("select * from tribe_members where tribe_id=%d",tribe->GetID())); if (!rs2.IsValid()) @@ -793,7 +855,7 @@ { tribe->LoadMember(rs2[j]); } - } // End Load Memebers scope + } // End Load Members scope { // Start Load Memories scope Result rs2(db->Select("select m.*,s.name AS sector_name from sc_tribe_memories m, sectors s WHERE s.id = m.sector_id and tribe_id=%d",tribe->GetID())); @@ -806,7 +868,7 @@ { tribe->LoadMemory(rs2[j]); } - } // End Load Memeories scope + } // End Load Memories scope { // Start Load Resources scope Result rs2(db->Select("select * from sc_tribe_resources WHERE tribe_id=%d",tribe->GetID())); @@ -820,7 +882,35 @@ tribe->LoadResource(rs2[j]); } } // End Load Resources scope - + + { // Start Load Knowledge scope + Result rs2(db->Select("select * from sc_tribe_knowledge WHERE tribe_id=%d", tribe->GetID())); + if(!rs2.IsValid()) + { + Error2("Could not load tribe knowledge from db: %s", db->GetLastError() ); + return false; + } + for(int i=0;i<rs2.Count(); i++) + { + tribe->AddKnowledge(rs2[i]["knowledge"]); + } + } // End Load Knowledge scope + + { // Start Load Assets scope + Result rs2(db->Select("select * from sc_tribe_assets WHERE tribe_id=%d", tribe->GetID())); + if(!rs2.IsValid()) + { + Error2("Could not load tribe assets from db: %s", db->GetLastError() ); + return false; + } + for(int i=0;i<rs2.Count();i++) + { + tribe->LoadAsset(rs2[i]); + } + } // End Load Assets scope + + // Enroll at Recipe Manager + recipemanager->AddTribe(tribe); } else { @@ -1434,62 +1524,81 @@ CPrintf(CON_CMDOUTPUT, "No tribes defined\n"); return; } + + + csVector3 pos; + iSector* sector; + float radius; + // Write basic details about tribes + if(strlen(pattern) == 0) + { + CPrintf(CON_CMDOUTPUT, "\n%9s %-30s %-7s %-11s\n", + "Tribe id", "Name", "MCount", "Location"); - for (size_t i = 0; i < tribes.GetSize(); i++) + for(size_t i=0;i<tribes.GetSize();i++) + { + tribes[i]->GetHome(pos,radius,sector); + CPrintf(CON_CMDOUTPUT, "%9d %-30s %-7d %3f;%3f;%3f\n", + tribes[i]->GetID(), + tribes[i]->GetName(), + tribes[i]->GetMemberCount(), + pos[0], + pos[1], + pos[2]); + } + } + else { - if (!pattern || strstr(tribes[i]->GetName(),pattern)) + int tribeID = atoi(pattern); + printf("%d\n", tribeID); + for(size_t i=0;i<tribes.GetSize();i++) { - csVector3 pos; - iSector* sector; - float radius; - CPrintf(CON_CMDOUTPUT, "\n%9s %-30s %-7s %-7s\n", - "Tribe id", "Name", "MCount","NPCs"); - tribes[i]->GetHome(pos,radius,sector); - CPrintf(CON_CMDOUTPUT, "%9d %-30s %-7d %-7d\n" , - tribes[i]->GetID(), - tribes[i]->GetName(), - tribes[i]->GetMemberIDCount(), - tribes[i]->GetMemberCount()); - CPrintf(CON_CMDOUTPUT,"Home position: %s Radius: %7.1f\n",toString(pos,sector).GetDataSafe(),radius); - CPrintf(CON_CMDOUTPUT," ShouldGrow: %s MaxSize : %4d Growth Active Rate: %5.2f Growth Active Limit: %d\n", - (tribes[i]->ShouldGrow()?"Yes":"No "),tribes[i]->GetMaxSize(), - tribes[i]->GetWealthResourceGrowthActive(),tribes[i]->GetWealthResourceGrowthActiveLimit()); - CPrintf(CON_CMDOUTPUT," CanGrow : %s Reproduction Cost: %4d Growth Rate : %5.2f\n", - (tribes[i]->CanGrow()?"Yes":"No "),tribes[i]->GetReproductionCost(), - tribes[i]->GetWealthResourceGrowth()); - CPrintf(CON_CMDOUTPUT,"Resource rate : %f ticks/resource\n",tribes[i]->GetResourceRate()); - CPrintf(CON_CMDOUTPUT,"Death rate : %f ticks/death\n",tribes[i]->GetDeathRate()); - CPrintf(CON_CMDOUTPUT,"Needed resource : '%s' Nick: '%s'\n",tribes[i]->GetNeededResource(),tribes[i]->GetNeededResourceNick()); - CPrintf(CON_CMDOUTPUT,"NPC Idle behavior : '%s'\n",tribes[i]->GetNPCIdleBehavior()); - - CPrintf(CON_CMDOUTPUT,"Members:\n"); - CPrintf(CON_CMDOUTPUT, "%-6s %-6s %-30s %-6s %-6s %-15s %-15s %-20s %-20s\n", - "NPC ID", "EID", "Name", "Entity", "Status", "Brain","Behaviour","Owner","TribeMemberType"); - for (size_t j = 0; j < tribes[i]->GetMemberCount(); j++) + // Find the ID + if(tribes[i]->GetID() == tribeID) { - NPC * npc = tribes[i]->GetMember(j); - CPrintf(CON_CMDOUTPUT, "%6u %6d %-30s %-6s %-6s %-15s %-15s %-20s %-20d\n" , - npc->GetPID().Unbox(), - npc->GetActor() ? npc->GetActor()->GetEID().Unbox() : 0, - npc->GetName(), - (npc->GetActor()?"Entity":"None "), - (npc->IsAlive()?"Alive":"Dead"), - (npc->GetBrain()?npc->GetBrain()->GetName():""), - (npc->GetCurrentBehavior()?npc->GetCurrentBehavior()->GetName():""), - npc->GetOwnerName(), - npc->GetTribeMemberType() - ); - } - CPrintf(CON_CMDOUTPUT,"Resources:\n"); - CPrintf(CON_CMDOUTPUT,"%7s %-20s %7s\n","ID","Name","Amount"); - for (size_t r = 0; r < tribes[i]->GetResourceCount(); r++) - { - CPrintf(CON_CMDOUTPUT,"%7d %-20s %d\n", - tribes[i]->GetResource(r).id, - tribes[i]->GetResource(r).name.GetData(), - tribes[i]->GetResource(r).amount); - } - { // Start print Memories scope + tribes[i]->GetHome(pos,radius,sector); + // Print basic tribe data + CPrintf(CON_CMDOUTPUT, "Tribe ID: %d\nTribe Name: %s\nLocation: %s\nMain Resource: %s (nick:%s)\nCanGrow: %s \nShouldGrow: %s \n", + tribes[i]->GetID(), + tribes[i]->GetName(), + toString(pos,sector).GetDataSafe(), + tribes[i]->GetNeededResource(), + tribes[i]->GetNeededResourceNick(), + (tribes[i]->CanGrow()?"Yes":"No"), + (tribes[i]->ShouldGrow()?"Yes":"No")); + + // Print Tribe Members + CPrintf(CON_CMDOUTPUT,"Members:\n"); + CPrintf(CON_CMDOUTPUT, "%-6s %-6s %-30s %-6s %-6s %-15s %-15s %-20s %-20s\n", + "NPC ID", "EID", "Name", "Entity", "Status", "Brain","Behaviour","Owner","TribeMemberType"); + for (size_t j = 0; j < tribes[i]->GetMemberCount(); j++) + { + NPC * npc = tribes[i]->GetMember(j); + CPrintf(CON_CMDOUTPUT, "%6u %6d %-30s %-6s %-6s %-15s %-15s %-20s %-20d\n" , + npc->GetPID().Unbox(), + npc->GetActor() ? npc->GetActor()->GetEID().Unbox() : 0, + npc->GetName(), + (npc->GetActor()?"Entity":"None "), + (npc->IsAlive()?"Alive":"Dead"), + (npc->GetBrain()?npc->GetBrain()->GetName():""), + (npc->GetCurrentBehavior()?npc->GetCurrentBehavior()->GetName():""), + npc->GetOwnerName(), + npc->GetTribeMemberType() + ); + } + + // Print Resources + CPrintf(CON_CMDOUTPUT,"Resources:\n"); + CPrintf(CON_CMDOUTPUT,"%7s %-20s %7s\n","ID","Name","Amount"); + for (size_t r = 0; r < tribes[i]->GetResourceCount(); r++) + { + CPrintf(CON_CMDOUTPUT,"%7d %-20s %d\n", + tribes[i]->GetResource(r).id, + tribes[i]->GetResource(r).name.GetData(), + tribes[i]->GetResource(r).amount); + } + + // Print Memories CPrintf(CON_CMDOUTPUT,"Memories:\n"); CPrintf(CON_CMDOUTPUT,"%7s %-20s Position Radius %-20s %-20s\n","ID","Name","Sector","Private to NPC"); csList<Tribe::Memory*>::Iterator it = tribes[i]->GetMemoryIterator(); @@ -1508,14 +1617,34 @@ (memory->sector?memory->sector->QueryObject()->GetName():""), name.GetDataSafe()); } - } // End print Memeories scope - CPrintf(CON_CMDOUTPUT,"Needs:\n"); - tribes[i]->DumpNeeds(); + // Print Recipe List + tribes[i]->DumpRecipesToConsole(); + + // Print Knowledge + tribes[i]->DumpKnowledge(); + + // Print Assets + tribes[i]->DumpAssets(); + } + return; } } + } +void psNPCClient::ListTribeRecipes(const char* tribeID) +{ + int tribeid = atoi(tribeID); + for(int i=0;i<tribes.GetSize();i++) + { + if(tribeid == tribes[i]->GetID()) + tribes[i]->DumpRecipesToConsole(); + return; + } + CPrintf(CON_CMDOUTPUT, "No Tribe with id '%d' found.\n", tribeID); +} + void psNPCClient::ListWaypoints(const char * pattern) { pathNetwork->ListWaypoints(pattern); Modified: trunk/src/npcclient/npcclient.h =================================================================== --- trunk/src/npcclient/npcclient.h 2011-12-18 18:29:42 UTC (rev 7842) +++ trunk/src/npcclient/npcclient.h 2011-12-18 23:15:24 UTC (rev 7843) @@ -47,6 +47,7 @@ class MsgHandler; class psNetConnection; class EventManager; +class RecipeManager; class NetworkManager; class NPCType; class NPC; @@ -108,6 +109,11 @@ { return objreg; } /** + * Make a tribe pointer available - for the network manager + */ + Tribe* GetTribe(int id); + + /** * Load and fork off a new thread for the Server Console. Then start * EventManager's main loop, processing all network and server events. */ @@ -366,6 +372,11 @@ * List all tribes matching pattern to console. */ void ListTribes(const char* pattern); + + /** + * List all the active recipes in a tribe + */ + void ListTribeRecipes(const char* tribeID); /** * List all waypoints matching pattern to console. @@ -500,25 +511,42 @@ */ csRef<iDocumentNode> GetRootNode(const char* xmlfile); + /** Add an NPCType + * + * Upon loading a tribe, the Recipe Manager creates a NPCType and + * uses this method to Put the assembled npctype into the npctypes map. + * + * @param newType String containing the npctype in xml format. + * @return False if any error is encountered, true otherwise. + */ + bool AddNPCType(csString newType); + bool LoadNPCTypes(iDocumentNode* root); + bool LoadNPCTypes(); - -protected: - bool ReadNPCsFromDatabase(); + /** Fire perception + * + * Method used by the console command 'fireperc'. + * It fires a perception on the given npc. + * + * @param NPCId NPC on which to fire perc + * @param perception The perception to fire + * @return True if npc is found and perception is sent. False otherwise (doh!) + */ + bool FirePerception(int NPCId, const char* perception); -public: - // has to be public as the networkmanager has to call it + // made public for the networkmanager to call it bool LoadPathNetwork(); + +protected: -protected: + bool ReadNPCsFromDatabase(); bool LoadLocations(); - + /** Load Tribes from db */ bool LoadTribes(); - -protected: /** * Find all items that are close to NPC's and percept the * NPC. @@ -540,6 +568,7 @@ csRef<MsgHandler> msghandler; ServerConsole* serverconsole; EventManager* eventmanager; + RecipeManager* recipemanager; NetworkManager* network; psDatabase* database; csRef<iVFS> vfs; Modified: trunk/src/npcclient/npcoperations.cpp =================================================================== --- trunk/src/npcclient/npcoperations.cpp 2011-12-18 18:29:42 UTC (rev 7842) +++ trunk/src/npcclient/npcoperations.cpp 2011-12-18 23:15:24 UTC (rev 7843) @@ -696,6 +696,14 @@ return OPERATION_FAILED; // This operation is complete } + /* + printf("ZeeDebug: MoveOp status \n"); + printf("ZeeDebug: myPos: %f,%f,%f\n", myPos[0], myPos[1], myPos[2]); + printf("ZeeDebug: mySector: %s\n", mySector->QueryObject()->GetName()); + printf("ZeeDebug: endPos: %f,%f,%f\n", endPos[0], endPos[1], endPos[2]); + printf("ZeeDebug: endSector: %s\n", endSector->QueryObject()->GetName()); + */ + // TODO -- Find reason and fix this mess path = npcclient->ShortestPath(npc, myPos,mySector,endPos,endSector); if(!path || !path->HasNext()) @@ -1423,13 +1431,27 @@ ScriptOperation::OperationResult DigOperation::Run(NPC *npc, EventManager *eventmgr, bool interrupted) { - if (resource == "tribe:wealth") + if(resource == "tribe:wealth") { if (npc->GetTribe()) { npcclient->GetNetworkMgr()->QueueDigCommand(npc->GetActor(), npc->GetTribe()->GetNeededResourceNick()); } } + else if(resource == "ownBuffer") + { + // To get the resource name we first try the npc buffer + csString nick = npc->GetBuffer(); + + if(nick == "new mi... [truncated message content] |