//
// Copyright (c) 2009 Froduald Kabanza and the Université de Sherbrooke.
// Use of this software is permitted for non-commercial research purposes, and
// it may be copied or applied only for that use. All copies must include this
// copyright message.
// 
// This is a research prototype that has not gone through intensive tests and
// is delivered as is. It may still contain bugs. Froduald Kabanza and the
// Université de Sherbrooke disclaim any responsibility for damage that may be
// caused by using it.
//
// Please note that some files were inspired in part by the PDDL4J library:
// http://www.math-info.univ-paris5.fr/~pellier/software/software.php 
//
// Implementation: Simon Chamberland
// Project Manager: Froduald Kabanza
//

#ifndef _OBJECT_ASSIGN_H
#define _OBJECT_ASSIGN_H

#include "AssignEffect.h"

#include "../../Formula/Described/ObjectFluentApplication.h"
#include "../../IInitEl.h"

namespace planning
{
  /// <summary>
  /// This class represents an object fluent assignment.
  /// </summary>
  class ObjectAssign : public AssignEffect<ObjectFluentApplication, ITerm>, public IInitEl
  {
  public:
    ObjectAssign(const ObjectFluentApplication* head, const ITerm* body)
      : AssignEffect<ObjectFluentApplication, ITerm>(s_image, head, body)
    {
      INITIALIZE_HASH_CODE();
    }

    virtual void update(const IClosedWorld* evaluationWorld, 
                        IDurativeClosedWorld* updateWorld, 
                        const Bindings* bindings, 
                        const ActionContext* actionContext) const
    {
      updateWorld->setObjectFluent(m_head->evaluateArguments(evaluationWorld, bindings),
                                   m_body->evaluate(evaluationWorld, bindings));
    }
  protected:
    virtual size_t _calculateHashCode() const
    {
      return CALCULATE_HASH_CODE(AssignEffect)
           + 89943007;
    }

    virtual const IExp* _internalApply(const Bindings* bindings) const
    {
      return new ObjectAssign(m_head->apply(bindings), m_body->apply(bindings));
    }

  private:
    static const std::string s_image;
  };
}

#endif