Nimbin2git.christianimmanuel.de / Games / Entropie / character.c

Entropie git · main

git clone https://git.christianimmanuel.de/games/Entropie.gitwget https://git.christianimmanuel.de/games/Entropie/archive/Entropie.tar.gz
character.c 3.5 KB · 94 lines raw
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include "character.h"


char* strdup(const char* s);


// Function to create a new character
Character Character_create(const char *name, int energy, int friendliness, int creativity) {
    Character c;
    c.name = strdup(name);
    c.energy = energy;
    c.friendliness = friendliness;
    c.creativity = creativity;
    c.object = (Object*)malloc(sizeof(Object));
    return c;
}


// Function to create characters with constant values and return the array
Character* Character_creates(Object* object_first, int* size) {
    *size = 4;  // Set the number of characters
    Character* characters = malloc(sizeof(Character) * (*size));  // Allocate memory for the characters
    for (int i = 0; i < *size; i++) {
        characters[i].object = Object_create_pos(0,0,20,30);
        Object_add(object_first, characters[i].object);
        characters[i].object->parent_type = Object_Character;
        characters[i].object->parent = (void*)&characters[i];
    }

    // Initialize each character with constant values
    characters[0].name = "Bob";
    characters[0].color = (Color){0, 0, 255, 255};
    characters[0].energy = 50;
    characters[0].friendliness = 80;
    characters[0].creativity = 70;
    characters[0].role = "Organizer";
    characters[0].preferences = "Music, Dance";

    characters[1].name = "Alice";
    characters[1].color = (Color){255, 0, 255, 255};
    characters[1].energy = 40;
    characters[1].friendliness = 60;
    characters[1].creativity = 90;
    characters[1].role = "Performer";
    characters[1].preferences = "Singing, Acting";

    characters[2].name = "Charlie";
    characters[2].color = (Color){255, 0, 255, 255};
    characters[2].energy = 70;
    characters[2].friendliness = 85;
    characters[2].creativity = 60;
    characters[2].role = "Technician";
    characters[2].preferences = "Sound, Lighting";

    characters[3].name = "Diana";
    characters[3].color = (Color){255, 0, 255, 255};
    characters[3].energy = 55;
    characters[3].friendliness = 75;
    characters[3].creativity = 80;
    characters[3].role = "Volunteer";
    characters[3].preferences = "Logistics, Helping";

    return characters;
}


// Function to print character details
void Character_log(const Character* character) {
    printf("╔════════════════════════════════════════════╗\n");
    printf("║ %3.0f/%3.0f         Character Info             ║\n", character->object->x, character->object->y);
    printf("╠════════════════════════════════════════════╣\n");
    printf("║ Name       : %-29s ║\n", character->name);
    printf("║ Role       : %-29s ║\n", character->role);
    printf("║ Preferences: %-29s ║\n", character->preferences);
    printf("╠════════════════════════════════════════════╣\n");
    printf("║ Energy     : %-29d ║\n", character->energy);
    printf("║ Friendliness: %-28d ║\n", character->friendliness);
    printf("║ Creativity : %-29d ║\n", character->creativity);
    printf("╚════════════════════════════════════════════╝\n");
}


// Free allocated memory for a character
void Character_free(Character* characters, int size) {
    if (characters) {
        free(characters);
    }
}