Creature.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "main.h"
  4. #include "Creature.h"
  5. #include "Game.h"
  6. #include "Character.h"
  7. creature CreateCreature(game g){
  8. creature G = NULL;
  9. G = malloc(sizeof(Creature));
  10. if(G) {
  11. G->Character = CreateCharacter(g);
  12. G->Next = NULL;
  13. return G;
  14. } else {
  15. fprintf( L, "Fatal error: failed to assign memory in CreateNode().\n" );
  16. exit(EXIT_FAILURE);
  17. }
  18. }
  19. void InsertCreatureNode( creature prev_obj, creature next_obj ){
  20. if( !next_obj ) {
  21. return;
  22. }
  23. if( !prev_obj ) {
  24. printf( "Prev object not found.\n" );
  25. CopyCreatureNode( prev_obj, next_obj );
  26. } else {
  27. next_obj->Next = prev_obj->Next;
  28. prev_obj->Next = next_obj;
  29. }
  30. }
  31. void CutCreatureNode( creature parent, creature child ){
  32. parent->Next = child->Next;
  33. child->Next = NULL;
  34. }
  35. void CopyCreatureNode( creature sink, creature source ){
  36. CopyCharacter( sink->Character, source->Character );
  37. sink->Next = source->Next;
  38. }
  39. void PurgeCreatureNode( creature N ){
  40. if(N) {
  41. PurgeCharacter(N->Character);
  42. DESTROY(N->Character);
  43. N->Next = NULL;
  44. }
  45. }