Magma create works

develop
Petr Mrázek 2010-04-06 13:05:54 +02:00
parent ea120a6709
commit d5aa1488a6
6 changed files with 270 additions and 208 deletions

@ -64,20 +64,7 @@ struct t_vein
uint32_t address_of; // this is NOT part of the DF vein, but an address of the vein as seen by DFhack.
};
*/
struct t_vein
{
uint32_t vtable;
int32_t type;
int16_t assignment[16];
uint32_t flags;
uint32_t address_of; // this is NOT part of the DF vein, but an address of the vein as seen by DFhack.
};
// stores what tiles should appear when the ice melts
struct t_frozenliquidvein
{
uint32_t vtable;
int16_t tiles[16][16];
};
struct t_matglossPair
{
@ -121,10 +108,12 @@ struct t_construction_df40d
{
int16_t x;
int16_t y;
// 4
int16_t z;
int16_t unk1;
// 8
int16_t unk2;
t_matglossPair material; // 4B
t_matglossPair material; // C points to the index part
// int16_t mat_type;
// int16_t mat_idx;
};
@ -695,165 +684,6 @@ struct t_itemType
char name[128];
};
enum e_traffic
{
traffic_normal,
traffic_low,
traffic_high,
traffic_restricted
};
enum e_designation
{
designation_no,
designation_default, // dig walls, remove stairs and ramps, gather plants, fell trees
designation_ud_stair, // dig up/down stairs
designation_channel, // dig a channel
designation_ramp, // dig ramp out of a wall
designation_d_stair, // dig a stair down
designation_u_stair, // dig a stair up
designation_7 // whatever
};
enum e_liquidtype
{
liquid_water,
liquid_magma
};
struct naked_designation
{
unsigned int flow_size : 3; // how much liquid is here?
unsigned int pile : 1; // stockpile?
/*
* All the different dig designations... needs more info, probably an enum
*/
e_designation dig : 3;
unsigned int smooth : 2;
unsigned int hidden : 1;
/*
* This one is rather involved, but necessary to retrieve the base layer matgloss index
* see http://www.bay12games.com/forum/index.php?topic=608.msg253284#msg253284 for details
*/
unsigned int geolayer_index :4;
unsigned int light : 1;
unsigned int subterranean : 1; // never seen the light of day?
unsigned int skyview : 1; // sky is visible now, it rains in here when it rains
/*
* Probably similar to the geolayer_index. Only with a different set of offsets and different data.
* we don't use this yet
*/
unsigned int biome : 4;
/*
* 0 = water
* 1 = magma
*/
e_liquidtype liquid_type : 1;
unsigned int water_table : 1; // srsly. wtf?
unsigned int rained : 1; // does this mean actual rain (as in the blue blocks) or a wet tile?
e_traffic traffic : 2; // needs enum
unsigned int flow_forbid : 1; // what?
unsigned int liquid_static : 1;
unsigned int moss : 1;// I LOVE MOSS
unsigned int feature_present : 1; // another wtf... is this required for magma pipes to work?
unsigned int liquid_character : 2; // those ripples on streams?
};
union t_designation
{
uint32_t whole;
naked_designation bits;
};
// occupancy flags (rat,dwarf,horse,built wall,not build wall,etc)
struct naked_occupancy
{
unsigned int building : 3;// building type... should be an enum?
// 7 = door
unsigned int unit : 1;
unsigned int unit_grounded : 1;
unsigned int item : 1;
// splatter. everyone loves splatter.
unsigned int mud : 1;
unsigned int vomit :1;
unsigned int broken_arrows_color :4;
unsigned int blood_g : 1;
unsigned int blood_g2 : 1;
unsigned int blood_b : 1;
unsigned int blood_b2 : 1;
unsigned int blood_y : 1;
unsigned int blood_y2 : 1;
unsigned int blood_m : 1;
unsigned int blood_m2 : 1;
unsigned int blood_c : 1;
unsigned int blood_c2 : 1;
unsigned int blood_w : 1;
unsigned int blood_w2 : 1;
unsigned int blood_o : 1;
unsigned int blood_o2 : 1;
unsigned int slime : 1;
unsigned int slime2 : 1;
unsigned int blood : 1;
unsigned int blood2 : 1;
unsigned int broken_arrows_variant : 1;
unsigned int snow : 1;
};
struct naked_occupancy_grouped
{
unsigned int building : 3;// building type... should be an enum?
// 7 = door
unsigned int unit : 1;
unsigned int unit_grounded : 1;
unsigned int item : 1;
// splatter. everyone loves splatter.
unsigned int splatter : 26;
};
union t_occupancy
{
uint32_t whole;
naked_occupancy bits;
naked_occupancy_grouped unibits;
};
// map block flags
struct naked_blockflags
{
unsigned int designated : 1;// designated for jobs (digging and stuff like that)
unsigned int unk_1 : 1; // possibly related to the designated flag
// two flags required for liquid flow. no idea why
unsigned int liquid_1 : 1;
unsigned int liquid_2 : 1;
unsigned int unk_2: 28; // rest of the flags is completely unknown
// there's a possibility that this flags field is shorter than 32 bits
};
union t_blockflags
{
uint32_t whole;
naked_blockflags bits;
};
typedef int16_t tiletypes40d [16][16];
typedef DFHack::t_designation designations40d [16][16];
typedef DFHack::t_occupancy occupancies40d [16][16];
typedef uint8_t biome_indices40d [16];
typedef struct
{
tiletypes40d tiletypes;
designations40d designation;
occupancies40d occupancy;
// really a '7', but I use 8 to make it neater :)
biome_indices40d biome_indices;
uint32_t origin; // the address where it came from
t_blockflags blockflags;
} mapblock40d;
struct t_viewscreen
{
int32_t type;

@ -1,12 +1,194 @@
/*******************************************************************************
M A P S
Read and write DF's map
*******************************************************************************/
#ifndef CL_MOD_MAPS
#define CL_MOD_MAPS
#include "Export.h"
/*
* Maps: Read and write DF's map
*/
namespace DFHack
{
/***************************************************************************
T Y P E S
***************************************************************************/
struct t_vein
{
uint32_t vtable;
int32_t type;
int16_t assignment[16];
uint32_t flags;
uint32_t address_of; // this is NOT part of the DF vein, but an address of the vein as seen by DFhack.
};
// stores what tiles should appear when the ice melts
struct t_frozenliquidvein
{
uint32_t vtable;
int16_t tiles[16][16];
};
enum e_traffic
{
traffic_normal,
traffic_low,
traffic_high,
traffic_restricted
};
enum e_designation
{
designation_no,
designation_default, // dig walls, remove stairs and ramps, gather plants, fell trees
designation_ud_stair, // dig up/down stairs
designation_channel, // dig a channel
designation_ramp, // dig ramp out of a wall
designation_d_stair, // dig a stair down
designation_u_stair, // dig a stair up
designation_7 // whatever
};
enum e_liquidtype
{
liquid_water,
liquid_magma
};
struct naked_designation
{
unsigned int flow_size : 3; // how much liquid is here?
unsigned int pile : 1; // stockpile?
/*
* All the different dig designations... needs more info, probably an enum
*/
e_designation dig : 3;
unsigned int smooth : 2;
unsigned int hidden : 1;
/*
* This one is rather involved, but necessary to retrieve the base layer matgloss index
* see http://www.bay12games.com/forum/index.php?topic=608.msg253284#msg253284 for details
*/
unsigned int geolayer_index :4;
unsigned int light : 1;
unsigned int subterranean : 1; // never seen the light of day?
unsigned int skyview : 1; // sky is visible now, it rains in here when it rains
/*
* Probably similar to the geolayer_index. Only with a different set of offsets and different data.
* we don't use this yet
*/
unsigned int biome : 4;
/*
* 0 = water
* 1 = magma
*/
e_liquidtype liquid_type : 1;
unsigned int water_table : 1; // srsly. wtf?
unsigned int rained : 1; // does this mean actual rain (as in the blue blocks) or a wet tile?
e_traffic traffic : 2; // needs enum
unsigned int flow_forbid : 1; // what?
unsigned int liquid_static : 1;
unsigned int moss : 1;// I LOVE MOSS
unsigned int feature_present : 1; // another wtf... is this required for magma pipes to work?
unsigned int liquid_character : 2; // those ripples on streams?
};
union t_designation
{
uint32_t whole;
naked_designation bits;
};
// occupancy flags (rat,dwarf,horse,built wall,not build wall,etc)
struct naked_occupancy
{
unsigned int building : 3;// building type... should be an enum?
// 7 = door
unsigned int unit : 1;
unsigned int unit_grounded : 1;
unsigned int item : 1;
// splatter. everyone loves splatter.
unsigned int mud : 1;
unsigned int vomit :1;
unsigned int broken_arrows_color :4;
unsigned int blood_g : 1;
unsigned int blood_g2 : 1;
unsigned int blood_b : 1;
unsigned int blood_b2 : 1;
unsigned int blood_y : 1;
unsigned int blood_y2 : 1;
unsigned int blood_m : 1;
unsigned int blood_m2 : 1;
unsigned int blood_c : 1;
unsigned int blood_c2 : 1;
unsigned int blood_w : 1;
unsigned int blood_w2 : 1;
unsigned int blood_o : 1;
unsigned int blood_o2 : 1;
unsigned int slime : 1;
unsigned int slime2 : 1;
unsigned int blood : 1;
unsigned int blood2 : 1;
unsigned int broken_arrows_variant : 1;
unsigned int snow : 1;
};
struct naked_occupancy_grouped
{
unsigned int building : 3;// building type... should be an enum?
// 7 = door
unsigned int unit : 1;
unsigned int unit_grounded : 1;
unsigned int item : 1;
// splatter. everyone loves splatter.
unsigned int splatter : 26;
};
union t_occupancy
{
uint32_t whole;
naked_occupancy bits;
naked_occupancy_grouped unibits;
};
// map block flags
struct naked_blockflags
{
unsigned int designated : 1;// designated for jobs (digging and stuff like that)
unsigned int unk_1 : 1; // possibly related to the designated flag
// two flags required for liquid flow. no idea why
unsigned int liquid_1 : 1;
unsigned int liquid_2 : 1;
unsigned int unk_2: 28; // rest of the flags is completely unknown
// there's a possibility that this flags field is shorter than 32 bits
};
union t_blockflags
{
uint32_t whole;
naked_blockflags bits;
};
typedef int16_t tiletypes40d [16][16];
typedef DFHack::t_designation designations40d [16][16];
typedef DFHack::t_occupancy occupancies40d [16][16];
typedef uint8_t biome_indices40d [16];
typedef struct
{
tiletypes40d tiletypes;
designations40d designation;
occupancies40d occupancy;
// really a '7', but I use 8 to make it neater :)
biome_indices40d biome_indices;
uint32_t origin; // the address where it came from
t_blockflags blockflags;
} mapblock40d;
/***************************************************************************
C L I E N T M O D U L E
***************************************************************************/
class APIPrivate;
struct t_viewscreen;
class DFHACK_EXPORT Maps

@ -6,6 +6,7 @@
#include <vector>
#include <sstream>
#include <ctime>
#include <cstdio>
using namespace std;
#include <DFTypes.h>
@ -13,6 +14,7 @@ using namespace std;
#include <DFProcess.h>
#include <DFMemInfo.h>
#include <DFVector.h>
#include <DFTypes.h>
void DumpObjStr0Vector (const char * name, DFHack::Process *p, uint32_t addr)
{
@ -25,7 +27,18 @@ void DumpObjStr0Vector (const char * name, DFHack::Process *p, uint32_t addr)
}
cout << endl;
}
void DumpObjVtables (const char * name, DFHack::Process *p, uint32_t addr)
{
cout << "----==== " << name << " ====----" << endl;
DFHack::DfVector vect(p,addr,4);
for(int i = 0; i < vect.getSize();i++)
{
uint32_t addr = *(uint32_t *) vect[i];
uint32_t vptr = p->readDWord(addr);
cout << p->readClassName(vptr) << endl;
}
cout << endl;
}
void DumpDWordVector (const char * name, DFHack::Process *p, uint32_t addr)
{
cout << "----==== " << name << " ====----" << endl;
@ -63,11 +76,41 @@ int main (int numargs, const char ** args)
DFHack::Process* p = DF.getProcess();
DFHack::memory_info* mem = DF.getMemoryInfo();
//const vector<string> * names = mem->getClassIDMapping();
/*
string name="Stuff";
cout << "----==== " << name << " ====----" << endl;
DFHack::DfVector vect(p,0x165b290,4);
for(int i = 0; i < vect.getSize();i++)
{
uint32_t addr = *(uint32_t *) vect[i];
DFHack::t_construction_df40d constr;
DF.ReadRaw(addr, sizeof(constr), (uint8_t *) &constr);
printf("0x%x %dX %dY %dZ: %d:%d\n", addr, constr.x, constr.y, constr.z,
constr.material.type,constr.material.index);
}
DumpObjStr0Vector("Material templates",p, mem->getAddress("mat_templates"));
cout << endl;
*/
/*
DumpObjVtables("Constructions?",p,0x165b278);
DumpObjVtables("Constructions?",p,0x166edb8);
*/
/*
DumpObjStr0Vector("Material templates",p, mem->getAddress("mat_templates"));
*/
DumpObjStr0Vector("Inorganics",p, mem->getAddress("mat_inorganics"));
cout << "----==== Inorganics ====----" << endl;
DFHack::DfVector vect(p,addr,4);
for(int i = 0; i < vect.getSize();i++)
{
uint32_t addr = *(uint32_t *) vect[i];
cout << p->readSTLString(addr) << endl;
}
cout << endl;
/*
DumpObjStr0Vector("Organics - all",p, mem->getAddress("mat_organics_all"));
DumpObjStr0Vector("Organics - plants",p, mem->getAddress("mat_organics_plants"));
@ -89,7 +132,7 @@ int main (int numargs, const char ** args)
DumpObjStr0Vector("Creature variations",p, mem->getAddress("mat_creature_variations"));
DumpObjStr0Vector("Creature types",p, mem->getAddress("mat_creature_types"));
*/
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;

@ -3012,6 +3012,11 @@ map_data_1b60_offset 0x1B9c
<Address name="creature_type_vector">0x016AFE58</Address>
<!--<Address name="mat_creature_types2">0x16AEE08</Address>-->
<!-- possible constructions -->
<Address name="construction_vector">0x165b290</Address>
<Offset name="sizeof_construction">0x14</Offset>
<!--
addresses from belal: vectors might need 8 subtracted from them
buildings 0x0166f9a8

@ -42,8 +42,8 @@ ENDIF(UNIX)
# a magma creation tool
# Author: Aleric
#ADD_EXECUTABLE(dfmagma_create magma_create.cpp)
#TARGET_LINK_LIBRARIES(dfmagma_create dfhack)
ADD_EXECUTABLE(dfmagma_create magma_create.cpp)
TARGET_LINK_LIBRARIES(dfmagma_create dfhack)
IF(UNIX)
install(TARGETS

@ -8,6 +8,8 @@ using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <modules/Maps.h>
#include <modules/Position.h>
int main (void)
{
@ -15,9 +17,13 @@ int main (void)
DFHack::designations40d designations;
DFHack::API DF("Memory.xml");
DFHack::Maps * Maps;
DFHack::Position * Position;
try
{
DF.Attach();
Maps = DF.getMaps();
Position = DF.getPosition();
}
catch (exception& e)
{
@ -28,39 +34,35 @@ int main (void)
return 1;
}
DF.InitMap();
Maps->Start();
if (DF.InitViewAndCursor())
if(Position->getCursorCoords(x,y,z))
{
if(DF.getCursorCoords(x,y,z))
cout << "cursor coords: " << x << "/" << y << "/" << z << endl;
if(Maps->isValidBlock(x/16,y/16,z))
{
cout << "cursor coords: " << x << "/" << y << "/" << z << endl;
if(DF.isValidBlock(x/16,y/16,z))
{
// place the magma
DF.ReadDesignations((x/16),(y/16),z, &designations);
designations[x%16][y%16].bits.flow_size = 7;
designations[x%16][y%16].bits.liquid_type = DFHack::liquid_magma;
DF.WriteDesignations(x/16,y/16,z, &designations);
// make the magma flow :)
DFHack::t_blockflags bflags;
DF.ReadBlockFlags((x/16),(y/16),z,bflags);
// 0x00000001 = job-designated
// 0x0000000C = run flows? - both bit 3 and 4 required for making magma placed on a glacier flow
bflags.bits.liquid_1 = true;
bflags.bits.liquid_2 = true;
DF.WriteBlockFlags((x/16),(y/16),z,bflags);
cout << "Success" << endl;
}
else
cout << "Failure 1" << endl;
// place the magma
Maps->ReadDesignations((x/16),(y/16),z, &designations);
designations[x%16][y%16].bits.flow_size = 7;
designations[x%16][y%16].bits.liquid_type = DFHack::liquid_magma;
Maps->WriteDesignations(x/16,y/16,z, &designations);
// make the magma flow :)
DFHack::t_blockflags bflags;
Maps->ReadBlockFlags((x/16),(y/16),z,bflags);
// 0x00000001 = job-designated
// 0x0000000C = run flows? - both bit 3 and 4 required for making magma placed on a glacier flow
bflags.bits.liquid_1 = true;
bflags.bits.liquid_2 = true;
Maps->WriteBlockFlags((x/16),(y/16),z,bflags);
Maps->Finish();
cout << "Success" << endl;
}
else
cout << "Failure 2" << endl;
cout << "Failure 1" << endl;
}
else
cout << "Process Failed" << endl;
cout << "Failure 2" << endl;
DF.Detach();
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;