2014-12-02 04:06:01 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "MiscUtils.h"
|
|
|
|
|
|
|
|
#include "df/world.h"
|
|
|
|
#include "df/world_data.h"
|
|
|
|
#include "df/creature_raw.h"
|
|
|
|
#include "df/plant_raw.h"
|
|
|
|
|
2014-12-04 02:47:17 -07:00
|
|
|
#include <string>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <functional>
|
2014-12-02 04:06:01 -07:00
|
|
|
|
2014-12-04 02:47:17 -07:00
|
|
|
// os
|
|
|
|
#include <sys/stat.h>
|
2014-12-02 04:06:01 -07:00
|
|
|
|
|
|
|
// Utility Functions {{{
|
|
|
|
// A set of convenience functions for doing common lookups
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve creature raw from index
|
|
|
|
*/
|
2018-04-06 13:17:34 -06:00
|
|
|
static inline df::creature_raw* find_creature ( int32_t idx )
|
2014-12-02 04:06:01 -07:00
|
|
|
{
|
|
|
|
return df::global::world->raws.creatures.all[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve creature index from id string
|
|
|
|
* @return -1 if not found
|
|
|
|
*/
|
2018-04-06 13:17:34 -06:00
|
|
|
static inline int16_t find_creature ( const std::string &creature_id )
|
2014-12-02 04:06:01 -07:00
|
|
|
{
|
|
|
|
return linear_index ( df::global::world->raws.creatures.all, &df::creature_raw::creature_id, creature_id );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve plant raw from index
|
|
|
|
*/
|
2018-04-06 13:17:34 -06:00
|
|
|
static inline df::plant_raw* find_plant ( size_t idx )
|
2014-12-02 04:06:01 -07:00
|
|
|
{
|
|
|
|
return df::global::world->raws.plants.all[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve plant index from id string
|
|
|
|
* @return -1 if not found
|
|
|
|
*/
|
2018-04-06 13:17:34 -06:00
|
|
|
static inline size_t find_plant ( const std::string &plant_id )
|
2014-12-02 04:06:01 -07:00
|
|
|
{
|
|
|
|
return linear_index ( df::global::world->raws.plants.all, &df::plant_raw::id, plant_id );
|
|
|
|
}
|
|
|
|
|
2014-12-04 02:47:17 -07:00
|
|
|
struct less_than_no_case: public std::binary_function< char,char,bool >
|
|
|
|
{
|
|
|
|
bool operator () (char x, char y) const
|
|
|
|
{
|
|
|
|
return toupper( static_cast< unsigned char >(x)) < toupper( static_cast< unsigned char >(y));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-04-06 13:17:34 -06:00
|
|
|
static inline bool CompareNoCase(const std::string &a, const std::string &b)
|
2014-12-04 02:47:17 -07:00
|
|
|
{
|
|
|
|
return std::lexicographical_compare( a.begin(),a.end(), b.begin(),b.end(), less_than_no_case() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the parameter has the dfstock extension.
|
|
|
|
* Doesn't check if the file exists or not.
|
|
|
|
*/
|
2018-04-06 13:17:34 -06:00
|
|
|
static inline bool is_dfstockfile ( const std::string& filename )
|
2014-12-04 02:47:17 -07:00
|
|
|
{
|
|
|
|
return filename.rfind ( ".dfstock" ) != std::string::npos;
|
|
|
|
}
|
|
|
|
|
2014-12-02 04:06:01 -07:00
|
|
|
// }}} utility Functions
|