From: <ma...@us...> - 2011-12-22 16:48:39
|
Revision: 7879 http://planeshift.svn.sourceforge.net/planeshift/?rev=7879&view=rev Author: magodra Date: 2011-12-22 16:48:30 +0000 (Thu, 22 Dec 2011) Log Message: ----------- - Added scripting for two different tribes. Did modifications to server to allow different recipes for each tribe. Modified Paths: -------------- trunk/src/npcclient/recipe.cpp trunk/src/npcclient/recipe.h trunk/src/server/database/mysql/item_stats.sql trunk/src/server/database/mysql/tribe_recipes.sql trunk/src/server/database/mysql/tribes.sql Modified: trunk/src/npcclient/recipe.cpp =================================================================== --- trunk/src/npcclient/recipe.cpp 2011-12-22 16:45:18 UTC (rev 7878) +++ trunk/src/npcclient/recipe.cpp 2011-12-22 16:48:30 UTC (rev 7879) @@ -72,6 +72,8 @@ } } unparsedReq.SplitString(row["requirements"], ";"); + // Assuming that requirements end with ; the last will be + // empty. Delete last empty index. unparsedReq.DeleteIndex(unparsedReq.GetSize() - 1); // Parse Requirements @@ -86,15 +88,20 @@ explodedReq.SplitString(unparsedReq.Get(i), "(,)"); Requirement newReq; reqText = explodedReq.Get(0); + + // Flags used to check parameters + bool recipeRequired = false; // And check its contents if(reqText == "tribesman") { newReq.type = REQ_TYPE_TRIBESMAN; + recipeRequired = true; } else if(reqText == "resource") { newReq.type = REQ_TYPE_RESOURCE; + recipeRequired = true; } else if(reqText == "item") { @@ -115,6 +122,7 @@ else if(reqText == "memory") { newReq.type = REQ_TYPE_MEMORY; + recipeRequired = true; } else { @@ -124,6 +132,17 @@ newReq.name = explodedReq.Get(1); newReq.quantity = explodedReq.Get(2); + if (explodedReq.GetSize() > 3) + { + newReq.recipe = explodedReq.Get(3); + } + else if (recipeRequired) + { + // We requried a recipe, but none where given. + Error3("Recipe %s requirements require recipe: %s", name.GetDataSafe(), explodedReq.Get(0)); + return false; + } + requirements.Push(newReq); } @@ -370,16 +389,16 @@ } else if(functionBody == "locateMemory" || functionBody == "locateResource") { - if(argSize != 1) + if(argSize != 2) { - DumpError(recipe->GetName(), functionBody.GetData(), 1, argSize); + DumpError(recipe->GetName(), functionBody.GetData(), 2, argSize); return false; } if(!tribe->LoadNPCMemoryBuffer(functionArguments.Get(0), npcs)) { // No such memory, then explore for it. tribe->SetBuffer("Buffer", functionArguments.Get(0)); - tribe->AddRecipe(GetRecipe("Explore"), recipe); + tribe->AddRecipe(GetRecipe(functionArguments.Get(1)), recipe); return false; } return true; @@ -603,8 +622,9 @@ { // Start ... erm... cell-dividing :) tribe->SetBuffer("Buffer", name); - tribe->AddRecipe(GetRecipe("mate"), recipe); + tribe->AddRecipe(GetRecipe(requirement.recipe), recipe); } + /* Shouldn't this be done by the requiements for mate else if(tribe->ShouldGrow()) { // Gather more resources @@ -619,6 +639,7 @@ tribe->AddRecipe(GetRecipe("Gather Resource"), recipe); } } + */ return false; } else if(requirement.type == REQ_TYPE_RESOURCE) @@ -630,15 +651,7 @@ // TODO -- Check to see if resource is diggable or gatherable tribe->SetBuffer("Buffer", name); - bool digable = true; // Provisional TODO - if(digable) - { - tribe->AddRecipe(GetRecipe("Dig Resource"), recipe); - } - else - { - tribe->AddRecipe(GetRecipe("Gather Resource"), recipe); - } + tribe->AddRecipe(GetRecipe(requirement.recipe), recipe); return false; } @@ -675,11 +688,11 @@ // We'll have to run a pre-check to check for unprospected // mines in case we need an ore we don't know - if(tribe->FindMemory("mine")) + if(tribe->FindMemory(requirement.quantity)) return true; // Explore for not found memory - tribe->AddRecipe(GetRecipe("Explore"), recipe); + tribe->AddRecipe(GetRecipe(requirement.recipe), recipe); return false; } else @@ -707,13 +720,13 @@ reaction = "<react event=\"attack\" behavior=\"aggressive_meet\" delta=\"150\" />"; assembledType += reaction; } - else if(currentTribe->aggressivity == "pacifist") + else if(currentTribe->aggressivity == "neutral") { reaction = "<react event=\"player nearby\" behavior=\"peace_meet\" delta=\"100\" />\n"; reaction += "<react event=\"attack\" behavior=\"normal_attacked\" delta=\"150\" />"; assembledType += reaction; } - else if(currentTribe->aggressivity == "coward") + else if(currentTribe->aggressivity == "peaceful") { reaction = "<react event=\"player nearby\" behavior=\"peace_meet\" delta=\"100\" />\n"; reaction += "<react event=\"attack\" behavior=\"coward_attacked\" delta=\"100\" />\n"; Modified: trunk/src/npcclient/recipe.h =================================================================== --- trunk/src/npcclient/recipe.h 2011-12-22 16:45:18 UTC (rev 7878) +++ trunk/src/npcclient/recipe.h 2011-12-22 16:48:30 UTC (rev 7879) @@ -70,6 +70,7 @@ int type; ///< Type. Can be workforce, resource, item, knowledge csString name; ///< Name of the requirement. csString quantity; ///< Number needed. + csString recipe; ///< If requirement isn't meet use this recipe to get it. }; /** Construct a Recipe object */ Modified: trunk/src/server/database/mysql/item_stats.sql =================================================================== --- trunk/src/server/database/mysql/item_stats.sql 2011-12-22 16:45:18 UTC (rev 7878) +++ trunk/src/server/database/mysql/item_stats.sql 2011-12-22 16:48:30 UTC (rev 7879) @@ -268,6 +268,7 @@ INSERT INTO `item_stats` VALUES (4815,'B','Forge',99999.00,100.00,1,50,16,'BULK','CONTAINER CANTRANSFORM',0.10,4,-1,-1,'0','0','0',0.00,0.00,0.00,0.00,1.00,0.00,2.10,1.00,0.20,0.20,0.20,0.00,'items#chest','/planeshift/items/chest.dds','','','','','0',6,5000.00,'TOOL','',0.00,'',0.00,'',0.00,'0',0,0.0000,0,0,0,1,'A standard smith forge used to heat metal so it is malleable.','nosound',50,'',NULL,NULL,-1,2,"",'Y'); INSERT INTO `item_stats` VALUES (4816,'B','Hammer',3.00,100.00,3,50,0,'BULK LEFTHAND RIGHTHAND','STACKABLE',0.10,4,-1,-1,'0','0','0',0.00,0.00,0.00,0.00,1.00,0.00,2.10,1.00,0.20,0.20,0.20,0.00,'weapons#doubleaxe01a','/planeshift/weapons/doubleaxe01a_icon.dds','','','','','Hammer',6,50.00,'TOOL','',0.00,'',0.00,'',0.00,'0',0,0.0000,0,0,0,1,'A simple smith hammer.','nosound',50,'',NULL,NULL,-1,2,"",'Y'); INSERT INTO `item_stats` VALUES (236,'B','Quiver',1.00,100.00,1,20,16,'BULK LEFTHAND RIGHTHAND','CONTAINER',0.10,-1,-1,-1,'0','0','0',0.00,0.00,0.00,0.00,1.00,0.00,2.10,1.00,0.20,0.20,0.20,0.00,'potions#potion01a','/planeshift/potions/smallpotion01a_icon.dds','','','','','0',3,4.00,'GENERIC','',0.00,'',0.00,'',0.00,'0',0,0.0000,0,0,0,1,'A Quiver','nosound',50,'','','',-1,2,"",'Y'); +INSERT INTO `item_stats` VALUES (7074,'B','Small Tent',30.000,100.00,150.000,0,0,'BULK','STACKABLE',0.01,-1,-1,-1,'0','0','0',0.00,0.00,0.00,0.00,1.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,'items#tentsmall_01','/planeshift/materials/food_generic01a_icon.dds','','','','','0',28,1000.00,'GENERIC','NULL',0.00,'NULL',0.00,'NULL',0.00,'0',0,0.0000,0,0,0,1,'A small tent','nosound',100,'','','',-1,2,'','Y'); INSERT INTO `item_stats` VALUES (7331,'B','Torch',8.00,5.00,80,0,0,'BULK LEFTHAND RIGHTHAND','STACKABLE',0.10,0,-1,-1,'0','0','0',0.00,0.00,0.00,9.00,0.00,0.00,4.00,2.00,0.20,0.20,0.20,0.00,'items#torch','/planeshift/items/torch.png','','','','','Torch',1,550.00,'TOOL','',0.00,'',0.00,'',0.00,'0',0,0.0000,0,0,0,1,'A torch to light your way.','env.fire_small',50,'',NULL,NULL,-1,2,"",'Y'); INSERT INTO `item_stats` VALUES (7332,'B','Campfire',8.00,5.00,80,0,0,'BULK','STACKABLE',0.10,0,-1,-1,'0','0','0',0.00,0.00,0.00,9.00,0.00,0.00,4.00,2.00,0.20,0.20,0.20,0.00,'items#campfire01a','/planeshift/items/campfire01a.dds','','','','','Campfire',1,550.00,'TOOL','',0.00,'',0.00,'',0.00,'0',0,0.0000,0,0,0,1,'A camp fire to keep you warm at night.','env.fire_medium',50,'',NULL,NULL,-1,2,"",'Y'); INSERT INTO `item_stats` VALUES (4001,'B','Red Paperclip',10.00,5.00,1,0,0,'BULK,RIGHTHAND,LEFTHAND','STACKABLE',0.10,-1,-1,-1,'0','0','0',0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,'weapons#doubleaxe01a','/planeshift/weapons/doubleaxe01a_icon.dds','','','','','0',7,50.00,'GENERIC','',0.00,'',0.00,'',0.00,'0',0,0.0000,0,0,0,0,'0','nosound',50,'',NULL,NULL,-1,2,"",'Y'); Modified: trunk/src/server/database/mysql/tribe_recipes.sql =================================================================== --- trunk/src/server/database/mysql/tribe_recipes.sql 2011-12-22 16:45:18 UTC (rev 7878) +++ trunk/src/server/database/mysql/tribe_recipes.sql 2011-12-22 16:48:30 UTC (rev 7879) @@ -23,26 +23,41 @@ # the sources. # -INSERT INTO `tribe_recipes` VALUES (1, 'Explore', 'tribesman(any,1);', 'select(any,1);explore();', 0, 0); -INSERT INTO `tribe_recipes` VALUES (2, 'Dig Resource', 'memory(BUFFER);tribesman(miner,1);', 'select(any,1);locateResource(BUFFER);mine();', 0, 0); -INSERT INTO `tribe_recipes` VALUES (3, 'Gather Resource', 'memory(BUFFER);tribesman(gatherer,1);', 'select(any,1);locateResource(BUFFER);gather();', 0, 0); -INSERT INTO `tribe_recipes` VALUES (4, 'mate', 'resource(REPRODUCTION_RESOURCE,REPRODUCTION_COST);tribesman(any,1);', 'select(any,1);mate();alterResource(REPRODUCTION_RESOURCE, -REPRODUCTION_COST);', 0 , 0); +INSERT INTO `tribe_recipes` VALUES (1, 'Do Nothing', '', 'wait(100);', 1,1); -# Tribal Recipes +INSERT INTO `tribe_recipes` VALUES (10, 'Miner Explore', 'tribesman(Miner,1);', 'select(Miner,1);explore();', 0, 0); +INSERT INTO `tribe_recipes` VALUES (11, 'Hunter Explore', 'tribesman(Hunter,1);', 'select(Hunter,1);explore();', 0, 0); -INSERT INTO `tribe_recipes` VALUES (5, 'tribe_mining', ' ', 'brain(civilised);aggressivity(pacifist);growth(conservatory);unity(organised);loadRecipe(do nothing);loadRecipe(evolve,distributed);loadRecipe(Miners Tribe Spots);', 1, 1); +INSERT INTO `tribe_recipes` VALUES (20, 'Dig Resource', 'memory(BUFFER,mine,Miner Explore);tribesman(Miner,1);', 'select(Miner,1);locateResource(BUFFER,Miner Explore);mine();', 0, 0); +INSERT INTO `tribe_recipes` VALUES (21, 'Hunt Resource', 'memory(BUFFER,hunting_ground,Hunter Explore);tribesman(Hunter,1);', 'select(Hunter,1);locateResource(BUFFER,Hnter Explore);gather();', 0, 0); + +INSERT INTO `tribe_recipes` VALUES (30, 'Miner Mate', 'resource(REPRODUCTION_RESOURCE,REPRODUCTION_COST,Dig Resource);tribesman(any,1);', 'select(any,1);mate();alterResource(REPRODUCTION_RESOURCE, -REPRODUCTION_COST);', 0 , 0); +INSERT INTO `tribe_recipes` VALUES (31, 'Hunter Mate', 'resource(REPRODUCTION_RESOURCE,REPRODUCTION_COST,Hunt Resource);tribesman(any,1);', 'select(any,1);mate();alterResource(REPRODUCTION_RESOURCE, -REPRODUCTION_COST);', 0 , 0); + # Spot Recipe -INSERT INTO `tribe_recipes` VALUES (7, 'Miners Tribe Spots', '', 'reserveSpot(-77,0,-189,campfire);reserveSpot(-90,0,-190,door);reserveSpot(-77,0,-208,campfire);reserveSpot(-80,0,-205,torch);reserveSpot(-70,0,-205,torch);reserveSpot(-70,0,-212,torch);reserveSpot(-80,0,-212,torch);reserveSpot(-49,0,-203,door);reserveSpot(-52,0,-174,campfire);reserveSpot(-67,0,-147,door);reserveSpot(-47,0,-140,campfire);', 0, 0); +INSERT INTO `tribe_recipes` VALUES (40, 'Miners Tribe Spots', '', 'reserveSpot(-77,0,-189,Campfire);reserveSpot(-90,0,-190,Tent);reserveSpot(-77,0,-208,Tent);reserveSpot(-80,0,-205,Tent);', 0, 0); +INSERT INTO `tribe_recipes` VALUES (41, 'Hunting Tribe Spots', '', 'reserveSpot(-70,0,-205,Campfire);reserveSpot(-70,0,-212,Campfire);reserveSpot(-80,0,-212,Tent);reserveSpot(-49,0,-203,Tent);reserveSpot(-52,0,-174,Tent);reserveSpot(-67,0,-147,Tent);reserveSpot(-47,0,-140,Tent);', 0, 0); + + # Upkeep -INSERT INTO `tribe_recipes` VALUES (8, 'upkeep', 'resource(REPRODUCTION_RESOURCE,10);', 'alterResource(REPRODUCTION_RESOURCE,-10);', 1, 1); +INSERT INTO `tribe_recipes` VALUES (50, 'Mining Upkeep', 'resource(REPRODUCTION_RESOURCE,10,Dig Resource);', 'alterResource(REPRODUCTION_RESOURCE,-10);', 1, 1); +INSERT INTO `tribe_recipes` VALUES (51, 'Hunting Upkeep', 'resource(REPRODUCTION_RESOURCE,10,Hunt Resource);', 'alterResource(REPRODUCTION_RESOURCE,-10);', 1, 1); -# Buildings -INSERT INTO `tribe_recipes` VALUES (9, 'campfire', 'tribesman(any,1);resource(Coal,10);', 'select(any,1);locateBuildingSpot(campfire);goWork(100);wait(100);addBuilding(campfire);alterResource(Coal,10);', 0, 0); -INSERT INTO `tribe_recipes` VALUES (10, 'door', 'tribesman(any,1);resource(Tin Ore,15);', 'select(any,1);locateBuildingSpot(door);goWork(150);wait(150);addBuilding(door);alterResource(Tin Ore,15);', 0, 0); -INSERT INTO `tribe_recipes` VALUES (11, 'torch', 'tribesman(any,1);resource(Coal Ore,5);resource(Tin Ore,5);', 'select(any,1);locateBuildingSpot(torch);goWork(50);wait(50);addBuilding(torch);alterResource(Tin Ore,5);alterResource(Coal Ore,5);', 0, 0); +# +INSERT INTO `tribe_recipes` VALUES (60, 'Mining Campfire', 'tribesman(Miner,1);resource(Coal,10,Dig Resource);', 'select(Miner,1);locateBuildingSpot(Campfire);goWork(100);wait(100);addBuilding(Campfire);alterResource(Coal,10);', 0, 0); +INSERT INTO `tribe_recipes` VALUES (61, 'Mining Tent', 'tribesman(Miner,1);resource(Skin,15,Buy Skin);', 'select(Miner,1);locateBuildingSpot(Tent);goWork(150);wait(150);addBuilding(Small Tent);alterResource(Skin,15);', 0, 0); +INSERT INTO `tribe_recipes` VALUES (70, 'Hunter Campfire', 'tribesman(Hunter,1);resource(Coal,10,Buy Coal);', 'select(Miner,1);locateBuildingSpot(Campfire);goWork(100);wait(100);addBuilding(Campfire);alterResource(Coal,10);', 0, 0); +INSERT INTO `tribe_recipes` VALUES (71, 'Hunter Tent', 'tribesman(Hunter,1);resource(Skin,15,Hunt Resource);', 'select(Miner,1);locateBuildingSpot(Tent);goWork(150);wait(150);addBuilding(Small Tent);alterResource(Skin,15);', 0, 0); + + # Targets ~ Missions -INSERT INTO `tribe_recipes` VALUES (12, 'do nothing', '', 'wait(100);', 1,1); -INSERT INTO `tribe_recipes` VALUES (13, 'evolve', 'tribesman(number,50);resource(Coal,150);resource(Gold Ore,200);resource(Tin Ore,150);resource(Silver Ore,50);resource(Platinum Ore,50);item(campfire,4);item(torch,4);item(door,2);', 'wait(1000);', 0, 0); +INSERT INTO `tribe_recipes` VALUES (90, 'Evolve Mining Tribe', 'tribesman(number,16,Miner Mate);resource(Coal,150,Dig Resource);resource(Gold Ore,200,Dig Resource);item(Campfire,2);item(Tent,8);', 'wait(1000);', 0, 0); +INSERT INTO `tribe_recipes` VALUES (91, 'Evolve Hunting Tribe', 'tribesman(number,4,Hunter Mate);resource(Skin,150,Hunt Resource);resource(Meat,200,Hunt Resource);item(Campfire,1);item(Tent,2);', 'wait(1000);', 0, 0); + +# Tribal Recipes + +INSERT INTO `tribe_recipes` VALUES (100, 'Mining Tribe', ' ', 'brain(civilised);aggressivity(peaceful);growth(conservatory);unity(organised);loadRecipe(Do Nothing);loadRecipe(Evolve Mining Tribe,distributed);loadRecipe(Miners Tribe Spots);', 1, 1); +INSERT INTO `tribe_recipes` VALUES (101, 'Hunting Tribe', ' ', 'brain(civilised);aggressivity(neutral);growth(conservatory);unity(organised);loadRecipe(Do Nothing);loadRecipe(Evolve Hunting Tribe,distributed);loadRecipe(Miners Tribe Spots);', 1, 1); Modified: trunk/src/server/database/mysql/tribes.sql =================================================================== --- trunk/src/server/database/mysql/tribes.sql 2011-12-22 16:45:18 UTC (rev 7878) +++ trunk/src/server/database/mysql/tribes.sql 2011-12-22 16:48:30 UTC (rev 7879) @@ -34,5 +34,5 @@ # Dumping data for table characters # -INSERT INTO `tribes` VALUES (1,'Mining tribe',3,-75,0,-180,20,100,'Gold Ore','gold','mine','Dig',1.00,0.0,0,10,'do nothing', 5); -INSERT INTO `tribes` VALUES (2,'Hunting tribe',3,-90,0,-230,5,5,'Flesh','flesh','hunting_ground','Hunt',1.00,0.50,100,60,'do nothing',5); +INSERT INTO `tribes` VALUES (1,'Mining tribe',3,-75,0,-180,20,100,'Gold Ore','gold','mine','Dig',1.00,0.0,0,10,'do nothing', 100); +INSERT INTO `tribes` VALUES (2,'Hunting tribe',3,-90,0,-230,5,5,'Meet','meet','hunting_ground','Hunt',1.00,0.50,100,60,'do nothing', 101); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |