view src/liblocfile.h @ 2833:d0e186348cb2 default tip

Add mention of soft level limitation to 'Eightleg woods'.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 26 May 2024 20:33:53 +0300
parents 99c6d0cea264
children
line wrap: on
line source

/*
 * liblocfile - Location file format handling
 * Programmed by Matti 'ccr' Hämäläinen <ccr@tnsp.org>
 * (C) Copyright 2006-2022 Tecnic Software productions (TNSP)
 */
#ifndef LIBLOCFILE_H
#define LIBLOCFILE_H

#include "libutil.h"
#include <time.h>
#include <stdio.h>


/* Version string
 */
#define LOC_MAGIC              "MapUtils LOC file"
#define LOC_VERSION_MAJOR      (4)
#define LOC_VERSION_MINOR      (1)


/* LOCD_* is an enum describing the preferred orientation of the
 * location marker _label_ in relation to the marker spot.
 */
enum {
    LOCD_NONE = 0,
    LOCD_LEFT,
    LOCD_LEFTDOWN,
    LOCD_DOWN
};


/* Timestamp used in loc-files, in sscanf() format.
 */
#define LOC_TIMEFMT            "%02d.%02d.%04d"


/* These flags are used to describe the marker/location  type and label
 * related information: [LOCF_M_*] Draw marker of specified type (by default,
 * no marker is drawn). LOCF_M_CITY and LOCF_M_PCITY are special, they also
 * work as aliases to LOCF_T_CITY/PCITY and thus have similar functionality.
 *
 * [LOCF_T_*] specify the type of the location/marker. Currently the effect
 * of this settings is addition of "GUILD", "SHRINE"-type strings to labels,
 * but this information can be used in other ways too.
 */
#define LOCF_NONE              (0x00000)

// Marker types
#define LOCF_M_SCENIC1         (0x000001)   // '?' Scenic marker
#define LOCF_M_SCENIC2         (0x000002)   // '%' Shrine marker/etc
#define LOCF_M_PCITY           (0x000004)   // 'C' Player city
#define LOCF_M_CITY            (0x000008)   // 'c' Major city
#define LOCF_M_MASK            (0x00000F)

// Location types
#define LOCF_T_SHRINE          (0x000010)   // 'S' Raceshrine
#define LOCF_T_GUILD           (0x000020)   // 'G' Guild
#define LOCF_T_SS              (0x000040)   // 'P' Player guild/Secret Society
#define LOCF_T_MONSTER         (0x000080)   // 'M' Special monster
#define LOCF_T_TRAINER         (0x000100)   // 'T' Guild-related trainer
#define LOCF_T_FORT            (0x000200)   // 'F' Regional fort
#define LOCF_T_MASK            (0x00FFF0)
#define LOCF_MASK              (LOCF_M_MASK | LOCF_T_MASK)

// Extra flags
#define LOCF_INVIS             (0x010000)   // '-' Invisible marker / Don't show label
#define LOCF_CLOSED            (0x020000)   // '!' Location is CLOSED
#define LOCF_INSTANCED         (0x040000)   // 'I' Location is "instanced" for each player
#define LOCF_INVALID           (0x400000)   // Possibly invalid location
#define LOCF_NOMARKER          (0x800000)   // Location has no marker in mapdata or explicitly defined
#define LOCF_Q_MASK            (0xFF0000)


/* Misc constants
 */
#define LOC_MAX_NAMES          (64)        // Probably more than enough?
#define LOC_MARKERS            "?%C"
#define LOC_MAX_FILES          (64)


/* Author roles
 */
#define AUTHOR_ORIG            (0x00001)   // '@' Original area author
#define AUTHOR_RECODER         (0x00002)   // '!' Converter or recoder of area
#define AUTHOR_MAINTAINER      (0x00004)   // '%' Maintainer
#define AUTHOR_EXPANDER        (0x00008)   // '&' Expander, adding new things


/* Area name flags
 */
#define NAME_ORIG              (0x00001)   // '@' Original area name


/* Timestamp accuracy
 */
#define TS_ACC_DEFAULT         0
#define TS_ACC_KNOWN           '!'
#define TS_ACC_GUESSTIMATE     '?'
#define TS_ACC_APPROXIMATE     '#'


/* Structures
 */
typedef struct
{
    int day, month, year, accuracy;
} LocDateStruct;


typedef struct
{
    char *filename;
    char *continent;
    int xoffs, yoffs;
} LocFileInfo;


typedef struct
{
    char *name;
    int flags;
} LocName;


typedef struct
{
    LocFileInfo *file;   // Reference to file/continent data

    int xc, yc, ox, oy;  // Location coordinates
    int align;           // Label alignment value
    int flags;           // Flags (see LOCF_*)

    LocDateStruct added; // Date / time information
    bool valid;

    int nnames, nauthors;
    LocName names[LOC_MAX_NAMES], authors[LOC_MAX_NAMES];

    char *uri, *freeform;

    union
    {
        int v_int;
        float v_float;
    } vsort;
} LocMarker;


typedef struct
{
    int    nlocations;
    LocMarker **locations;
} MapLocations;


/* Location file parsing and data handling
 */
const char * locGetAreaNameType(const int flags, const bool type);
const char * locGetAreaAuthorRole(const int flags, const bool type);
const char * locGetTypePrefix(const int flags);
const char * locGetTypeName(const int flags);


LocMarker *locCopyLocMarker(const LocMarker *);
void   locCopyLocations(MapLocations *dst, const MapLocations *src);

bool   locAddNew(MapLocations *l, int xc, int yc, int dir, int flags,
           LocName *names, LocName *authors, LocDateStruct *added, bool valid,
           const char *uri, const char *freeform, LocFileInfo *file);

bool   locParseLocStream(FILE *fp, LocFileInfo *file, MapLocations *l, const int offX, const int offY);
void   locFreeMarkerData(LocMarker *marker);
void   locFreeMapLocations(MapLocations *loc);

int    locFindByCoords(const MapLocations *l, const int x, const int y, const bool locTrue);

void   locSetFileInfo(LocFileInfo *file, const char *filename, const char *continent);
void   locFreeFileInfo(LocFileInfo *file);


#endif