Skip to content

Commit

Permalink
Made farms work.
Browse files Browse the repository at this point in the history
Farm plots have the plants shown as part of the building, rather than
actually as plants. this is both simpler to do, and allows for differing
sprites.
  • Loading branch information
RosaryMala committed Jan 20, 2013
1 parent 21e6f03 commit 67669da
Show file tree
Hide file tree
Showing 10 changed files with 216 additions and 76 deletions.
6 changes: 6 additions & 0 deletions ContentLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ int lookupMaterialIndex(int matType, const char* strValue)
return lookupIndexedType(strValue,contentLoader->inorganic);
} else if (matType == WOOD && !ssConfig.skipOrganicMats) {
return lookupIndexedType(strValue,contentLoader->organic);
} else if (matType == PLANT && !ssConfig.skipOrganicMats) {
return lookupIndexedType(strValue,contentLoader->organic);
} else if (matType == PLANTCLOTH && !ssConfig.skipOrganicMats) {
return lookupIndexedType(strValue,contentLoader->organic);
} else if (matType == LEATHER && !ssConfig.skipCreatureTypes) {
Expand Down Expand Up @@ -447,6 +449,8 @@ const char *lookupMaterialTypeName(int matType)
return "GreenGlass";
case WOOD:
return "Wood";
case PLANT:
return "Plant";
case ICE:
return "Ice";
case CLEAR_GLASS:
Expand Down Expand Up @@ -478,6 +482,8 @@ MAT_BASICS lookupMaterialType(const char* strValue)
return GREEN_GLASS;
} else if( strcmp(strValue, "Wood") == 0) {
return WOOD;
} else if( strcmp(strValue, "Plant") == 0) {
return PLANT;
} else if( strcmp(strValue, "Ice") == 0) {
return ICE;
} else if( strcmp(strValue, "ClearGlass") == 0) {
Expand Down
9 changes: 9 additions & 0 deletions GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,15 @@ void drawDebugCursorAndInfo(WorldSegment * segment)
b->building.info->material.type,b->building.info->material.index,
b->occ.bits.building,
b->building.special);
for(int index = 0; index < b->building.constructed_mats.size(); index++) {
const char* partMatName = lookupMaterialTypeName(b->building.constructed_mats[index].matt.type);
const char* partSubMatName = lookupMaterialName(b->building.constructed_mats[index].matt.type, b->building.constructed_mats[index].matt.index);
draw_textf_border(font, al_map_rgb(255,255,255), 2, (i++*al_get_font_line_height(font)), 0,
"Material[%i]: %s%s%s (%d,%d)",
index,
partMatName?partMatName:"Unknown",partSubMatName?"/":"",partSubMatName?partSubMatName:"",
b->building.constructed_mats[index].matt.type, b->building.constructed_mats[index].matt.index);
}

//if(b->building.custom_building_type != -1)
//{
Expand Down
20 changes: 17 additions & 3 deletions GameBuildings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "BuildingConfiguration.h"
#include "ContentLoader.h"
#include "GUI.h"
#include "MapLoading.h"

#include "df/buildings_other_id.h"
#include "df/building_wellst.h"
Expand Down Expand Up @@ -118,11 +119,11 @@ void ReadBuildings(DFHack::Core& DF, vector<Buildings::t_building>* buildingHold
void MergeBuildingsToSegment(vector<Buildings::t_building>* buildings, WorldSegment* segment)
{
uint32_t numBuildings = (uint32_t)buildings->size();
for(uint32_t i=0; i < numBuildings; i++) {
Buildings::t_building* copiedbuilding = segment->AddBuilding((*buildings)[i]);
for(uint32_t i=0; i < numBuildings; i++) {
Buildings::t_building* copiedbuilding = segment->AddBuilding((*buildings)[i]);

//int bheight = tempbuilding.y2 - tempbuilding.y1;
for(uint32_t yy = copiedbuilding->y1; yy <= copiedbuilding->y2; yy++)
for(uint32_t yy = copiedbuilding->y1; yy <= copiedbuilding->y2; yy++) {
for(uint32_t xx = copiedbuilding->x1; xx <= copiedbuilding->x2; xx++) {
int z2 = copiedbuilding->z;
//if it's a well, add the bucket status.
Expand Down Expand Up @@ -179,6 +180,18 @@ void MergeBuildingsToSegment(vector<Buildings::t_building>* buildings, WorldSegm

df::item * item = Actual_building->contained_items[index]->item;

if(b->building.type == df::enums::building_type::FarmPlot) {
if(item->pos.x == xx && item->pos.y == yy && item->pos.z == zz) {
if(item->getType() == df::enums::item_type::SEEDS) {
b->building.special = 1;
}
else if(item->getType() == df::enums::item_type::PLANT) {
b->building.special = 2;
}
}
else continue;
}

item_matt.matt.type = item->getActualMaterial();
item_matt.matt.index = item->getActualMaterialIndex();

Expand Down Expand Up @@ -207,6 +220,7 @@ void MergeBuildingsToSegment(vector<Buildings::t_building>* buildings, WorldSegm
}
}
}
}
}
}

Expand Down
109 changes: 58 additions & 51 deletions MapLoading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,50 @@ void readMaterialToTile( Tile * b, uint32_t lx, uint32_t ly,
}
}

SS_Item ConvertItem(df::item * found_item, WorldSegment& segment){
SS_Item Tempitem;
Tempitem.item.type = found_item->getType(); //itemtype
Tempitem.item.index = found_item->getSubtype(); //item subtype

Tempitem.matt.type = found_item->getActualMaterial();
Tempitem.matt.index = found_item->getActualMaterialIndex();

if(1) { //found_item->isDyed())
auto Constructed_Item = virtual_cast<df::item_constructed>(found_item);
if(Constructed_Item) {
for(int idex = 0; idex < Constructed_Item->improvements.size(); idex++) {
if(!Constructed_Item->improvements[idex]) {
continue;
}
if(Constructed_Item->improvements[idex]->getType() != improvement_type::THREAD) {
continue;
}
auto Improvement_Thread = virtual_cast<df::itemimprovement_threadst>(Constructed_Item->improvements[idex]);
if(!Improvement_Thread) {
continue;
}
if (Improvement_Thread->dye.mat_type < 0) {
break;
}
Tempitem.dyematt.type = Improvement_Thread->dye.mat_type;
Tempitem.dyematt.index = Improvement_Thread->dye.mat_index;
}
} else if (found_item->getType() == item_type::THREAD) {
auto Thread_Item = virtual_cast<df::item_threadst>(found_item);
if(!Thread_Item) {
return Tempitem;
}
if (Thread_Item->dye_mat_type < 0) {
return Tempitem;
}
Tempitem.dyematt.type = Thread_Item->dye_mat_type;
Tempitem.dyematt.index = Thread_Item->dye_mat_index;
}
}
return Tempitem;
}


/**
* reads one 16x16 map block into stonesense tiles
* attempts to only read as much information as is necessary to do the tile optimization
Expand Down Expand Up @@ -392,57 +436,20 @@ void readBlockToSegment(DFHack::Core& DF, WorldSegment& segment,

//add items
for(auto iter = trueBlock->items.begin(); iter != trueBlock->items.end(); iter++) {
int32_t item_index = *iter;
df::item * found_item = df::item::find(item_index);
if(!found_item) {
continue;
}
Tile* b = segment.getTile( found_item->pos.x, found_item->pos.y, found_item->pos.z);
if(!b) {
b = segment.ResetTile(found_item->pos.x, found_item->pos.y, found_item->pos.z, tiletype::OpenSpace);
if(!b) {
continue;
}
}
b->Item.item.type = found_item->getType(); //itemtype
b->Item.item.index = found_item->getSubtype(); //item subtype

b->Item.matt.type = found_item->getActualMaterial();
b->Item.matt.index = found_item->getActualMaterialIndex();

if(1) { //found_item->isDyed())
auto Constructed_Item = virtual_cast<df::item_constructed>(found_item);
if(Constructed_Item) {
for(int idex = 0; idex < Constructed_Item->improvements.size(); idex++) {
if(!Constructed_Item->improvements[idex]) {
continue;
}
if(Constructed_Item->improvements[idex]->getType() != improvement_type::THREAD) {
continue;
}
auto Improvement_Thread = virtual_cast<df::itemimprovement_threadst>(Constructed_Item->improvements[idex]);
if(!Improvement_Thread) {
continue;
}
if (Improvement_Thread->dye.mat_type < 0) {
break;
}
b->Item.dyematt.type = Improvement_Thread->dye.mat_type;
b->Item.dyematt.index = Improvement_Thread->dye.mat_index;
}
} else if (found_item->getType() == item_type::THREAD) {
auto Thread_Item = virtual_cast<df::item_threadst>(found_item);
if(!Thread_Item) {
break;
}
if (Thread_Item->dye_mat_type < 0) {
break;
}
b->Item.dyematt.type = Thread_Item->dye_mat_type;
b->Item.dyematt.index = Thread_Item->dye_mat_index;
}
}
}
int32_t item_index = *iter;
df::item * found_item = df::item::find(item_index);
if(!found_item) {
continue;
}
Tile* b = segment.getTile( found_item->pos.x, found_item->pos.y, found_item->pos.z);
if(!b) {
b = segment.ResetTile(found_item->pos.x, found_item->pos.y, found_item->pos.z, tiletype::OpenSpace);
if(!b) {
return;
}
}
b->Item = ConvertItem(found_item, segment);
}


//add effects
Expand Down
3 changes: 3 additions & 0 deletions MapLoading.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ void read_segment( void *arg);

extern const VersionInfo *dfMemoryInfo;

struct SS_Item;
SS_Item ConvertItem(df::item * found_item, WorldSegment& segment);

struct segParams {
int x;
int y;
Expand Down
12 changes: 7 additions & 5 deletions Tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ struct worn_item {
worn_item();
};

struct SS_Item {
DFHack::t_matglossPair item;
DFHack::t_matglossPair matt;
DFHack::t_matglossPair dyematt;
};

struct unit_inventory {
//[item_type][item_subtype][item_number]
std::vector<std::vector<std::vector<worn_item>>> item;
Expand Down Expand Up @@ -93,11 +99,7 @@ class Tile
df::flow_type type;
} tileeffect;

struct SS_Item {
DFHack::t_matglossPair item;
DFHack::t_matglossPair matt;
DFHack::t_matglossPair dyematt;
} Item;
SS_Item Item;

struct SS_Building {
DFHack::Buildings::t_building* info;
Expand Down
1 change: 1 addition & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ enum MAT_BASICS {
BLOOD_5 = 43,
BLOOD_6 = 44,
BLOOD_NAMED = 242,
PLANT = 419,
WOOD = 420,
PLANTCLOTH = 421,
};
Expand Down
132 changes: 115 additions & 17 deletions resources/buildings/Farm.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,116 @@
<?xml version="1.0" ?>



<?xml version="1.0"?>
<building name="Farm plot" game_type="FarmPlot">
<if>
<BuildingOccupancy value="2" />
<sprite index = 106 />
</if>
<else>
<BuildingOccupancy value="1" />
<sprite index = 321 />
</else>
<else>
<empty/>
</else>

</building>
<if>
<and>
<BuildingSpecial value="0" />
<BuildingOccupancy value="2" />
</and>
<sprite index="106" />
</if>
<else>
<and>
<BuildingSpecial value="1" />
<BuildingOccupancy value="2" />
</and>
<sprite index="106" />
<sprite index="21" file="farm.png" />
</else>
<else>
<and>
<BuildingSpecial value="2" />
<BuildingOccupancy value="2" />
</and>
<sprite index="106" />
<if>
<MaterialType value="Plant" subtype="MUSHROOM_HELMET_PLUMP" pattern_index="0" />
<sprite index="0" file="farm.png" />
</if>
<else>
<MaterialType value="Plant" subtype="GRASS_TAIL_PIG" pattern_index="0" />
<sprite index="1" file="farm.png" />
</else>
<else>
<MaterialType value="Plant" subtype="GRASS_WHEAT_CAVE" pattern_index="0" />
<sprite index="2" file="farm.png" />
</else>
<else>
<MaterialType value="Plant" subtype="POD_SWEET" pattern_index="0" />
<sprite index="3" file="farm.png" />
</else>
<else>
<MaterialType value="Plant" subtype="BUSH_QUARRY" pattern_index="0" />
<sprite index="4" file="farm.png" />
</else>
<else>
<MaterialType value="Plant" subtype="ROOT_MUCK" pattern_index="0" />
<sprite index="5" file="farm.png" />
</else>
<else>
<MaterialType value="Plant" subtype="TUBER_BLOATED" pattern_index="0" />
<sprite index="6" file="farm.png" />
</else>
<else>
<MaterialType value="Plant" subtype="BULB_KOBOLD" pattern_index="0" />
<sprite index="7" file="farm.png" />
</else>
<else>
<MaterialType value="Plant" subtype="BERRIES_PRICKLE" pattern_index="0" />
<sprite index="8" file="farm.png" />
</else>
<else>
<MaterialType value="Plant" subtype="BERRIES_STRAW_WILD" pattern_index="0" />
<sprite index="9" file="farm.png" />
</else>
<else>
<MaterialType value="Plant" subtype="GRASS_LONGLAND" pattern_index="0" />
<sprite index="10" file="farm.png" />
</else>
<else>
<MaterialType value="Plant" subtype="HERB_VALLEY" pattern_index="0" />
<sprite index="11" file="farm.png" />
</else>
<else>
<MaterialType value="Plant" subtype="WEED_RAT" pattern_index="0" />
<sprite index="12" file="farm.png" />
</else>
<else>
<MaterialType value="Plant" subtype="BERRIES_FISHER" pattern_index="0" />
<sprite index="13" file="farm.png" />
</else>
<else>
<MaterialType value="Plant" subtype="REED_ROPE" pattern_index="0" />
<sprite index="14" file="farm.png" />
</else>
<else>
<MaterialType value="Plant" subtype="MUSHROOM_CUP_DIMPLE" pattern_index="0" />
<sprite index="15" file="farm.png" />
</else>
<else>
<MaterialType value="Plant" subtype="WEED_BLADE" pattern_index="0" />
<sprite index="16" file="farm.png" />
</else>
<else>
<MaterialType value="Plant" subtype="ROOT_HIDE" pattern_index="0" />
<sprite index="17" file="farm.png" />
</else>
<else>
<MaterialType value="Plant" subtype="SLIVER_BARB" pattern_index="0" />
<sprite index="18" file="farm.png" />
</else>
<else>
<MaterialType value="Plant" subtype="BERRY_SUN" pattern_index="0" />
<sprite index="19" file="farm.png" />
</else>
<else>
<MaterialType value="Plant" subtype="VINE_WHIP" pattern_index="0" />
<sprite index="20" file="farm.png" />
</else>
</else>
<else>
<BuildingOccupancy value="0" />
<sprite index="321" />
</else>
<else>
<empty />
</else>
</building>
Binary file added resources/buildings/farm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/objects.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 67669da

Please sign in to comment.